예제 #1
0
        public void GetTasks_NullListsElement_InitsEmptyList()
        {
            var fakeResponseData = new GetListResponseData
            {
                Lists = new GetListResponseData.ListOfLists
                {
                    Lists = null
                }
            };
            var responseParser = GetItemUnderTest();
            var actual         = responseParser.GetTasks(fakeResponseData);

            Assert.AreEqual(0, actual.Count);
        }
예제 #2
0
        public async Task GetTasksByListIdAsync_ListAlreadySynced_IgnoresLastSyncDate()
        {
            // Setup
            const string listId   = "My Fake List ID";
            var          lastSync = DateTime.Parse("2018-01-23 12:34:56");

            var fakeSyncTracker = Substitute.For <ISyncTracker>();

            fakeSyncTracker.GetLastSync(listId).Returns(lastSync);

            var fakeResponseData = new GetListResponseData();
            var fakeApiClient    = Substitute.For <ITaskApiClient>();

            fakeApiClient.GetTasksByListIdAsync(listId).Returns(Task.FromResult(fakeResponseData));

            var fakeTaskList        = new List <IRtmTask>();
            var fakeDeletedTaskList = new List <IRtmTask>();
            var fakeResponseParser  = Substitute.For <IResponseParser>();

            fakeResponseParser.GetTasks(fakeResponseData).Returns(fakeTaskList);
            fakeResponseParser.GetDeletedTasks(fakeResponseData).Returns(fakeDeletedTaskList);

            IList <IRtmTask> expectedTaskList = new List <IRtmTask>();
            var mockTaskCache = Substitute.For <ITaskCache>();

            mockTaskCache.GetAllAsync(listId).Returns(Task.FromResult(expectedTaskList));

            // Execute
            var taskRepository = GetItemUnderTest(fakeApiClient, fakeResponseParser, mockTaskCache, fakeSyncTracker);
            var actual         = await taskRepository.GetTasksByListIdAsync(listId).ConfigureAwait(false);

            // Verify
            Assert.AreSame(expectedTaskList, actual);
#pragma warning disable 4014
            mockTaskCache.DidNotReceive().ClearAsync();
            mockTaskCache.Received(1).AddOrReplaceAsync(listId, fakeTaskList, true);
            mockTaskCache.DidNotReceive().RemoveAsync(fakeDeletedTaskList);
#pragma warning restore 4014
        }
예제 #3
0
        public async Task GetAllTasksAsync_IncludeCompletedTasks_ExcludesIncompleteFilter()
        {
            // Setup
            var fakeAuthToken = new AuthenticationToken {
                Id = "My Fake Token ID", Permissions = PermissionLevel.Read
            };
            const string fakeTasksUrl = "My Fake URL";

            var fakeUrlFactory = Substitute.For <ITasksUrlFactory>();

            fakeUrlFactory.CreateGetListsUrl(fakeAuthToken.Id).Returns(fakeTasksUrl);

            var fakeResponseData = new GetListResponseData();
            var fakeApiClient    = Substitute.For <IApiClient>();

            fakeApiClient.GetAsync <GetListResponseData>(fakeTasksUrl).Returns(Task.FromResult(fakeResponseData));

            // Execute
            var taskRepository = GetItemUnderTest(fakeUrlFactory, fakeApiClient, fakeAuthToken);
            var actual         = await taskRepository.GetAllTasksAsync(true).ConfigureAwait(false);

            // Verify
            Assert.AreSame(fakeResponseData, actual);
        }
