本文整理汇总了C#中Microsoft.AspNet.JsonPatch.Test.SimpleDTO类的典型用法代码示例。如果您正苦于以下问题:C# SimpleDTO类的具体用法?C# SimpleDTO怎么用?C# SimpleDTO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SimpleDTO类属于Microsoft.AspNet.JsonPatch.Test命名空间,在下文中一共展示了SimpleDTO类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: AddToListInvalidPositionTooLarge
public void AddToListInvalidPositionTooLarge()
{
// 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, 4);
// Act & Assert
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() => { patchDoc.ApplyTo(doc); });
Assert.Equal(
"For operation 'add' on array property at path '/integerlist/4', the index is " +
"larger than the array size.",
exception.Message);
}
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:19,代码来源:ObjectAdapterTests.cs
示例17: CopyFromNonListToList
public void CopyFromNonListToList()
{
// Arrange
var doc = new SimpleDTO()
{
IntegerValue = 5,
IntegerList = new List<int>() { 1, 2, 3 }
};
// create patch
var patchDoc = new JsonPatchDocument<SimpleDTO>();
patchDoc.Copy<int>(o => o.IntegerValue, o => o.IntegerList, 0);
// Act
patchDoc.ApplyTo(doc);
// Assert
Assert.Equal(new List<int>() { 5, 1, 2, 3 }, doc.IntegerList);
}
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:19,代码来源:ObjectAdapterTests.cs
示例18: CopyFromListToNonListWithSerialization
public void CopyFromListToNonListWithSerialization()
{
// Arrange
var doc = new SimpleDTO()
{
IntegerList = new List<int>() { 1, 2, 3 }
};
// create patch
var patchDoc = new JsonPatchDocument<SimpleDTO>();
patchDoc.Copy<int>(o => o.IntegerList, 0, o => o.IntegerValue);
var serialized = JsonConvert.SerializeObject(patchDoc);
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTO>>(serialized);
// Act
deserialized.ApplyTo(doc);
// Assert
Assert.Equal(1, doc.IntegerValue);
}
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:21,代码来源:ObjectAdapterTests.cs
示例19: RemoveFromEndOfList
public void RemoveFromEndOfList()
{
// 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);
// Act
patchDoc.ApplyTo(doc);
// Assert
Assert.Equal(new List<int>() { 1, 2 }, doc.IntegerList);
}
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:18,代码来源:ObjectAdapterTests.cs
示例20: MoveToEndOfListWithSerialization
public void MoveToEndOfListWithSerialization()
{
// 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);
var serialized = JsonConvert.SerializeObject(patchDoc);
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTO>>(serialized);
// Act
deserialized.ApplyTo(doc);
// Assert
Assert.Equal(0, doc.IntegerValue);
Assert.Equal(new List<int>() { 1, 2, 3, 5 }, doc.IntegerList);
}
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:23,代码来源:ObjectAdapterTests.cs
注:本文中的Microsoft.AspNet.JsonPatch.Test.SimpleDTO类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论