public void PatchObjetShouldNotReplace() { PatchObjectUtils <EntityTest> .PatchObject(orig, new ManahostPatcherModel[] { new ManahostPatcherModel() { Field = "ShouldNotReplace", Value = -1 }, new ManahostPatcherModel() { Field = "ClientId", Value = -1 }, new ManahostPatcherModel() { Field = "DateCreation", Value = DateTime.Now }, new ManahostPatcherModel() { Field = "Id", Value = -1 }, }); Assert.AreEqual(1, orig.ClientId); Assert.AreEqual(DateTime.MinValue, orig.DateCreation); Assert.AreEqual(1, orig.HomeId); Assert.AreEqual(1, orig.Id); Assert.AreEqual(1, orig.ShouldNotReplace); Assert.AreEqual(1, orig.ShouldReplace); }
public void ForbiddenReplacement() { PatchObjectUtils <EntityTest> .ReplacementOrigByGiven(new EntityTest() { ClientId = 2, DateCreation = DateTime.Now, HomeId = 2, Id = 2, ShouldNotReplace = 1000, }, orig, new string[] { }); Assert.AreEqual(1, orig.ClientId); Assert.AreEqual(DateTime.MinValue, orig.DateCreation); Assert.AreEqual(2, orig.HomeId); Assert.AreEqual(1, orig.ShouldNotReplace); Assert.AreEqual(1, orig.Id); }
public void PatchObjetPropertyDoesNotExist() { PatchObjectUtils <EntityTest> .PatchObject(orig, new ManahostPatcherModel[] { new ManahostPatcherModel() { Field = "DoesNotExist", Value = "blabla" }, }); Assert.AreEqual(1, orig.ClientId); Assert.AreEqual(DateTime.MinValue, orig.DateCreation); Assert.AreEqual(1, orig.HomeId); Assert.AreEqual(1, orig.Id); Assert.AreEqual(1, orig.ShouldNotReplace); Assert.AreEqual(1, orig.ShouldReplace); }
// TODO : to remove once document has been migrated to dto public void PrePut(Client currentClient, ENTITY entity, Object param) { ValidateNull(entity); ((IEntity)entity).SetDateModification(DateTime.UtcNow); PutIncludeProps(null); ProcessDTOPostPut(GetMapper.Map <ENTITY, DTO>(entity), 0, currentClient); ValidateOrig(); PatchObjectUtils <ENTITY> .ReplacementOrigByGiven(entity, orig, new string[] { }); if (!validation.PreValidatePut(validationDictionnary, currentClient, orig, param, repo)) { throw new ManahostValidationException(validationDictionnary); } DoPut(currentClient, orig, param); repo.Update(orig); repo.Save(); DoPutAfterSave(currentClient, orig, param); }