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 Constructor_WithNullFilesClient_CreatesDefaultClient()
        {
            MobileServiceFileSyncContext context = CreateContext(MobileServiceFileSyncContextArgs.FilesClient);

            Assert.NotNull(context.MobileServiceFilesClient);
            Assert.IsType <MobileServiceFilesClient>(context.MobileServiceFilesClient);
        }
Beispiel #3
0
        public MobileServiceFileSyncContextScenario()
        {
            this.mobileServiceClientMock = new Mock <IMobileServiceClient>();
            this.triggerFactory          = new Mock <IFileSyncTriggerFactory>();

            SyncHandlerMock        = new Mock <IFileSyncHandler>();
            FileMetadataStoreMock  = new Mock <IFileMetadataStore>();
            FileOperationQueueMock = new Mock <IFileOperationQueue>();
            FilesClientMock        = new Mock <IMobileServiceFilesClient>();

            EventManagerMock = new Mock <IMobileServiceEventManager>();

            this.mobileServiceClientMock.Setup(m => m.EventManager)
            .Returns(EventManagerMock.Object);

            SyncContext = new MobileServiceFileSyncContext(mobileServiceClientMock.Object, FileMetadataStoreMock.Object,
                                                           FileOperationQueueMock.Object, triggerFactory.Object, SyncHandlerMock.Object, FilesClientMock.Object);
        }
        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());
        }