Skip to content

Commit

Permalink
Merge pull request #13 from a-legotin/develop
Browse files Browse the repository at this point in the history
Version 1.2.3
  • Loading branch information
a-legotin authored Apr 9, 2017
2 parents 675997b + b4055e5 commit d55ebce
Show file tree
Hide file tree
Showing 30 changed files with 759 additions and 76 deletions.
12 changes: 6 additions & 6 deletions InstaSharper.Examples/InstaSharperExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private static void Main(string[] args)
.Build();
// login
var logInResult = _instaApi.Login();
if (!logInResult.Succeeded) { Console.WriteLine($"Unable to login: {logInResult.Message}"); }
if (!logInResult.Succeeded) { Console.WriteLine($"Unable to login: {logInResult.Info.Message}"); }
else
{
// get currently logged in user
Expand All @@ -42,18 +42,18 @@ private static void Main(string[] args)
}

//get user feed, first 5 pages
var userFeed = _instaApi.GetUserFeed(5);
var userFeed = _instaApi.GetExploreFeed(5);
if (userFeed.Succeeded)
{
Console.WriteLine($"Feed items (in {userFeed.Value.Pages} pages) [{currentUser.UserName}]: {userFeed.Value.Items.Count}");
foreach (var media in userFeed.Value.Items) Console.WriteLine($"Feed item - code:{media.Code}, likes: {media.LikesCount}");
Console.WriteLine($"Feed items (in {userFeed.Value.Pages} pages) [{currentUser.UserName}]: {userFeed.Value.Medias.Count}");
foreach (var media in userFeed.Value.Medias) Console.WriteLine($"Feed item - code:{media.Code}, likes: {media.LikesCount}");
}
// get tag feed, first 5 pages
var tagFeed = _instaApi.GetTagFeed("gm", 5);
if (userFeed.Succeeded)
{
Console.WriteLine($"Tag feed items (in {tagFeed.Value.Pages} pages) [{currentUser.UserName}]: {tagFeed.Value.Count}");
foreach (var media in tagFeed.Value) Console.WriteLine($"Tag feed item - code: {media.Code}, likes: {media.LikesCount}");
Console.WriteLine($"Tag feed items (in {tagFeed.Value.Pages} pages) [{currentUser.UserName}]: {tagFeed.Value.Medias.Count}");
foreach (var media in tagFeed.Value.Medias) Console.WriteLine($"Tag feed item - code: {media.Code}, likes: {media.LikesCount}");
}
var logoutResult = _instaApi.Logout();
if (logoutResult.Value) Console.WriteLine("Logout succeed");
Expand Down
4 changes: 2 additions & 2 deletions InstaSharper.Tests/Endpoints/AuthTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ namespace InstaSharper.Tests.Endpoints
[Collection("Endpoints")]
public class AuthTest
{
private readonly ITestOutputHelper _output;

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

private readonly ITestOutputHelper _output;

[RunnableInDebugOnlyFact]
public async void UserLoginFailTest()
{
Expand Down
16 changes: 14 additions & 2 deletions InstaSharper.Tests/Endpoints/FeedTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using InstaSharper.Classes;
using InstaSharper.Tests.Utils;
using Xunit;
Expand All @@ -20,7 +21,6 @@ public FeedTest(ITestOutputHelper output)

[RunnableInDebugOnlyTheory]
[InlineData("christmas")]
[InlineData("rock")]
public async void GetTagFeedTest(string tag)
{
//arrange
Expand All @@ -41,11 +41,15 @@ public async void GetTagFeedTest(string tag)
return;
}
Assert.True(loginSucceed.Succeeded);
var result = await apiInstance.GetTagFeedAsync(tag);
var result = await 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);
//assert
Assert.True(result.Succeeded);
Assert.NotNull(tagFeed);
Assert.False(anyMediaDuplicate);
Assert.False(anyStoryDuplicate);
}


Expand Down Expand Up @@ -73,9 +77,11 @@ public async void GetUserTagFeedTest(string username)
Assert.True(loginSucceed.Succeeded);
var result = await apiInstance.GetUserTagsAsync(username, 5);
var tagFeed = result.Value;
var anyMediaDuplicate = tagFeed.GroupBy(x => x.Code).Any(g => g.Count() > 1);
//assert
Assert.True(result.Succeeded);
Assert.NotNull(tagFeed);
Assert.False(anyMediaDuplicate);
}

