本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}