Пример #1
0
 private ComparisonContext GetContext(Normalizers normalizers)
 {
     return(new ComparisonContext(
                "NuGet.Versioning",
                "https://example/api/a",
                "https://example/api/b",
                "https://example/api/a/index.json",
                "https://example/api/b/index.json",
                normalizers));
 }
Пример #2
0
        public void AllowsObjectPropertyOrderToBeIgnored()
        {
            var normalizers = new Normalizers(
                scalarNormalizers: new List <ValueNormalizer>(),
                unsortedObjects: new List <ShouldNormalizeByPath>
            {
                (path) => path == "inner",
            },
                unsortedArrays: new List <ArrayNormalizer>());
            var a = Json(new { inner = new { a = "a", b = "b" } });
            var b = Json(new { inner = new { b = "b", a = "a" } });

            Target.Compare(a, b, GetContext(normalizers));
        }
Пример #3
0
        public void AllowsArrayItemOrderToBeIgnored()
        {
            var normalizers = new Normalizers(
                scalarNormalizers: new List <ValueNormalizer>(),
                unsortedObjects: new List <ShouldNormalizeByPath>(),
                unsortedArrays: new List <ArrayNormalizer>
            {
                new ArrayNormalizer(
                    array => array.Path == "array",
                    (x, y) => Comparer <JToken> .Default.Compare(x, y)),
            });
            var a = Json(new { array = new[] { 0, 2, 1 } });
            var b = Json(new { array = new[] { 0, 1, 2 } });

            Target.Compare(a, b, GetContext(normalizers));
        }
Пример #4
0
        public void AllowsValueToBeNormalized()
        {
            var normalizers = new Normalizers(
                scalarNormalizers: new List <ValueNormalizer>
            {
                new ValueNormalizer(
                    (path) => path == "random",
                    (token, isLeft, context) => "999"),
            },
                unsortedObjects: new List <ShouldNormalizeByPath>(),
                unsortedArrays: new List <ArrayNormalizer>());
            var a = Json(new { array = new[] { 0, 1, 2 }, random = 23 });
            var b = Json(new { array = new[] { 0, 1, 2 }, random = 42 });

            Target.Compare(a, b, GetContext(normalizers));
        }