예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        // 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);
        }