public void Setup() { PatchEngine.Init(config => { config.EnableAttributes(); config.SetCustomAttributesConfigurator(new CustomAttributesConfigurator()); config .SetPrePatchProcessingFunction(context => { if (context.PropertyConfiguration.ExtraSettings.ContainsKey(RoundValueAttribute.PARAMETER_NAME)) { if (!(context.NewValue is double)) { return(context.NewValue); } var precision = (int)(context.PropertyConfiguration.ExtraSettings[RoundValueAttribute.PARAMETER_NAME]); return(Math.Round((double)(context.NewValue), precision)); } return(context.NewValue); }); }); }
public void SimpleInitEntityCreationTest() { PatchEngineCore.Cleanup(); PatchEngine.Init(); var request = GetPatchRequestWithFields("Login", "LastSeenFrom"); var entity = request.CreateNewEntity(); Assert.NotNull(entity); Assert.AreEqual(request["Login"].ToString(), entity.Login); }
public void RFC7396PatchingEnabledTest() { PatchEngineCore.Cleanup(); PatchEngine.Init(cfg => { cfg.EnableNestedPatching(); }); var model = new Post { Title = "Hello!", Author = new Author { GivenName = "John", FamilyName = "Doe" }, Tags = new[] { "example", "sample" }, Content = "This will be unchanged" }; var jsonPatch = @"{ ""title"": ""Hello!"", ""phoneNumber"": ""+01-123-456-7890"", ""author"": { ""familyName"": null }, ""tags"": [ ""example"" ] }"; var patchObject = JObject.Parse(jsonPatch).ToObject <PatchObject <Post> >(); patchObject.ApplyTo(model); Assert.AreEqual("+01-123-456-7890", model.PhoneNumber); Assert.IsNull(model.Author.FamilyName); Assert.AreEqual("John", model.Author.GivenName); Assert.AreEqual(1, model.Tags.Length); Assert.AreEqual("example", model.Tags.First()); }
protected override void Setup() { PatchEngine.Init(Configure); }