Beispiel #1
0
        private async void Add_Button_Clicked(object sender, EventArgs e)
        {
            var item = new TodoItem()
            {
                Name = "New Item"
            };
            await _nubeClient.SaveAsync(item);

            await RefreshItemsAsync();
        }
        public async Task Does_not_clean_up_operations_from_different_tables_or_currently_added_operations()
        {
            await AddTablesAsync();

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

            _newItem.CreatedAt = Item.CreatedAt;
            var existingOperations = new List <NubeOperation>()
            {
                new NubeOperation()
                {
                    ItemId = Item.Id, TableName = "DifferentTable", Property = "CreatedAt", Type = OperationType.Modified
                },
                new NubeOperation()
                {
                    ItemId = Item.Id, TableName = "DifferentTable", Property = "Name", Type = OperationType.Modified
                },
            };

            DataStore.GetOperationsAsync().Returns(existingOperations.AsQueryable());
            var changeTracker = new ChangeTracker();
            var addOperations = await changeTracker.TrackModifyAsync(Item, _newItem);

            ChangeTracker.TrackModifyAsync(Arg.Any <TestItem>(), Arg.Any <TestItem>()).Returns(addOperations);
            existingOperations.AddRange(addOperations);

            await NubeClient.SaveAsync(_newItem);

            Assert.Empty(RemovedOperations);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
0
        public async Task Does_not_track_insert_when_change_tracker_is_disabled()
        {
            await AddTablesAsync();

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

            await NubeClient.SaveAsync(Item, true);

            await ChangeTracker.DidNotReceive().TrackDeleteAsync(Arg.Any <TestItem>());
        }
Beispiel #6
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);
        }
Beispiel #7
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);
        }
Beispiel #9
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);
        }
Beispiel #10
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);
        }
Beispiel #11
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>());
        }
Beispiel #13
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);
        }
        public async Task Cleans_up_obsolete_operations()
        {
            await AddTablesAsync();

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

            _newItem.CreatedAt = Item.CreatedAt;
            var existingOperations = new List <NubeOperation>()
            {
                new NubeOperation()
                {
                    ItemId = "otherId", TableName = "TestItem", Type = OperationType.Modified
                },
                new NubeOperation()
                {
                    ItemId = Item.Id, TableName = "TestItem", Property = "CreatedAt", Type = OperationType.Modified
                },
                new NubeOperation()
                {
                    ItemId = Item.Id, TableName = "TestItem", Property = "Name", Type = OperationType.Modified
                },
                new NubeOperation()
                {
                    ItemId = Item.Id, TableName = "TestItem", Property = "UpdatedAt", Type = OperationType.Modified
                },
            };
            var expectedOperations = existingOperations.Skip(2).ToList();

            DataStore.GetOperationsAsync().Returns(existingOperations.AsQueryable());
            var changeTracker = new ChangeTracker();
            var addOperations = await changeTracker.TrackModifyAsync(Item, _newItem);

            ChangeTracker.TrackModifyAsync(Arg.Any <TestItem>(), Arg.Any <TestItem>()).Returns(addOperations);
            existingOperations.AddRange(addOperations);

            await NubeClient.SaveAsync(_newItem);

            Assert.Equal(expectedOperations, RemovedOperations);
        }
Beispiel #15
0
        public async Task Throws_when_store_update_fails()
        {
            await AddTablesAsync();

            _AddItemToStore();

            var ex = await Assert.ThrowsAsync <StoreOperationFailedException>(async() => await NubeClient.SaveAsync(Item));

            Assert.Equal("Could not update item", ex.Message);
        }
Beispiel #16
0
        public async Task Throws_when_operations_cannot_be_stored()
        {
            await AddTablesAsync();

            DataStore.InsertAsync(Arg.Any <TestItem>()).Returns(true);
            DataStore.AddOperationsAsync(Arg.Any <NubeOperation[]>()).Returns(false);

            var ex = await Assert.ThrowsAsync <StoreOperationFailedException>(async() => await NubeClient.SaveAsync(_newItem));

            Assert.Equal($"Could not save add operations for item {Item.Id}", ex.Message);
        }
Beispiel #17
0
        public async Task Throws_when_operations_cannot_be_removed()
        {
            _AddItemToStore();
            await AddTablesAsync();

            DataStore.UpdateAsync(Arg.Any <TestItem>()).Returns(true);
            DataStore.DeleteOperationsAsync(Arg.Any <NubeOperation[]>()).Returns(false);

            var ex = await Assert.ThrowsAsync <StoreOperationFailedException>(async() => await NubeClient.SaveAsync(_newItem));

            Assert.Equal($"Could not delete obsolete operations for modified item", ex.Message);
        }
Beispiel #18
0
        public async Task Checks_if_table_is_valid()
        {
            var ex = await Assert.ThrowsAsync <InvalidOperationException>(async() => await NubeClient.SaveAsync(Item));

            Assert.Equal("Table TestItem is not registered in the nube client", ex.Message);
        }