Skip to content

Commit

Permalink
refactored naming conventions in test projects
Browse files Browse the repository at this point in the history
  • Loading branch information
budgetpreneur committed Jan 8, 2013
1 parent ae1b544 commit e35ec49
Show file tree
Hide file tree
Showing 23 changed files with 1,170 additions and 1,192 deletions.

Large diffs are not rendered by default.

Expand Up @@ -259,7 +259,7 @@ public bool EnableStubTest


public string GetStubResponse(Uri request) public string GetStubResponse(Uri request)
{ {
Dictionary<string, string> respDic = null; Dictionary<string, string> responseDictionary = null;
string stubResponse = "!! Stub Response Not Assigned !!"; string stubResponse = "!! Stub Response Not Assigned !!";


switch (_testClassName) switch (_testClassName)
Expand All @@ -268,10 +268,10 @@ public string GetStubResponse(Uri request)
switch (_testCaseName) switch (_testCaseName)
{ {
case "ThenPresenceShouldReturnReceivedMessage": case "ThenPresenceShouldReturnReceivedMessage":
respDic = LoadWhenAClientIsPresentedThenPresenceShouldReturnReceivedMessage(); responseDictionary = LoadWhenAClientIsPresentedThenPresenceShouldReturnReceivedMessage();
break; break;
case "IfHereNowIsCalledThenItShouldReturnInfo": case "IfHereNowIsCalledThenItShouldReturnInfo":
respDic = LoadWhenAClientIsPresentedIfHereNowIsCalledThenItShouldReturnInfo(); responseDictionary = LoadWhenAClientIsPresentedIfHereNowIsCalledThenItShouldReturnInfo();
break; break;
default: default:
break; break;
Expand All @@ -281,25 +281,25 @@ public string GetStubResponse(Uri request)
switch (_testCaseName) switch (_testCaseName)
{ {
case "ThenUnencryptPublishShouldReturnSuccessCodeAndInfo": case "ThenUnencryptPublishShouldReturnSuccessCodeAndInfo":
respDic = LoadWhenAMessageIsPublishedThenUnencryptPublishShouldReturnSuccessCodeAndInfo(); responseDictionary = LoadWhenAMessageIsPublishedThenUnencryptPublishShouldReturnSuccessCodeAndInfo();
break; break;
case "ThenUnencryptObjectPublishShouldReturnSuccessCodeAndInfo": case "ThenUnencryptObjectPublishShouldReturnSuccessCodeAndInfo":
respDic = LoadWhenAMessageIsPublishedThenUnencryptObjectPublishShouldReturnSuccessCodeAndInfo(); responseDictionary = LoadWhenAMessageIsPublishedThenUnencryptObjectPublishShouldReturnSuccessCodeAndInfo();
break; break;
case "ThenEncryptObjectPublishShouldReturnSuccessCodeAndInfo": case "ThenEncryptObjectPublishShouldReturnSuccessCodeAndInfo":
respDic = LoadWhenAMessageIsPublishedThenEncryptObjectPublishShouldReturnSuccessCodeAndInfo(); responseDictionary = LoadWhenAMessageIsPublishedThenEncryptObjectPublishShouldReturnSuccessCodeAndInfo();
break; break;
case "ThenEncryptPublishShouldReturnSuccessCodeAndInfo": case "ThenEncryptPublishShouldReturnSuccessCodeAndInfo":
respDic = LoadWhenAMessageIsPublishedThenEncryptPublishShouldReturnSuccessCodeAndInfo(); responseDictionary = LoadWhenAMessageIsPublishedThenEncryptPublishShouldReturnSuccessCodeAndInfo();
break; break;
case "ThenSecretKeyWithEncryptPublishShouldReturnSuccessCodeAndInfo": case "ThenSecretKeyWithEncryptPublishShouldReturnSuccessCodeAndInfo":
respDic = LoadWhenAMessageIsPublishedThenSecretKeyWithEncryptPublishShouldReturnSuccessCodeAndInfo(); responseDictionary = LoadWhenAMessageIsPublishedThenSecretKeyWithEncryptPublishShouldReturnSuccessCodeAndInfo();
break; break;
case "ThenOptionalSecretKeyShouldBeProvidedInConstructor": case "ThenOptionalSecretKeyShouldBeProvidedInConstructor":
respDic = LoadWhenAMessageIsPublishedThenOptionalSecretKeyShouldBeProvidedInConstructor(); responseDictionary = LoadWhenAMessageIsPublishedThenOptionalSecretKeyShouldBeProvidedInConstructor();
break; break;
case "IfSSLNotProvidedThenDefaultShouldBeFalse": case "IfSSLNotProvidedThenDefaultShouldBeFalse":
respDic = LoadWhenAMessageIsPublishedIfSSLNotProvidedThenDefaultShouldBeFalse(); responseDictionary = LoadWhenAMessageIsPublishedIfSSLNotProvidedThenDefaultShouldBeFalse();
break; break;
default: default:
break; break;
Expand All @@ -309,13 +309,13 @@ public string GetStubResponse(Uri request)
switch (_testCaseName) switch (_testCaseName)
{ {
case "DetailHistoryCount10ReturnsRecords": case "DetailHistoryCount10ReturnsRecords":
respDic = LoadWhenDetailedHistoryIsRequestedDetailHistoryCount10ReturnsRecords(); responseDictionary = LoadWhenDetailedHistoryIsRequestedDetailHistoryCount10ReturnsRecords();
break; break;
case "DetailHistoryCount10ReverseTrueReturnsRecords": case "DetailHistoryCount10ReverseTrueReturnsRecords":
respDic = LoadWhenDetailedHistoryIsRequestedDetailHistoryCount10ReverseTrueReturnsRecords(); responseDictionary = LoadWhenDetailedHistoryIsRequestedDetailHistoryCount10ReverseTrueReturnsRecords();
break; break;
case "DetailedHistoryStartWithReverseTrue": case "DetailedHistoryStartWithReverseTrue":
respDic = LoadWhenDetailedHistoryIsRequestedDetailedHistoryStartWithReverseTrue(); responseDictionary = LoadWhenDetailedHistoryIsRequestedDetailedHistoryStartWithReverseTrue();
break; break;
default: default:
break; break;
Expand All @@ -325,10 +325,10 @@ public string GetStubResponse(Uri request)
switch (_testCaseName) switch (_testCaseName)
{ {
case "ThenItShouldReturnTimeStamp": case "ThenItShouldReturnTimeStamp":
respDic = LoadWhenGetRequestServerTimeThenItShouldReturnTimeStamp(); responseDictionary = LoadWhenGetRequestServerTimeThenItShouldReturnTimeStamp();
break; break;
case "ThenWithProxyItShouldReturnTimeStamp": case "ThenWithProxyItShouldReturnTimeStamp":
respDic = LoadWhenGetRequestServerTimeThenWithProxyItShouldReturnTimeStamp(); responseDictionary = LoadWhenGetRequestServerTimeThenWithProxyItShouldReturnTimeStamp();
break; break;
default: default:
break; break;
Expand All @@ -338,10 +338,10 @@ public string GetStubResponse(Uri request)
switch (_testCaseName) switch (_testCaseName)
{ {
case "ThenSubscribeShouldReturnReceivedMessage": case "ThenSubscribeShouldReturnReceivedMessage":
respDic = LoadWhenSubscribedToAChannelThenSubscribeShouldReturnReceivedMessage(); responseDictionary = LoadWhenSubscribedToAChannelThenSubscribeShouldReturnReceivedMessage();
break; break;
case "ThenSubscribeShouldReturnConnectStatus": case "ThenSubscribeShouldReturnConnectStatus":
respDic = LoadWhenSubscribedToAChannelThenSubscribeShouldReturnConnectStatus(); responseDictionary = LoadWhenSubscribedToAChannelThenSubscribeShouldReturnConnectStatus();
break; break;
default: default:
break; break;
Expand All @@ -351,9 +351,9 @@ public string GetStubResponse(Uri request)
break; break;
} }


if (respDic != null && respDic.ContainsKey(request.AbsolutePath)) if (responseDictionary != null && responseDictionary.ContainsKey(request.AbsolutePath))
{ {
stubResponse = respDic[request.AbsolutePath]; stubResponse = responseDictionary[request.AbsolutePath];
} }
else else
{ {
Expand Down
Expand Up @@ -22,20 +22,20 @@ namespace PubnubWindowsPhone.Test.UnitTest
[TestClass] [TestClass]
public class WhenAClientIsPresented : WorkItemTest public class WhenAClientIsPresented : WorkItemTest
{ {
ManualResetEvent manualEvent1 = new ManualResetEvent(false); ManualResetEvent subscribeManualEvent = new ManualResetEvent(false);
ManualResetEvent manualEvent2 = new ManualResetEvent(false); ManualResetEvent presenceManualEvent = new ManualResetEvent(false);
ManualResetEvent manualEvent3 = new ManualResetEvent(false); ManualResetEvent unsubscribeManualEvent = new ManualResetEvent(false);


ManualResetEvent manualEvent4 = new ManualResetEvent(false); ManualResetEvent hereNowManualEvent = new ManualResetEvent(false);
ManualResetEvent preUnsubEvent = new ManualResetEvent(false); ManualResetEvent presenceUnsubscribeEvent = new ManualResetEvent(false);


static bool receivedFlag1 = false; static bool receivedPresenceMessage = false;
static bool receivedFlag2 = false; static bool receivedHereNowMessage = false;


[TestMethod,Asynchronous] [TestMethod,Asynchronous]
public void ThenPresenceShouldReturnReceivedMessage() public void ThenPresenceShouldReturnReceivedMessage()
{ {
receivedFlag1 = false; receivedPresenceMessage = false;
ThreadPool.QueueUserWorkItem((s) => ThreadPool.QueueUserWorkItem((s) =>
{ {
Pubnub pubnub = new Pubnub("demo", "demo", "", "", false); Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
Expand All @@ -50,18 +50,18 @@ public void ThenPresenceShouldReturnReceivedMessage()
//since presence expects from stimulus from sub/unsub... //since presence expects from stimulus from sub/unsub...
pubnub.Subscribe<string>(channel, DummyMethodForSubscribe); pubnub.Subscribe<string>(channel, DummyMethodForSubscribe);
manualEvent1.WaitOne(2000); subscribeManualEvent.WaitOne(2000);
pubnub.Unsubscribe<string>(channel, DummyMethodForUnSubscribe); pubnub.Unsubscribe<string>(channel, DummyMethodForUnSubscribe);
manualEvent3.WaitOne(2000); unsubscribeManualEvent.WaitOne(2000);
pubnub.PresenceUnsubscribe<string>(channel, DummyMethodForPreUnSub); pubnub.PresenceUnsubscribe<string>(channel, DummyMethodForPreUnSub);
preUnsubEvent.WaitOne(2000); presenceUnsubscribeEvent.WaitOne(2000);
manualEvent2.WaitOne(310 * 1000); presenceManualEvent.WaitOne(310 * 1000);
Deployment.Current.Dispatcher.BeginInvoke(() => Deployment.Current.Dispatcher.BeginInvoke(() =>
{ {
Assert.IsTrue(receivedFlag1, "Presence message not received"); Assert.IsTrue(receivedPresenceMessage, "Presence message not received");
TestComplete(); TestComplete();
}); });
}); });
Expand All @@ -74,27 +74,27 @@ void ThenPresenceShouldReturnMessage(string receivedMessage)
{ {
if (!string.IsNullOrWhiteSpace(receivedMessage)) if (!string.IsNullOrWhiteSpace(receivedMessage))
{ {
object[] receivedObj = JsonConvert.DeserializeObject<object[]>(receivedMessage); object[] serializedMessage = JsonConvert.DeserializeObject<object[]>(receivedMessage);
JContainer dic = receivedObj[0] as JContainer; JContainer dictionary = serializedMessage[0] as JContainer;
var uuid = dic["uuid"].ToString(); var uuid = dictionary["uuid"].ToString();
if (uuid != null) if (uuid != null)
{ {
receivedFlag1 = true; receivedPresenceMessage = true;
} }
} }
} }
catch { } catch { }
finally finally
{ {
manualEvent2.Set(); presenceManualEvent.Set();
} }
} }




[TestMethod,Asynchronous] [TestMethod,Asynchronous]
public void IfHereNowIsCalledThenItShouldReturnInfo() public void IfHereNowIsCalledThenItShouldReturnInfo()
{ {
receivedFlag2 = false; receivedHereNowMessage = false;
ThreadPool.QueueUserWorkItem((s) => ThreadPool.QueueUserWorkItem((s) =>
{ {
Pubnub pubnub = new Pubnub("demo", "demo", "", "", false); Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
Expand All @@ -106,10 +106,10 @@ public void IfHereNowIsCalledThenItShouldReturnInfo()
pubnub.PubnubUnitTest = unitTest; pubnub.PubnubUnitTest = unitTest;
pubnub.HereNow<string>(channel, ThenHereNowShouldReturnMessage); pubnub.HereNow<string>(channel, ThenHereNowShouldReturnMessage);
manualEvent4.WaitOne(); hereNowManualEvent.WaitOne();
Deployment.Current.Dispatcher.BeginInvoke(() => Deployment.Current.Dispatcher.BeginInvoke(() =>
{ {
Assert.IsTrue(receivedFlag2, "here_now message not received"); Assert.IsTrue(receivedHereNowMessage, "here_now message not received");
TestComplete(); TestComplete();
}); });
}); });
Expand All @@ -124,40 +124,40 @@ void ThenHereNowShouldReturnMessage(string receivedMessage)
{ {
if (!string.IsNullOrWhiteSpace(receivedMessage)) if (!string.IsNullOrWhiteSpace(receivedMessage))
{ {
object[] receivedObj = JsonConvert.DeserializeObject<object[]>(receivedMessage); object[] serializedMessage = JsonConvert.DeserializeObject<object[]>(receivedMessage);
var dic = ((JContainer)receivedObj[0])["uuids"]; var dictionary = ((JContainer)serializedMessage[0])["uuids"];
if (dic != null) if (dictionary != null)
{ {
receivedFlag2 = true; receivedHereNowMessage = true;
} }
} }
}); });
} }
catch { } catch { }
finally finally
{ {
manualEvent4.Set(); hereNowManualEvent.Set();
} }
} }


[Asynchronous] [Asynchronous]
void DummyMethodForSubscribe(string receivedMessage) void DummyMethodForSubscribe(string receivedMessage)
{ {
manualEvent1.Set(); subscribeManualEvent.Set();
//Dummary callback method for subscribe and unsubscribe to test presence //Dummary callback method for subscribe and unsubscribe to test presence
} }


[Asynchronous] [Asynchronous]
void DummyMethodForUnSubscribe(string receivedMessage) void DummyMethodForUnSubscribe(string receivedMessage)
{ {
manualEvent3.Set(); unsubscribeManualEvent.Set();
//Dummary callback method for unsubscribe to test presence //Dummary callback method for unsubscribe to test presence
} }


[Asynchronous] [Asynchronous]
void DummyMethodForPreUnSub(string receivedMessage) void DummyMethodForPreUnSub(string receivedMessage)
{ {
preUnsubEvent.Set(); presenceUnsubscribeEvent.Set();
} }
} }
} }

0 comments on commit e35ec49

Please sign in to comment.