当前位置: 首页>>代码示例>>C#>>正文


C# CustomClass类代码示例

本文整理汇总了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");
     }
 }
开发者ID:Vlanta,项目名称:c-sharp,代码行数:54,代码来源:WhenSubscribedToAChannel.cs

示例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);
        }
开发者ID:leloulight,项目名称:Scaffolding,代码行数:12,代码来源:RazorTemplateBaseTests.cs

示例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");
        }
开发者ID:gabrielgreen,项目名称:spring-net-rest,代码行数:13,代码来源:XmlSerializableHttpMessageConverterTests.cs

示例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");
        }
开发者ID:nsavga,项目名称:spring-net-rest,代码行数:13,代码来源:DataContractJsonHttpMessageConverterTests.cs

示例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());
            }
        }
开发者ID:leloulight,项目名称:Scaffolding,代码行数:14,代码来源:RazorTemplateBaseTests.cs

示例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 ();
        }
开发者ID:jdstroy,项目名称:c-sharp,代码行数:60,代码来源:WhenSubscribedToAChannel.cs

示例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();
                });
        }
开发者ID:RecursosOnline,项目名称:c-sharp,代码行数:45,代码来源:WhenAMessageIsPublished.cs

示例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");
            }
        }
开发者ID:RecursosOnline,项目名称:c-sharp,代码行数:32,代码来源:WhenAMessageIsPublished.cs

示例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);
        }
开发者ID:Vlanta,项目名称:c-sharp,代码行数:14,代码来源:EncryptionTests.cs

示例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]);
 }
开发者ID:walrus7521,项目名称:code,代码行数:11,代码来源:Indexer.cs

示例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();
                       });
                    }
                });
        }
开发者ID:hellogurus,项目名称:pubnub-api,代码行数:38,代码来源:WhenAMessageIsPublished.cs

示例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");
            }
        }
开发者ID:TharinduMunasinge,项目名称:c-sharp,代码行数:73,代码来源:WhenSubscribedToAChannel.cs

示例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));
        }
开发者ID:eval01-tts,项目名称:unity,代码行数:16,代码来源:EncryptionTests.cs

示例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);
        }
开发者ID:jugalkishor-sujal,项目名称:c-sharp,代码行数:14,代码来源:EncryptionTests.cs

示例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");
     }
 }
开发者ID:jugalkishor-sujal,项目名称:c-sharp,代码行数:32,代码来源:WhenAMessageIsPublished.cs


注:本文中的CustomClass类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。