public async Task Saves_the_last_sync_timestamp()
        {
            await AddTablesAsync();

            await NubeClient.PullTableAsync <TestItem>();

            await DataStore.Received().SetSettingAsync("lastSync-TestItem", Arg.Any <string>());
        }
        public async Task Forwards_the_predicate_to_the_datastore()
        {
            await AddTablesAsync();

            await NubeClient.FindByAsync(_predicate);

            await DataStore.Received().FindByAsync(_predicate);
        }
        public async Task Uses_default_path_for_table()
        {
            await AddTablesAsync();

            await NubeClient.PullTableAsync <TestItem>();

            Assert.StartsWith("https://myserver/TestItem", HttpMessageHandler.LastRequest.RequestUri.AbsoluteUri);
        }
Example #4
0
        public async Task Throws_when_table_is_not_found_in_the_datastore()
        {
            DataStore.TableExistsAsync <TestItem>().Returns(false);

            var ex = await Assert.ThrowsAsync <ArgumentException>(async() => await NubeClient.AddTableAsync <TestItem>());

            Assert.Equal("The table type TestItem cannot be found in the data store", ex.Message);
        }
        public async Task Queries_the_last_sync_timestamp()
        {
            await AddTablesAsync();

            await NubeClient.PullTableAsync <TestItem>();

            await DataStore.Received().GetSettingAsync("lastSync-TestItem");
        }
Example #6
0
        public async Task Returns_true_when_there_are_no_operations()
        {
            DataStore.GetOperationsAsync(Arg.Any <int>()).Returns(new List <NubeOperation>().AsQueryable());

            var result = await NubeClient.PushChangesAsync();

            Assert.True(result);
        }
Example #7
0
        public async Task Adds_the_table_to_the_datastore()
        {
            DataStore.TableExistsAsync <TestItem>().Returns(true);

            await NubeClient.AddTableAsync <TestItem>();

            await DataStore.Received().AddTableAsync <TestItem>();
        }
Example #8
0
        public async Task Uses_special_table_path_when_set()
        {
            await AddTablesAsync();

            await NubeClient.PullTableAsync <TestItem2>();

            Assert.Equal("https://myserver/differentPath", HttpMessageHandler.LastRequest.RequestUri.AbsoluteUri);
        }
Example #9
0
        public async Task Returns_the_number_of_pulled_records()
        {
            await AddTablesAsync();

            var result = await NubeClient.PullTableAsync <TestItem>();

            Assert.Equal(HttpMessageHandler.Results.Count, result);
        }
        public async Task Queries_all_items_from_the_datastore()
        {
            await AddTablesAsync();

            await NubeClient.GetByIdAsync <TestItem>(_id);

            await DataStore.Received().FindByIdAsync <TestItem>(_id);
        }
Example #11
0
        public async Task Stops_when_the_number_of_returned_items_is_not_equal_to_the_page_size()
        {
            HttpMessageHandler.UserLargeResultSet(7);
            await AddTablesAsync();

            var result = await NubeClient.PullTableAsync <TestItem>();

            Assert.Equal(7, result);
        }
Example #12
0
        public async Task Stops_when_no_more_items_are_returned()
        {
            HttpMessageHandler.UserLargeResultSet(170);
            await AddTablesAsync();

            var result = await NubeClient.PullTableAsync <TestItem>();

            Assert.Equal(170, result);
        }
Example #13
0
        public async Task Includes_the_last_sync_timestamp_in_the_request()
        {
            await AddTablesAsync();

            DataStore.GetSettingAsync("lastSync-TestItem").Returns("2001-1-1");

            await NubeClient.PullTableAsync <TestItem>();

            Assert.Equal("https://myserver/TestItem?pageNumber=1&pageSize=100&laterThan=2000-12-31T23:00:00.000Z", HttpMessageHandler.LastRequest.RequestUri.AbsoluteUri);
        }
Example #14
0
        public async Task Returns_0_when_cancelled()
        {
            var tokenSource = new CancellationTokenSource();

            tokenSource.Cancel();

            var result = await NubeClient.PullTableAsync <TestItem>(tokenSource.Token);

            Assert.Equal(0, result);
        }
Example #15
0
        public async Task Does_not_track_the_delete_when_change_tracker_is_disabled()
        {
            await AddTablesAsync();

            DataStore.DeleteAsync(Arg.Any <TestItem>()).Returns(true);

            await NubeClient.DeleteAsync(Item, true);

            await ChangeTracker.DidNotReceive().TrackDeleteAsync(Arg.Any <TestItem>());
        }
Example #16
0
        public async Task Deletes_the_item_from_the_store()
        {
            await AddTablesAsync();

            DataStore.DeleteAsync(Arg.Any <TestItem>()).Returns(true);

            await NubeClient.DeleteAsync(Item);

            await DataStore.Received().DeleteAsync(Item);
        }
        public void Does_not_set_the_server_base_address_when_it_is_null()
        {
            var baseAddress = "https://something_else/";

            HttpClient.BaseAddress = new Uri(baseAddress);

            NubeClient = new NubeClient(DataStore, null, Authentication, HttpClient, ChangeTracker);

            Assert.Equal(baseAddress, HttpClient.BaseAddress.AbsoluteUri);
        }
