Ejemplo n.º 1
0
    public void CanDumpObjectUsingDelegateTransform()
    {
        // Arrange
        var input = new MyType {
            Name = "John Doe", Age = 21, Weight = 80.1
        };
        var transform = new DelegateTransform(i => i is MyType myType
            ? new
        {
            myType.Name,
            myType.Age,
            myType.Weight,
            AdditionalProperty = "Test"
        }
            : i);

        // Act
        var actual = input.Dump(transform);

        // Assert
        actual.Should().Be(@"{
    ""Name"": ""John Doe"" [System.String],
    ""Age"": 21 [System.Int32],
    ""Weight"": 80.1 [System.Double],
    ""AdditionalProperty"": ""Test"" [System.String]
} [CrossCutting.Utilities.ObjectDumper.Tests.Helpers.MyType]");
    }
Ejemplo n.º 2
0
    public void CanDumpObjectWithNullProperty()
    {
        // Arrange
        var input = new MyType();

        // Act
        var actual = input.Dump();

        // Assert
        actual.Should().Be(@"{
    ""Name"": NULL [System.String],
    ""Age"": 0 [System.Int32],
    ""Weight"": 0 [System.Double]
} [CrossCutting.Utilities.ObjectDumper.Tests.Helpers.MyType]");
    }
Ejemplo n.º 3
0
    public void CanDumpObjectUsingTypedDelegateTransform()
    {
        // Arrange
        var input = new MyType
        {
            Name   = "John Doe",
            Age    = 21,
            Weight = 80.1
        };
        var transform = new TypedDelegateTransform <MyType>(mt => mt?.ToString() ?? string.Empty);

        // Act
        var actual = input.Dump(transform);

        // Assert
        actual.Should().Be(@"""CrossCutting.Utilities.ObjectDumper.Tests.Helpers.MyType"" [System.String]");
    }
Ejemplo n.º 4
0
    public void CanDumpObjectWithDynamicallyAddedProperties()
    {
        // Arrange
        var input = new MyType {
            Name = "Hello world"
        };

        using var manager = new DynamicPropertyManager <MyType>(input);
        manager.Properties.Add(DynamicPropertyManager.CreateProperty <MyType, string>("Name2", _ => "Name 2", null));
        manager.Properties.Add(DynamicPropertyManager.CreateProperty <MyType, string>("Name3", _ => "Name 3", null));

        // Act
        var actual = input.Dump();

        // Assert
        actual.Should().Be(@"{
    ""Name"": ""Hello world"" [System.String],
    ""Age"": 0 [System.Int32],
    ""Weight"": 0 [System.Double],
    ""Name2"": ""Name 2"" [System.String],
    ""Name3"": ""Name 3"" [System.String]
} [CrossCutting.Utilities.ObjectDumper.Tests.Helpers.MyType]");
    }