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


C# Test.SimpleDTOWithNestedDTO类代码示例

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


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

示例1: ReplacePropertyInNestedObject

        public void ReplacePropertyInNestedObject()
        {
            // Arrange
            var doc = new SimpleDTOWithNestedDTO()
            {
                IntegerValue = 1
            };

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

            // Act
            patchDoc.ApplyTo(doc);

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

示例2: AddResultsInReplace

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

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

            // Act
            patchDoc.ApplyTo(doc);

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

示例3: ReplacePropertyInNestedObjectWithSerialization

        public void ReplacePropertyInNestedObjectWithSerialization()
        {
            // Arrange
            var doc = new SimpleDTOWithNestedDTO()
            {
                IntegerValue = 1
            };

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

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

            // Act
            deserialized.ApplyTo(doc);

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

示例4: AddResultsInReplaceWithSerialization

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

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

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

            // Act
            deserialized.ApplyTo(doc);

            // Assert
            Assert.Equal("B", doc.SimpleDTO.StringProperty);
        }
开发者ID:slideroom,项目名称:JsonPatch,代码行数:24,代码来源:NestedObjectTests.cs

示例5: ReplaceInListWithSerialization

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

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

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

            // Act
            deserialized.ApplyTo(doc);

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

示例6: SerializationTests

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

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

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

            // Act
            deserizalized.ApplyTo(doc);

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

示例7: RemoveFromListInvalidPositionTooSmall_LogsError

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

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

            var logger = new TestErrorLogger<SimpleDTOWithNestedDTO>();

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

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

示例8: RemoveFromListInvalidPositionTooLarge_LogsError

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

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

            var logger = new TestErrorLogger<SimpleDTOWithNestedDTO>();

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

            // Assert
            Assert.Equal(
                "For operation 'remove' on array property at path '/simpledto/integerlist/3', the index is " +
                    "larger than the array size.",
                logger.ErrorMessage);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:26,代码来源:NestedObjectTests.cs

示例9: Remove

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

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
            patchDoc.Remove<string>(o => o.SimpleDTO.StringProperty);

            // Act
            patchDoc.ApplyTo(doc);

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

示例10: AddToListInvalidPositionTooSmall

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

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

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

示例11: MoveFomListToNonListBetweenHierarchy

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

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

            // Act
            patchDoc.ApplyTo(doc);

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

示例12: MoveWithSerialization

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

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

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

            // Act
            deserialized.ApplyTo(doc);

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

示例13: CopyFromNonListToList

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

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

            // Act
            patchDoc.ApplyTo(doc);

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

示例14: Copy

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

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

            // Act
            patchDoc.ApplyTo(doc);

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

示例15: ReplaceFullListWithCollection

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

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

            // Act
            patchDoc.ApplyTo(doc);

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


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