Beispiel #1
0
        public async Task DeletePreviousUserAllergensByUserId_WithExistentUserId_ShouldSuccessfullyDelete()
        {
            var errorMessagePrefix = "UserAllergenService DeletePreviousUserAllergensByUserId() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var userAllergenRepository = new EfRepository <UserAllergen>(context);
            var userAllergenService    = new UserAllergenService(userAllergenRepository);

            await this.SeedDataAsync(context);

            var userId = context.Users.First(x => x.Biography == "User with milk and eggs allergies").Id;

            // Act
            var userAllergensCount = userAllergenRepository.All().Count();

            userAllergenService.DeletePreviousUserAllergensByUserId(userId);
            await userAllergenRepository.SaveChangesAsync();

            var actualResult   = userAllergenRepository.All().Count();
            var expectedResult = userAllergensCount - 2;

            // Assert
            Assert.True(expectedResult == actualResult, errorMessagePrefix + " " + "Count is not reduced properly.");
        }
Beispiel #2
0
        public async Task DeletePreviousUserAllergensByUserId_WithNonExistentUserId_ShouldWorkProperly()
        {
            var errorMessagePrefix = "RecipeAllergenService DeletePreviousRecipeAllergensByRecipeId() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var userAllergenRepository = new EfRepository <UserAllergen>(context);
            var userAllergenService    = new UserAllergenService(userAllergenRepository);

            await this.SeedDataAsync(context);

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

            // Act
            var userAllergensCount = userAllergenRepository.All().Count();

            userAllergenService.DeletePreviousUserAllergensByUserId(nonExistentUserId);
            await userAllergenRepository.SaveChangesAsync();

            var actualResult   = userAllergenRepository.All().Count();
            var expectedResult = userAllergensCount;

            // Assert
            Assert.True(expectedResult == actualResult, errorMessagePrefix + " " + "Count does not match.");
        }