public async Task QueueOperationAsync_RemovesExistingOperation_WhenOperationIsCancelled()
        {
            var testNewOperation      = new CreateMobileServiceFileOperation("id", "fileId");
            var testExistingOperation = new Mock <IMobileServiceFileOperation>();

            testExistingOperation.SetupGet(m => m.Id).Returns("testID");
            testExistingOperation.Setup(m => m.OnQueueingNewOperation(It.Is <IMobileServiceFileOperation>(o => o == testNewOperation)))
            .Callback(() => testExistingOperation.SetupGet(m => m.State).Returns(FileOperationState.Cancelled));


            MobileServiceFileSyncContextInput input = MobileServiceFileSyncContextInput.CreateWithout(MobileServiceFileSyncContextArgs.OperationQueue);

            var operationQueueMock = new Mock <IFileOperationQueue>();

            operationQueueMock.Setup(m => m.GetOperationByFileIdAsync(It.Is <string>(s => string.Compare(s, testNewOperation.FileId) == 0)))
            .Returns(() => Task.FromResult <IMobileServiceFileOperation>(testExistingOperation.Object));

            input.OperationsQueue = operationQueueMock.Object;

            MobileServiceFileSyncContext context = CreateContext(input);

            await context.QueueOperationAsync(testNewOperation);

            Assert.Equal(FileOperationState.Cancelled, testExistingOperation.Object.State);
            operationQueueMock.Verify(m => m.RemoveAsync(It.Is <string>(s => s == testExistingOperation.Object.Id)), Times.Once());
        }
        public void Disposing_DisposesTriggers()
        {
            MobileServiceFileSyncContextInput input = MobileServiceFileSyncContextInput.CreateWithout(MobileServiceFileSyncContextArgs.TriggerFactory);

            var triggers = Enumerable.Range(0, 5).Select(i => new FileSyncTrigger()).ToList();

            var triggerFactoryMock = new Mock <IFileSyncTriggerFactory>();

            triggerFactoryMock.Setup(f => f.CreateTriggers(It.IsAny <IFileSyncContext>()))
            .Returns(() => new List <IFileSyncTrigger>(triggers));

            input.TriggerFactory = triggerFactoryMock.Object;

            MobileServiceFileSyncContext context = CreateContext(input);

            context.Dispose();

            Assert.True(triggers.All(t => t.Disposed));
        }
        public async Task QueueOperationAsync_NotifiesExistingOperation_WhenOperationIsQueued()
        {
            var testNewOperation      = new CreateMobileServiceFileOperation("id", "fileId");
            var testExistingOperation = new Mock <IMobileServiceFileOperation>();

            MobileServiceFileSyncContextInput input = MobileServiceFileSyncContextInput.CreateWithout(MobileServiceFileSyncContextArgs.OperationQueue);

            var operationQueueMock = new Mock <IFileOperationQueue>();

            operationQueueMock.Setup(m => m.GetOperationByFileIdAsync(It.Is <string>(s => string.Compare(s, testNewOperation.FileId) == 0)))
            .Returns(() => Task.FromResult <IMobileServiceFileOperation>(testExistingOperation.Object));

            input.OperationsQueue = operationQueueMock.Object;

            MobileServiceFileSyncContext context = CreateContext(input);

            await context.QueueOperationAsync(testNewOperation);

            testExistingOperation.Verify(m => m.OnQueueingNewOperation(It.Is <IMobileServiceFileOperation>(o => o.Equals(testNewOperation))), Times.Once());
        }
        private MobileServiceFileSyncContext CreateContext(MobileServiceFileSyncContextArgs nullArguments)
        {
            MobileServiceFileSyncContextInput input = MobileServiceFileSyncContextInput.CreateWithout(nullArguments);

            return(CreateContext(input));
        }