[RunnableInDebugOnlyFact]
Expand All @@ -102,6 +108,7 @@ public async void GetFollowingRecentActivityFeedTest()
Assert.True(loginSucceed.Succeeded);
var getFeedResult = await apiInstance.GetFollowingRecentActivityAsync(5);
var folloowingRecentFeed = getFeedResult.Value;

//assert
Assert.True(getFeedResult.Succeeded);
Assert.NotNull(folloowingRecentFeed);
Expand Down Expand Up @@ -160,9 +167,14 @@ public async void GetUserFeedTest()
Assert.True(loginSucceed.Succeeded);
var getFeedResult = await 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);

//assert
Assert.True(getFeedResult.Succeeded);
Assert.NotNull(feed);
Assert.False(anyDuplicate);
Assert.False(anyStoryDuplicate);
}
}
}
25 changes: 24 additions & 1 deletion InstaSharper.Tests/Endpoints/FollowersTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using InstaSharper.Classes;
using InstaSharper.Tests.Utils;
using Xunit;
Expand All @@ -17,7 +18,7 @@ public FollowersTest(ITestOutputHelper output)
}

[RunnableInDebugOnlyTheory]
[InlineData("discovery")]
[InlineData("therock")]
public async void GetUserFollowersTest(string username)
{
var currentUsername = "alex_codegarage";
Expand All @@ -30,9 +31,12 @@ public async void GetUserFollowersTest(string username)
if (!TestHelpers.Login(apiInstance, _output)) return;
var result = await apiInstance.GetUserFollowersAsync(username, 10);
var followers = result.Value;
var anyDuplicate = followers.GroupBy(x => x.Pk).Any(g => g.Count() > 1);

//assert
Assert.True(result.Succeeded);
Assert.NotNull(followers);
Assert.False(anyDuplicate);
}

[RunnableInDebugOnlyFact]
Expand All @@ -53,5 +57,24 @@ public async void GetCurrentUserFollwersTest()
Assert.True(result.Succeeded);
Assert.NotNull(followers);
}

[RunnableInDebugOnlyTheory]
[InlineData(196754384)]
public async void FollowUserTest(long userId)
{
var currentUsername = "alex_codegarage";
var password = Environment.GetEnvironmentVariable("instaapiuserpassword");
var apiInstance = TestHelpers.GetDefaultInstaApiInstance(new UserSessionData
{
UserName = currentUsername,
Password = password
});
if (!TestHelpers.Login(apiInstance, _output)) return;
var result = await apiInstance.FollowUserAsync(userId);
var followers = result.Value;
//assert
Assert.True(result.Succeeded);
Assert.NotNull(followers);
}
}
}
63 changes: 63 additions & 0 deletions InstaSharper.Tests/Endpoints/LikesTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using InstaSharper.Classes;
using InstaSharper.Tests.Utils;
using Xunit;
using Xunit.Abstractions;

namespace InstaSharper.Tests.Endpoints
{
[Collection("Endpoints")]
public class LikesTest
{
private readonly ITestOutputHelper _output;
private readonly string _password = Environment.GetEnvironmentVariable("instaapiuserpassword");
private readonly string _username = "alex_codegarage";

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

[RunnableInDebugOnlyTheory]
[InlineData("1484832969772514291_196754384")]
public async void LikeTest(string mediaId)
{
//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.LikeMediaAsync(mediaId);
var exploreGeed = result.Value;
//assert
Assert.True(result.Succeeded);
Assert.NotNull(exploreGeed);
}

[RunnableInDebugOnlyTheory]
[InlineData("1484832969772514291_196754384")]
public async void UnLikeTest(string mediaId)
{
//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.UnLikeMediaAsync(mediaId);
var exploreGeed = result.Value;
//assert
Assert.True(result.Succeeded);
Assert.NotNull(exploreGeed);
}
}
}
63 changes: 56 additions & 7 deletions InstaSharper.Tests/Endpoints/MediaTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using InstaSharper.Classes;
using InstaSharper.Tests.Utils;
using Xunit;
Expand All @@ -17,8 +18,8 @@ public MediaTest(ITestOutputHelper output)
}

