public void GetConflictingItems_ChangesHaveNoConflicts_NoConflictsInSyncResult() { // Create non conflicting items Guid id = Guid.NewGuid(); var serverStamp = new Stamp(); var clientStamp = serverStamp.Fork(); var serverItem = new TestItem { Id = id, Stamp = serverStamp }; var clientItem = new TestItem { Id = id, Stamp = clientStamp }; // Arrange server repository to return server item var repository = Mocking.MockAndBind <IRepository <TestItem, Guid> >(_container); Mock.Arrange(() => repository.Find(id)).Returns(serverItem); // Arrange client sync request ISyncRequest <Guid> syncRequest = new SyncRequest <TestItem, Guid> { new SyncItem <Guid>(clientItem) }; var target = new SyncResult <TestItem, Guid>(_container); target.GetConflictingItems(syncRequest); Assert.IsFalse(target.ConflictingItems.Contains(serverItem)); }
public void SendChangedItemsToRemoteReplica_BothParmsHaveChanges_ChangesAggregated() { IReplica replica = new Replica("Test"); var testItem1 = new TestItem(); var testItem2 = new TestItem(); var requestSender = Mocking.MockAndBind <ISyncRequestSender <TestItem, Guid> >(_container); var repository = Mocking.MockAndBind <IRepository <TestItem, Guid> >(_container); Mock.Arrange(() => repository.Find(testItem2.Id)).Returns(testItem2); var syncResult = new SyncResult <TestItem, Guid>(_container) { ChangesRequest = new List <Guid> { testItem2.Id } }; var conflictResolutions = new ConflictResolutionsToSend <TestItem, Guid> { new Resolution <TestItem, Guid>(replica, testItem1) }; var target = new SendingSynchronizer <TestItem, Guid>(_container); target.SendChangedItemsToRemoteReplica(syncResult.ChangesRequest, conflictResolutions); Mock.Assert(() => requestSender.SendChangedItems( Arg.Matches <IEnumerable <TestItem> >(items => items.Contains(testItem1) && items.Contains(testItem2)))); }
public void ResolveItemConflicts__RequestsResolutionFromConflictResolverForItemType() { var conflictResolver = Mocking.MockAndBind <ISyncConflictResolver <TestItem, Guid> >(_container); var syncResult = Mock.Create <ISyncResult <TestItem, Guid> >(); var target = new SendingSynchronizer <TestItem, Guid>(_container); target.ResolveItemConflicts(syncResult); Mock.Assert(() => conflictResolver.Resolve(syncResult.ConflictingItems), Occurs.Once()); }
public void SendChangedItemsToRemoteReplica__SendsChangesViaRequestSenderForType() { var requestSender = Mocking.MockAndBind <ISyncRequestSender <TestItem, Guid> >(_container); var syncResult = Mock.Create <ISyncResult <TestItem, Guid> >(); var target = new SendingSynchronizer <TestItem, Guid>(_container); ConflictResolutionsToSend <TestItem, Guid> conflictResolutions = new ConflictResolutionsToSend <TestItem, Guid>(); target.SendChangedItemsToRemoteReplica(syncResult.ChangesRequest, conflictResolutions); Mock.Assert(() => requestSender.SendChangedItems(Arg.IsAny <IEnumerable <TestItem> >()), Occurs.Once()); }
public void SendSyncRequestToRemoteReplica_GivenValidSyncRequest_CallsSyncRequestSender() { var mockSyncRequestSender = Mocking.MockAndBind <ISyncRequestSender <TestItem, Guid> >(_container); var syncRequest = Mock.Create <ISyncRequest <Guid> >(); var target = new SendingSynchronizer <TestItem, Guid>(_container); target.SendSyncRequestToRemoteReplica(syncRequest); Mock.Assert(() => mockSyncRequestSender.SendInitialRequest(syncRequest), Occurs.Once()); }
public void FulfillSyncRequest_ValidRequest_SyncResultBuildCalled() { var syncResult = Mocking.MockAndBind <ISyncResult <TestItem, Guid> >(_container); var replica = new Replica("test"); var syncRequest = Mock.Create <ISyncRequest <Guid> >(); var target = new ReceivingSynchronizer <TestItem, Guid>(_container); var result = target.FulfillSyncRequest(syncRequest); Mock.Assert(() => syncResult.Build(syncRequest), Occurs.Once()); }
public void GetFulfillingReplicaItemChanges_RepositoryHasChanges_ChangesInSyncResult() { var repository = Mocking.MockAndBind <IRepository <TestItem, Guid> >(_container); var changes = new List <TestItem> { new TestItem() }; Mock.Arrange(() => repository.GetChangesSince(Arg.AnyDateTime)).Returns(changes); var target = new SyncResult <TestItem, Guid>(_container); target.GetFulfillingReplicaItemChanges(Mock.Create <ISyncRequest <Guid> >()); Assert.IsTrue(target.FulfillingReplicaItemChanges.Any(si => si.Id == changes.First().Id)); }
public void ReceiveChangedItemsAsRemoteReplica_ChangeToExistingRecord_ChangeIsUpdated() { var testItem = new TestItem(); var repository = Mocking.MockAndBind <IRepository <TestItem, Guid> >(_container); Mock.Arrange(() => repository.Find(testItem.Id)).Returns(testItem); var changes = new List <TestItem> { testItem }; var target = new ReceivingSynchronizer <TestItem, Guid>(_container); target.ReceiveChangedItemsAsRemoteReplica(changes); Mock.Assert(() => repository.Update(testItem), Occurs.Once()); }
public void ReceiveChangedItemsAsRemoteReplica_ChangesExist_ChangesAreSaved() { var testItem = new TestItem(); TestItem nullTestItem = null; var repository = Mocking.MockAndBind <IRepository <TestItem, Guid> >(_container); // ReSharper disable once ExpressionIsAlwaysNull Mock.Arrange(() => repository.Find(testItem.Id)).Returns(nullTestItem); var changes = new List <TestItem> { testItem }; var target = new ReceivingSynchronizer <TestItem, Guid>(_container); target.ReceiveChangedItemsAsRemoteReplica(changes); Mock.Assert(() => repository.Insert(testItem), Occurs.Once()); }