public void Transform_UpdateDocument_To_Delta_Containing_ComplexObject() { // Arrange var dimensions = new Dimensions() { Height = "80mm", Width = "10mm" }; var updateDocument = new UpdateDocument { Data = new SingleResource() { Id = "123", Type = "product", Attributes = new Dictionary <string, object>() { { "name", "Widget" }, { "dimensions", dimensions } } } }; var config = TestModelConfigurationBuilder.BuilderForEverything.Build(); var context = new Context(new Uri("http://fakehost:1234", UriKind.Absolute)); var transformer = new JsonApiTransformerBuilder().With(config).Build(); // Act var resultDelta = transformer.TransformBack(updateDocument, typeof(Product), context); // Assert Assert.True(resultDelta.ObjectPropertyValues.ContainsKey("name")); Assert.True(resultDelta.ObjectPropertyValues.ContainsKey("dimensions")); Assert.Equal(dimensions, resultDelta.ObjectPropertyValues["dimensions"]); }
public void Transform_UpdateDocument_To_Delta_TwoFields() { // Arrange var updateDocument = new UpdateDocument { Data = new SingleResource() { Id = "123", Type = "post", Attributes = new Dictionary <string, object>() { { "title", "someTitle" }, { "authorId", "1234" }, } } }; var config = TestModelConfigurationBuilder.BuilderForEverything.Build(); var context = new Context(new Uri("http://fakehost:1234", UriKind.Absolute)); var transformer = new JsonApiTransformerBuilder().With(config).Build(); // Act var resultDelta = transformer.TransformBack(updateDocument, typeof(Post), context); // Assert Assert.True(resultDelta.ObjectPropertyValues.ContainsKey("Title")); Assert.True(resultDelta.ObjectPropertyValues.ContainsKey("AuthorId")); }
public void Transform_UpdateDocument_To_Delta_Containing_ListAttribute() { //DS: TODO - should widgetParts be provided as a JArray? // Arrange var widgetParts = new List <WidgetPart>() { new WidgetPart() { PartNumber = "WIDGET-001" }, new WidgetPart() { PartNumber = "WIDGET-002" } }; var updateDocument = new UpdateDocument { Data = new SingleResource() { Id = "123", Type = "widget", Attributes = new Dictionary <string, object>() { { "name", "A widget" }, { "parts", widgetParts } } } }; var config = TestModelConfigurationBuilder.BuilderForEverything.Build(); var context = new Context(new Uri("http://fakehost:1234", UriKind.Absolute)); var transformer = new JsonApiTransformerBuilder().With(config).Build(); // Act var resultDelta = transformer.TransformBack(updateDocument, typeof(Widget), context); // Assert Assert.True(resultDelta.ObjectPropertyValues.ContainsKey("name")); Assert.True(resultDelta.ObjectPropertyValues.ContainsKey("parts")); Assert.Equal(resultDelta.ObjectPropertyValues["parts"], widgetParts); }