geirsagberg / NormalNet

Normalizer for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NormalNet

.NET Standard Library providing normalization of entities for easier API consumption.

  • Normalize simple entities
  • Normalize nested entities
  • Normalize list entities
  • Normalize entities without ID

Example:

var viewModel = new SimpleViewModel {
    Owner = new Person {
        Id = 1,
        FirstName = "Geir",
        LastName = "Sagberg"
    },
    Employee = new Person {
        Id = 2,
        FirstName = "Ola",
        LastName = "Normann"
    }
};

var normalized = new Normalizer().Normalize(viewModel);

var expectation = new Dictionary<string, object> {
    {"OwnerId", 1},
    {"EmployeeId", 2}, {
        "Entities", new Dictionary<string, object> {
            {
                "Person", new Dictionary<string, object> {
                    {
                        "1", new Dictionary<string, object> {
                            {"Id", 1},
                            {"FirstName", "Geir"},
                            {"LastName", "Sagberg"}
                        }
                    }, {
                        "2", new Dictionary<string, object> {
                            {"Id", 2},
                            {"FirstName", "Ola"},
                            {"LastName", "Normann"}
                        }
                    }
                }
            }
        }
    }
};
normalized.ShouldBeEquivalentTo(expectation);

See NormalNet.Test for more examples.

About

Normalizer for .NET

License:MIT License


Languages

Language:C# 100.0%