Beispiel #1
0
        public static void AssertSameObjectJson(object obj, string eventReferenceFile, bool clean)
        {
            var eventJObject = JsonSerializeUtils.toJobject(obj);

            if (clean)
            {
                eventJObject = JsonSerializeUtils.clean(eventJObject);
            }

            var refJsonString = TestUtils.LoadReferenceJsonFixture(eventReferenceFile);
            var refJObject    = JObject.Parse(refJsonString);

            bool equals = JToken.DeepEquals(refJObject, eventJObject);

            if (!equals)
            {
                var    jdp   = new JsonDiffPatchDotNet.JsonDiffPatch();
                JToken patch = jdp.Diff(eventJObject, refJObject);
                Console.WriteLine("diff:");
                Console.WriteLine(patch);
                Console.WriteLine("fixture:");
                Console.WriteLine(refJObject);
                Console.WriteLine("created:");
                Console.WriteLine(eventJObject);
            }

            Assert.True(equals);
        }
        private string compare(string source, string destination)
        {
            JsonDiffPatchDotNet.JsonDiffPatch jdp = new JsonDiffPatchDotNet.JsonDiffPatch();

            Newtonsoft.Json.Linq.JToken patch = jdp.Diff(source, destination);

            return(patch.ToString());
        }
        public string GetDiff(DiffCandidate diffCandidate)
        {
            var jdp   = new JsonDiffPatchDotNet.JsonDiffPatch();
            var left  = JToken.Parse(diffCandidate.Left);
            var right = JToken.Parse(diffCandidate.Right);

            var patch = jdp.Diff(left, right);

            return(patch?.ToString());
        }
        public string CalculateValue()
        {
            if (this.InputVariable == null || this.InputVariable.FunctionArguments == null || this.InputVariable.FunctionArguments.Count < 2)
            {
                return(string.Empty);
            }

            JsonDiffPatchDotNet.JsonDiffPatch jdp = new JsonDiffPatchDotNet.JsonDiffPatch();
            var left  = Helper.JsonHelper.Fetch(this.Data, this.InputVariable.FunctionArguments[0]);
            var right = Helper.JsonHelper.Fetch(this.Data, this.InputVariable.FunctionArguments[1]);

            JToken patch = jdp.Diff(left, right);

            return(Helper.JsonHelper.DescribeJsonComparison(patch));;
        }
Beispiel #5
0
        public void Coupon()
        {
            var actual = new PassBuilder()
                         .Standard
                         .PassTypeIdentifier("pass.com.apple.devpubs.example")
                         .SerialNumber("E5982H-I2")
                         .TeamIdentifier("A93A5CM278")
                         .OrganizationName("Paw Planet")
                         .Description("Paw Planet Coupon")
                         .WebService
                         .AuthenticationToken("vxwxd7J8AlNNFPS8k0a0FfUFtq0ewzFdc")
                         .WebServiceURL("https://example.com/passes/")
                         .Relevance
                         .Locations(37.6189722, -122.3748889)
                         .Locations(37.33182, -122.03118)
                         .VisualAppearance
                         .Barcodes("123456789", BarcodeFormat.Pdf417)
                         .LogoText("Paw Planet")
                         .ForegroundColor("rgb(255, 255, 255)")
                         .BackgroundColor("rgb(206, 140, 53)")
                         .Coupon
                         .PrimaryFields
                         .Add("offer")
                         .Label("Any premium dog food")
                         .Value("20% off")
                         .AuxiliaryFields
                         .Add("expires")
                         .Label("EXPIRES")
                         .Value("2013-04-24T10:00-05:00")
                         .IsRelative(true)
                         .DateStyle(DateStyle.Short)
                         .Build();

            output.WriteLine("Actual JSON:");
            output.WriteLine(actual.ToString(Formatting.Indented));

            var expected = LoadFromResource("Coupon.pass.json");

            var jdp  = new JsonDiffPatchDotNet.JsonDiffPatch();
            var diff = jdp.Diff(expected, actual);

            output.WriteLine("Differences (expected -> actual):");
            output.WriteLine(diff == null ? "No differences!" : diff.ToString());

            Assert.True(JToken.DeepEquals(expected, actual));
        }
