public async Task SetAsync_Poco_SkipsUpdate_IfSame() { // Arrange var mockService = new Mock <IDocumentDBService>(MockBehavior.Strict); Item original = new Item { Id = "abc123", Text = "hello" }; Item updated = new Item { Id = "abc123", Text = "hello" }; DocumentDBAttribute attribute = new DocumentDBAttribute(DatabaseName, CollectionName) { Id = Id }; var context = new DocumentDBContext { Service = mockService.Object, ResolvedAttribute = attribute }; JObject clonedOrig = DocumentDBItemValueBinder <object> .CloneItem(original); // Act await DocumentDBItemValueBinder <Item> .SetValueInternalAsync(clonedOrig, updated, context); // Assert // nothing on the client should be called mockService.VerifyAll(); }
public async Task SetAsync_Poco_Throws_IfIdChanges() { // Arrange var mockService = new Mock <IDocumentDBService>(MockBehavior.Strict); Item original = new Item { Id = "abc123", }; Item updated = new Item { Id = "def456", }; DocumentDBAttribute attribute = new DocumentDBAttribute(DatabaseName, CollectionName) { Id = Id }; var context = new DocumentDBContext { Service = mockService.Object, ResolvedAttribute = attribute }; var originalJson = JObject.FromObject(original); // Act var ex = await Assert.ThrowsAsync <InvalidOperationException>( () => DocumentDBItemValueBinder <Item> .SetValueInternalAsync(originalJson, updated, context)); // Assert Assert.Equal("Cannot update the 'Id' property.", ex.Message); mockService.Verify(); }