예제 #4
0
        public async Task GetTasksByListIdAsync_HasTasksFromOtherLists_GetsOtherListsTooUsingLastSync()
        {
            // Setup
            const string masterListId        = "My Master List ID";
            const string firstForeignListId  = "First Foreign List ID";
            const string secondForeignListId = "Second Foreign List ID";

            var masterLastSync        = DateTime.Parse("2018-01-23 12:34:56");
            var firstForeignLastSync  = masterLastSync.Subtract(TimeSpan.FromSeconds(1));
            var secondForeignLastSync = masterLastSync.Add(TimeSpan.FromSeconds(1));

            var testSyncTracker = new InMemorySyncTracker();

            testSyncTracker.SetLastSync(masterListId, masterLastSync);
            testSyncTracker.SetLastSync(firstForeignListId, firstForeignLastSync);
            testSyncTracker.SetLastSync(secondForeignListId, secondForeignLastSync);

            var masterResponseData        = new GetListResponseData();
            var firstForeignResponseData  = new GetListResponseData();
            var secondForeignResponseData = new GetListResponseData();
            var fakeApiClient             = Substitute.For <ITaskApiClient>();

            fakeApiClient.GetTasksByListIdAsync(masterListId).Returns(Task.FromResult(masterResponseData));
            fakeApiClient.GetTasksByListIdAsync(firstForeignListId, firstForeignLastSync).Returns(Task.FromResult(firstForeignResponseData));
            fakeApiClient.GetTasksByListIdAsync(secondForeignListId, secondForeignLastSync).Returns(Task.FromResult(secondForeignResponseData));

            var firstTask = Substitute.For <IRtmTask>();

            firstTask.ListId.Returns(firstForeignListId);
            var secondTask = Substitute.For <IRtmTask>();

            secondTask.ListId.Returns(secondForeignListId);

            var masterTaskList = new List <IRtmTask> {
                firstTask, secondTask
            };
            var firstForeignTaskList = new List <IRtmTask> {
                firstTask, secondTask
            };
            var secondForeignTaskList = new List <IRtmTask> {
                firstTask, secondTask
            };
            var masterDeletedTaskList        = new List <IRtmTask>();
            var firstForeignDeletedTaskList  = new List <IRtmTask>();
            var secondForeignDeletedTaskList = new List <IRtmTask>();
            var fakeResponseParser           = Substitute.For <IResponseParser>();

            fakeResponseParser.GetTasks(masterResponseData).Returns(masterTaskList);
            fakeResponseParser.GetDeletedTasks(masterResponseData).Returns(masterDeletedTaskList);
            fakeResponseParser.GetTasks(firstForeignResponseData).Returns(firstForeignTaskList);
            fakeResponseParser.GetDeletedTasks(firstForeignResponseData).Returns(firstForeignDeletedTaskList);
            fakeResponseParser.GetTasks(secondForeignResponseData).Returns(secondForeignTaskList);
            fakeResponseParser.GetDeletedTasks(secondForeignResponseData).Returns(secondForeignDeletedTaskList);

            IList <IRtmTask> expectedTaskList = new List <IRtmTask>();
            var mockTaskCache = Substitute.For <ITaskCache>();

            mockTaskCache.GetAllAsync(masterListId).Returns(Task.FromResult(expectedTaskList));

            // Execute
            var taskRepository = GetItemUnderTest(fakeApiClient, fakeResponseParser, mockTaskCache, testSyncTracker);
            var actual         = await taskRepository.GetTasksByListIdAsync(masterListId).ConfigureAwait(false);

            // Verify
            Assert.AreSame(expectedTaskList, actual);
#pragma warning disable 4014
            mockTaskCache.DidNotReceive().ClearAsync();
            mockTaskCache.Received(1).AddOrReplaceAsync(masterListId, masterTaskList, true);
            mockTaskCache.DidNotReceive().RemoveAsync(masterDeletedTaskList);
            mockTaskCache.Received(1).AddOrReplaceAsync(firstForeignListId, firstForeignTaskList);
            mockTaskCache.Received(1).RemoveAsync(firstForeignDeletedTaskList);
            mockTaskCache.Received(1).AddOrReplaceAsync(secondForeignListId, secondForeignTaskList);
            mockTaskCache.Received(1).RemoveAsync(secondForeignDeletedTaskList);
#pragma warning restore 4014
        }