本文整理汇总了C#中CustomClass类的典型用法代码示例。如果您正苦于以下问题:C# CustomClass类的具体用法?C# CustomClass怎么用?C# CustomClass使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CustomClass类属于命名空间,在下文中一共展示了CustomClass类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ThenItShouldReturnReceivedMessageForComplexMessage
public void ThenItShouldReturnReceivedMessageForComplexMessage ()
{
Pubnub pubnub = new Pubnub (
"demo",
"demo",
"",
"",
false);
string channel = "hello_world";
Common common = new Common();
common.DeliveryStatus = false;
common.Response = null;
pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenSubscribedToAChannel", "ThenItShouldReturnReceivedMessageForComplexMessage");
pubnub.Subscribe (channel, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);
Thread.Sleep(3000);
CustomClass message = new CustomClass();
pubnub.Publish (channel, (object)message, common.DisplayReturnMessageDummy);
//cm.deliveryStatus = false;
while (!common.DeliveryStatus);
if (common.Response != null) {
IList<object> fields = common.Response as IList<object>;
if (fields [0] != null)
{
var myObjectArray = (from item in fields select item as object).ToArray ();
Console.WriteLine ("Response:" + myObjectArray[0].ToString ());
CustomClass cc = JsonConvert.DeserializeObject<CustomClass>(myObjectArray[0].ToString());
if(cc.bar.SequenceEqual(message.bar) && cc.foo.Equals(message.foo))
{
Assert.Pass("Complex message test successful");
}
else
{
Assert.Fail("Complex message test not successful");
}
}
else
{
Assert.Fail("No response");
}
}
else
{
Assert.Fail("No response");
}
}
示例2: ExecuteTemplate_Sets_Output_And_Calls_ExecuteAsync
public async void ExecuteTemplate_Sets_Output_And_Calls_ExecuteAsync()
{
//Arrange
var customInstance = new CustomClass();
//Act
var result = await customInstance.ExecuteTemplate();
//Assert
Assert.Equal("SampleText", result);
Assert.True(customInstance.ExecuteAsyncCalled);
}
示例3: Write
public void Write()
{
string expectedBody = "<CustomClass xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><ID>1</ID><Name>Bruno Baïa</Name></CustomClass>";
CustomClass body = new CustomClass("1", "Bruno Baïa");
MockHttpOutputMessage message = new MockHttpOutputMessage();
converter.Write(body, null, message);
Assert.AreEqual(expectedBody, message.GetBodyAsString(Encoding.UTF8), "Invalid result");
Assert.AreEqual(new MediaType("application", "xml"), message.Headers.ContentType, "Invalid content-type");
//Assert.IsTrue(message.Headers.ContentLength > -1, "Invalid content-length");
}
示例4: Write
public void Write()
{
string expectedBody = "{\"ID\":\"1\",\"Name\":\"Bruno Baïa\"}";
CustomClass body = new CustomClass("1", "Bruno Baïa");
MockHttpOutputMessage message = new MockHttpOutputMessage();
converter.Write(body, null, message);
Assert.AreEqual(expectedBody, message.GetBodyAsString(Encoding.UTF8), "Invalid result");
Assert.AreEqual(new MediaType("application", "json"), message.Headers.ContentType, "Invalid content-type");
//Assert.IsTrue(message.Headers.ContentLength > -1, "Invalid content-length");
}
示例5: WriteTo_Does_Not_Fail_For_Null_Object
public void WriteTo_Does_Not_Fail_For_Null_Object()
{
using (var writer = new StringWriter())
{
//Arrange
var customInstace = new CustomClass();
//Act
customInstace.WriteTo(writer, null);
//Assert
Assert.Equal(string.Empty, writer.ToString());
}
}
示例6: SubscribePublishAndParseComplex
void SubscribePublishAndParseComplex (Pubnub pubnub, Common common, string channel)
{
Random r = new Random ();
channel = "hello_world_sub" + r.Next (1000);
CustomClass message = new CustomClass ();
pubnub.Subscribe<string> (channel, common.DisplayReturnMessage, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);
Thread.Sleep (5000);
pubnub.NonSubscribeTimeout = 30;
pubnub.Publish (channel, (object)message, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);
pubnub.NonSubscribeTimeout = 15;
common.WaitForResponse ();
if (common.Response != null) {
object[] fields = Common.Deserialize<object[]> (common.Response.ToString ());
if (fields [0] != null) {
var myObjectArray = (from item in fields
select item as object).ToArray ();
CustomClass cc = new CustomClass ();
//If the custom class is serialized with jsonfx the response is received as a dictionary and
//on deserialization with Newtonsoft.Json we get an error.
//As a work around we parse the dictionary object.
var dict = myObjectArray [0] as IDictionary;
if ((dict != null) && (dict.Count > 1)) {
cc.foo = (string)dict ["foo"];
cc.bar = (int[])dict ["bar"];
} else {
cc = Common.Deserialize<CustomClass> (myObjectArray [0].ToString ());
/* #if (USE_JSONFX)
var reader = new JsonFx.Json.JsonReader();
cc = reader.Read<CustomClass>(myObjectArray[0].ToString());
#else
cc = JsonConvert.DeserializeObject<CustomClass>(myObjectArray[0].ToString());
#endif*/
}
if (cc.bar.SequenceEqual (message.bar) && cc.foo.Equals (message.foo)) {
Assert.Pass ("Complex message test successful");
} else {
Assert.Fail ("Complex message test not successful");
}
} else {
Assert.Fail ("No response");
}
} else {
Assert.Fail ("No response");
}
common.DeliveryStatus = false;
common.Response = null;
pubnub.Unsubscribe<string> (channel, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);
common.WaitForResponse (20);
pubnub.EndPendingRequests ();
}
示例7: ThenUnencryptObjectPublishShouldReturnSuccessCodeAndInfo
public void ThenUnencryptObjectPublishShouldReturnSuccessCodeAndInfo()
{
isUnencryptObjectPublished = false;
mrePublish = new ManualResetEvent(false);
mreDetailedHistory = new ManualResetEvent(false);
ThreadPool.QueueUserWorkItem((s) =>
{
Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false);
string channel = "hello_my_channel";
object message = new CustomClass();
messageObjectForUnencryptPublish = JsonConvert.SerializeObject(message);
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "WhenAMessageIsPublished";
unitTest.TestCaseName = "ThenUnencryptObjectPublishShouldReturnSuccessCodeAndInfo";
pubnub.PubnubUnitTest = unitTest;
EnqueueCallback(() => pubnub.Publish<string>(channel, message, ReturnSuccessUnencryptObjectPublishCodeCallback, DummyPublishErrorCallback));
mrePublish.WaitOne(310 * 1000);
EnqueueCallback(() =>
{
if (!isUnencryptObjectPublished)
{
Assert.IsTrue(isUnencryptObjectPublished, "Unencrypt Publish Failed");
}
else
{
pubnub.DetailedHistory<string>(channel, -1, unEncryptObjectPublishTimetoken, -1, false, CaptureUnencryptObjectDetailedHistoryCallback, DummyDetailedHistoryErrorCallback);
mreDetailedHistory.WaitOne(310 * 1000);
Assert.IsTrue(isUnencryptObjectDH, "Unable to match the successful unencrypt object Publish");
}
});
EnqueueCallback(() =>
{
pubnub.PubnubUnitTest = null;
pubnub = null;
}
);
EnqueueTestComplete();
});
}
示例8: ThenUnencryptObjectPublishShouldReturnSuccessCodeAndInfo
public void ThenUnencryptObjectPublishShouldReturnSuccessCodeAndInfo()
{
isUnencryptObjectPublished = false;
Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false);
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "WhenAMessageIsPublished";
unitTest.TestCaseName = "ThenUnencryptObjectPublishShouldReturnSuccessCodeAndInfo";
pubnub.PubnubUnitTest = unitTest;
string channel = "hello_my_channel";
object message = new CustomClass();
messageObjectForUnencryptPublish = JsonConvert.SerializeObject(message);
pubnub.Publish<string>(channel, message, ReturnSuccessUnencryptObjectPublishCodeCallback, DummyErrorCallback);
manualResetEventsWaitTimeout = (unitTest.EnableStubTest) ? 1000 : 310 * 1000;
mreUnencryptObjectPublish.WaitOne(manualResetEventsWaitTimeout);
if (!isUnencryptObjectPublished)
{
pubnub.PubnubUnitTest = null;
pubnub = null;
Assert.IsTrue(isUnencryptObjectPublished, "Unencrypt Publish Failed");
}
else
{
Task.Delay(1000);
pubnub.DetailedHistory<string>(channel, -1, unEncryptObjectPublishTimetoken, -1, false, CaptureUnencryptObjectDetailedHistoryCallback, DummyErrorCallback);
mreUnencryptObjectDetailedHistory.WaitOne(manualResetEventsWaitTimeout);
pubnub.PubnubUnitTest = null;
pubnub = null;
Assert.IsTrue(isUnencryptObjectDetailedHistory, "Unable to match the successful unencrypt object Publish");
}
}
示例9: TestMyObjectDecryption
public void TestMyObjectDecryption()
{
PubnubCrypto pc = new PubnubCrypto("enigma");
//Deserialized
string message = "Zbr7pEF/GFGKj1rOstp0tWzA4nwJXEfj+ezLtAr8qqE=";
//Decrypt
string decryptedMessage = pc.Decrypt(message);
//create an object of the custom class
CustomClass cc = new CustomClass();
//Serialize it
string result = JsonConvert.SerializeObject(cc);
Assert.AreEqual(result, decryptedMessage);
}
示例10: TestCC4
public static void TestCC4()
{
Console.WriteLine("Test CC4");
CustomClass cc = new CustomClass();
cc[0] = "bart";
cc[1] = "grant";
cc[2] = "chad";
Console.WriteLine("cc[{0}] = {1}", 0, cc[0]);
Console.WriteLine("cc[{0}] = {1}", 1, cc[1]);
Console.WriteLine("cc[{0}] = {1}", 2, cc[2]);
}
示例11: ThenUnencryptObjectPublishShouldReturnSuccessCodeAndInfo
public void ThenUnencryptObjectPublishShouldReturnSuccessCodeAndInfo()
{
ThreadPool.QueueUserWorkItem((s) =>
{
isUnencryptObjectPublished = false;
Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
string channel = "my/channel";
object message = new CustomClass();
messageObjectForUnencryptPublish = JsonConvert.SerializeObject(message);
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "WhenAMessageIsPublished";
unitTest.TestCaseName = "ThenUnencryptObjectPublishShouldReturnSuccessCodeAndInfo";
pubnub.PubnubUnitTest = unitTest;
pubnub.Publish<string>(channel, message, ReturnSuccessUnencryptObjectPublishCodeCallback);
mreUnencryptObjectPublish.WaitOne(310 * 1000);
if (!isUnencryptObjectPublished)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
Assert.IsTrue(isUnencryptObjectPublished, "Unencrypt Publish Failed");
TestComplete();
});
}
else
{
pubnub.DetailedHistory<string>(channel, -1, unEncryptObjectPublishTimetoken, -1, false, CaptureUnencryptObjectDetailedHistoryCallback);
mreUnencryptObjectDetailedHistory.WaitOne(310 * 1000);
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
Assert.IsTrue(isUnencryptObjectDetailedHistory, "Unable to match the successful unencrypt object Publish");
TestComplete();
});
}
});
}
示例12: ThenItShouldReturnReceivedMessageCipherForComplexMessage
public void ThenItShouldReturnReceivedMessageCipherForComplexMessage ()
{
Pubnub pubnub = new Pubnub (
"demo",
"demo",
"",
"enigma",
false);
string channel = "hello_world";
Common common = new Common();
common.DeliveryStatus = false;
common.Response = null;
pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenSubscribedToAChannel", "ThenItShouldReturnReceivedMessageCipherForComplexMessage");
CustomClass message = new CustomClass();
pubnub.Subscribe (channel, common.DisplayReturnMessage, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);
Thread.Sleep(3000);
pubnub.Publish (channel, (object)message, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);
common.WaitForResponse();
if (common.Response != null) {
IList<object> fields = common.Response as IList<object>;
if (fields [0] != null)
{
var myObjectArray = (from item in fields select item as object).ToArray ();
CustomClass cc = new CustomClass();
//If the custom class is serialized with jsonfx the response is received as a dictionary and
//on deserialization with Newtonsoft.Json we get an error.
//As a work around we parse the dictionary object.
var dict = myObjectArray [0] as IDictionary;
if ((dict != null) && (dict.Count > 1))
{
cc.foo = (string)dict["foo"];
cc.bar = (int[])dict["bar"];
}
else
{
cc = Common.Deserialize<CustomClass>(myObjectArray[0].ToString());
/* #if (USE_JSONFX)
var reader = new JsonFx.Json.JsonReader();
cc = reader.Read<CustomClass>(myObjectArray[0].ToString());
#else
cc = JsonConvert.DeserializeObject<CustomClass>(myObjectArray[0].ToString());
#endif*/
}
if(cc.bar.SequenceEqual(message.bar) && cc.foo.Equals(message.foo))
{
Assert.Pass("Complex message test successful");
}
else
{
Assert.Fail("Complex message test not successful");
}
}
else
{
Assert.Fail("No response");
}
}
else
{
Assert.Fail("No response");
}
}
示例13: TestMyObjectEncryptionMiniJson
//will fail with minijson
//[Test]
public void TestMyObjectEncryptionMiniJson ()
{
PubnubCrypto pubnubCrypto = new PubnubCrypto ("enigma");
//create an object of the custom class
CustomClass cc = new CustomClass ();
//serialize it
string result = Common.SerializeMiniJson (cc);
//encrypt it
string encrypted = pubnubCrypto.Encrypt (result);
UnityEngine.Debug.Log ("encrypted:" + encrypted);
UnityEngine.Debug.Log ("result:" + result);
Assert.True (("Zbr7pEF/GFGKj1rOstp0tWzA4nwJXEfj+ezLtAr8qqE=").Equals (encrypted));
}
示例14: TestMyObjectDecryptionJSONFx
public void TestMyObjectDecryptionJSONFx()
{
PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma");
//Deserialized
string message = "Zbr7pEF/GFGKj1rOstp0tWzA4nwJXEfj+ezLtAr8qqE=";
//Decrypt
string decrypted = pubnubCrypto.Decrypt(message);
//create an object of the custom class
CustomClass cc = new CustomClass();
//Serialize it
string result = Common.SerializeUsingJSONFx(cc);
Assert.AreEqual(decrypted, result);
}
示例15: ThenItShouldReturnSuccessCodeAndInfoForComplexMessage
public void ThenItShouldReturnSuccessCodeAndInfoForComplexMessage ()
{
Pubnub pubnub = new Pubnub (
Common.PublishKey,
Common.SubscribeKey,
"",
"",
false
);
string channel = "hello_world";
object message = new CustomClass ();
Common common = new Common ();
pubnub.PubnubUnitTest = common.CreateUnitTestInstance ("WhenAMessageIsPublished", "ThenItShouldReturnSuccessCodeAndInfoForComplexMessage");
common.DeliveryStatus = false;
common.Response = null;
pubnub.Publish (channel, message, common.DisplayReturnMessage, common.DisplayErrorMessage);
//wait till the response is received from the server
common.WaitForResponse ();
if (common.Response != null) {
IList<object> fields = common.Response as IList<object>;
string sent = fields [1].ToString ();
string one = fields [0].ToString ();
Assert.True (("Sent").Equals (sent));
Assert.True (("1").Equals (one));
} else {
Assert.Fail ("Null response");
}
}