Skip to content

Commit

Permalink
Merge pull request #43 from interneth3ro/master
Browse files Browse the repository at this point in the history
Major commit for exception handling
  • Loading branch information
briandek committed Sep 28, 2011
2 parents 7c44240 + 4ed939b commit 688d2de
Show file tree
Hide file tree
Showing 16 changed files with 508 additions and 220 deletions.
37 changes: 22 additions & 15 deletions Explorers.Test/AuctionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,40 @@ namespace WowDotNetAPI.Explorers.Test
[TestClass]
public class AuctionTests
{
private void testRealm(Region region, string realm)
{
WowExplorer explorer = new WowExplorer(region);
public TestContext TestContext { get; set; }
private static WowExplorer explorer;

Auctions auctions = explorer.GetAuctions(realm);
[ClassInitialize()]
public static void ClassInit(TestContext context)
{
explorer = new WowExplorer(Region.US, Locale.en_US);
}

[TestMethod]
public void testUsRealm()
{
Auctions auctions = explorer.GetAuctions("Skullcrusher");
Assert.IsTrue(auctions.Horde.Auctions.Count() > 0);
// Is this check really necessary?
Assert.IsTrue((from n in auctions.Horde.Auctions where n.ItemId == 53010 select n).Count() > 0);
}

[TestMethod]
public void Get_Simple_Auction_Data_From_US_Realm()
public void testEuRealm()
{
this.testRealm(Region.US, "Skullcrusher");
explorer.Region = Region.EU;
Auctions auctions = explorer.GetAuctions("Twisting Nether");
Assert.IsTrue(auctions.Horde.Auctions.Count() > 0);

}

[TestMethod]
public void Get_Simple_Auction_Data_From_EU_Realm()
public void testTwRealm()
{
this.testRealm(Region.EU, "Twisting Nether");
explorer.Region = Region.TW;
Auctions auctions = explorer.GetAuctions("Balnazzar");
Assert.IsTrue(auctions.Horde.Auctions.Count() > 0);

}

// BROKEN
//[TestMethod]
//public void testTwRealm()
//{
// this.testRealm(Region.TW, "Balnazzar");
//}
}
}
9 changes: 9 additions & 0 deletions Explorers.Test/AuthTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ namespace WowDotNetAPI.Explorers.Test
[TestClass]
public class AuthTests
{
public TestContext TestContext { get; set; }
private static WowExplorer explorer;

[ClassInitialize()]
public static void ClassInit(TestContext context)
{
explorer = new WowExplorer(Region.US, Locale.en_US);
}

[TestMethod]
public void FetchData_When_Authenticated()
{
Expand Down
36 changes: 10 additions & 26 deletions Explorers.Test/CharacterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ namespace WowDotNetAPI.Test
[TestClass]
public class CharacterTests
{
public static IExplorer WowExplorer;
public TestContext TestContext { get; set; }
private static WowExplorer explorer;

[ClassInitialize]
public static void Initialize(TestContext testContext)
[ClassInitialize()]
public static void ClassInit(TestContext context)
{
WowExplorer = new WowExplorer(Region.US);
explorer = new WowExplorer(Region.US, Locale.en_US);
}

[TestMethod]
public void Get_Simple_Character_Briandek_From_Skullcrusher()
{
Character briandek = WowExplorer.GetCharacter("skullcrusher", "briandek");
var briandek = explorer.GetCharacter("skullcrusher", "briandek");

Assert.IsNull(briandek.Guild);
Assert.IsNull(briandek.Stats);
Expand All @@ -36,7 +37,7 @@ public void Get_Simple_Character_Briandek_From_Skullcrusher()
Assert.IsNull(briandek.Mounts);
//Assert.IsNull(briandek.Pets);
Assert.IsNull(briandek.Achievements);
Assert.IsNull(briandek.Progression);
Assert.IsNull(briandek.Progression);

Assert.IsTrue(briandek.Name.Equals("briandek", StringComparison.InvariantCultureIgnoreCase));
Assert.AreEqual(85, briandek.Level);
Expand All @@ -48,8 +49,7 @@ public void Get_Simple_Character_Briandek_From_Skullcrusher()
[TestMethod]
public void Get_Complex_Character_Briandek_From_Skullcrusher()
{

Character briandek = WowExplorer.GetCharacter("skullcrusher", "briandek", CharacterOptions.GetEverything);
var briandek = explorer.GetCharacter("skullcrusher", "briandek", CharacterOptions.GetEverything);

Assert.IsNotNull(briandek.Guild);
Assert.IsNotNull(briandek.Stats);
Expand All @@ -71,7 +71,6 @@ public void Get_Complex_Character_Briandek_From_Skullcrusher()
Assert.AreEqual(CharacterClass.WARRIOR, briandek.@Class);
Assert.AreEqual(CharacterRace.HUMAN, briandek.Race);
Assert.AreEqual(CharacterGender.MALE, briandek.Gender);
Assert.AreEqual(CharacterPowerType.RAGE.ToString(), briandek.Stats.PowerType.ToString(), true);

Assert.IsTrue(briandek.Talents.Where(t => t.Selected).FirstOrDefault().Name.Equals("protection", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(briandek.Talents.ElementAt(1).Glyphs.Prime.ElementAt(0).Name.Equals("Glyph of Revenge", StringComparison.InvariantCultureIgnoreCase));
Expand All @@ -87,8 +86,7 @@ public void Get_Complex_Character_Briandek_From_Skullcrusher()
[TestMethod]
public void Get_Complex_Character_Talasi_From_Skullcrusher()
{

Character talasi = WowExplorer.GetCharacter("skullcrusher", "talasi", CharacterOptions.GetEverything);
var talasi = explorer.GetCharacter("skullcrusher", "talasi", CharacterOptions.GetEverything);

Assert.IsNotNull(talasi.Guild);
Assert.IsNotNull(talasi.Stats);
Expand All @@ -114,20 +112,6 @@ public void Get_Complex_Character_Talasi_From_Skullcrusher()

Assert.AreEqual(11, talasi.Mounts.Count());
}

[TestMethod]
public void Get_Simple_Character_DeathKnight_From_Skullcrusher()
{
Character sinthesis = WowExplorer.GetCharacter("skullcrusher", "sinthesis", CharacterOptions.GetStats);

Assert.IsNotNull(sinthesis.Stats);

Assert.IsTrue(sinthesis.Name.Equals("sinthesis", StringComparison.InvariantCultureIgnoreCase));
Assert.AreEqual(85, sinthesis.Level);
Assert.AreEqual(CharacterClass.DEATH_KNIGHT, sinthesis.@Class);
Assert.AreEqual(CharacterRace.WORGEN, sinthesis.Race);
Assert.AreEqual(CharacterGender.MALE, sinthesis.Gender);
Assert.AreEqual(CharacterPowerType.RUNICPOWER.ToString(), sinthesis.Stats.PowerType.ToString(), true);
}

}
}
76 changes: 34 additions & 42 deletions Explorers.Test/DataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,35 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WowDotNetAPI.Test;
using System.Collections;
using WowDotNetAPI.Models;
using WowDotNetAPI.Utilities;
using System.IO;
using WowDotNetAPI.Exceptions;
using WowDotNetAPI;

namespace WowDotNetAPI.Explorers.Test
{
[TestClass]
public class DataTests
{
public static IExplorer WowExplorer;
public TestContext TextContext { get; set; }
private static WowExplorer explorer;

[ClassInitialize]
public static void Initialize(TestContext testContext)
[ClassInitialize()]
public static void ClassInit(TestContext context)
{
WowExplorer = new WowExplorer(Region.US);
explorer = new WowExplorer(Region.US, Locale.en_US);
}

[TestMethod]
public void Get_Character_Races_Data()
{
IEnumerable<CharacterRaceInfo> races = WowExplorer.GetCharacterRaces();
var races = explorer.GetCharacterRaces();

Assert.IsTrue(races.Count() == 12);
Assert.IsTrue(races.Any(r => r.Name == "Human" || r.Name == "Night Elf"));
Expand All @@ -35,7 +39,7 @@ public void Get_Character_Races_Data()
[TestMethod]
public void Get_Character_Classes_Data()
{
IEnumerable<CharacterClassInfo> classes = WowExplorer.GetCharacterClasses();
var classes = explorer.GetCharacterClasses();

Assert.IsTrue(classes.Count() == 10);
Assert.IsTrue(classes.Any(r => r.Name == "Warrior" || r.Name == "Death Knight"));
Expand All @@ -44,7 +48,7 @@ public void Get_Character_Classes_Data()
[TestMethod]
public void Get_Guild_Rewards_Data()
{
IEnumerable<GuildRewardInfo> rewards = WowExplorer.GetGuildRewards();
var rewards = explorer.GetGuildRewards();
Assert.IsTrue(rewards.Count() == 42);
Assert.IsTrue(rewards.Any(r => r.Achievement != null));
}
Expand All @@ -53,70 +57,58 @@ public void Get_Guild_Rewards_Data()
[TestMethod]
public void Get_Guild_Perks_Data()
{
IEnumerable<GuildPerkInfo> perks = WowExplorer.GetGuildPerks();
var perks = explorer.GetGuildPerks();
Assert.IsTrue(perks.Count() == 24);
Assert.IsTrue(perks.Any(r => r.Spell != null));
}

//Update the file path to the Data folder in the Explorers.Test project
[TestMethod]
public void Get_Realms_From_Json_File()
public void Get_Realms_From_Json_String()
{
IEnumerable<Realm> realms1 = WowExplorer.GetRealms();
IEnumerable<Realm> realms2 =
JsonUtility.FromJSONStream<RealmsData>(File.OpenText(@"D:\Visual Studio 2010\Projects\WowDotNetAPI\Explorers.Test\Data\jsonRealmsFile.txt")).Realms;

IEnumerable<Realm> realms3 = realms1.Intersect(realms2);
var realms1 = explorer.GetRealms();
var realms2 = JsonUtility.FromJSONString<RealmsData>(TestStrings.TestRealms).Realms;
var realms3 = realms1.Intersect(realms2);
Assert.AreEqual(0, realms3.Count());

}


//Update the file path to the Data folder in the Explorers.Test project
[TestMethod]
public void Get_Character_From_Json_File()
public void Get_Character_From_Json_String()
{
Character briandek = WowExplorer.GetCharacter("skullcrusher", "briandek", CharacterOptions.GetEverything);
Character briandekFromJsonFile =
JsonUtility.FromJSONStream<Character>(File.OpenText(@"D:\Visual Studio 2010\Projects\WowDotNetAPI\Explorers.Test\Data\jsonCharacterFile.txt"));

Assert.AreEqual(0, briandek.CompareTo(briandekFromJsonFile));
var briandek = explorer.GetCharacter("skullcrusher", "briandek", CharacterOptions.GetEverything);
var briandekFromJsonString = JsonUtility.FromJSONString<Character>(TestStrings.TestCharacter);
Assert.AreEqual(0, briandek.CompareTo(briandekFromJsonString));

}

[TestMethod]
[ExpectedException(typeof(InvalidLocaleException))]
public void Set_Invalid_Locale_To_US_Region()
{
Action a = () => WowExplorer.SetLocale(Locale.fr_FR);

TestUtility.ThrowsException<InvalidLocaleException>(a, "The fr_FR locale is not associated with the US region");

explorer.SetLocale(Locale.fr_FR);
}

//Need to Fix This
[TestMethod]
public void Get_Invalid_Data_From_CN_Region_Throws_Exception()
public void Get_Invalid_Character_From_Skullcrusher()
{
WowExplorer wEx = new WowExplorer(Region.CN);
var character = explorer.GetCharacter("skullcrusher", "talasix");
var error = explorer.ErrorInfo;

Action a = () => wEx.GetCharacterClasses();
TestUtility.ThrowsException<Exception>(a, "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.");
Assert.IsNull(character);
Assert.IsNotNull(error);
}

[TestMethod]
public void Get_Invalid_Character_From_Skullcrusher_Throws_Exception()
public void Get_Invalid_Data_From_CN_Region_Throws_Exception()
{
Action a = () => WowExplorer.GetCharacter("skullcrusher", "talasix");
TestUtility.ThrowsException<WowException>(a, "Response Status: 404 NotFound. Character not found.");
}
explorer.Region = Region.CN;
explorer.Locale = Locale.zh_CN;
var characterClasses = explorer.GetCharacterClasses();
var error = explorer.ErrorInfo;

[TestMethod]
public void Get_Invalid_Guild_From_Skullcrusher_Throws_Exception()
{
Action a = () => WowExplorer.GetGuild("skullcrusher", "dekufanzero");
TestUtility.ThrowsException<WowException>(a, "Response Status: 404 NotFound. Guild not found.");
Assert.IsNull(characterClasses);
Assert.IsNotNull(error);
}

}

}
13 changes: 11 additions & 2 deletions Explorers.Test/Explorers.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,31 @@
<Compile Include="CharacterTests.cs" />
<Compile Include="DataTests.cs" />
<Compile Include="ItemTests.cs" />
<Compile Include="TestUtility.cs" />
<Compile Include="GuildTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RealmTests.cs" />
<Compile Include="TestStrings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>TestStrings.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Explorers\Explorers.csproj">
<Project>{2A828141-9EF2-4A8A-8944-B2F2D1775CC9}</Project>
<Name>Explorers</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Content Include="Data\jsonCharacterFile.txt" />
<Content Include="Data\jsonRealmsFile.txt" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="TestStrings.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>TestStrings.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Loading

0 comments on commit 688d2de

Please sign in to comment.