public async Task SetAsync_Poco_Throws_IfIdChanges() { // Arrange var mockClient = new Mock <IMobileServiceClient>(MockBehavior.Strict); TodoItem original = new TodoItem { Id = "abc123", }; TodoItem updated = new TodoItem { Id = "def456", }; var context = new MobileTableContext { Client = mockClient.Object, }; var originalJson = JObject.FromObject(original); // Act var ex = await Assert.ThrowsAsync <InvalidOperationException>( () => MobileTableItemValueBinder <TodoItem> .SetValueInternalAsync(originalJson, updated, context)); // Assert Assert.Equal("Cannot update the 'Id' property.", ex.Message); mockClient.Verify(); }
public async Task SetValue_PocoWithTable_UpdatesCorrectTable() { // Arrange var handler = new TestHandler("{}"); var attribute = new MobileTableAttribute { TableName = "SomeOtherTable" }; var context = new MobileTableContext { ResolvedAttribute = attribute, Client = new MobileServiceClient("https://someuri", handler) }; var original = JObject.Parse("{'Id':'abc123'}"); var updated = new TodoItem { Id = "abc123", Text = "updated" }; // Act await MobileTableItemValueBinder <TodoItem> .SetValueInternalAsync(original, updated, context); // Assert Assert.Equal("https://someuri/tables/SomeOtherTable/abc123", handler.IssuedRequest.RequestUri.ToString()); }
public async Task SetAsync_JObject_Throws_IfIdChanges() { // Arrange var mockClient = new Mock <IMobileServiceClient>(MockBehavior.Strict); JObject original = new JObject(); original["id"] = "abc123"; original["data"] = "hello"; JObject updated = original.DeepClone() as JObject; original["id"] = "def456"; var attribute = new MobileTableAttribute { TableName = "TodoItem" }; var context = new MobileTableContext { Client = mockClient.Object, ResolvedAttribute = attribute }; // Act var ex = await Assert.ThrowsAsync <InvalidOperationException>( () => MobileTableItemValueBinder <JObject> .SetValueInternalAsync(original, updated, context)); // Assert Assert.Equal("Cannot update the 'Id' property.", ex.Message); mockClient.Verify(); }
public async Task SetAsync_JObject_SkipsUpdate_IfSame() { // Arrange var mockClient = new Mock <IMobileServiceClient>(MockBehavior.Strict); JObject original = new JObject(); original["id"] = "abc123"; original["data"] = "hello"; JObject updated = original.DeepClone() as JObject; var attribute = new MobileTableAttribute { TableName = "TodoItem" }; var context = new MobileTableContext { Client = mockClient.Object, ResolvedAttribute = attribute }; // Act await MobileTableItemValueBinder <JObject> .SetValueInternalAsync(original, updated, context); // Assert mockClient.VerifyAll(); }
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 async Task SetAsync_JObject_Updates_IfPropertyChanges() { // Arrange var mockClient = new Mock <IMobileServiceClient>(MockBehavior.Strict); var mockTable = new Mock <IMobileServiceTable>(MockBehavior.Strict); JObject original = new JObject(); original["id"] = "abc123"; original["data"] = "hello"; JObject updated = original.DeepClone() as JObject; original["data"] = "goodbye"; mockTable .Setup(m => m.UpdateAsync(updated)) .Returns(Task.FromResult <JToken>(null)); mockClient .Setup(m => m.GetTable("TodoItem")) .Returns(mockTable.Object); var attribute = new MobileTableAttribute { TableName = "TodoItem" }; var context = new MobileTableContext { Client = mockClient.Object, ResolvedAttribute = attribute }; // Act await MobileTableItemValueBinder <JObject> .SetValueInternalAsync(original, updated, context); // Assert mockClient.VerifyAll(); mockTable.VerifyAll(); }
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(); }