public void Creates_CompondDocument_for_collection_not_nested_class_and_propertly_map_properties() { // Arrange var context = CreateContext(); IEnumerable<SampleClass> objectsToTransform = CreateObjectToTransform(); var transformer = new JsonApiTransformerBuilder() .With(CreateConfiguration()) .Build(); // Act CompoundDocument result = transformer.Transform(objectsToTransform, context); // Assert var transformedObject = result.Data as ResourceCollection; Action<SingleResource, SampleClass> assertSame = (actual, expected) => { Assert.Equal(actual.Attributes["someValue"], expected.SomeValue); Assert.Equal(actual.Attributes["date"], expected.DateTime); Assert.Equal(actual.Attributes.Count(), 2); }; assertSame(transformedObject[0], objectsToTransform.First()); assertSame(transformedObject[1], objectsToTransform.Last()); }
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 Creates_CompondDocument_for_metadatawrapper_single_not_nested_class_and_propertly_map_type() { // Arrange var context = CreateContext(); MetaDataWrapper<SampleClass> objectToTransform = CreateObjectToTransform(); var transfomer = new JsonApiTransformerBuilder() .With(CreateConfiguration()) .Build(); // Act CompoundDocument result = transfomer.Transform(objectToTransform, context); // Assert var transformedObject = result.Data as SingleResource; Assert.Equal(transformedObject.Type, "sampleClasses"); }
public void Creates_CompondDocument_for_single_not_nested_class_and_propertly_map_id() { // Arrange var context = CreateContext(); SampleClass objectToTransform = CreateObjectToTransform(); var transformer = new JsonApiTransformerBuilder() .With(CreateConfiguration()) .Build(); // Act CompoundDocument result = transformer.Transform(objectToTransform, context); // Assert var transformedObject = result.Data as SingleResource; Assert.Equal(transformedObject.Id, objectToTransform.Id.ToString()); }
public void Serilized_properly() { // Arrange var context = CreateContext(); var objectToTransform = CreateObjectToTransform(); var transformer = new JsonApiTransformerBuilder() .With(CreateConfiguration()) .Build(); var transformed = transformer.Transform(objectToTransform, context); // Act var json = JsonConvert.SerializeObject(transformed); // Assert Assert.DoesNotContain(json, "Data"); }
public void Creates_CompondDocument_for_collection_not_nested_class_and_propertly_map_id() { // Arrange var configuration = CreateContext(); IEnumerable<SampleClass> objectsToTransform = CreateObjectToTransform(); var transformer = new JsonApiTransformerBuilder() .With(CreateConfiguration()) .Build(); // Act CompoundDocument result = transformer.Transform(objectsToTransform, configuration); // Assert var transformedObject = result.Data as ResourceCollection; Assert.Equal(transformedObject[0].Id, objectsToTransform.First().Id.ToString()); Assert.Equal(transformedObject[1].Id, objectsToTransform.Last().Id.ToString()); }
public void Creates_CompondDocument_for_collection_not_nested_single_class() { // Arrange var configuration = CreateContext(); IEnumerable<SampleClass> objectsToTransform = CreateObjectToTransform().Take(1); var transformer = new JsonApiTransformerBuilder() .With(CreateConfiguration()) .Build(); // Act CompoundDocument result = transformer.Transform(objectsToTransform, configuration); // Assert Assert.NotNull(result.Data); var transformedObject = result.Data as ResourceCollection; Assert.NotNull(transformedObject); }
public void Creates_CompondDocument_for_metadatawrapper_single_not_nested_class_and_propertly_map_properties() { // Arrange var context = CreateContext(); MetaDataWrapper<SampleClass> objectToTransform = CreateObjectToTransform(); var transfomer = new JsonApiTransformerBuilder() .With(CreateConfiguration()) .Build(); // Act CompoundDocument result = transfomer.Transform(objectToTransform, context); // Assert var transformedObject = result.Data as SingleResource; Assert.Equal(transformedObject.Attributes["someValue"], objectToTransform.Value.SomeValue); Assert.Equal(transformedObject.Attributes["date"], objectToTransform.Value.DateTime); Assert.Equal(transformedObject.Attributes.Count, 2); }
public void Creates_CompondDocument_for_metadatawrapper_single_not_nested_class_and_propertly_map_metadata() { // Arrange const string pagingValue = "1"; const string countValue = "2"; var context = CreateContext(); MetaDataWrapper<SampleClass> objectToTransform = CreateObjectToTransform(); objectToTransform.MetaData.Add("Paging", pagingValue); objectToTransform.MetaData.Add("Count", countValue); var transfomer = new JsonApiTransformerBuilder() .With(CreateConfiguration()) .Build(); // Act CompoundDocument result = transfomer.Transform(objectToTransform, context); // Assert var transformedObjectMetadata = result.Meta; Assert.Equal(transformedObjectMetadata["Paging"], pagingValue); Assert.Equal(transformedObjectMetadata["Count"], countValue); }
public void Creates_CompondDocument_for_collectione_of_metadatawrapper_throws_notSupportedException() { // Arrange var configuration = CreateContext(); var objectsToTransform = new List<MetaDataWrapper<SampleClass>> { new MetaDataWrapper<SampleClass>(new SampleClass()) }; var transformer = new JsonApiTransformerBuilder().Build(); // Act => Assert Assert.Throws<NotSupportedException>(() => transformer.Transform(objectsToTransform, configuration)); }
private JsonApiActionFilter GetActionFilterForTestModel() { var config = TestModelConfigurationBuilder.BuilderForEverything.Build(); var transformer = new JsonApiTransformerBuilder().With(config).Build(); return new JsonApiActionFilter(transformer, config, JsonSerializerBuilder.Build()); }