public async Task CreateAllAsync_WithCorrectData_ShouldSuccessfullyCreate()
        {
            var errorMessagePrefix = "LifestyleService CreateAllAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context             = ApplicationDbContextInMemoryFactory.InitializeContext();
            var lifestyleRepository = new EfRepository <Lifestyle>(context);
            var lifestyleService    = new LifestyleService(lifestyleRepository);
            var lifestyleTypes      = new string[] { "Vegetarian", "Dairy Free" };

            // Act
            await lifestyleService.CreateAllAsync(lifestyleTypes);

            var actualResult = await lifestyleRepository
                               .All()
                               .Select(x => x.Type)
                               .ToListAsync();

            var expectedResult = lifestyleTypes;

            // Assert
            for (int i = 0; i < actualResult.Count; i++)
            {
                Assert.True(expectedResult[i] == actualResult[i], errorMessagePrefix + " " + "Expected type and actual type do not match.");
            }
        }
        public async Task GetIdByTypeAsync_WithExistentType_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "LifestyleService GetIdByTypeAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(context);

            var lifestyleRepository = new EfRepository <Lifestyle>(context);
            var lifestyleService    = new LifestyleService(lifestyleRepository);
            var existentType        = "Vegetarian";

            // Act
            var actualResult = await lifestyleService.GetIdByTypeAsync(existentType);

            var expectedResult = (await lifestyleRepository
                                  .All()
                                  .SingleOrDefaultAsync(x => x.Type == existentType))
                                 .Id;

            // Assert
            Assert.True(actualResult == expectedResult, errorMessagePrefix + " " + "Id is not returned properly.");
        }
        public async Task SetLifestyleToUserAsync_WithCorrectData_ShouldSuccessfullySet()
        {
            var errorMessagePrefix = "LifestyleService SetLifestyleToUserAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(context);

            var lifestyleRepository = new EfRepository <Lifestyle>(context);
            var lifestyleService    = new LifestyleService(lifestyleRepository);
            var user = new ApplicationUser();

            // Act
            await lifestyleService.SetLifestyleToUserAsync("Vegetarian", user);

            var actualResult   = user.Lifestyle;
            var expectedResult = await lifestyleRepository
                                 .All()
                                 .SingleOrDefaultAsync(x => x.Type == "Vegetarian");

            // Assert
            Assert.True(actualResult.Id == expectedResult.Id, errorMessagePrefix + " " + "Id is not returned properly.");
            Assert.True(actualResult.Type == expectedResult.Type, errorMessagePrefix + " " + "Type is not returned properly.");
        }
        public async Task CreateAllAsync_WithZeroData_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "LifestyleService CreateAllAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context             = ApplicationDbContextInMemoryFactory.InitializeContext();
            var lifestyleRepository = new EfRepository <Lifestyle>(context);
            var lifestyleService    = new LifestyleService(lifestyleRepository);
            var lifestyleTypes      = new string[] { };

            // Act
            var result = await lifestyleService.CreateAllAsync(lifestyleTypes);

            // Assert
            Assert.False(result, errorMessagePrefix + " " + "Returns true.");
        }
        public async Task GetIdByTypeAsync_WithNonExistentType_ShouldThrowArgumentNullException()
        {
            // Arrange
            MapperInitializer.InitializeMapper();
            var context             = ApplicationDbContextInMemoryFactory.InitializeContext();
            var lifestyleRepository = new EfRepository <Lifestyle>(context);
            var lifestyleService    = new LifestyleService(lifestyleRepository);
            var nonExistentType     = "NonExistent";

            // Act

            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await lifestyleService.GetIdByTypeAsync(nonExistentType);
            });
        }
        public async Task SetLifestyleToUserAsync_WithNonExistentLifestyle_ShouldThrowArgumentNullException()
        {
            // Arrange
            MapperInitializer.InitializeMapper();
            var context             = ApplicationDbContextInMemoryFactory.InitializeContext();
            var lifestyleRepository = new EfRepository <Lifestyle>(context);
            var lifestyleService    = new LifestyleService(lifestyleRepository);
            var user = new ApplicationUser();

            // Act

            // Arrange
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await lifestyleService.SetLifestyleToUserAsync("NonExistent", user);
            });
        }
        public async Task GetAllTypesAsync_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "LifestyleService GetAllTypesAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(context);

            var lifestyleRepository = new EfRepository <Lifestyle>(context);
            var lifestyleService    = new LifestyleService(lifestyleRepository);

            // Act
            var actualResult   = (await lifestyleService.GetAllTypesAsync()).ToList();
            var expectedResult = this.GetDummyData().Select(x => x.Type).ToList();

            // Assert
            for (int i = 0; i < actualResult.Count; i++)
            {
                Assert.True(expectedResult[i] == actualResult[i], errorMessagePrefix + " " + "Expected type and actual type do not match.");
            }
        }