Ejemplo n.º 1
0
        public void TestInitialize()
        {
            this.testFieldObject = new SimpleField
            {
                boolField = true,
                floatField = 1.2f,
                integerField = 5,
                stringField = "test"
            };

            this.testPropertyObject = new SimpleProperty(true, "test", 1.2f)
            {
                StringProperty = "test",
                IntegerProperty = 5,
                FloatProperty = 1.2f,
                BoolProperty = true,
                ActualNameInJsonAttribute = 5
            };

            this.testComplexObject = new ComplexObject()
            {
                TestBoolean = true,
                testField = 1.2f,
                NestedObject = new NestedObject() { testfield = "test", TestProperty = 5 }
            };

            this.changer = new UntypedObjectChanger();
        }
Ejemplo n.º 2
0
        public void supportToEncodeAggregateObjectsAsMembers()
        {
            Formatter.Encoder<List<string>>((path, list) => string.Join(" ", list));

            var co = new ComplexObject { Encoded = new List<string>(){"Hello", "World"}};

            var encoded = Formatter.Encode(co);
            Assert.That(encoded, Is.EqualTo("Encoded=\"Hello World\""));
        }
Ejemplo n.º 3
0
      public void NullCollectionIsPreserved()
      {
         var expected = new ComplexObject();
         byte[] data = Serializer.Serialize(expected);
         var actual = Deserializer.Deserialize<ComplexObject>(data);

         Assert.Equal(null, actual.Security);
         Assert.Equal(0, actual.Roles.Count);
      }
Ejemplo n.º 4
0
      public void CollectionsAreLossless()
      {
         var expected = new ComplexObject
                           {
                              Security = new[] {'a', 'z', '4', '*'},
                           };
         expected.Roles.Add("abc123");
         expected.Roles.Add("lkasdk");
         byte[] data = Serializer.Serialize(expected);
         var actual = Deserializer.Deserialize<ComplexObject>(data);

         Assert.Equal(expected.Security, actual.Security);
         Assert.Equal(expected.Roles, actual.Roles);
      }
Ejemplo n.º 5
0
      public void ProcessIsLossless()
      {
         var expected = new ComplexObject
                           {
                              Enabled = true,
                              Id = 433,
                              Name = "Goku"
                           };
         byte[] data = Serializer.Serialize(expected);
         var actual = Deserializer.Deserialize<ComplexObject>(data);

         Assert.Equal(true, actual.Enabled);
         Assert.Equal(433, actual.Id);
         Assert.Equal("Goku", actual.Name);
         Assert.Equal(null, actual.Initial);
         Assert.Equal(null, actual.Description);
      }
Ejemplo n.º 6
0
      public void IgnoredPropertiesArentPreserved()
      {
         LittleConfiguration.ForType<ComplexObject>(c => c.Ignore(u => u.Name).Ignore(u => u.Id));

         var expected = new ComplexObject
                           {
                              Enabled = false,
                              Id = 433,
                              Initial = 'z',
                              Name = "Goku"
                           };
         byte[] data = Serializer.Serialize(expected);
         var actual = Deserializer.Deserialize<ComplexObject>(data);

         Assert.Equal(false, actual.Enabled);
         Assert.Equal(0, actual.Id);
         Assert.Equal(null, actual.Name);
         Assert.Equal('z', actual.Initial);
         Assert.Equal(null, actual.Description);
      }
        public void ShouldBeAbleToDequeueAComplexObjectAfterDisposeAndRecreation()
        {
            var queue = this.CreateNew();
            var item = new ComplexObject { SomeTextProperty = "text lololo", SomeInt32Property = 123456 };

            queue.Enqueue(item);

            queue.Dispose();
            using (var newQueue = this.Create(queue.Name))
            {
                var dequeueItem = newQueue.Dequeue();

                dequeueItem.CastTo<ComplexObject>().Should().Equals(item);
            }
        }
Ejemplo n.º 8
0
		public void MethodWithObjectValidator()
		{
			ExpectFail(delegate
			           	{
			           		service.MethodWithObject("invalid", new ComplexObject());
			           	}, 3);

			ComplexObject complex = new ComplexObject();
			complex.Id = 1;

			ExpectFail(delegate
			           	{
			           		service.MethodWithObject("4111-1111-1111-1111", complex);
			           	}, 1);

			complex.Names = new string[] { "valid" };

			service.MethodWithObject("4111-1111-1111-1111", complex);
		}
Ejemplo n.º 9
0
        public void SerializeComplextObject()
        {
            var serializer = new ProtobufObjectSerializer();
            var stream = new MemoryStream();
            var obj = new ComplexObject { Prop1 = new DataV1 { Prop1 = 1 }, Prop2 = new DataV2 { Prop1 = 2 } };
            serializer.WriteObject(stream, obj);
            Assert.IsTrue(stream.ToArray().Length > 0);
            stream.Position = 0;
            var deserialized = (ComplexObject)serializer.ReadObject(stream, typeof(ComplexObject));

            Assert.IsNotNull(deserialized);
            Assert.IsNotNull(deserialized.Prop1);
            Assert.IsNotNull(deserialized.Prop2);
        }
