PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/MalApi.Tests/MalAppInfoXmlTests.cs

https://bitbucket.org/LHCGreg/mal-api
C# | 107 lines | 78 code | 12 blank | 17 comment | 4 complexity | b00cf840e77018daba4f92da4491e75d MD5 | raw file
Possible License(s): Apache-2.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using NUnit.Framework;
  6. using System.IO;
  7. using System.Xml.Linq;
  8. namespace MalApi.Tests
  9. {
  10. [TestFixture]
  11. public partial class MalAppInfoXmlTests
  12. {
  13. [Test]
  14. public void ParseWithTextReaderTest()
  15. {
  16. using (StringReader reader = new StringReader(TestXml))
  17. {
  18. MalUserLookupResults results = MalAppInfoXml.Parse(reader);
  19. DoAsserts(results);
  20. }
  21. }
  22. [Test]
  23. public void ParseWithXElementTest()
  24. {
  25. XDocument doc = XDocument.Parse(CleanTestXml);
  26. MalUserLookupResults results = MalAppInfoXml.Parse(doc);
  27. DoAsserts(results);
  28. }
  29. [Test]
  30. public void ParseInvalidUserWithTextReaderTest()
  31. {
  32. using (StringReader reader = new StringReader(InvalidUserXml))
  33. {
  34. Assert.Throws<MalUserNotFoundException>(() => MalAppInfoXml.Parse(reader));
  35. }
  36. }
  37. [Test]
  38. public void ParseInvalidUserWithXElementTest()
  39. {
  40. XDocument doc = XDocument.Parse(InvalidUserXml);
  41. Assert.Throws<MalUserNotFoundException>(() => MalAppInfoXml.Parse(doc));
  42. }
  43. private void DoAsserts(MalUserLookupResults results)
  44. {
  45. Assert.That(results.CanonicalUserName, Is.EqualTo("LordHighCaptain"));
  46. Assert.That(results.UserId, Is.EqualTo(158667));
  47. Assert.That(results.AnimeList.Count, Is.EqualTo(163));
  48. MyAnimeListEntry entry = results.AnimeList.Where(anime => anime.AnimeInfo.AnimeId == 853).First();
  49. Assert.That(entry.AnimeInfo.Title, Is.EqualTo("Ouran Koukou Host Club"));
  50. Assert.That(entry.AnimeInfo.Type, Is.EqualTo(MalAnimeType.Tv));
  51. Assert.That(entry.AnimeInfo.Synonyms, Is.EquivalentTo(new List<string>() { "Ohran Koko Host Club", "Ouran Koukou Hosutobu", "Ouran High School Host Club" }));
  52. Assert.That(entry.NumEpisodesWatched, Is.EqualTo(7));
  53. Assert.That(entry.Score, Is.EqualTo(7));
  54. Assert.That(entry.Status, Is.EqualTo(CompletionStatus.Watching));
  55. Assert.That(entry.Tags, Is.EqualTo(new List<string>() { "duck", "goose" }));
  56. entry = results.AnimeList.Where(anime => anime.AnimeInfo.AnimeId == 7311).First();
  57. Assert.That(entry.AnimeInfo.Title, Is.EqualTo("Suzumiya Haruhi no Shoushitsu"));
  58. Assert.That(entry.AnimeInfo.Type, Is.EqualTo(MalAnimeType.Movie));
  59. Assert.That(entry.AnimeInfo.Synonyms, Is.EquivalentTo(new List<string>() { "The Vanishment of Haruhi Suzumiya", "Suzumiya Haruhi no Syoshitsu", "Haruhi movie", "The Disappearance of Haruhi Suzumiya" }));
  60. Assert.That(entry.Score, Is.EqualTo((decimal?)null));
  61. Assert.That(entry.NumEpisodesWatched, Is.EqualTo(0));
  62. Assert.That(entry.Status, Is.EqualTo(CompletionStatus.PlanToWatch));
  63. Assert.That(entry.Tags, Is.EqualTo(new List<string>()));
  64. entry = results.AnimeList.Where(anime => anime.AnimeInfo.AnimeId == 889).First();
  65. Assert.That(entry.AnimeInfo.Title, Is.EqualTo("Black Lagoon"));
  66. // Make sure synonyms that are the same as the real name get filtered out
  67. Assert.That(entry.AnimeInfo.Synonyms, Is.EquivalentTo(new List<string>()));
  68. entry = results.AnimeList.Where(anime => anime.AnimeInfo.Title == "Test").First();
  69. // Make sure that <series_synonyms/> is the same as <series_synonyms></series_synonyms>
  70. Assert.That(entry.AnimeInfo.Synonyms, Is.EquivalentTo(new List<string>()));
  71. Assert.That(entry.AnimeInfo.StartDate, Is.EqualTo(new UncertainDate(2010, 2, 6)));
  72. Assert.That(entry.AnimeInfo.EndDate, Is.EqualTo(UncertainDate.Unknown));
  73. Assert.That(entry.AnimeInfo.ImageUrl, Is.EqualTo("http://cdn.myanimelist.net/images/anime/9/24646.jpg"));
  74. Assert.That(entry.MyStartDate, Is.EqualTo(new UncertainDate(year: null, month: 2, day: null)));
  75. Assert.That(entry.MyFinishDate, Is.EqualTo(UncertainDate.Unknown));
  76. Assert.That(entry.MyLastUpdate, Is.EqualTo(new DateTime(year: 2011, month: 4, day: 2, hour: 22, minute: 50, second: 58, kind: DateTimeKind.Utc)));
  77. Assert.That(entry.Tags, Is.EqualTo(new List<string>() { "test&test", "< less than", "> greater than", "apos '", "quote \"", "hex รถ", "dec !", "control character" }));
  78. }
  79. }
  80. }
  81. /*
  82. Copyright 2012 Greg Najda
  83. Licensed under the Apache License, Version 2.0 (the "License");
  84. you may not use this file except in compliance with the License.
  85. You may obtain a copy of the License at
  86. http://www.apache.org/licenses/LICENSE-2.0
  87. Unless required by applicable law or agreed to in writing, software
  88. distributed under the License is distributed on an "AS IS" BASIS,
  89. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  90. See the License for the specific language governing permissions and
  91. limitations under the License.
  92. */