Esempio n. 1
0
        public void Creates_CompoundDocument_for_single_not_nested_class_and_properly_do_not_suppress_nullable_properties()
        {
            // Arrange
            var context = CreateContext();
            SampleClassWithNullableProperty objectToTransform = CreateObjectWithNullPropertyToTransform();
            var transformer = new JsonApiTransformerBuilder()
                              .With(CreateConfiguration())
                              .Build();

            // Act
            CompoundDocument result = transformer.Transform(objectToTransform, context);

            // Assert
            var transformedObject = result.Data as SingleResource;

            Assert.Equal(transformedObject.Attributes["someValue"], objectToTransform.SomeValue);
            Assert.Equal(transformedObject.Attributes["date"], null);
            Assert.Equal(transformedObject.Attributes.Count, 2);
        }
Esempio n. 2
0
        public void Creates_CompoundDocument_for_single_not_nested_class_and_properly_suppress_nullable_properties()
        {
            // Arrange
            var context = CreateContext();
            SampleClassWithNullableProperty objectToTransform = CreateObjectWithNullPropertyToTransform();
            var config = CreateConfiguration();

            config.GetJsonSerializerSettings().NullValueHandling = NullValueHandling.Ignore;
            var transformer = new JsonApiTransformerBuilder()
                              .With(config)
                              .Build();

            // Act
            CompoundDocument result = transformer.Transform(objectToTransform, context);

            // Assert
            var transformedObject = result.Data as SingleResource;

            Assert.Equal(transformedObject.Attributes["someValue"], objectToTransform.SomeValue);
            Assert.False(transformedObject.Attributes.ContainsKey("date"));
            Assert.Equal(transformedObject.Attributes.Count, 1);
        }