Ejemplo n.º 10
0
 private ComplexObject Overloaded(ComplexObject t)
 {
     return new ComplexObject();
 }
 public IActionResult Post([FromBody] ComplexObject obj)
 {
     return(Ok());
 }
Ejemplo n.º 12
0
        private void AssertComplexObjectEqual(ComplexObject expectedValues, ComplexObject actualValues)
        {
            Assert.AreNotEqual(expectedValues, actualValues);

            Assert.AreEqual(expectedValues.TestBoolean, actualValues.TestBoolean);
            Assert.AreEqual(expectedValues.testField, actualValues.testField);

            if (expectedValues.NestedObject != null)
            {
                Assert.AreEqual(expectedValues.NestedObject.TestProperty, actualValues.NestedObject.TestProperty);
                Assert.AreEqual(expectedValues.NestedObject.testfield, expectedValues.NestedObject.testfield);
            }
            else
            {
                Assert.IsNull(actualValues.NestedObject);
            }
        }
Ejemplo n.º 13
0
        private void AnimateRace(Camera camera, ComplexObject redCar, ComplexObject greenCar, float redRadius)
        {
            var distance = Math.Max(_redDistance, _greenDistance / _greenMultipleFactor);

            if (distance >= 0)
            {
                camera.Rotation = new Vector3(0, -(float)Math.PI / 2, 0);
                camera.Position = new Vector3(1.1f, 0.1f, 4.8f);
                distance       -= 2;
            }

            if (distance > 0)
            {
                camera.Rotation = new Vector3(0, (float)Math.PI / 2, 0);
                distance       -= 5;
            }

            if (distance > 0)
            {
                camera.Position = new Vector3(5, 4, 2);
                var direction        = camera.Position - redCar.Position;
                var vectorY          = new Vector3(direction.X, 0, direction.Z);
                var defaultDirection = -Vector3.UnitZ;

                var angleX = Vector3.CalculateAngle(direction, vectorY);

                var angleY = Vector3.CalculateAngle(vectorY, defaultDirection);
                if (vectorY.X > 0)
                {
                    angleY = 2 * (float)Math.PI - angleY;
                }

                camera.Rotation = new Vector3(angleX, angleY, 0);
                distance       -= (float)Math.PI * redRadius;
            }

            if (distance > 0)
            {
                camera.Position = redCar.Position;

                camera.Position += new Vector3(-0.2f, 0.3f, 0.5f);
                camera.Rotation  = new Vector3(0, (float)Math.PI, 0);

                distance -= 10;
            }
            if (distance > 0)
            {
                camera.Position = new Vector3(-8, 0.4f, -4);
                var direction        = camera.Position - redCar.Position;
                var vectorY          = new Vector3(direction.X, 0, direction.Z);
                var defaultDirection = -Vector3.UnitZ;

                var angleX = Vector3.CalculateAngle(direction, vectorY);

                var angleY = Vector3.CalculateAngle(vectorY, defaultDirection);
                if (vectorY.X > 0)
                {
                    angleY = 2 * (float)Math.PI - angleY;
                }

                camera.Rotation = new Vector3(angleX, angleY, 0);
                distance       -= (float)Math.PI * redRadius / 2;
            }

            if (distance > 0)
            {
                camera.Position = new Vector3(-8, 0.4f, 4);
                var direction        = camera.Position - redCar.Position;
                var vectorY          = new Vector3(direction.X, 0, direction.Z);
                var defaultDirection = -Vector3.UnitZ;

                var angleX = Vector3.CalculateAngle(direction, vectorY);

                var angleY = Vector3.CalculateAngle(vectorY, defaultDirection);
                if (vectorY.X > 0)
                {
                    angleY = 2 * (float)Math.PI - angleY;
                }

                camera.Rotation = new Vector3(angleX, angleY, 0);
                distance       -= (float)Math.PI * redRadius / 2 + 2;
            }

            if (distance > 0)
            {
                camera.Position = new Vector3(0, 0.2f, 6);
                camera.Rotation = new Vector3(0, (float)Math.PI, 0);
            }
        }
