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


C# Test.SimpleDTO类代码示例

本文整理汇总了C#中Microsoft.AspNet.JsonPatch.Test.SimpleDTO的典型用法代码示例。如果您正苦于以下问题:C# SimpleDTO类的具体用法?C# SimpleDTO怎么用?C# SimpleDTO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SimpleDTO类属于Microsoft.AspNet.JsonPatch.Test命名空间,在下文中一共展示了SimpleDTO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddResultsShouldReplace

        public void AddResultsShouldReplace()
        {
            // Arrange
            var doc = new SimpleDTO()
            {
                StringProperty = "A"
            };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Add<string>(o => o.StringProperty, "B");

            // Act
            patchDoc.ApplyTo(doc);

            // Assert
            Assert.Equal("B", doc.StringProperty);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:18,代码来源:ObjectAdapterTests.cs

示例2: AddToList

        public void AddToList()
        {
            // Arrange
            var doc = new SimpleDTO()
            {
                IntegerList = new List<int>() { 1, 2, 3 }
            };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Add<int>(o => o.IntegerList, 4, 0);

            // Act
            patchDoc.ApplyTo(doc);

            // Assert
            Assert.Equal(new List<int>() { 4, 1, 2, 3 }, doc.IntegerList);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:18,代码来源:ObjectAdapterTests.cs

示例3: AddResultsShouldReplaceWithSerialization

        public void AddResultsShouldReplaceWithSerialization()
        {
            // Arrange
            var doc = new SimpleDTO()
            {
                StringProperty = "A"
            };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Add<string>(o => o.StringProperty, "B");

            var serialized = JsonConvert.SerializeObject(patchDoc);
            var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTO>>(serialized);

            // Act
            deserialized.ApplyTo(doc);

            // Assert
            Assert.Equal("B", doc.StringProperty);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:21,代码来源:ObjectAdapterTests.cs

示例4: AddToListWithSerialization

        public void AddToListWithSerialization()
        {
            // Arrange
            var doc = new SimpleDTO()
            {
                IntegerList = new List<int>() { 1, 2, 3 }
            };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Add<int>(o => o.IntegerList, 4, 0);

            var serialized = JsonConvert.SerializeObject(patchDoc);
            var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTO>>(serialized);

            // Act
            deserialized.ApplyTo(doc);

            // Assert
            Assert.Equal(new List<int>() { 4, 1, 2, 3 }, doc.IntegerList);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:21,代码来源:ObjectAdapterTests.cs

示例5: MoveToEndOfList

        public void MoveToEndOfList()
        {
            // Arrange
            var doc = new SimpleDTO()
            {
                IntegerValue = 5,
                IntegerList = new List<int>() { 1, 2, 3 }
            };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Move<int>(o => o.IntegerValue, o => o.IntegerList);

            // Act
            patchDoc.ApplyTo(doc);

            // Assert
            Assert.Equal(0, doc.IntegerValue);
            Assert.Equal(new List<int>() { 1, 2, 3, 5 }, doc.IntegerList);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:20,代码来源:ObjectAdapterTests.cs

示例6: RemoveFromListInvalidPositionTooSmallWithSerialization

        public void RemoveFromListInvalidPositionTooSmallWithSerialization()
        {
            // Arrange
            var doc = new SimpleDTO()
            {
                IntegerList = new List<int>() { 1, 2, 3 }
            };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Remove<int>(o => o.IntegerList, -1);

            var serialized = JsonConvert.SerializeObject(patchDoc);
            var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTO>>(serialized);

            // Act & Assert
            var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() => { deserialized.ApplyTo(doc); });
            Assert.Equal("Property does not exist at path '/integerlist/-1'.", exception.Message);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:19,代码来源:ObjectAdapterTests.cs

示例7: AddToListInvalidPositionTooSmall_LogsError

        public void AddToListInvalidPositionTooSmall_LogsError()
        {
            // Arrange
            var doc = new SimpleDTO()
            {
                IntegerList = new List<int>() { 1, 2, 3 }
            };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Add<int>(o => o.IntegerList, 4, -1);

            var logger = new TestErrorLogger<SimpleDTO>();

            patchDoc.ApplyTo(doc, logger.LogErrorMessage);
             
            // Assert
            Assert.Equal(
                "For operation 'add' on array property at path '/integerlist/-1', the index is negative.",
                logger.ErrorMessage);
        }
开发者ID:ryanbrandenburg,项目名称:Mvc,代码行数:21,代码来源:ObjectAdapterTests.cs

示例8: ReplaceFullListFromEnumerable

        public void ReplaceFullListFromEnumerable()
        {
            // Arrange
            var doc = new SimpleDTO()
            {
                IntegerList = new List<int>() { 1, 2, 3 }
            };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Replace<IEnumerable<int>>(o => o.IntegerList, new List<int>() { 4, 5, 6 });

            // Act
            patchDoc.ApplyTo(doc);

            // Assert
            Assert.Equal(new List<int>() { 4, 5, 6 }, doc.IntegerList);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:18,代码来源:ObjectAdapterTests.cs

示例9: SerializeAndReplaceGuidTest

        public void SerializeAndReplaceGuidTest()
        {
            // Arrange
            var doc = new SimpleDTO()
            {
                GuidValue = Guid.NewGuid()
            };

            var newGuid = Guid.NewGuid();
            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Replace(o => o.GuidValue, newGuid);

            // serialize & deserialize
            var serialized = JsonConvert.SerializeObject(patchDoc);
            var deserizalized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTO>>(serialized);

            // Act
            deserizalized.ApplyTo(doc);

            // Assert
            Assert.Equal(newGuid, doc.GuidValue);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:23,代码来源:ObjectAdapterTests.cs

示例10: Replace

        public void Replace()
        {
            // Arrange
            var doc = new SimpleDTO()
            {
                StringProperty = "A",
                DecimalValue = 10
            };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Replace<string>(o => o.StringProperty, "B");

            patchDoc.Replace(o => o.DecimalValue, 12);

            // Act
            patchDoc.ApplyTo(doc);

            // Assert
            Assert.Equal("B", doc.StringProperty);
            Assert.Equal(12, doc.DecimalValue);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:22,代码来源:ObjectAdapterTests.cs

示例11: SerializationMustNotIncudeEnvelope

        public void SerializationMustNotIncudeEnvelope()
        {
            // Arrange
            var doc = new SimpleDTO()
            {
                StringProperty = "A",
                DecimalValue = 10,
                DoubleValue = 10,
                FloatValue = 10,
                IntegerValue = 10
            };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Replace(o => o.StringProperty, "B");
            patchDoc.Replace(o => o.DecimalValue, 12);
            patchDoc.Replace(o => o.DoubleValue, 12);
            patchDoc.Replace(o => o.FloatValue, 12);
            patchDoc.Replace(o => o.IntegerValue, 12);

            // Act
            var serialized = JsonConvert.SerializeObject(patchDoc);

            // Assert
            Assert.Equal(false, serialized.Contains("operations"));
            Assert.Equal(false, serialized.Contains("Operations"));
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:27,代码来源:ObjectAdapterTests.cs

示例12: MoveFomListToNonList

        public void MoveFomListToNonList()
        {
            // Arrange
            var doc = new SimpleDTO()
            {
                IntegerList = new List<int>() { 1, 2, 3 }
            };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Move<int>(o => o.IntegerList, 0, o => o.IntegerValue);

            // Act
            patchDoc.ApplyTo(doc);

            // Assert
            Assert.Equal(new List<int>() { 2, 3 }, doc.IntegerList);
            Assert.Equal(1, doc.IntegerValue);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:19,代码来源:ObjectAdapterTests.cs

示例13: RemoveFromListInvalidPositionTooSmall_LogsError

        public void RemoveFromListInvalidPositionTooSmall_LogsError()
        {
            // Arrange
            var doc = new SimpleDTO()
            {
                IntegerList = new List<int>() { 1, 2, 3 }
            };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Remove<int>(o => o.IntegerList, -1);

            var logger = new TestErrorLogger<SimpleDTO>();

            // Act
            patchDoc.ApplyTo(doc, logger.LogErrorMessage);

            // Assert
            Assert.Equal("Property does not exist at path '/integerlist/-1'.", logger.ErrorMessage);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:20,代码来源:ObjectAdapterTests.cs

示例14: Copy

        public void Copy()
        {
            // Arrange
            var doc = new SimpleDTO()
            {
                StringProperty = "A",
                AnotherStringProperty = "B"
            };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Copy<string>(o => o.StringProperty, o => o.AnotherStringProperty);

            // Act
            patchDoc.ApplyTo(doc);

            // Assert
            Assert.Equal("A", doc.AnotherStringProperty);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:19,代码来源:ObjectAdapterTests.cs

示例15: MoveWithSerialization

        public void MoveWithSerialization()
        {
            // Arrange
            var doc = new SimpleDTO()
            {
                StringProperty = "A",
                AnotherStringProperty = "B"
            };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Move<string>(o => o.StringProperty, o => o.AnotherStringProperty);

            var serialized = JsonConvert.SerializeObject(patchDoc);
            var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTO>>(serialized);

            // Act
            deserialized.ApplyTo(doc);

            // Assert
            Assert.Equal("A", doc.AnotherStringProperty);
            Assert.Equal(null, doc.StringProperty);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:23,代码来源:ObjectAdapterTests.cs


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