Exemplo n.º 1
0
        public void TestApplyPatchOnIndividualProperty()
        {
            // clear respository
            this.ClearRepository("DeltaTests_Todoes");

            this.Client.GetStringAsync(this.BaseAddress + "/$metadata").Wait();

            Random r = new Random(RandomSeedGenerator.GetRandomSeed());

            var s = new CreatorSettings()
            {
                NullValueProbability = 0.0,
                MaxArrayLength       = 100
            };

            // post new entity to repository
            var todo = InstanceCreator.CreateInstanceOf <DeltaTests_TodoClient>(r, s);

            todo.NullableBool = true;
            todo.NullableInt  = 100000;
            todo.Enum         = "One";
            todo.Estimation   = new DeltaTests_Estimation()
            {
                CompletedBy   = new DateTime(2012, 10, 18),
                EstimatedTime = TimeSpan.FromDays(1)
            };
            todo.XElement = @"<a><b/></a>";
            DataServiceContext ctx = WriterClient(new Uri(this.BaseAddress), ODataProtocolVersion.V4);

            ctx.ResolveName = ResolveName;
            ctx.ResolveType = ResolveType;
            ctx.AddObject("DeltaTests_Todoes", todo);
            ctx.SaveChangesAsync().Wait();

            int id = todo.ID;

            //todo.ID = InstanceCreator.CreateInstanceOf<int>(r, s);
            todo.Name                   = InstanceCreator.CreateInstanceOf <string>(r, s);
            todo.Enum                   = "Two";
            todo.NullableBool           = null;
            todo.Items                  = InstanceCreator.CreateInstanceOf <DeltaTests_TodoItems>(r, s);
            todo.Tags                   = InstanceCreator.CreateInstanceOf <List <DeltaTests_TodoTag> >(r, s);
            todo.Estimation.CompletedBy = new DateTime(2012, 11, 18);
            todo.NullableInt            = 999999;

            todo.Bool           = InstanceCreator.CreateInstanceOf <bool>(r, s);
            todo.Byte           = InstanceCreator.CreateInstanceOf <Byte>(r, s);
            todo.ByteArray      = InstanceCreator.CreateInstanceOf <byte[]>(r, s);
            todo.DateTime       = InstanceCreator.CreateInstanceOf <DateTime>(r, s);
            todo.DateTimeOffset = InstanceCreator.CreateInstanceOf <DateTimeOffset>(r, s);
            todo.Decimal        = InstanceCreator.CreateInstanceOf <Decimal>(r, s);
            todo.Double         = InstanceCreator.CreateInstanceOf <Double>(r, s);
            todo.Float          = InstanceCreator.CreateInstanceOf <float>(r, s);
            todo.Guid           = InstanceCreator.CreateInstanceOf <Guid>(r, s);
            todo.Integer        = InstanceCreator.CreateInstanceOf <Int32>(r, s);
            todo.Long           = InstanceCreator.CreateInstanceOf <long>(r, s);
            todo.Short          = InstanceCreator.CreateInstanceOf <short>(r, s);
            todo.String         = InstanceCreator.CreateInstanceOf <string>(r, s);
            todo.TimeSpan       = InstanceCreator.CreateInstanceOf <TimeSpan>(r, s);
            todo.XElement       = @"<b><a/></b>";

            ctx.UpdateObject(todo);
            ctx.SaveChangesAsync().Wait();

            ctx             = ReaderClient(new Uri(this.BaseAddress), ODataProtocolVersion.V4);
            ctx.ResolveName = ResolveName;
            ctx.ResolveType = ResolveType;

            var query   = ctx.CreateQuery <DeltaTests_TodoClient>("DeltaTests_Todoes");
            var results = query.ExecuteAsync().Result;
            var actual  = results.Where(t => t.ID == id).First();

            //Assert.Equal(id, actual.ID);
            Assert.Equal(todo.Name, actual.Name);
            Assert.Equal(todo.Estimation.CompletedBy, actual.Estimation.CompletedBy);
            Assert.Equal(todo.Estimation.EstimatedTime, actual.Estimation.EstimatedTime);
            Assert.Equal(todo.NullableBool, actual.NullableBool);
            Assert.Equal(todo.NullableInt, actual.NullableInt);

            Assert.Equal(todo.Bool, actual.Bool);
            Assert.Equal(todo.Byte, actual.Byte);
            Assert.Equal(todo.ByteArray, actual.ByteArray);
            Assert.Equal(todo.DateTime, actual.DateTime);
            Assert.Equal(todo.DateTimeOffset, actual.DateTimeOffset);
            Assert.Equal(todo.Decimal, actual.Decimal);
            AssertExtension.DoubleEqual(todo.Double, actual.Double);
            AssertExtension.SingleEqual(todo.Float, actual.Float);
            Assert.Equal(todo.Guid, actual.Guid);
            Assert.Equal(todo.Integer, actual.Integer);
            Assert.Equal(todo.Long, actual.Long);
            Assert.Equal(todo.Short, actual.Short);
            Assert.Equal(todo.String, actual.String);
            Assert.Equal(todo.TimeSpan, actual.TimeSpan);
            Assert.Equal(todo.XElement.Replace(" ", string.Empty).Replace(Environment.NewLine, string.Empty),
                         actual.XElement.Replace(" ", string.Empty).Replace(Environment.NewLine, string.Empty));

            // clear respository
            this.ClearRepository("DeltaTests_Todoes");
        }