Skip to content

Commit

Permalink
Merge pull request #39 from a-legotin/develop
Browse files Browse the repository at this point in the history
1.2.5
  • Loading branch information
a-legotin authored Jun 11, 2017
2 parents 0417b8f + c8f2942 commit 6fe6395
Show file tree
Hide file tree
Showing 62 changed files with 1,560 additions and 1,000 deletions.
46 changes: 46 additions & 0 deletions InstaSharper.Tests/Classes/AuthenticatedTestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Threading.Tasks;
using InstaSharper.API;
using InstaSharper.Classes;
using InstaSharper.Tests.Utils;

namespace InstaSharper.Tests.Classes
{
public class AuthenticatedTestFixture : IDisposable
{
private readonly string _password = Environment.GetEnvironmentVariable("instaapiuserpassword");
private readonly string _username = "alex_codegarage";

public AuthenticatedTestFixture()
{
ApiInstance = TestHelpers.GetDefaultInstaApiInstance(new UserSessionData
{
UserName = _username,
Password = _password
});

var loginTask = Task.Run(ApiInstance.LoginAsync);
if (!loginTask.Wait(TimeSpan.FromSeconds(10)))
throw new Exception($"Unable to login, user: {_username}, password: {_password}.");
}

public IInstaApi ApiInstance { get; }

public void Dispose()
{
var logoutTask = Task.Run(ApiInstance.LogoutAsync);
if (!logoutTask.Wait(TimeSpan.FromSeconds(10)))
throw new Exception($"Not able to logout, user: {_username}, password: {_password}.");
}

public string GetUsername()
{
return _username;
}

public string GetPassword()
{
return _password;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Diagnostics;
using Xunit;

namespace InstaSharper.Tests.Utils
namespace InstaSharper.Tests.Classes
{
public sealed class RunnableInDebugOnlyFact : FactAttribute
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Diagnostics;
using Xunit;

namespace InstaSharper.Tests.Utils
namespace InstaSharper.Tests.Classes
{
public sealed class RunnableInDebugOnlyTheory : TheoryAttribute
{
Expand Down
12 changes: 12 additions & 0 deletions InstaSharper.Tests/Classes/SkippableFact.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Xunit;

namespace InstaSharper.Tests.Classes
{
public sealed class SkippableFact : FactAttribute
{
public SkippableFact()
{
Skip = "This fact marked as skippable.";
}
}
}
13 changes: 8 additions & 5 deletions InstaSharper.Tests/Endpoints/AuthTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,45 @@ namespace InstaSharper.Tests.Endpoints
[Collection("Endpoints")]
public class AuthTest
{
private readonly ITestOutputHelper _output;

public AuthTest(ITestOutputHelper output)
{
_output = output;
}

[RunnableInDebugOnlyFact]
private readonly ITestOutputHelper _output;

[Fact]
public async void UserLoginFailTest()
{
var username = "alex_codegarage";
var password = "boombaby!";

var apiInstance =
TestHelpers.GetDefaultInstaApiInstance(new UserSessionData
{
UserName = username,
Password = password
});
_output.WriteLine("Got API instance");

var loginResult = await apiInstance.LoginAsync();
Assert.False(loginResult.Succeeded);
Assert.False(apiInstance.IsUserAuthenticated);
}

[RunnableInDebugOnlyFact]
[Fact]
public async void UserLoginSuccessTest()
{
var username = "alex_codegarage";
var password = Environment.GetEnvironmentVariable("instaapiuserpassword");

var apiInstance = TestHelpers.GetDefaultInstaApiInstance(new UserSessionData
{
UserName = username,
Password = password
});
Assert.False(apiInstance.IsUserAuthenticated);

Assert.False(apiInstance.IsUserAuthenticated);
var loginResult = await apiInstance.LoginAsync();
Assert.True(loginResult.Succeeded);
Assert.True(apiInstance.IsUserAuthenticated);
Expand Down
34 changes: 10 additions & 24 deletions InstaSharper.Tests/Endpoints/DiscoverTest.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
using System;
using InstaSharper.Classes;
using InstaSharper.Tests.Utils;
using InstaSharper.Tests.Classes;
using Xunit;
using Xunit.Abstractions;

namespace InstaSharper.Tests.Endpoints
{
[Collection("Endpoints")]
public class DiscoverTest
[Trait("Category", "Endpoint")]
public class DiscoverTest : IClassFixture<AuthenticatedTestFixture>
{
private readonly ITestOutputHelper _output;
private readonly string _password = Environment.GetEnvironmentVariable("instaapiuserpassword");
private readonly string _username = "alex_codegarage";

public DiscoverTest(ITestOutputHelper output)
public DiscoverTest(AuthenticatedTestFixture authInfo)
{
_output = output;
_authInfo = authInfo;
}

[RunnableInDebugOnlyFact]
private readonly AuthenticatedTestFixture _authInfo;

[Fact]
public async void ExploreTest()
{
//arrange
var apiInstance =
TestHelpers.GetDefaultInstaApiInstance(new UserSessionData
{
UserName = _username,
Password = _password
});
//act
var loginSucceed = TestHelpers.Login(apiInstance, _output);
Assert.True(loginSucceed);
var result = await apiInstance.GetExploreFeedAsync(0);
Assert.True(_authInfo.ApiInstance.IsUserAuthenticated);
var result = await _authInfo.ApiInstance.GetExploreFeedAsync(2);
var exploreGeed = result.Value;
//assert
Assert.True(result.Succeeded);
Expand Down
157 changes: 43 additions & 114 deletions InstaSharper.Tests/Endpoints/FeedTest.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,26 @@
using System;
using System.Linq;
using InstaSharper.Classes;
using InstaSharper.Tests.Utils;
using System.Linq;
using InstaSharper.Tests.Classes;
using Xunit;
using Xunit.Abstractions;

namespace InstaSharper.Tests.Endpoints
{
[Collection("Endpoints")]
public class FeedTest
[Trait("Category", "Endpoint")]
public class FeedTest : IClassFixture<AuthenticatedTestFixture>
{
private readonly ITestOutputHelper _output;
private readonly string _password = Environment.GetEnvironmentVariable("instaapiuserpassword");
private readonly string _username = "alex_codegarage";

public FeedTest(ITestOutputHelper output)
public FeedTest(AuthenticatedTestFixture authInfo)
{
_output = output;
_authInfo = authInfo;
}

[RunnableInDebugOnlyTheory]
private readonly AuthenticatedTestFixture _authInfo;

[Theory]
[InlineData("christmas")]
public async void GetTagFeedTest(string tag)
{
//arrange
var apiInstance =
TestHelpers.GetDefaultInstaApiInstance(new UserSessionData
{
UserName = _username,
Password = _password
});
//act
var loginSucceed = await apiInstance.LoginAsync();
//no need to perform test if account marked as unsafe
if (loginSucceed.Info.ResponseType == ResponseType.LoginRequired
|| loginSucceed.Info.ResponseType == ResponseType.LoginRequired
|| loginSucceed.Info.ResponseType == ResponseType.RequestsLimit)
{
_output.WriteLine("Unable to login: limit reached or checkpoint required");
return;
}
Assert.True(loginSucceed.Succeeded);
var result = await apiInstance.GetTagFeedAsync(tag, 10);
Assert.True(_authInfo.ApiInstance.IsUserAuthenticated);

var result = await _authInfo.ApiInstance.GetTagFeedAsync(tag, 10);
var tagFeed = result.Value;
var anyMediaDuplicate = tagFeed.Medias.GroupBy(x => x.Code).Any(g => g.Count() > 1);
var anyStoryDuplicate = tagFeed.Stories.GroupBy(x => x.Id).Any(g => g.Count() > 1);
Expand All @@ -53,29 +32,13 @@ public async void GetTagFeedTest(string tag)
}


[RunnableInDebugOnlyTheory]
[Theory]
[InlineData("rock")]
public async void GetUserTagFeedTest(string username)
{
//arrange
var apiInstance =
TestHelpers.GetDefaultInstaApiInstance(new UserSessionData
{
UserName = _username,
Password = _password
});
//act
var loginSucceed = await apiInstance.LoginAsync();
//no need to perform test if account marked as unsafe
if (loginSucceed.Info.ResponseType == ResponseType.LoginRequired
|| loginSucceed.Info.ResponseType == ResponseType.LoginRequired
|| loginSucceed.Info.ResponseType == ResponseType.RequestsLimit)
{
_output.WriteLine("Unable to login: limit reached or checkpoint required");
return;
}
Assert.True(loginSucceed.Succeeded);
var result = await apiInstance.GetUserTagsAsync(username, 5);
Assert.True(_authInfo.ApiInstance.IsUserAuthenticated);

var result = await _authInfo.ApiInstance.GetUserTagsAsync(username, 5);
var tagFeed = result.Value;
var anyMediaDuplicate = tagFeed.GroupBy(x => x.Code).Any(g => g.Count() > 1);
//assert
Expand All @@ -84,29 +47,12 @@ public async void GetUserTagFeedTest(string username)
Assert.False(anyMediaDuplicate);
}

[RunnableInDebugOnlyFact]
[Fact]
public async void GetFollowingRecentActivityFeedTest()
{
//arrange
var apiInstance =
TestHelpers.GetDefaultInstaApiInstance(new UserSessionData
{
UserName = _username,
Password = _password
});
//act
//no need to perform test if account marked as unsafe
var loginSucceed = await apiInstance.LoginAsync();
//no need to perform test if account marked as unsafe
if (loginSucceed.Info.ResponseType == ResponseType.LoginRequired
|| loginSucceed.Info.ResponseType == ResponseType.LoginRequired
|| loginSucceed.Info.ResponseType == ResponseType.RequestsLimit)
{
_output.WriteLine("Unable to login: limit reached or checkpoint required");
return;
}
Assert.True(loginSucceed.Succeeded);
var getFeedResult = await apiInstance.GetFollowingRecentActivityAsync(5);
Assert.True(_authInfo.ApiInstance.IsUserAuthenticated);

var getFeedResult = await _authInfo.ApiInstance.GetFollowingRecentActivityAsync(5);
var folloowingRecentFeed = getFeedResult.Value;

//assert
Expand All @@ -115,57 +61,25 @@ public async void GetFollowingRecentActivityFeedTest()
Assert.True(!folloowingRecentFeed.IsOwnActivity);
}

[RunnableInDebugOnlyFact]
[Fact]
public async void GetRecentActivityFeedTest()
{
//arrange
var apiInstance =
TestHelpers.GetDefaultInstaApiInstance(new UserSessionData
{
UserName = _username,
Password = _password
});
//act
var loginSucceed = await apiInstance.LoginAsync();
//no need to perform test if account marked as unsafe
if (loginSucceed.Info.ResponseType == ResponseType.LoginRequired
|| loginSucceed.Info.ResponseType == ResponseType.LoginRequired
|| loginSucceed.Info.ResponseType == ResponseType.RequestsLimit)
{
_output.WriteLine("Unable to login: limit reached or checkpoint required");
return;
}
Assert.True(loginSucceed.Succeeded);
var getFeedResult = await apiInstance.GetRecentActivityAsync(5);
Assert.True(_authInfo.ApiInstance.IsUserAuthenticated);

var getFeedResult = await _authInfo.ApiInstance.GetRecentActivityAsync(5);
var ownRecentFeed = getFeedResult.Value;
//assert
Assert.True(getFeedResult.Succeeded);
Assert.NotNull(ownRecentFeed);
Assert.True(ownRecentFeed.IsOwnActivity);
}

[RunnableInDebugOnlyFact]
[Fact]
public async void GetUserFeedTest()
{
//arrange
var apiInstance =
TestHelpers.GetDefaultInstaApiInstance(new UserSessionData
{
UserName = _username,
Password = _password
});
//act
var loginSucceed = await apiInstance.LoginAsync();
//no need to perform test if account marked as unsafe
if (loginSucceed.Info.ResponseType == ResponseType.LoginRequired
|| loginSucceed.Info.ResponseType == ResponseType.LoginRequired
|| loginSucceed.Info.ResponseType == ResponseType.RequestsLimit)
{
_output.WriteLine("Unable to login: limit reached or checkpoint required");
return;
}
Assert.True(loginSucceed.Succeeded);
var getFeedResult = await apiInstance.GetUserTimelineFeedAsync(5);
Assert.True(_authInfo.ApiInstance.IsUserAuthenticated);

var getFeedResult = await _authInfo.ApiInstance.GetUserTimelineFeedAsync(5);
var feed = getFeedResult.Value;
var anyDuplicate = feed.Medias.GroupBy(x => x.Code).Any(g => g.Count() > 1);
var anyStoryDuplicate = feed.Stories.GroupBy(x => x.Id).Any(g => g.Count() > 1);
Expand All @@ -176,5 +90,20 @@ public async void GetUserFeedTest()
Assert.False(anyDuplicate);
Assert.False(anyStoryDuplicate);
}

[Fact]
public async void GetUserLikeFeedTest()
{
Assert.True(_authInfo.ApiInstance.IsUserAuthenticated);

var getFeedResult = await _authInfo.ApiInstance.GetLikeFeedAsync(2);
var feed = getFeedResult.Value;
var anyDuplicate = feed.GroupBy(x => x.Code).Any(g => g.Count() > 1);

//assert
Assert.True(getFeedResult.Succeeded);
Assert.NotNull(feed);
Assert.False(anyDuplicate);
}
}
}
Loading

0 comments on commit 6fe6395

Please sign in to comment.