Skip to content

Commit

Permalink
Put the IoC config into the ClassInitialize method and made all subse…
Browse files Browse the repository at this point in the history
…quent tests use this as the default client.
  • Loading branch information
hugorodgerbrown committed Mar 22, 2011
1 parent f4a98fd commit 83ec8d0
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions HipChatClientTests/ClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ namespace HipChatClientTests
[TestClass]
public class TestHipChatClient
{
const string TEST_AUTH_TOKEN = "ABC";
const int TEST_ROOM_ID = 123;
const string TEST_SENDER = "UnitTests";
private static HipChatClient DefaultClient;

[TestMethod]
public void TestWindsorInstaller()
[ClassInitialize]
public static void Initialize(TestContext context)
{
IWindsorContainer container = new WindsorContainer();
container.Install(new HipChatClientInstaller());
var client = container.Resolve<HipChatClient>("ChatClient1");
client.SendMessage("TestWindsorInstaller");
DefaultClient = container.Resolve<HipChatClient>("ChatClient1");
}

[TestMethod]
Expand All @@ -35,7 +32,7 @@ public void TestAuthenticationException()
[TestMethod]
public void TestYieldRooms()
{
var client = new HipChat.HipChatClient(TEST_AUTH_TOKEN);
var client = new HipChat.HipChatClient(DefaultClient.Token);
var x = 0;
foreach (HipChat.Entities.Room room in client.YieldRooms())
{
Expand All @@ -55,7 +52,7 @@ public void TestSenderLengthExecption()
[TestMethod]
public void TestListRoomsAsJson()
{
var client = new HipChat.HipChatClient(TEST_AUTH_TOKEN, HipChat.HipChatClient.ApiResponseFormat.JSON);
var client = new HipChat.HipChatClient(DefaultClient.Token, HipChat.HipChatClient.ApiResponseFormat.JSON);
var json = client.ListRooms();
// not the most scientific test, but it's sunday night
Assert.IsTrue(json.Contains("{"));
Expand All @@ -64,7 +61,7 @@ public void TestListRoomsAsJson()
[TestMethod]
public void TestListRoomsAsXml()
{
var client = new HipChat.HipChatClient(TEST_AUTH_TOKEN, HipChat.HipChatClient.ApiResponseFormat.XML);
var client = new HipChat.HipChatClient(DefaultClient.Token, HipChat.HipChatClient.ApiResponseFormat.XML);
var xml = client.ListRooms();
// not the most scientific test, but it's sunday night
Assert.IsTrue(xml.StartsWith("<?xml version=\"1.0\" encoding=\"utf-8\"?>"));
Expand All @@ -73,7 +70,7 @@ public void TestListRoomsAsXml()
[TestMethod]
public void TestListRoomsAsNativeObjects()
{
var client = new HipChat.HipChatClient(TEST_AUTH_TOKEN, HipChat.HipChatClient.ApiResponseFormat.XML);
var client = new HipChat.HipChatClient(DefaultClient.Token, HipChat.HipChatClient.ApiResponseFormat.XML);
var rooms = client.ListRoomsAsNativeObjects();
Assert.IsInstanceOfType(rooms, typeof(List<HipChat.Entities.Room>));
Assert.AreEqual(3, rooms.Count);
Expand All @@ -82,55 +79,55 @@ public void TestListRoomsAsNativeObjects()
[TestMethod]
public void TestSendMessage1()
{
var client = new HipChat.HipChatClient(TEST_AUTH_TOKEN, TEST_ROOM_ID, "UnitTests");
var client = new HipChat.HipChatClient(DefaultClient.Token, DefaultClient.RoomId, DefaultClient.From);
client.SendMessage("TestSendMessage1");
}

[TestMethod]
public void TestSendMessage2()
{
var client = new HipChat.HipChatClient(TEST_AUTH_TOKEN, TEST_ROOM_ID);
client.SendMessage("TestSendMessage2", TEST_SENDER);
var client = new HipChat.HipChatClient(DefaultClient.Token, DefaultClient.RoomId);
client.SendMessage("TestSendMessage2", DefaultClient.From);
}

[TestMethod]
public void TestSendMessage3()
{
var client = new HipChat.HipChatClient(TEST_AUTH_TOKEN);
client.SendMessage("TestSendMessage3", TEST_ROOM_ID, TEST_SENDER);
var client = new HipChat.HipChatClient(DefaultClient.Token);
client.SendMessage("TestSendMessage3", DefaultClient.RoomId, DefaultClient.From);
}

[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void TestSendMessageEmptyException()
{
var client = new HipChat.HipChatClient(TEST_AUTH_TOKEN);
client.SendMessage("", TEST_ROOM_ID, TEST_SENDER);
var client = new HipChat.HipChatClient(DefaultClient.Token);
client.SendMessage("", DefaultClient.RoomId, DefaultClient.From);
}

[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void TestSendMessageTooLongException()
{
var client = new HipChat.HipChatClient(TEST_AUTH_TOKEN);
var client = new HipChat.HipChatClient(DefaultClient.Token);
var s = new StringBuilder();
while (s.Length <= 5000)
{
s.Append("The quick brown fox jumped over the lazy dog");
}
client.SendMessage(s.ToString(), TEST_ROOM_ID, TEST_SENDER);
client.SendMessage(s.ToString(), DefaultClient.RoomId, DefaultClient.From);
}

[TestMethod]
public void TestSendMessageStatic()
{
HipChat.HipChatClient.SendMessage(TEST_AUTH_TOKEN, TEST_ROOM_ID, "UnitTests", "TestSendMessageStatic");
HipChat.HipChatClient.SendMessage(DefaultClient.Token, DefaultClient.RoomId, DefaultClient.From, "TestSendMessageStatic");
}

[TestMethod]
public void TestGetRoomHistory()
{
var client = new HipChat.HipChatClient(TEST_AUTH_TOKEN, TEST_ROOM_ID);
var client = new HipChat.HipChatClient(DefaultClient.Token, DefaultClient.RoomId);
var s = client.RoomHistory(DateTime.Today.AddDays(-1));
System.Diagnostics.Trace.WriteLine(s.Length > 50 ? s.Substring(0, 50) : s);
Assert.IsNotNull(s);
Expand Down

0 comments on commit 83ec8d0

Please sign in to comment.