public void DynamicReplyChannel()
 {
     QueueChannel replyChannel1 = new QueueChannel();
     QueueChannel replyChannel2 = new QueueChannel();
     replyChannel2.ObjectName = "replyChannel2";
     Object handler = new TestObject2();
     ServiceActivatingHandler endpoint = new ServiceActivatingHandler(handler, "Handle");
     TestChannelResolver channelResolver = new TestChannelResolver();
     channelResolver.AddChannel(replyChannel2);
     endpoint.ChannelResolver = channelResolver;
     IMessage testMessage1 = MessageBuilder.WithPayload("bar").SetReplyChannel(replyChannel1).Build();
     endpoint.HandleMessage(testMessage1);
     IMessage reply1 = replyChannel1.Receive(TimeSpan.FromMilliseconds(50));
     Assert.IsNotNull(reply1);
     Assert.That(reply1.Payload, Is.EqualTo("foobar"));
     IMessage reply2 = replyChannel2.Receive(TimeSpan.Zero);
     Assert.IsNull(reply2);
     IMessage testMessage2 =
         MessageBuilder.FromMessage(testMessage1).SetReplyChannelName("replyChannel2").Build();
     endpoint.HandleMessage(testMessage2);
     reply1 = replyChannel1.Receive(TimeSpan.Zero);
     Assert.IsNull(reply1);
     reply2 = replyChannel2.Receive(TimeSpan.Zero);
     Assert.IsNotNull(reply2);
     Assert.That(reply2.Payload, Is.EqualTo("foobar"));
 }
Esempio n. 2
0
        public void Value_change_shall_be_ignored_if_subproperty_does_not_implement_INotifyPropertyChanged()
        {
            TestObject2 TestObject = new TestObject2 {
                Property = 21
            };
            TestProxy4 TestProxy = new TestProxy4(TestObject);

            Assert.AreEqual(21, TestProxy.Property);

            bool EventCalled = false;

            TestProxy.Property.ToString();
            TestProxy.PropertyChanged += (s, e) => { if (e.PropertyName == "Property")
                                                     {
                                                         EventCalled = true;
                                                     }
            };


            TestObject.Property = 42;

            Assert.IsFalse(EventCalled);

            //Value shall not be changed -> it is cached, no event received, cache not updated
            Assert.AreEqual(21, TestProxy.Property);
        }
Esempio n. 3
0
    void Test2()
    {
        string      jsonString     = "{\"success\":[false,false,false,true],\"hoursSpent\":[5,10.2,15,2],\"author\":[\"vic\",\"vic\",\"vic\",\"vic\"]}";
        TestObject2 expectedResult = new TestObject2(new bool[] { false, false, false, true }, new float[] { 5f, 10.2f, 15f, 2f }, new string[] { "vic", "vic", "vic", "vic" });

        TestObject2 obj = JsonParser.FromJson <TestObject2>(jsonString);

        if (expectedResult.Equals(obj))
        {
            Debug.Log("Reader Test 2 : Success");
        }
        else
        {
            Debug.LogWarning("Reader Test 2 : Failure");
        }

        string json = JsonParser.ToJson <TestObject2>(obj);

        if (jsonString == json)
        {
            Debug.Log("Writer Test 2 : Success");
        }
        else
        {
            Debug.LogWarning(String.Format("Writer Test 2 : Failure : {0}", json));
        }
    }
Esempio n. 4
0
        public void Test2()
        {
            SourceObject so = new SourceObject();
            TestObject2  to = Map.ObjectToObject <TestObject2>(so);

            Assert.AreEqual(true, to.Value);
        }
Esempio n. 5
0
        public void DynamicReplyChannel()
        {
            QueueChannel replyChannel1 = new QueueChannel();
            QueueChannel replyChannel2 = new QueueChannel();

            replyChannel2.ObjectName = "replyChannel2";
            Object handler = new TestObject2();
            ServiceActivatingHandler endpoint        = new ServiceActivatingHandler(handler, "Handle");
            TestChannelResolver      channelResolver = new TestChannelResolver();

            channelResolver.AddChannel(replyChannel2);
            endpoint.ChannelResolver = channelResolver;
            IMessage testMessage1 = MessageBuilder.WithPayload("bar").SetReplyChannel(replyChannel1).Build();

            endpoint.HandleMessage(testMessage1);
            IMessage reply1 = replyChannel1.Receive(TimeSpan.FromMilliseconds(50));

            Assert.IsNotNull(reply1);
            Assert.That(reply1.Payload, Is.EqualTo("foobar"));
            IMessage reply2 = replyChannel2.Receive(TimeSpan.Zero);

            Assert.IsNull(reply2);
            IMessage testMessage2 =
                MessageBuilder.FromMessage(testMessage1).SetReplyChannelName("replyChannel2").Build();

            endpoint.HandleMessage(testMessage2);
            reply1 = replyChannel1.Receive(TimeSpan.Zero);
            Assert.IsNull(reply1);
            reply2 = replyChannel2.Receive(TimeSpan.Zero);
            Assert.IsNotNull(reply2);
            Assert.That(reply2.Payload, Is.EqualTo("foobar"));
        }
