public async Task SetAsync_Poco_SkipsUpdate_IfSame() { // Arrange var mockClient = new Mock <IMobileServiceClient>(MockBehavior.Strict); TodoItem original = new TodoItem { Id = "abc123", Text = "hello" }; TodoItem updated = new TodoItem { Id = "abc123", Text = "hello" }; var context = new MobileTableContext { Client = mockClient.Object, }; JObject clonedOrig = MobileTableItemValueBinder <object> .CloneItem(original); // Act await MobileTableItemValueBinder <TodoItem> .SetValueInternalAsync(clonedOrig, updated, context); // Assert // nothing on the client should be called mockClient.VerifyAll(); }
public void CloneItem_JObject_CorrectlySerializes() { // Arrange var jObject = new JObject(); jObject["id"] = "abc123"; jObject["text"] = "hello"; jObject["complete"] = false; jObject["completedDate"] = DateTimeOffset.Now; // Act JObject cloned = MobileTableItemValueBinder <object> .CloneItem(jObject); // Assert Assert.NotSame(jObject, cloned); Assert.True(JToken.DeepEquals(jObject, cloned)); }
public async Task SetAsync_Poco_Updates_IfPropertyChanges() { // Arrange var mockClient = new Mock <IMobileServiceClient>(MockBehavior.Strict); var mockTable = new Mock <IMobileServiceTable <TodoItem> >(MockBehavior.Strict); TodoItem original = new TodoItem { Id = "abc123", Text = "hello" }; TodoItem updated = new TodoItem { Id = "abc123", Text = "goodbye" }; mockTable .Setup(m => m.UpdateAsync(updated)) .Returns(Task.FromResult <TodoItem>(null)); mockClient .Setup(m => m.GetTable <TodoItem>()) .Returns(mockTable.Object); var context = new MobileTableContext { Client = mockClient.Object, }; JObject clonedOrig = MobileTableItemValueBinder <object> .CloneItem(original); // Act await MobileTableItemValueBinder <TodoItem> .SetValueInternalAsync(clonedOrig, updated, context); // Assert mockClient.VerifyAll(); mockTable.VerifyAll(); }
public void CloneItem_Poco_CorrectlySerializes() { // Arrange TodoItem todoItem = new TodoItem { Id = "abc123", Text = "hello", Complete = false, CompletedDate = DateTimeOffset.Now }; // Act JObject cloned = MobileTableItemValueBinder <object> .CloneItem(todoItem); TodoItem deserialized = cloned.ToObject <TodoItem>(); // Assert Assert.Equal(todoItem.Id, deserialized.Id); Assert.Equal(todoItem.Text, deserialized.Text); Assert.Equal(todoItem.Complete, deserialized.Complete); Assert.Equal(todoItem.CompletedDate, deserialized.CompletedDate); }