public async Task CorrectlyUpdatePartially() { // Arrange var asyncDataCrudMock = new Mock <IAsyncCrud <Category, int, CategoryResourceParameters> >(); asyncDataCrudMock .Setup(s => s.Update(It.IsAny <Category>())).Returns(Task.FromResult(new Category() //// Todo: Can It.IsAny<> be made more concrete? { Id = 1, Name = "UpdateNameForMockCategory", OwnerGuid = _ownerGuid })); var categoryOfmRepository = new CategoryOfmRepository(asyncDataCrudMock.Object, new PropertyMappingService(), new TypeHelperService()); categoryOfmRepository.CachedEntityForPatch = new Category() { Id = 1, Name = "MockCategory", OwnerGuid = _ownerGuid }; var modifiedOfmForPatch = new CategoryOfmForPatch() { Id = 1, Name = "UpdateNameForMockCategory" }; // Act var categoryOfmResult = await categoryOfmRepository.UpdatePartially(modifiedOfmForPatch); // Assert var actualOfmResult = JsonConvert.SerializeObject(categoryOfmResult, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Formatting = Formatting.Indented }); var expectedOfmResult = JsonConvert.SerializeObject( new CategoryOfmForGet() { Id = 1, Name = "UpdateNameForMockCategory" }, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Formatting = Formatting.Indented }); Assert.AreEqual(expectedOfmResult, actualOfmResult); }
public async Task ThrowArgumentNullException_WhenCachedEntityIsNull() { await Task.Run(() => { // Arrange var asyncDataCrudMock = new Mock <IAsyncCrud <Category, int, CategoryResourceParameters> >(); var categoryOfmRepository = new CategoryOfmRepository(asyncDataCrudMock.Object, new PropertyMappingService(), new TypeHelperService()); categoryOfmRepository.CachedEntityForPatch = null; // Act and Assert Assert.ThrowsAsync <ArgumentNullException>(() => categoryOfmRepository.UpdatePartially((CategoryOfmForPatch)null)); }); }