Beispiel #1
0
        public async Task CreateAllAsync_ShouldReturnCorrectCount()
        {
            var errorMessage = "SpecialOffersService CreateAllAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var seeder  = new SpecialOffersServiceTestsSeeder();
            await seeder.SeedHotelAsync(context);

            await seeder.SeedSpecialOffersAsync(context);

            var specialOfferRepository = new EfDeletableEntityRepository <SpecialOffer>(context);
            var specialOffersService   = this.GetSpecialOffersService(specialOfferRepository, context);

            // Act
            var specialOffer = new SpecialOffer
            {
                Title        = "Title1",
                Content      = "Content1",
                ShortContent = "ShortContenr1",
                HotelDataId  = context.Hotels.FirstOrDefault().Id,
            };
            var specialOffersCount = specialOfferRepository.All().Count();
            await specialOffersService.CreateAllAsync(new List <SpecialOffer> {
                specialOffer
            });

            var actualResult   = specialOfferRepository.All().Count();
            var expectedResult = specialOffersCount + 1;

            // Assert
            Assert.True(actualResult == expectedResult, errorMessage + " " + "Special offers count is not reduced.");
        }
Beispiel #2
0
        public async Task GetViewModelByIdAsync_WithExistentId_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "SpecialOffersService GetViewModelByIdAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var seeder  = new SpecialOffersServiceTestsSeeder();
            await seeder.SeedSpecialOffersAsync(context);

            var specialOfferRepository = new EfDeletableEntityRepository <SpecialOffer>(context);
            var specialOffersService   = this.GetSpecialOffersService(specialOfferRepository, context);

            var specialOfferId = specialOfferRepository.All().First().Id;

            // Act
            var actualResult = await specialOffersService.GetViewModelByIdAsync <EditSpecialOfferViewModel>(specialOfferId);

            var expectedResult = new EditSpecialOfferViewModel
            {
                Id           = specialOfferId,
                Title        = specialOfferRepository.All().First().Title,
                Content      = specialOfferRepository.All().First().Content,
                ShortContent = specialOfferRepository.All().First().ShortContent,
                HotelDataId  = context.Hotels.FirstOrDefault().Id,
            };

            // Assert
            Assert.True(expectedResult.Id == actualResult.Id, errorMessagePrefix + " " + "Id is not returned properly.");
            Assert.True(expectedResult.Title == actualResult.Title, errorMessagePrefix + " " + "Title is not returned properly.");
            Assert.True(expectedResult.Content == actualResult.Content, errorMessagePrefix + " " + "Content is not returned properly.");
            Assert.True(expectedResult.ShortContent == actualResult.ShortContent, errorMessagePrefix + " " + "Short content is not returned properly.");
            Assert.True(expectedResult.HotelDataId == actualResult.HotelDataId, errorMessagePrefix + " " + "Hotel is not returned properly.");
        }
Beispiel #3
0
        public async Task DeleteByIdAsync_WithExistentId_ShouldSuccessfullyDelete()
        {
            var errorMessagePrefix = "SpecialOffersService DeleteByIdAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var seeder  = new SpecialOffersServiceTestsSeeder();
            await seeder.SeedSpecialOffersAsync(context);

            var specialOfferRepository = new EfDeletableEntityRepository <SpecialOffer>(context);
            var specialOffersService   = this.GetSpecialOffersService(specialOfferRepository, context);

            var specialOfferId = specialOfferRepository.All().First().Id;

            // Act
            var specialOffersCount = specialOfferRepository.All().Count();
            await specialOffersService.DeleteByIdAsync(specialOfferId);

            var actualResult   = specialOfferRepository.All().Count();
            var expectedResult = specialOffersCount - 1;

            // Assert
            Assert.True(actualResult == expectedResult, errorMessagePrefix + " " + "Special offers count is not reduced.");
        }
Beispiel #4
0
        public async Task GetAllSpecialOffersCountAsync_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "SpecialOffersService GetAllSpecialOffersCountAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var seeder  = new SpecialOffersServiceTestsSeeder();
            await seeder.SeedSpecialOffersAsync(context);

            var specialOfferRepository = new EfDeletableEntityRepository <SpecialOffer>(context);
            var specialOffersService   = this.GetSpecialOffersService(specialOfferRepository, context);

            // Act
            var actualResult = await specialOffersService.GetAllSpecialOffersCountAsync();

            var expectedResult = specialOfferRepository.All().Count();

            // Assert
            Assert.True(actualResult == expectedResult, errorMessagePrefix + " " + "SpecialOffersService GetAllSpecialOffersCountAsync() method does not work properly.");
        }
Beispiel #5
0
        public async Task DeleteByIdAsync_WithExistentId_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "SpecialOffersService DeleteByIdAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var seeder  = new SpecialOffersServiceTestsSeeder();
            await seeder.SeedSpecialOffersAsync(context);

            var specialOfferRepository = new EfDeletableEntityRepository <SpecialOffer>(context);
            var specialOffersService   = this.GetSpecialOffersService(specialOfferRepository, context);

            var specialOfferId = specialOfferRepository.All().First().Id;

            // Act
            var result = await specialOffersService.DeleteByIdAsync(specialOfferId);

            // Assert
            Assert.True(result, errorMessagePrefix + " " + "Returns false.");
        }