public void StoreControllerTest_Post_Delete()
        {
            Task.Run(async() =>
            {
                var store = new Store()
                {
                    Name     = "Shop 2137",
                    Address  = "Address 2137",
                    District = new District()
                    {
                        Id = 2
                    }
                };
                var p        = await controller.GetAllAsync();
                int countOld = p.Count();
                await controller.PersistAsync(store);
                p            = await controller.GetAllAsync();
                int countNew = p.Count();

                Assert.AreNotEqual(countOld, countNew);

                int id = p.ToList().SingleOrDefault(x => { return(x.Name.Equals(store.Name) && x.Address.Equals(store.Address)); }).Id;
                await controller.DeleteAsync(id);

                p        = await controller.GetAllAsync();
                countNew = p.Count();
                Assert.AreEqual(countOld, countNew);
            }).GetAwaiter().GetResult();
        }
Пример #2
0
            public async Task ShouldCallDeleteStoreAsync_WhenGivenAUri()
            {
                // Arrange
                var uri = "/test";

                var storeServiceMock = new Mock <IStoreService>();

                storeServiceMock.Setup(service => service.DeleteStoreAsync(uri, default));

                var controller = new StoreController(storeServiceMock.Object);

                // Act
                await controller.DeleteAsync(uri, default);

                // Assert
                storeServiceMock.Verify(service => service.DeleteStoreAsync(uri, default), Times.Once);
            }
        private async void DeleteSelected_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show($"Are you sure you want to delete {SelectedStore.Name}?",
                                                      "Delete operation",
                                                      MessageBoxButton.YesNo,
                                                      MessageBoxImage.Question);

            if (result.Equals(MessageBoxResult.Yes))
            {
                try
                {
                    await storeContext.DeleteAsync(SelectedStore.Id);
                }
                catch (ApiException ex)
                {
                    MessageBox.Show(ex.Message, "API Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                finally
                {
                    LoadData();
                }
            }
        }