Beispiel #6
0
        private static IEnumerable <YamlSchema> GetYamlSchemas(string file)
        {
            var deserializer   = new Deserializer();
            var contents       = File.ReadAllText(file);
            var yamlObject     = deserializer.Deserialize(new StringReader(contents));
            var asJson         = yamlObject.ToJSON();
            var jsonSerializer = JsonSerializer.Create(new JsonSerializerSettings
            {
                Converters =
                {
                    new ExpectedConverter()
                }
            });
            var spec = jsonSerializer.Deserialize <Dictionary <string, YamlSchema> >(new JsonTextReader(new StringReader(asJson)));

            var serialised = JsonConvert.SerializeObject(spec,
                                                         new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore,
                Converters        =
                {
                    new FormatAsTextConverter <int>(),
                    new FormatAsTextConverter <int?>(),
                    new FormatAsTextConverter <bool?>()
                }
            });

            var differ = new JsonDiffPatchDotNet.JsonDiffPatch();
            var diffs  = differ.Diff(asJson, serialised);

            if (diffs != null)
            {
                Warnings.Add($"{file}:{diffs}");
            }

            return(spec.Select(d => d.Value)
                   .Select(s =>
            {
                foreach (var(key, value) in s.Fields)
                {
                    value.Schema = s;
                }
                return s;
            }));
        }
Beispiel #7
0
        public void Event()
        {
            var actual = new PassBuilder()
                         .Standard
                         .PassTypeIdentifier("pass.com.apple.devpubs.example")
                         .SerialNumber("nmyuxofgna")
                         .TeamIdentifier("A93A5CM278")
                         .OrganizationName("Apple Inc.")
                         .Description("Apple Event Ticket")
                         .WebService
                         .AuthenticationToken("vxwxd7J8AlNNFPS8k0a0FfUFtq0ewzFdc")
                         .WebServiceURL("https://example.com/passes/")
                         .Relevance
                         .Locations(37.6189722, -122.3748889)
                         .Locations(37.33182, -122.03118)
                         .RelevantDate(new DateTimeOffset(2011, 12, 8, 13, 0, 0, TimeSpan.FromHours(-8)))
                         .VisualAppearance
                         .Barcodes("123456789", BarcodeFormat.Pdf417)
                         .ForegroundColor("rgb(255, 255, 255)")
                         .BackgroundColor("rgb(60, 65, 76)")
                         .EventTicket
                         .PrimaryFields
                         .Add("event")
                         .Label("EVENT")
                         .Value("The Beat Goes On")
                         .SecondaryFields
                         .Add("loc")
                         .Label("LOCATION")
                         .Value("Moscone West")
                         .Build();

            output.WriteLine("Actual JSON:");
            output.WriteLine(actual.ToString(Formatting.Indented));

            var expected = LoadFromResource("Event.pass.json");

            var jdp  = new JsonDiffPatchDotNet.JsonDiffPatch();
            var diff = jdp.Diff(expected, actual);

            output.WriteLine("Differences (expected -> actual):");
            output.WriteLine(diff == null ? "No differences!" : diff.ToString());

            Assert.True(JToken.DeepEquals(expected, actual));
        }
Beispiel #8
0
        public void StoreCard()
        {
            var actual = new PassBuilder()
                         .Standard
                         .PassTypeIdentifier("pass.com.apple.devpubs.example")
                         .SerialNumber("p69f2J")
                         .TeamIdentifier("A93A5CM278")
                         .OrganizationName("Organic Produce")
                         .Description("Organic Produce Loyalty Card")
                         .WebService
                         .AuthenticationToken("vxwxd7J8AlNNFPS8k0a0FfUFtq0ewzFdc")
                         .WebServiceURL("https://example.com/passes/")
                         .Relevance
                         .Locations(37.6189722, -122.3748889)
                         .VisualAppearance
                         .Barcodes("123456789", BarcodeFormat.Pdf417)
                         .LogoText("Organic Produce")
                         .ForegroundColor("rgb(255, 255, 255)")
                         .BackgroundColor("rgb(55, 117, 50)")
                         .StoreCard
                         .PrimaryFields
                         .Add("balance")
                         .Label("remaining balance")
                         .Value(21.75)
                         .CurrencyCode("USD")
                         .AuxiliaryFields
                         .Add("deal")
                         .Label("Deal of the Day")
                         .Value("Lemons")
                         .Build();

            output.WriteLine("Actual JSON:");
            output.WriteLine(actual.ToString(Formatting.Indented));

            var expected = LoadFromResource("StoreCard.pass.json");

            var jdp  = new JsonDiffPatchDotNet.JsonDiffPatch();
            var diff = jdp.Diff(expected, actual);

            output.WriteLine("Differences (expected -> actual):");
            output.WriteLine(diff == null ? "No differences!" : diff.ToString());

            Assert.True(JToken.DeepEquals(expected, actual));
        }