Example #18
0
        public async Task Tracks_the_delete()
        {
            await AddTablesAsync();

            DataStore.DeleteAsync(Arg.Any <TestItem>()).Returns(true);

            await NubeClient.DeleteAsync(Item);

            await ChangeTracker.Received().TrackDeleteAsync(Item);
        }
Example #19
0
        public async Task Tracks_the_insert_operation()
        {
            await AddTablesAsync();

            DataStore.InsertAsync(Arg.Any <TestItem>()).Returns(true);

            await NubeClient.SaveAsync(Item);

            await ChangeTracker.Received().TrackAddAsync(Item);
        }
Example #20
0
        public async Task Inserts_the_item_in_the_store()
        {
            await AddTablesAsync();

            DataStore.InsertAsync(Arg.Any <TestItem>()).Returns(true);

            await NubeClient.SaveAsync(Item);

            await DataStore.Received().InsertAsync(Item);
        }
Example #21
0
        public async Task Creates_a_new_item()
        {
            await AddTablesAsync();

            await NubeClient.PullTableAsync <TestItem>();

            await DataStore.Received().InsertAsync(Arg.Is <TestItem>(i => i.Id == HttpMessageHandler.Results[0].Id));

            await DataStore.Received().InsertAsync(Arg.Is <TestItem>(i => i.Id == HttpMessageHandler.Results[1].Id));
        }
Example #22
0
        public async Task Returns_false_when_cancelled()
        {
            var tokenSource = new CancellationTokenSource();

            tokenSource.Cancel();

            var result = await NubeClient.PushChangesAsync(tokenSource.Token);

            Assert.False(result);
        }
Example #23
0
        public async Task Updates_the_item_in_the_store()
        {
            await AddTablesAsync();

            _AddItemToStore();
            DataStore.UpdateAsync(Arg.Any <TestItem>()).Returns(true);

            await NubeClient.SaveAsync(Item);

            await DataStore.Received().UpdateAsync(Item);
        }
Example #24
0
        public async Task Does_not_track_update_when_change_tracker_is_disabled()
        {
            await AddTablesAsync();

            _AddItemToStore();
            DataStore.UpdateAsync(Arg.Any <TestItem>()).Returns(true);

            await NubeClient.SaveAsync(Item, true);

            await ChangeTracker.DidNotReceive().TrackModifyAsync(Arg.Any <TestItem>(), Arg.Any <TestItem>());
        }
        public async Task Tries_to_load_the_existing_item_from_the_database_when_it_is_null()
        {
            await AddTablesAsync();

            _AddItemToStore();
            DataStore.UpdateAsync(Arg.Any <TestItem>()).Returns(true);

            await NubeClient.SaveAsync(Item);

            await DataStore.Received().FindByIdAsync <TestItem>(Item.Id);
        }
Example #26
0
        public async Task Tracks_the_update_operation()
        {
            await AddTablesAsync();

            _AddItemToStore();
            DataStore.UpdateAsync(Arg.Any <TestItem>()).Returns(true);

            await NubeClient.SaveAsync(Item);

            await ChangeTracker.Received().TrackModifyAsync(Arg.Is <TestItem>(
                                                                t => t.Id == Item.Id && t.Name == Item.Name && t.UpdatedAt == Item.UpdatedAt && t.CreatedAt == Item.CreatedAt), Item);
        }
Example #27
0
        public async Task Sets_updated_at_when_change_tracker_is_enabled()
        {
            await AddTablesAsync();

            var updatedAt = Item.UpdatedAt;

            DataStore.InsertAsync(Arg.Any <TestItem>()).Returns(true);

            await NubeClient.SaveAsync(Item);

            Assert.NotEqual(updatedAt, Item.UpdatedAt);
        }
Example #28
0
        public async Task Does_not_set_created_at_when_change_tracker_is_disabled()
        {
            await AddTablesAsync();

            var createdAt = Item.CreatedAt;

            DataStore.InsertAsync(Arg.Any <TestItem>()).Returns(true);

            await NubeClient.SaveAsync(Item, true);

            Assert.Equal(createdAt, Item.CreatedAt);
        }
        public async Task Does_not_try_to_load_the_existing_item_from_the_database_when_the_id_is_null()
        {
            await AddTablesAsync();

            _AddItemToStore();
            DataStore.UpdateAsync(Arg.Any <TestItem>()).Returns(true);
            DataStore.InsertAsync(Arg.Any <TestItem>()).Returns(true);
            Item.Id = null;

            await NubeClient.SaveAsync(Item);

            await DataStore.DidNotReceive().FindByIdAsync <TestItem>(Arg.Any <string>());
        }
Example #30
0
        public async Task Creates_a_id_when_the_item_is_new()
        {
            var oldItemId = Item.Id;

            Item.Id = null;
            await AddTablesAsync();

            DataStore.InsertAsync(Arg.Any <TestItem>()).Returns(true);

            await NubeClient.SaveAsync(Item);

            Assert.NotNull(Item.Id);
            Assert.NotEqual(oldItemId, Item.Id);
        }