Esempio n. 6
0
        public void StructuredChildDictionary()
        {
            var child1 = new Dictionary <string, object>()
            {
                { "X", "A" },
                { "Y", 1 }
            };

            var list1 = new ArrayList()
            {
                "x", child1
            };
            var obj2 = new TestObject2()
            {
                M = "y", N = child1
            };

            var properties = new Dictionary <string, object>()
            {
                { "a", list1 },
                { "@b", obj2 },
            };

            IStructuredData data   = new StructuredData(properties);
            var             actual = data.ToString();

            Assert.AreEqual("a=['x','System.Collections.Generic.Dictionary`2[System.String,System.Object]'] b=(M='y' N='System.Collections.Generic.Dictionary`2[System.String,System.Object]')", actual);
        }
Esempio n. 7
0
        public MFTestResults SystemType9_GetInterfaces_Test()
        {
            /// <summary>
            ///  1. Test the GetInterfaces(String) method
            ///  2. Test the GetInterfaces(String,BindingFlags) method
            ///  This test is currently a stub
            ///  TODO: Write test #2 once bug 17246 is resolved
            /// </summary>
            ///
            bool testResult = true;

            try
            {
                Log.Comment("This tests the GetInterfaces() method");
                Log.Comment("This test must be re-written once BindingFlags is working, ");
                Log.Comment("see 17246 for more details.");

                Type myType1 = Type.GetType("System.Int32");
                Log.Comment("The full name is " + myType1.FullName);
                testResult &= (myType1.GetInterfaces().Length == 0);
                TestObject2 testTestObject2 = new TestObject2(5);
                Type        myType2         = testTestObject2.GetType();
                Log.Comment("The full name is " + myType2.FullName);
                Type myType3 =
                    Type.GetType("Microsoft.SPOT.Platform.Tests.SystemTypeTests+iEmpty");
                testResult &= (myType2.GetInterfaces()[0] == myType3);
            }
            catch (Exception e)
            {
                Log.Comment("Typeless " + e.Message); testResult = false;
            }
            return(testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
Esempio n. 8
0
        public MFTestResults SystemType12_InvokeMember_Test()
        {
            /// <summary>
            ///  1. Test the InvokeMember(String,BindingFlags) method
            ///  This test is currently a stub
            ///  TODO: expand test #1 once bug 17246 is resolved
            /// </summary>
            ///
            bool testResult = true;

            try
            {
                Log.Comment("This tests the InvokeMember(String,BindingFlags) method");
                Log.Comment("This test must be re-written once BindingFlags is working, ");
                Log.Comment("see 17246 for more details.");
                //Assigned and manipulated to avoid compiler warning
                Int32 I = 0;
                I++;
                TestObject2 testTestObject2 = new TestObject2(5);
                Type        myType2         = testTestObject2.GetType();
                Log.Comment("The full name is " + myType2.FullName);
                testResult &= ((int)myType2.InvokeMember("Method2", BindingFlags.Default
                                                         | BindingFlags.InvokeMethod, null, testTestObject2,
                                                         new object[] { -6 }) == -6);
            }
            catch (NotImplementedException)
            {
                return(MFTestResults.KnownFailure);
            }
            catch (Exception e)
            {
                Log.Comment("Typeless " + e.Message); testResult = false;
            }
            return(testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
Esempio n. 9
0
        public void StructuredChildArray()
        {
            var child1 = new ArrayList()
            {
                1, "A"
            };

            var list1 = new ArrayList()
            {
                "x", child1
            };
            var obj2 = new TestObject2()
            {
                M = "y", N = child1
            };
            var dict3 = new Dictionary <string, object>()
            {
                { "P", "z" },
                { "Q", child1 }
            };

            var properties = new Dictionary <string, object>()
            {
                { "a", list1 },
                { "@b", obj2 },
                { "c", dict3 },
            };

            IStructuredData data   = new StructuredData(properties);
            var             actual = data.ToString();

            Assert.AreEqual("a=['x','System.Collections.ArrayList'] b=(M='y' N=[1,'A']) c=(P='z' Q=[1,'A'])", actual);
        }
Esempio n. 10
0
        public void CallsEqualsOverride()
        {
            TestObject2 target = new TestObject2();

            target.Name = "SOME-NAME";
            ProxyFactory pf    = new ProxyFactory(target);
            object       proxy = pf.GetProxy();
            ITestObject  to    = proxy as ITestObject;

            Assert.IsNotNull(to);
            Assert.AreEqual("SOME-NAME", to.Name);

            target.EqualsOverrideWasCalled = false;
            Assert.IsTrue(to.Equals(proxy));
            Assert.IsTrue(target.EqualsOverrideWasCalled);

            target.EqualsOverrideWasCalled = false;
            Assert.IsTrue(proxy.Equals(to));
            Assert.IsTrue(target.EqualsOverrideWasCalled);

            target.EqualsOverrideWasCalled = false;
            Assert.IsTrue(target.Equals(to));
            Assert.IsTrue(target.EqualsOverrideWasCalled);

            target.EqualsOverrideWasCalled = false;
            Assert.IsTrue(to.Equals(target));
            Assert.IsTrue(target.EqualsOverrideWasCalled);
        }
Esempio n. 11
0
        public void SystemType10_GetMethod_Test()
        {
            OutputHelper.WriteLine("This tests the GetMethod(String) method");
            OutputHelper.WriteLine("This test must be re-written once BindingFlags is working, ");
            OutputHelper.WriteLine("see 17246 for more details.");

            Int32 I = 0;

            I++;
            TestObject2 testTestObject2 = new TestObject2(5);
            Type        myType2         = testTestObject2.GetType();

            OutputHelper.WriteLine("The full name is " + myType2.FullName);
            MethodInfo methodInfo1 = myType2.GetMethod("Method2");

            Assert.Equal(methodInfo1.IsAbstract, false);
            Assert.Equal(methodInfo1.IsFinal, false);
            Assert.Equal(methodInfo1.IsPublic, true);
            Assert.Equal(methodInfo1.IsStatic, false);
            Assert.Equal(methodInfo1.IsVirtual, false);
            Assert.True(methodInfo1.MemberType == MemberTypes.Method);
            Assert.Equal(methodInfo1.Name, "Method2");
            Assert.IsType(methodInfo1.ReturnType, I.GetType());
            Assert.IsType(methodInfo1.DeclaringType, myType2);
            Assert.Equal((int)(methodInfo1.Invoke(testTestObject2, new object[] { 1 })), 1);
        }
Esempio n. 12
0
        public void Locks_Only_Modified_Tables_When_Different_datalyer()
        {
            using (var application = SequenceGeneratorModule().Application){
                var defaultDataLayer1  = NewSimpleDataLayer(application);
                var explicitUnitOfWork = new ExplicitUnitOfWork(defaultDataLayer1);
                var testObject         = new TestObject(explicitUnitOfWork);
                explicitUnitOfWork.FlushChanges();

                var defaultDataLayer2   = NewSimpleDataLayer(application);
                var explicitUnitOfWork1 = new ExplicitUnitOfWork(defaultDataLayer2);
                var testObject2         = new TestObject2(explicitUnitOfWork1);
                explicitUnitOfWork1.FlushChanges();

                Should.Throw <ShouldCompleteInException>(() => Should.CompleteIn(
                                                             () => explicitUnitOfWork.GetObjectByKey <TestObject2>(testObject2.Oid).ShouldNotBeNull(),
                                                             TimeSpan.FromSeconds(1)));
                Should.Throw <ShouldCompleteInException>(() => Should.CompleteIn(
                                                             () => explicitUnitOfWork1.GetObjectByKey <TestObject>(testObject.Oid).ShouldNotBeNull(),
                                                             TimeSpan.FromSeconds(1)));
                explicitUnitOfWork.Close();
                defaultDataLayer1.Dispose();
                explicitUnitOfWork1.Close();
                defaultDataLayer2.Dispose();
            }
        }
Esempio n. 13
0
        public MFTestResults SystemType5_GetConstructor_Test()
        {
            /// <summary>
            ///  1. Tests the GetConstructor(Type[]) method for a user defined type
            /// </summary>
            ///
            bool testResult = true;

            try
            {
                Log.Comment("This tests the GetConstructor(Type[]) method");
                TestObject2 testTestObject2 = new TestObject2(5);
                Type        myType2         = testTestObject2.GetType();
                Log.Comment("The full name is " + myType2.FullName);
                Type[]      typeOfInt32Arr  = new Type[] { Type.GetType("System.Int32") };
                object[]    value5Arr       = new object[] { 5 };
                TestObject2 testTestObject3 =
                    (TestObject2)myType2.GetConstructor(typeOfInt32Arr).Invoke(value5Arr);
                testResult &= (testTestObject2.m_data == testTestObject3.m_data);
            }
            catch (Exception e)
            {
                Log.Comment("Typeless " + e.Message);
                testResult = false;
            }

            return(testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
Esempio n. 14
0
        public void TestPrivate()
        {
            TestObject2 o = (TestObject2)TypeAccessor.CreateInstance(typeof(TestObject2));

            o.ID = 1;

            Assert.AreEqual("ID", o.NotifiedName);
        }
Esempio n. 15
0
        public void ThrowsIfObjectsDoNotHaveSameType()
        {
            var obj1 = new TestObject1();
            var obj2 = new TestObject2();
            var sut  = new ObjectComparer();

            sut.Compare(obj1, obj2);
        }
Esempio n. 16
0
        public async Task ElasticBand_methods_should_index_get_query_and_delete_documents_in_elasticsearch_for_type_TestObject2()
        {
            // Decide the index name and instantiate an ElasticBand...
            var index       = "testindex2";
            var elasticBand = new ElasticBand(new DefaultHttpClientFactory(), new ElasticQueryBuilder());

            elasticBand.SetElasticsearchUrl("https://localhost:9200");
            elasticBand.SetElasticsearchAuthentication("B0pGRnABUbqCwsoaMxi0:gexHoph8SnK_HpTuLkOgtw");

            elasticBand.GetClient().DeleteAsync(index).Wait();

            // Create some objects to index
            var object1 = new TestObject2 {
                Name = "Andrew", Birthday = new DateTime(2019, 2, 7)
            };
            var object2 = new TestObject2 {
                Name = "James", Birthday = new DateTime(2019, 7, 27)
            };
            var object3 = new TestObject2 {
                Name = "Drew", Birthday = new DateTime(2019, 1, 9)
            };

            // Index the objects, optionally pass in an id, if omitted a new Guid will be generated...
            var indexResponse1 = await elasticBand.Index <TestObject2>(index, object1, "id1");

            var indexResponse2 = await elasticBand.Index <TestObject2>(index, object2, "id2");

            var indexResponse3 = await elasticBand.Index <TestObject2>(index, object3, "id3");

            // Speedy lookup if you know an id...
            var getResponse1 = await elasticBand.GetDocumentByID <TestObject2>(index, "id2");

            // Update a property and re-index...
            getResponse1.Data.Name = "Jamie";
            await elasticBand.Index <TestObject2>(index, getResponse1.Data, "id2");

            await Task.Delay(1000); // Give ES a chance to internally update the indicies

            // Query in various ways...
            var queryResult1 = await elasticBand.Query <TestObject2>(index, "Jamie");

            var queryResult2 = await elasticBand.Query <TestObject2>(index, "name:Drew");

            var queryResult3 = await elasticBand.Query <TestObject2>(index, "birthday>2019-03-01");

            var queryResult4 = await elasticBand.Query <TestObject2>(index, "birthday<2019-03-01T09:05:00");

            var queryResult5 = await elasticBand.Query <TestObject2>(index, "*rew");

            // Delete...
            await elasticBand.Delete(index, "id2");

            Assert.That(queryResult1.Data.Count, Is.EqualTo(1));
            Assert.That(queryResult2.Data.Count, Is.EqualTo(1));
            Assert.That(queryResult3.Data.Count, Is.EqualTo(1));
            Assert.That(queryResult4.Data.Count, Is.EqualTo(2));
            Assert.That(queryResult5.Data.Count, Is.EqualTo(2));
        }
Esempio n. 17
0
        public void Dependecy_ValueObject2_ExpFalse()
        {
            ITestObject valeur = new TestObject2();

            ClassToTest.TestObject = valeur;
            bool ExpResult = false;
            bool result    = ClassToTest.IsEnabled();

            Assert.AreEqual(ExpResult, result);
        }
        public void ParamTest()
        {
            TestObject2 o = (TestObject2)TypeAccessor.CreateInstance(typeof(TestObject2));

            Assert.AreEqual(10, o.List.Capacity);
            Assert.AreEqual("test", o.Str);
            Assert.AreEqual(50, o.Field1.Value);
            Assert.AreEqual(77, o.Field2.Value);
            Assert.AreEqual(55, o.InnerObject.Field);
        }
        public void Test()
        {
            TestObject2 o = TypeAccessor <TestObject2> .Instance.Create();

            int i  = o.Int1;
            int?i2 = o.Int2;

            o.Int1 = 5;
            o.Int2 = 6;
        }
Esempio n. 20
0
        public void Serialize_ComplexClass_ReturnsString()
        {
            //ARRANGE
            TestObject2 underTest = new TestObject2();
            var         dumper    = new ObjectDumper();
            //ACT
            var result = dumper.Serialize(underTest);

            //ASSERT
            Assert.AreEqual("Value=1         Text=abc\r\n", result);
        }
Esempio n. 21
0
        public MFTestResults SystemType11_GetMethods_Test()
        {
            /// <summary>
            ///  1. Test the GetMethods(String) method
            ///  2. Test the GetMethods(String,BindingFlags) method
            ///  This test is currently a stub
            ///  TODO: Write test #2 once bug 17246 is resolved
            /// </summary>
            ///
            bool testResult = true;

            try
            {
                Log.Comment("This tests the GetMethods() method");
                Log.Comment("This test must be re-written once BindingFlags is working, ");
                Log.Comment("see 17246 for more details.");

                //Assigned and manipulated to avoid compiler warning
                Int32 I = 0;
                I++;

                TestObject2 testTestObject2 = new TestObject2(5);
                Type        myType2         = testTestObject2.GetType();
                Log.Comment("The full name is " + myType2.FullName);
                MethodInfo[] methodInfoArr1 = myType2.GetMethods();
                MethodInfo   methodInfo1    = null;
                if (methodInfoArr1[0].Name == "Method2")
                {
                    methodInfo1 = methodInfoArr1[0];
                    Log.Comment("Method2 found in position 0");
                }
                else if (methodInfoArr1[1].Name == "Method2")
                {
                    methodInfo1 = methodInfoArr1[1];
                    Log.Comment("Method2 found in position 1");
                }
                testResult &= (methodInfo1.IsAbstract == false);
                testResult &= (methodInfo1.IsFinal == false);
                testResult &= (methodInfo1.IsPublic == true);
                testResult &= (methodInfo1.IsStatic == false);
                testResult &= (methodInfo1.IsVirtual == false);
                testResult &= (methodInfo1.MemberType == MemberTypes.Method);
                testResult &= (methodInfo1.Name == "Method2");
                testResult &= (methodInfo1.ReturnType == I.GetType());
                testResult &= (methodInfo1.DeclaringType == myType2);
                testResult &=
                    ((int)(methodInfo1.Invoke(testTestObject2, new object[] { 1 })) == 1);
            }
            catch (Exception e)
            {
                Log.Comment("Typeless " + e.Message); testResult = false;
            }
            return(testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
Esempio n. 22
0
    public TestObject()
    {
        Address = "710 Grove Dr";
        Object2 = new TestObject2();
        TestObject2 object22 = new TestObject2();
        TestObject2 object23 = new TestObject2();

        Twos = new Dictionary <string, TestObject2>();
        Twos.Add("1", object22);
        Twos.Add("2", object23);
    }
Esempio n. 23
0
        public void ComplexType()
        {
            var obj1 = new TestObject2 { PropX = "xyz", PropY = new TestObject1 { Prop1 = "abc", Prop2 = 123 } };
              var obj2 = new TestObject2 { PropX = "zyx", PropY = new TestObject1 { Prop1 = "abc", Prop2 = 345 } };
              var sut = new ObjectComparer();

              var result = sut.Compare(obj1, obj2).ToList();

              Assert.AreEqual(3, result.Count());
              CheckComparison(result[0], ComparisonResult.NotEqual, ".PropX", "xyz", "zyx");
              CheckComparison(result[1], ComparisonResult.Equal, ".PropY.Prop1", "abc", "abc");
              CheckComparison(result[2], ComparisonResult.NotEqual, ".PropY.Prop2", 123, 345);
        }
Esempio n. 24
0
        public void SystemType7_GetField_Test()
        {
            OutputHelper.WriteLine("This tests the GetField(String) ");
            OutputHelper.WriteLine("and the GetField(String,BindingFlags) methods)");
            OutputHelper.WriteLine("Currently this test fails, see 17246 for more details.");

            Type myType1 = Type.GetType("System.Int32");

            OutputHelper.WriteLine("The full name is " + myType1.FullName);
            Assert.True(myType1.GetField("m_data") == null);

            OutputHelper.WriteLine(" TestObject2 type has one data member \"m_data\" of type Int32.");
            TestObject2 testTestObject2 = new TestObject2(5);
            Type        myType2         = testTestObject2.GetType();

            OutputHelper.WriteLine("The full name is " + myType2.FullName);

            OutputHelper.WriteLine(" Check that type of m_data is Int32");
            Assert.IsType(myType2.GetField("m_data", BindingFlags.GetField |
                                           BindingFlags.Public | BindingFlags.Instance).FieldType, myType1);

            OutputHelper.WriteLine(" Check that value in m_data is 5 ( becuase we called new TestObject2(5))");
            Assert.Equal((int)myType2.GetField("m_data", BindingFlags.IgnoreCase |
                                               BindingFlags.GetField | BindingFlags.Public |
                                               BindingFlags.Instance).GetValue(testTestObject2), 5);

            OutputHelper.WriteLine(" Check that m_data  is a field");
            Assert.True(myType2.GetField("m_data").MemberType == MemberTypes.Field);

            OutputHelper.WriteLine(" Check that field m_data has Name \"m_data\"");
            Assert.Equal(myType2.GetField("m_data").Name, "m_data");

            OutputHelper.WriteLine(" Check that  misspelling of m_data return NULL.");
            Assert.True(null == myType2.GetField("data"));

            OutputHelper.WriteLine(" Checks that case misspelling of m_data return NULL if flag BindingFlags.IgnoreCase not specified.");
            Assert.True(null == myType2.GetField("m_Data"));

            OutputHelper.WriteLine("Check retrieval with BindingFlags.IgnoreCase. If flag BindingFlags.IgnoreCase is ised, then the case should be ignored. We should get the same type information.");
            FieldInfo fInfo_m_Data = myType2.GetField("m_Data", BindingFlags.IgnoreCase | BindingFlags.GetField | BindingFlags.Public | BindingFlags.Instance);
            FieldInfo fInfo_m_data = myType2.GetField("m_data");

            Assert.NotNull(fInfo_m_Data);
            Assert.NotNull(fInfo_m_data);
            Assert.True(fInfo_m_Data.Name.Equals(fInfo_m_data.Name));

            OutputHelper.WriteLine(" Indirectly set m_data in testTestObject2 to 6 and then check it.");
            myType2.GetField("m_data").SetValue(testTestObject2, 6);
            Assert.Equal((int)myType2.GetField("m_data").GetValue(testTestObject2), 6);
            Assert.Equal(testTestObject2.m_data, 6);
        }
Esempio n. 25
0
        public void SystemType5_GetConstructor_Test()
        {
            OutputHelper.WriteLine("This tests the GetConstructor(Type[]) method");
            TestObject2 testTestObject2 = new TestObject2(5);
            Type        myType2         = testTestObject2.GetType();

            OutputHelper.WriteLine("The full name is " + myType2.FullName);
            Type[]      typeOfInt32Arr  = new Type[] { Type.GetType("System.Int32") };
            object[]    value5Arr       = new object[] { 5 };
            TestObject2 testTestObject3 =
                (TestObject2)myType2.GetConstructor(typeOfInt32Arr).Invoke(value5Arr);

            Assert.Equal(testTestObject2.m_data, testTestObject3.m_data);
        }
Esempio n. 26
0
        public void TestWritePortableArray()
        {
            var ss           = new SerializationServiceBuilder(new NullLoggerFactory()).SetInitialOutputBufferSize(16).Build();
            var testObject2s = new TestObject2[100];

            for (var i = 0; i < testObject2s.Length; i++)
            {
                testObject2s[i] = new TestObject2();
            }

            var testObject1 = new TestObject1(testObject2s);

            ss.ToData(testObject1);
        }
Esempio n. 27
0
        public void Test2()
        {
            TestObject2 o = (TestObject2)TypeAccessor.CreateInstance(typeof(TestObject2));

            Assert.AreEqual(10, o.Value);

            o = (TestObject2)TypeAccessor.CreateInstance(typeof(TestObject2), null);
            Assert.AreEqual(10, o.Value);

            InitContext ic = new InitContext();

            ic.Parameters = new object[] { 30 };
            o             = (TestObject2)TypeAccessor.CreateInstance(typeof(TestObject2), ic);
            Assert.AreEqual(10, o.Value);
        }
Esempio n. 28
0
        public void MethodTest()
        {
            TestObject2 o = TypeAccessor.CreateInstance <TestObject2>();

            Assert.AreEqual(27, o.IntValue);
            o.IntValue += 8;
            Assert.AreEqual(35, o.IntValue);

            o.FloatValue  = 0.1f;
            o.FloatValue *= 2.0f;
            Assert.AreEqual(0.2f, o.FloatValue);

            o.StrValue  = "foo";
            o.StrValue += "Bar";
            Assert.AreEqual("fooBar", o.StrValue);
        }
Esempio n. 29
0
        public void FieldDataContractConvertObject()
        {
            var obj = new TestObject2()
            {
                Name = "Jackpot!",
            };
            var datum = testObject2Converter.ConvertObject(obj);

            Assert.That(datum.type, Is.EqualTo(Datum.DatumType.R_OBJECT));
            Assert.That(datum.r_object.Count, Is.EqualTo(1));

            var pair = datum.r_object[0];

            Assert.That(pair.key, Is.EqualTo("name"));
            Assert.That(pair.val.type, Is.EqualTo(Datum.DatumType.R_STR));
            Assert.That(pair.val.r_str, Is.EqualTo("Jackpot!"));
        }
Esempio n. 30
0
        public void ReturnsEqualForIntProperty()
        {
            const int VALUE = 123;

            var obj1 = new TestObject2 {
                Prop1 = VALUE
            };
            var obj2 = new TestObject2 {
                Prop1 = VALUE
            };
            var sut = new ObjectComparer();

            var result = sut.Compare(obj1, obj2).ToList();

            Assert.AreEqual(1, result.Count);
            CheckComparison(result[0], ComparisonResult.Equal, ".Prop1", VALUE, VALUE);
        }
Esempio n. 31
0
        public void EditablObjectParamTest()
        {
            TestObject2 o = (TestObject2)TypeAccessor.CreateInstance(typeof(TestObject2), new InitContext());

            Assert.That(o.List.Capacity, Is.EqualTo(10));
            Assert.That(o.Str, Is.EqualTo("t"));
            Assert.That(o.Field1.Value, Is.EqualTo(50));
            Assert.That(o.Field2.Value, Is.EqualTo(77));
            Assert.That(o.InnerObject1.Field, Is.EqualTo(55));
            Assert.That(o.Int1, Is.EqualTo(54));
            Assert.That(o.Int2, Is.EqualTo(null));
            Assert.That(o.Date, Is.EqualTo(new DateTime(2, 2, 2)));
            Assert.That(o.Decimal1, Is.EqualTo(222m));
            Assert.That(o.Decimal2, Is.EqualTo(-0.01m));
            Assert.That(o.Decimal3, Is.EqualTo(2m));
            Assert.That(o.Decimal4, Is.EqualTo(22.05m));
            Assert.That(o.Decimal5, Is.EqualTo(null));
        }
Esempio n. 32
0
        public void SystemType9_GetInterfaces_Test()
        {
            OutputHelper.WriteLine("This tests the GetInterfaces() method");
            OutputHelper.WriteLine("This test must be re-written once BindingFlags is working, ");
            OutputHelper.WriteLine("see 17246 for more details.");

            Type myType1 = Type.GetType("System.Int32");

            OutputHelper.WriteLine("The full name is " + myType1.FullName);
            Assert.Equal(myType1.GetInterfaces().Length, 0);
            TestObject2 testTestObject2 = new TestObject2(5);
            Type        myType2         = testTestObject2.GetType();

            OutputHelper.WriteLine("The full name is " + myType2.FullName);
            Type myType3 =
                Type.GetType("NFUnitTestSystemLib.UnitTestTypeTests+iEmpty");

            Assert.IsType(myType2.GetInterfaces()[0], myType3);
        }
Esempio n. 33
0
        public void ThrowsIfObjectsDoNotHaveSameType()
        {
            var obj1 = new TestObject1();
              var obj2 = new TestObject2();
              var sut = new ObjectComparer();

              sut.Compare(obj1, obj2);
        }
Esempio n. 34
0
        public void CallsEqualsOverride()
        {
            TestObject2 target = new TestObject2();
            target.Name = "SOME-NAME";
            ProxyFactory pf = new ProxyFactory(target);
            object proxy = pf.GetProxy();
            ITestObject to = proxy as ITestObject;
            Assert.IsNotNull(to);
            Assert.AreEqual("SOME-NAME", to.Name);

            target.EqualsOverrideWasCalled = false;
            Assert.IsTrue(to.Equals(proxy));
            Assert.IsTrue(target.EqualsOverrideWasCalled);

            target.EqualsOverrideWasCalled = false;
            Assert.IsTrue(proxy.Equals(to));
            Assert.IsTrue(target.EqualsOverrideWasCalled);

            target.EqualsOverrideWasCalled = false;
            Assert.IsTrue(target.Equals(to));
            Assert.IsTrue(target.EqualsOverrideWasCalled);

            target.EqualsOverrideWasCalled = false;
            Assert.IsTrue(to.Equals(target));
            Assert.IsTrue(target.EqualsOverrideWasCalled);
        }
Esempio n. 35
0
 public MFTestResults SystemType12_InvokeMember_Test()
 {
     /// <summary>
     ///  1. Test the InvokeMember(String,BindingFlags) method
     ///  This test is currently a stub
     ///  TODO: expand test #1 once bug 17246 is resolved
     /// </summary>
     ///
     bool testResult = true;
     try
     {
         Log.Comment("This tests the InvokeMember(String,BindingFlags) method");
         Log.Comment("This test must be re-written once BindingFlags is working, ");
         Log.Comment("see 17246 for more details.");
         //Assigned and manipulated to avoid compiler warning
         Int32 I = 0;
         I++;
         TestObject2 testTestObject2 = new TestObject2(5);
         Type myType2 = testTestObject2.GetType();
         Log.Comment("The full name is " + myType2.FullName);
         testResult &= ((int)myType2.InvokeMember("Method2", BindingFlags.Default
             | BindingFlags.InvokeMethod, null, testTestObject2,
             new object[] { -6 }) == -6);
     }
     catch (NotImplementedException)
     {
         return MFTestResults.KnownFailure;
     }
     catch (Exception e)
     {
         Log.Comment("Typeless " + e.Message); testResult = false;
     }
     return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
 }
Esempio n. 36
0
        public MFTestResults SystemType11_GetMethods_Test()
        {
            /// <summary>
            ///  1. Test the GetMethods(String) method
            ///  2. Test the GetMethods(String,BindingFlags) method
            ///  This test is currently a stub
            ///  TODO: Write test #2 once bug 17246 is resolved
            /// </summary>
            ///
            bool testResult = true;
            try
            {
                Log.Comment("This tests the GetMethods() method");
                Log.Comment("This test must be re-written once BindingFlags is working, ");
                Log.Comment("see 17246 for more details.");

                //Assigned and manipulated to avoid compiler warning
                Int32 I = 0;
                I++;

                TestObject2 testTestObject2 = new TestObject2(5);
                Type myType2 = testTestObject2.GetType();
                Log.Comment("The full name is " + myType2.FullName);
                MethodInfo[] methodInfoArr1 = myType2.GetMethods();
                MethodInfo methodInfo1 = null;
                if (methodInfoArr1[0].Name == "Method2")
                {
                    methodInfo1 = methodInfoArr1[0];
                    Log.Comment("Method2 found in position 0");
                }
                else if (methodInfoArr1[1].Name == "Method2")
                {
                    methodInfo1 = methodInfoArr1[1];
                    Log.Comment("Method2 found in position 1");
                }
                testResult &= (methodInfo1.IsAbstract == false);
                testResult &= (methodInfo1.IsFinal == false);
                testResult &= (methodInfo1.IsPublic == true);
                testResult &= (methodInfo1.IsStatic == false);
                testResult &= (methodInfo1.IsVirtual == false);
                testResult &= (methodInfo1.MemberType == MemberTypes.Method);
                testResult &= (methodInfo1.Name == "Method2");
                testResult &= (methodInfo1.ReturnType == I.GetType());
                testResult &= (methodInfo1.DeclaringType == myType2);
                testResult &=
                    ((int)(methodInfo1.Invoke(testTestObject2, new object[] { 1 })) == 1);
            }
            catch (Exception e)
            {
                Log.Comment("Typeless " + e.Message); testResult = false;
            }
            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
Esempio n. 37
0
        public MFTestResults SystemType9_GetInterfaces_Test()
        {
            /// <summary>
            ///  1. Test the GetInterfaces(String) method
            ///  2. Test the GetInterfaces(String,BindingFlags) method
            ///  This test is currently a stub
            ///  TODO: Write test #2 once bug 17246 is resolved
            /// </summary>
            ///
            bool testResult = true;
            try
            {
                Log.Comment("This tests the GetInterfaces() method");
                Log.Comment("This test must be re-written once BindingFlags is working, ");
                Log.Comment("see 17246 for more details.");

                Type myType1 = Type.GetType("System.Int32");
                Log.Comment("The full name is " + myType1.FullName);
                testResult &= (myType1.GetInterfaces().Length == 0);
                TestObject2 testTestObject2 = new TestObject2(5);
                Type myType2 = testTestObject2.GetType();
                Log.Comment("The full name is " + myType2.FullName);
                Type myType3 =
                    Type.GetType("Microsoft.SPOT.Platform.Tests.SystemTypeTests+iEmpty");
                testResult &= (myType2.GetInterfaces()[0] == myType3);
            }
            catch (Exception e)
            {
                Log.Comment("Typeless " + e.Message); testResult = false;
            }
            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
Esempio n. 38
0
        public MFTestResults SystemType8_GetFields_Test()
        {
            /// <summary>
            ///  1. Test the GetFields(String) method
            ///  2. Test the GetFields(String,BindingFlags) method
            ///  This test is currently a stub
            ///  TODO: Write test #2 once bug 17246 is resolved
            /// </summary>
            ///
            bool testResult = true;
            try
            {
                Log.Comment("This tests the GetFields(String) method");
                Log.Comment("This test must be re-written once BindingFlags is working, ");
                Log.Comment("see 17246 for more details.");

                Type myType1 = Type.GetType("System.Int32");
                Log.Comment("The full name is " + myType1.FullName);
                testResult &= (myType1.GetField("m_data") == null);
                TestObject2 testTestObject2 = new TestObject2(5);
                Type myType2 = testTestObject2.GetType();
                Log.Comment("The full name is " + myType2.FullName);
                testResult &= (myType2.GetField("m_data").FieldType == myType1);
                testResult &= ((int)myType2.GetField("m_data").GetValue(testTestObject2) == 5);
                testResult &= (myType2.GetField("m_data").MemberType == MemberTypes.Field);
                testResult &= (myType2.GetField("m_data").Name == "m_data");
                myType2.GetField("m_data").SetValue(testTestObject2, 6);
                testResult &= ((int)myType2.GetField("m_data").GetValue(testTestObject2) == 6);
            }
            catch (Exception e)
            {
                Log.Comment("Typeless " + e.Message); testResult = false;
            }
            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
Esempio n. 39
0
        public MFTestResults SystemType7_GetField_Test()
        {
            /// <summary>
            ///  1. Test the GetField(String) method
            ///  2. Test the GetField(String,BindingFlags) method
            ///  TODO: Expand test #2 once bug 17246 is resolved
            /// </summary>
            ///
            bool testResult = true;
            try
            {
                Log.Comment("This tests the GetField(String) ");
                Log.Comment("and the GetField(String,BindingFlags) methods)");
                Log.Comment("Currently this test fails, see 17246 for more details.");

                Type myType1 = Type.GetType("System.Int32");
                Log.Comment("The full name is " + myType1.FullName);
                testResult &= (myType1.GetField("m_data") == null);

                Log.Comment(" TestObject2 type has one data member \"m_data\" of type Int32.");
                TestObject2 testTestObject2 = new TestObject2(5);
                Type myType2 = testTestObject2.GetType();           
                Log.Comment("The full name is " + myType2.FullName);
                
                Log.Comment(" Check that type of m_data is Int32");
                testResult &= (myType2.GetField("m_data", BindingFlags.GetField | 
                    BindingFlags.Public | BindingFlags.Instance).FieldType == myType1);

                Log.Comment(" Check that value in m_data is 5 ( becuase we called new TestObject2(5))");
                testResult &= ((int)myType2.GetField("m_data", BindingFlags.IgnoreCase | 
                    BindingFlags.GetField | BindingFlags.Public | 
                    BindingFlags.Instance).GetValue(testTestObject2) == 5);
                if ( !testResult ) { Log.Exception( " Last test failed " ); }
                                                                          
                Log.Comment(" Check that m_data  is a field");
                testResult &= (myType2.GetField("m_data").MemberType == MemberTypes.Field);
                if (!testResult) { Log.Exception(" Last test failed "); }

                Log.Comment(" Check that field m_data has Name \"m_data\"");
                testResult &= (myType2.GetField("m_data").Name == "m_data");
                if (!testResult) { Log.Exception(" Last test failed "); }

                Log.Comment(" Check that  misspelling of m_data return NULL.");
                testResult &= null == myType2.GetField("data");
                if (!testResult) { Log.Exception(" Last test failed "); }

                Log.Comment(" Checks that case misspelling of m_data return NULL if flag BindingFlags.IgnoreCase not specified."); 
                testResult &= null == myType2.GetField("m_Data");
                if (!testResult) { Log.Exception(" Last test failed "); }

                Log.Comment("Check retrieval with BindingFlags.IgnoreCase. If flag BindingFlags.IgnoreCase is ised, then the case should be ignored. We should get the same type information."); 
                FieldInfo fInfo_m_Data = myType2.GetField("m_Data", BindingFlags.IgnoreCase | BindingFlags.GetField | BindingFlags.Public | BindingFlags.Instance);
                FieldInfo fInfo_m_data = myType2.GetField("m_data");
                testResult &= fInfo_m_Data != null && fInfo_m_data != null;
                testResult &= fInfo_m_Data.Name.Equals( fInfo_m_data.Name );
                if (!testResult) { Log.Exception(" Last test failed "); }

                Log.Comment(" Indirectly set m_data in testTestObject2 to 6 and then check it.");
                myType2.GetField("m_data").SetValue(testTestObject2, 6);
                testResult &= ((int)myType2.GetField("m_data").GetValue(testTestObject2) == 6);
                testResult &= testTestObject2.m_data == 6;
                if (!testResult) { Log.Exception(" Last test failed "); }
            }
            // In case of exceptions we log it and set testResult = false;
            catch (NullReferenceException e)
            {
                Log.Comment("NullRef " + e.Message);
                testResult = false;
            }
            catch (Exception e)
            {
                Log.Comment("Typeless " + e.Message); 
                testResult = false;
            }
            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
Esempio n. 40
0
        public MFTestResults SystemType5_GetConstructor_Test()
        {
            /// <summary>
            ///  1. Tests the GetConstructor(Type[]) method for a user defined type
            /// </summary>
            ///
            bool testResult = true;
            try
            {
                Log.Comment("This tests the GetConstructor(Type[]) method");
                TestObject2 testTestObject2 = new TestObject2(5);
                Type myType2 = testTestObject2.GetType();
                Log.Comment("The full name is " + myType2.FullName);
                Type[] typeOfInt32Arr = new Type[] { Type.GetType("System.Int32") };
                object[] value5Arr = new object[] { 5 };
                TestObject2 testTestObject3 = 
                    (TestObject2)myType2.GetConstructor(typeOfInt32Arr).Invoke(value5Arr);
                testResult &= (testTestObject2.m_data == testTestObject3.m_data);

            }
            catch (Exception e)
            {
                Log.Comment("Typeless " + e.Message); 
                testResult = false;
            }

            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
Esempio n. 41
0
        public void ReturnsEqualForIntProperty()
        {
            const int VALUE = 123;

              var obj1 = new TestObject2 { Prop1 = VALUE };
              var obj2 = new TestObject2 { Prop1 = VALUE };
              var sut = new ObjectComparer();

              var result = sut.Compare(obj1, obj2).ToList();

              Assert.AreEqual(1, result.Count);
              CheckComparison(result[0], ComparisonResult.Equal, ".Prop1", VALUE, VALUE);
        }
        public void Test_Issue2172_WritePortableArray()
        {
            var ss = new SerializationServiceBuilder().SetInitialOutputBufferSize(16).Build();
            var testObject2s = new TestObject2[100];
            for (var i = 0; i < testObject2s.Length; i++)
            {
                testObject2s[i] = new TestObject2();
            }

            var testObject1 = new TestObject1(testObject2s);
            ss.ToData(testObject1);
        }