Ejemplo n.º 14
0
        public void TestPingComplexModelOutAndRefSerialization(SoapSerializer soapSerializer)
        {
            var sampleServiceClient = _fixture.GetSampleServiceClient(soapSerializer);

            _fixture.ServiceMock
            .Setup(x => x.PingComplexModelOutAndRef(
                       It.IsAny <ComplexModel1>(),
                       It.IsAny <string[]>(),
                       ref It.Ref <ComplexModel2> .IsAny,
                       It.IsAny <ComplexObject>(),
                       ref It.Ref <ComplexModel1> .IsAny,
                       It.IsAny <ComplexObject>(),
                       out It.Ref <ComplexModel2> .IsAny,
                       out It.Ref <ComplexModel1> .IsAny))
            .Callback(new PingComplexModelOutAndRefCallback(
                          (
                              ComplexModel1 inputModel_service,
                              string[] inputArrayParam,
                              ref ComplexModel2 responseModelRef1_service,
                              ComplexObject data1_service,
                              ref ComplexModel1 responseModelRef2_service,
                              ComplexObject data2_service,
                              out ComplexModel2 responseModelOut1_service,
                              out ComplexModel1 responseModelOut2_service) =>
            {
                // check input paremeters serialization
                inputModel_service.ShouldDeepEqual(ComplexModel1.CreateSample2());
                responseModelRef1_service.ShouldDeepEqual(ComplexModel2.CreateSample1());
                responseModelRef2_service.ShouldDeepEqual(ComplexModel1.CreateSample2());
                data1_service.ShouldDeepEqual(ComplexObject.CreateSample1());
                data2_service.ShouldDeepEqual(ComplexObject.CreateSample2());

                //sample response
                responseModelRef1_service = ComplexModel2.CreateSample2();
                responseModelRef2_service = ComplexModel1.CreateSample1();
                responseModelOut1_service = ComplexModel2.CreateSample3();
                responseModelOut2_service = ComplexModel1.CreateSample1();
            }))
            .Returns(true);

            var responseModelRef1_client = ComplexModel2.CreateSample1();
            var responseModelRef2_client = ComplexModel1.CreateSample2();

            var pingComplexModelOutAndRefResult_client =
                sampleServiceClient.PingComplexModelOutAndRef(
                    ComplexModel1.CreateSample2(),
                    new string[0],
                    ref responseModelRef1_client,
                    ComplexObject.CreateSample1(),
                    ref responseModelRef2_client,
                    ComplexObject.CreateSample2(),
                    out var responseModelOut1_client,
                    out var responseModelOut2_client);

            // check output paremeters serialization
            pingComplexModelOutAndRefResult_client.ShouldBeTrue();
            responseModelRef1_client.ShouldDeepEqual(ComplexModel2.CreateSample2());
            responseModelRef2_client.ShouldDeepEqual(ComplexModel1.CreateSample1());
            responseModelOut1_client.ShouldDeepEqual(ComplexModel2.CreateSample3());
            responseModelOut2_client.ShouldDeepEqual(ComplexModel1.CreateSample1());
        }
Ejemplo n.º 15
0
        public ComplexObject GetComplexObjectWithComplexParameterFifeenSecondCacheAbsoluteNinetySeconds(ComplexObject obj)
        {
            NumberOfCalls++;
            var newObject = new ComplexObject();

            newObject.Ints = obj.Ints;

            return(newObject);
        }
Ejemplo n.º 16
0
        public void TestToJson_ComplexObject()
        {
            var input = new ComplexObject
            {
                ParentId = 456,
                ChildObject = new TestObject {  IntProperty = 123, StringProperty = "Some String" }
            };

            var output = input.ToJson();

            Assert.AreEqual(output, "{\"ParentId\":456,\"ChildObject\":{\"IntProperty\":123,\"StringProperty\":\"Some String\"}}");
        }
Ejemplo n.º 17
0
        public void TestToJson_ComplexObjectWithNullChild()
        {
            var input = new ComplexObject
            {
                ParentId = 456,
                ChildObject = null
            };

            var output = input.ToJson();

            Assert.AreEqual(output, "{\"ParentId\":456,\"ChildObject\":null}");
        }
 public ComplexObjectHttpClientFactory(ComplexObject response)
 {
     _response = response;
 }
Ejemplo n.º 19
0
        public void Serialize_Can_Serialize_Complex_Static_Type()
        {
            var testObject = new ComplexObject
                                 {
                                     IntValue = 1,
                                     ListValue = new List<SimpleObject>
                                                     {
                                                         new SimpleObject
                                                             {
                                                                 Test = "test"
                                                             }
                                                     },
                                     ObjectValue = new SimpleObject
                                                       {
                                                           Test = "test"
                                                       },
                                     StringValue = "test"
                                 };

            var serialized = jsonParser.Serialize(testObject);

            serialized.ShouldEqual("{\"StringValue\":\"test\",\"IntValue\":1,\"ObjectValue\":{\"Test\":\"test\"},\"ListValue\":[{\"Test\":\"test\"}]}");
        }
        public void CanCreateComplexObject()
        {
            string document = ComplexObject.Create();

            Assert.Equal("{}", document);
        }