[RunnableInDebugOnlyTheory]
[InlineData("1379932752706850783")]
public async void GetMediaByCodeTest(string mediaId)
[InlineData("1484832969772514291")]
public async void GetMediaByIdTest(string mediaId)
{
//arrange
var username = "alex_codegarage";
Expand All @@ -32,15 +33,59 @@ public async void GetMediaByCodeTest(string mediaId)
_output.WriteLine($"Trying to login as user: {username}");
if (!TestHelpers.Login(apiInstance, _output)) return;
_output.WriteLine($"Getting media by ID: {mediaId}");
var media = await apiInstance.GetMediaByCodeAsync(mediaId);
var media = await apiInstance.GetMediaByIdAsync(mediaId);
//assert
Assert.NotNull(media);
}

[RunnableInDebugOnlyTheory]
[InlineData("alex_codegarage")]
[InlineData("instagram")]
[InlineData("therock")]
[InlineData("1379932752706850783")]
public async void GetMediaLikersTest(string mediaId)
{
//arrange
var username = "alex_codegarage";
var password = Environment.GetEnvironmentVariable("instaapiuserpassword");
var apiInstance = TestHelpers.GetDefaultInstaApiInstance(new UserSessionData
{
UserName = username,
Password = password
});
//act
_output.WriteLine($"Trying to login as user: {username}");
if (!TestHelpers.Login(apiInstance, _output)) return;
_output.WriteLine($"Getting media [{mediaId}] likers");
var likers = await apiInstance.GetMediaLikersAsync(mediaId);
var anyDuplicate = likers.Value.GroupBy(x => x.Pk).Any(g => g.Count() > 1);
//assert
Assert.NotNull(likers);
Assert.False(anyDuplicate);
}

[RunnableInDebugOnlyTheory]
[InlineData("1379932752706850783")]
public async void GetMediaCommentsTest(string mediaId)
{
//arrange
var username = "alex_codegarage";
var password = Environment.GetEnvironmentVariable("instaapiuserpassword");
var apiInstance = TestHelpers.GetDefaultInstaApiInstance(new UserSessionData
{
UserName = username,
Password = password
});
//act
_output.WriteLine($"Trying to login as user: {username}");
if (!TestHelpers.Login(apiInstance, _output)) return;
_output.WriteLine($"Getting media [{mediaId}] comments");
var comments = await apiInstance.GetMediaCommentsAsync(mediaId, 0);
var anyDuplicate = comments.Value.Comments.GroupBy(x => x.Pk).Any(g => g.Count() > 1);
//assert
Assert.NotNull(comments);
Assert.False(anyDuplicate);
}

[RunnableInDebugOnlyTheory]
[InlineData("mohammadq74")]
public async void GetUserMediaListTest(string userToFetch)
{
//arrange
Expand All @@ -52,16 +97,20 @@ public async void GetUserMediaListTest(string userToFetch)
Password = password
});
var random = new Random(DateTime.Today.Millisecond);
var pages = random.Next(1, 10);
var pages = 5;
//act
_output.WriteLine($"Trying to login as user: {username}");
if (!TestHelpers.Login(apiInstance, _output)) return;
_output.WriteLine($"Getting posts of user: {userToFetch}");

var posts = await apiInstance.GetUserMediaAsync(userToFetch, pages);
var anyDuplicate = posts.Value.GroupBy(x => x.Code).Any(g => g.Count() > 1);

//assert
Assert.NotNull(posts);
Assert.Equal(userToFetch, posts.Value[random.Next(0, posts.Value.Count)].User.UserName);
Assert.Equal(pages, posts.Value.Pages);
Assert.False(anyDuplicate);
}
}
}
19 changes: 19 additions & 0 deletions InstaSharper.Tests/Utils/InstaApiHelperTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using InstaSharper.Helpers;
using Xunit;

namespace InstaSharper.Tests.Utils
{
[Collection("Infrastructure")]
public class InstaApiHelperTest
{
[Fact]
public void GetCodeFromIdTest()
{
var expectedCode = "BQiSd7KFk9r";
var sourceId = 1450803251188748139;

var actualCode = InstaApiHelper.GetCodeFromId(sourceId);
Assert.Equal(expectedCode, actualCode);
}
}
}
2 changes: 1 addition & 1 deletion InstaSharper.Tests/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"testRunner": "xunit",
"dependencies": {
"xunit": "2.2.0-beta2-build3300",
"InstaSharper": "1.2.2",
"InstaSharper": "1.2.3",
"dotnet-test-xunit": "2.2.0-preview2-build1029"
},
"frameworks": {
Expand Down
Loading

0 comments on commit d55ebce

Please sign in to comment.