예제 #1
0
        public async Task DeleteByShoppingListIdAsync_WithNonExistentShoppingListId_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "UserShoppingListService DeleteByShoppingListIdAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var userShoppingListRepository = new EfRepository <UserShoppingList>(context);
            var userShoppingListService    = new UserShoppingListService(userShoppingListRepository);

            await this.SeedDataAsync(context);

            var nonExistentShoppingListId = Guid.NewGuid().ToString();

            // Act
            var result = await userShoppingListService.DeleteByShoppingListIdAsync(nonExistentShoppingListId);

            // Assert
            Assert.False(result, errorMessagePrefix + " " + "Returns true.");
        }
예제 #2
0
        public async Task DeleteByShoppingListIdAsync_WithExistentShoppingListId_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "UserShoppingListService DeleteByShoppingListIdAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var userShoppingListRepository = new EfRepository <UserShoppingList>(context);
            var userShoppingListService    = new UserShoppingListService(userShoppingListRepository);

            await this.SeedDataAsync(context);

            var shoppingListId = context.ShoppingLists.First(x => x.Ingredients == "Ingredients 1").Id;

            // Act
            var result = await userShoppingListService.DeleteByShoppingListIdAsync(shoppingListId);

            // Assert
            Assert.True(result, errorMessagePrefix + " " + "Returns false.");
        }
예제 #3
0
        public async Task DeleteByShoppingListIdAsync_WithExistentShoppingListId_ShouldSuccessfullyDelete()
        {
            var errorMessagePrefix = "UserShoppingListService DeleteByShoppingListIdAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var userShoppingListRepository = new EfRepository <UserShoppingList>(context);
            var userShoppingListService    = new UserShoppingListService(userShoppingListRepository);

            await this.SeedDataAsync(context);

            var shoppingListId = context.ShoppingLists.First(x => x.Ingredients == "Ingredients 1").Id;

            // Act
            var userShoppingListsCount = userShoppingListRepository.All().Count();
            await userShoppingListService.DeleteByShoppingListIdAsync(shoppingListId);

            var actualResult   = userShoppingListRepository.All().Count();
            var expectedResult = userShoppingListsCount - 1;

            // Assert
            Assert.True(expectedResult == actualResult, errorMessagePrefix + " " + "Count is not reduced properly.");
        }