當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。