Skip to content
This repository was archived by the owner on Mar 30, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ obj/
*.suo
*.pubxml
packages/*/
MalApi/package/
MalApi/package/
.vs/
24 changes: 23 additions & 1 deletion MalApi.Example/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;


namespace MalApi.Example
{
class Program
Expand All @@ -24,7 +26,27 @@ static void Main(string[] args)
api.UserAgent = "MalApiExample";
api.TimeoutInMs = 15000;

MalUserLookupResults userLookup = api.GetAnimeListForUser("LordHighCaptain");
var animeUpdateInfo = new UpdateAnime()
{
Episode = 26,
Status = AnimeCompletionStatus.Completed,
Score = 9,
DateStart = new DateTime(1999, 01, 02)
};
string userUpdateAnime = api.UpdateAnimeForUser(1, animeUpdateInfo, "user", "password");

var mangaUpdateInfo = new UpdateManga()
{
Chapter = 20,
Volume = 3,
Score = 8,
Status = MangaCompletionStatus.Completed
};
string userUpdateManga = api.UpdateMangaForUser(952, mangaUpdateInfo, "user", "password");



MalUserLookupResults userLookup = api.GetAnimeListForUser("user");
foreach (MyAnimeListEntry listEntry in userLookup.AnimeList)
{
Console.WriteLine("Rating for {0}: {1}", listEntry.AnimeInfo.Title, listEntry.Score);
Expand Down
65 changes: 65 additions & 0 deletions MalApi.IntegrationTests/GetMangaListForUserTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MalApi;
using System.Threading.Tasks;
using Xunit;
using System.Threading;

namespace MalApi.IntegrationTests
{
// Environment variables in the Initialize method have to be set up properly
// In order for the test to succeed they need to be executed at the same (so the Environment variable can be set and used).
public class GetMangaListForUserTest
{
[Fact]
public static void Initialize()
{
System.Environment.SetEnvironmentVariable("IntegrationTestMalUsername", "username");
}

[Fact]
public void GetMangaListForUser()
{
string username = System.Environment.GetEnvironmentVariable("IntegrationTestMalUsername");
using (MyAnimeListApi api = new MyAnimeListApi())
{
MalUserLookupResults userLookup = api.GetMangaListForUser(username);

Assert.NotEmpty(userLookup.MangaList);
}
}

[Fact]
public void GetMangaListForUserCanceled()
{
string username = System.Environment.GetEnvironmentVariable("IntegrationTestMalUsername");
using (MyAnimeListApi api = new MyAnimeListApi())
{
CancellationTokenSource tokenSource = new CancellationTokenSource();
Task<MalUserLookupResults> userLookupTask = api.GetMangaListForUserAsync(username, tokenSource.Token);
tokenSource.Cancel();
Assert.Throws<TaskCanceledException>(() => userLookupTask.GetAwaiter().GetResult());
}
}

[Fact]
public void GetMangaListForNonexistentUserThrowsCorrectException()
{
using (MyAnimeListApi api = new MyAnimeListApi())
{
Assert.Throws<MalUserNotFoundException>(() => api.GetMangaListForUser("oijsfjisfdjfsdojpfsdp"));
}
}

[Fact]
public void GetMangaListForNonexistentUserThrowsCorrectExceptionAsync()
{
using (MyAnimeListApi api = new MyAnimeListApi())
{
Assert.ThrowsAsync<MalUserNotFoundException>(() => api.GetMangaListForUserAsync("oijsfjisfdjfsdojpfsdp"));
}
}
}
}
73 changes: 73 additions & 0 deletions MalApi.IntegrationTests/UpdateUserAnimeTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xunit;

namespace MalApi.IntegrationTests
{
// Environment variables in the Initialize method have to be set up properly
// In order for the test to succeed they need to be executed at the same (so the Environment variable can be set and used).
public class UpdateUserAnimeTest
{
[Fact]
public void Initialize()
{
System.Environment.SetEnvironmentVariable("IntegrationTestMalUsername", "user");
System.Environment.SetEnvironmentVariable("IntegrationTestMalPassword", "password");

System.Environment.SetEnvironmentVariable("IntegrationTestAnimeId", "1");

System.Environment.SetEnvironmentVariable("IntegrationTestEpisodeNumber", "26");
System.Environment.SetEnvironmentVariable("IntegrationTestScore", "9");
System.Environment.SetEnvironmentVariable("IntegrationTestStatus", "2");
}

[Fact]
public void UpdateAnimeForUserTest()
{
string username = System.Environment.GetEnvironmentVariable("IntegrationTestMalUsername");
string password = System.Environment.GetEnvironmentVariable("IntegrationTestMalPassword");

int animeId = int.Parse(System.Environment.GetEnvironmentVariable("IntegrationTestAnimeId"));
UpdateAnime updateInfo = new UpdateAnime()
{
Episode = int.Parse(System.Environment.GetEnvironmentVariable("IntegrationTestEpisodeNumber")),
Score = int.Parse(System.Environment.GetEnvironmentVariable("IntegrationTestScore")),
Status = (AnimeCompletionStatus) int.Parse(System.Environment.GetEnvironmentVariable("IntegrationTestStatus"))
};

using (MyAnimeListApi api = new MyAnimeListApi())
{
string result = api.UpdateAnimeForUser(animeId, updateInfo, username, password);

Assert.Equal("Updated", result);
}
}

[Fact]
public void GetAnimeListForUserCanceled()
{
string username = System.Environment.GetEnvironmentVariable("IntegrationTestMalUsername");
string password = System.Environment.GetEnvironmentVariable("IntegrationTestMalPassword");

int animeId = int.Parse(System.Environment.GetEnvironmentVariable("IntegrationTestAnimeId"));
UpdateAnime updateInfo = new UpdateAnime()
{
Episode = int.Parse(System.Environment.GetEnvironmentVariable("IntegrationTestEpisodeNumber")),
Score = int.Parse(System.Environment.GetEnvironmentVariable("IntegrationTestScore")),
Status = (AnimeCompletionStatus)int.Parse(System.Environment.GetEnvironmentVariable("IntegrationTestStatus"))
};

using (MyAnimeListApi api = new MyAnimeListApi())
{
CancellationTokenSource tokenSource = new CancellationTokenSource();
Task<string> userLookupTask = api.UpdateAnimeForUserAsync(animeId, updateInfo, username, password, tokenSource.Token);
tokenSource.Cancel();
Assert.Throws<TaskCanceledException>(() => userLookupTask.GetAwaiter().GetResult());
}
}
}
}
73 changes: 73 additions & 0 deletions MalApi.IntegrationTests/UpdateUserMangaTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xunit;

namespace MalApi.IntegrationTests
{
// Environment variables in the Initialize method have to be set up properly
// In order for the test to succeed they need to be executed at the same (so the Environment variable can be set and used).
public class UpdateUserMangaTest
{
[Fact]
public void AInitialize()
{
System.Environment.SetEnvironmentVariable("IntegrationTestMalUsername", "user");
System.Environment.SetEnvironmentVariable("IntegrationTestMalPassword", "password");

System.Environment.SetEnvironmentVariable("IntegrationTestMangaId", "952");

System.Environment.SetEnvironmentVariable("IntegrationTestChapterNumber", "10");
System.Environment.SetEnvironmentVariable("IntegrationTestScore", "8");
System.Environment.SetEnvironmentVariable("IntegrationTestStatus", "1");
}

[Fact]
public void UpdateMangaForUserTest()
{
string username = System.Environment.GetEnvironmentVariable("IntegrationTestMalUsername");
string password = System.Environment.GetEnvironmentVariable("IntegrationTestMalPassword");

int mangaId = int.Parse(System.Environment.GetEnvironmentVariable("IntegrationTestMangaId"));
UpdateManga updateInfo = new UpdateManga()
{
Chapter = int.Parse(System.Environment.GetEnvironmentVariable("IntegrationTestChapterNumber")),
Score = int.Parse(System.Environment.GetEnvironmentVariable("IntegrationTestScore")),
Status = (MangaCompletionStatus)int.Parse(System.Environment.GetEnvironmentVariable("IntegrationTestStatus"))
};

using (MyAnimeListApi api = new MyAnimeListApi())
{
string result = api.UpdateMangaForUser(mangaId, updateInfo, username, password);

Assert.Equal("Updated", result);
}
}

[Fact]
public void GetMangaListForUserCanceled()
{
string username = System.Environment.GetEnvironmentVariable("IntegrationTestMalUsername");
string password = System.Environment.GetEnvironmentVariable("IntegrationTestMalPassword");

int mangaId = int.Parse(System.Environment.GetEnvironmentVariable("IntegrationTestMangaId"));
UpdateManga updateInfo = new UpdateManga()
{
Chapter = int.Parse(System.Environment.GetEnvironmentVariable("IntegrationTestChapterNumber")),
Score = int.Parse(System.Environment.GetEnvironmentVariable("IntegrationTestScore")),
Status = (MangaCompletionStatus)int.Parse(System.Environment.GetEnvironmentVariable("IntegrationTestStatus"))
};

using (MyAnimeListApi api = new MyAnimeListApi())
{
CancellationTokenSource tokenSource = new CancellationTokenSource();
Task<string> userLookupTask = api.UpdateMangaForUserAsync(mangaId, updateInfo, username, password, tokenSource.Token);
tokenSource.Cancel();
Assert.Throws<TaskCanceledException>(() => userLookupTask.GetAwaiter().GetResult());
}
}
}
}
3 changes: 1 addition & 2 deletions MalApi.NetCoreExample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using MalApi;
using System;
using System;

namespace MalApi.NetCoreExample
{
Expand Down
14 changes: 9 additions & 5 deletions MalApi.UnitTests/MalAppInfoXmlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void ParseWithTextReaderTest()
public void ParseWithXElementTest()
{
XDocument doc = XDocument.Parse(Helpers.GetResourceText("test_clean.xml"));
MalUserLookupResults results = MalAppInfoXml.Parse(doc);
MalUserLookupResults results = MalAppInfoXml.ParseAnimeResults(doc);
DoAsserts(results);
}

Expand All @@ -42,7 +42,9 @@ public void ParseInvalidUserWithTextReaderTest()
public void ParseInvalidUserWithXElementTest()
{
XDocument doc = XDocument.Parse(Helpers.GetResourceText("test_no_such_user.xml"));
Assert.Throws<MalUserNotFoundException>(() => MalAppInfoXml.Parse(doc));
Assert.Throws<MalUserNotFoundException>(() => MalAppInfoXml.ParseAnimeResults(doc));

Assert.Throws<MalUserNotFoundException>(() => MalAppInfoXml.ParseMangaResults(doc));
}

[Fact]
Expand All @@ -58,7 +60,9 @@ public void ParseOldInvalidUserWithTextReaderTest()
public void ParseOldInvalidUserWithXElementTest()
{
XDocument doc = XDocument.Parse(Helpers.GetResourceText("test_no_such_user_old.xml"));
Assert.Throws<MalUserNotFoundException>(() => MalAppInfoXml.Parse(doc));
Assert.Throws<MalUserNotFoundException>(() => MalAppInfoXml.ParseAnimeResults(doc));

Assert.Throws<MalUserNotFoundException>(() => MalAppInfoXml.ParseMangaResults(doc));
}

private void DoAsserts(MalUserLookupResults results)
Expand All @@ -74,7 +78,7 @@ private void DoAsserts(MalUserLookupResults results)

Assert.Equal(7, entry.NumEpisodesWatched);
Assert.Equal(7, entry.Score);
Assert.Equal(CompletionStatus.Watching, entry.Status);
Assert.Equal(AnimeCompletionStatus.Watching, entry.Status);

// Test tags with Equal, not equivalent, because order in tags matters
Assert.Equal(new List<string>() { "duck", "goose" }, entry.Tags);
Expand All @@ -85,7 +89,7 @@ private void DoAsserts(MalUserLookupResults results)
entry.AnimeInfo.Synonyms.Should().BeEquivalentTo(new List<string>() { "The Vanishment of Haruhi Suzumiya", "Suzumiya Haruhi no Syoshitsu", "Haruhi movie", "The Disappearance of Haruhi Suzumiya" });
Assert.Equal((decimal?)null, entry.Score);
Assert.Equal(0, entry.NumEpisodesWatched);
Assert.Equal(CompletionStatus.PlanToWatch, entry.Status);
Assert.Equal(AnimeCompletionStatus.PlanToWatch, entry.Status);
Assert.Equal(new List<string>(), entry.Tags);

entry = results.AnimeList.Where(anime => anime.AnimeInfo.AnimeId == 889).First();
Expand Down
4 changes: 2 additions & 2 deletions MalApi.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.14
VisualStudioVersion = 15.0.26430.15
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MalApi", "MalApi\MalApi.csproj", "{85BC477F-4798-4006-A342-715E7565B3BB}"
EndProject
Expand All @@ -18,7 +18,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{00247D
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MalApi.NetCoreExample", "MalApi.NetCoreExample\MalApi.NetCoreExample.csproj", "{EF72FAC1-AE34-4D7B-9839-4ED50288CFB4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MalApi.NetCoreExample", "MalApi.NetCoreExample\MalApi.NetCoreExample.csproj", "{EF72FAC1-AE34-4D7B-9839-4ED50288CFB4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace MalApi
{
public enum CompletionStatus
// XML enum attributes are needed for proper serialization upon sending an update request
public enum AnimeCompletionStatus
{
[XmlEnum(Name = "watching")]
Watching = 1,
[XmlEnum(Name = "completed")]
Completed = 2,
[XmlEnum(Name = "onhold")]
OnHold = 3,
[XmlEnum(Name = "dropped")]
Dropped = 4,
[XmlEnum(Name = "plantowatch")]
PlanToWatch = 6,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class MalAnimeInfoFromUserLookup : IEquatable<MalAnimeInfoFromUserLookup>
public MalAnimeType Type { get; private set; }

public ICollection<string> Synonyms { get; private set; }
public MalSeriesStatus Status { get; private set; }
public MalAnimeSeriesStatus Status { get; private set; }

/// <summary>
/// Could be 0 for anime that hasn't aired yet or less than the planned number of episodes for a series currently airing.
Expand All @@ -27,7 +27,7 @@ public class MalAnimeInfoFromUserLookup : IEquatable<MalAnimeInfoFromUserLookup>
public UncertainDate EndDate { get; private set; }
public string ImageUrl { get; private set; }

public MalAnimeInfoFromUserLookup(int animeId, string title, MalAnimeType type, ICollection<string> synonyms, MalSeriesStatus status,
public MalAnimeInfoFromUserLookup(int animeId, string title, MalAnimeType type, ICollection<string> synonyms, MalAnimeSeriesStatus status,
int numEpisodes, UncertainDate startDate, UncertainDate endDate, string imageUrl)
{
AnimeId = animeId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace MalApi
{
public enum MalSeriesStatus
public enum MalAnimeSeriesStatus
{
Airing = 1,
FinishedAiring = 2,
Expand Down
File renamed without changes.
Loading