public void TestNotPrimitives() { var original = new NotPrimitiveEntity { reference = new SimpleEntityReference { StringProp = "prop1" }, referenceCollection = new List <SimpleEntityReference> { new SimpleEntityReference { StringProp = "inCollection1" }, new SimpleEntityReference { StringProp = "inCollection2" } } }; var patch = new NotPrimitiveEntity { reference = new SimpleEntityReference { StringProp = "propPatched" }, referenceCollection = new List <SimpleEntityReference>() }; NextApiUtils.PatchEntity(patch, original); Assert.False(original.reference .IsDeepEqual(patch.reference)); Assert.False(original.referenceCollection .IsDeepEqual(patch.referenceCollection)); }
/// <inheritdoc /> public virtual async Task <TDto> Update(TKey key, TDto patch) { var entity = await _repository.GetByIdAsync(key); if (entity == null) { throw new NextApiException(NextApiErrorCode.EntityIsNotExist, $"Entity with id {key.ToString()} is not found!", new Dictionary <string, object> { { "id", key } }); } await BeforeUpdate(entity, patch); NextApiUtils.PatchEntity(patch, entity); await _repository.UpdateAsync(entity); await AfterUpdate(entity); await CommitAsync(); var updatedEntity = await _repository.GetByIdAsync(entity.Id); return(_mapper.Map <TEntity, TDto>(updatedEntity)); }
public void TestPrimitives() { var original = new PrimitiveEntity { IntProp = 1, BoolProp = true, DoubleProp = 3d, DateTimeProp = new DateTime(2017, 5, 3), NullableIntProp = null, StringProp = "originalString" }; var patch = new PrimitiveEntity { IntProp = 2, BoolProp = false, DoubleProp = 4d, StringProp = "changedString", DateTimeProp = new DateTime(2018, 2, 2), NullableIntProp = 2 }; NextApiUtils.PatchEntity(patch, original); original.ShouldDeepEqual(patch); }