예제 #1
0
        public async Task AddSpecialOfferAsync_WithIncorrectProperty_ShouldThrowArgumentNullException()
        {
            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var seeder  = new SpecialOffersServiceTestsSeeder();
            await seeder.SeedSpecialOfferAsync(context);

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

            var specialOffer = new SpecialOffer
            {
                Title        = null,
                Content      = null,
                ShortContent = "ShortContenr1",
                HotelDataId  = context.Hotels.FirstOrDefault().Id,
            };

            // Act

            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await specialOffersService.AddSpecialOfferAsync(specialOffer);
            });
        }
예제 #2
0
        public async Task GetAllSpecialOffers_ShouldReturnCorrectCount()
        {
            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var seeder  = new SpecialOffersServiceTestsSeeder();
            await seeder.SeedSpecialOfferAsync(context);

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

            // Act
            var actualResult   = specialOffersService.GetAllSpecialOffers <DetailsSpecialOfferViewModel>().ToList();
            var expectedResult = new DetailsSpecialOfferViewModel[]
            {
                new DetailsSpecialOfferViewModel
                {
                    Id           = specialOfferRepository.All().First().Id,
                    Title        = specialOfferRepository.All().First().Title,
                    Content      = specialOfferRepository.All().First().Content,
                    ShortContent = specialOfferRepository.All().First().ShortContent,
                },
            };

            Assert.Equal(expectedResult.Length, actualResult.Count());
        }
예제 #3
0
        public async Task GetAllSpecialOffers_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "SpecialOffersService GetAllSpecialOffers() method does not work properly.";

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

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

            // Act
            var actualResult   = specialOffersService.GetAllSpecialOffers <DetailsSpecialOfferViewModel>().ToList();
            var expectedResult = new DetailsSpecialOfferViewModel[]
            {
                new DetailsSpecialOfferViewModel
                {
                    Id           = specialOfferRepository.All().First().Id,
                    Title        = specialOfferRepository.All().First().Title,
                    Content      = specialOfferRepository.All().First().Content,
                    ShortContent = specialOfferRepository.All().First().ShortContent,
                },
            };

            Assert.True(expectedResult[0].Id == actualResult[0].Id, errorMessagePrefix + " " + "Id is not returned properly.");
            Assert.True(expectedResult[0].Title == actualResult[0].Title, errorMessagePrefix + " " + "Name is not returned properly.");
            Assert.True(expectedResult[0].Content == actualResult[0].Content, errorMessagePrefix + " " + "Content is not returned properly.");
            Assert.True(expectedResult[0].ShortContent == actualResult[0].ShortContent, errorMessagePrefix + " " + "ShortContent is not returned properly.");
        }
예제 #4
0
        public async Task EditAsync_WithCorrectData_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "SpecialOffersService EditAsync() method does not work properly.";

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

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

            var specialOffer = context.SpecialOffers.First();

            var model = new EditSpecialOfferViewModel
            {
                Id           = specialOffer.Id,
                Title        = "Title-Edited",
                Content      = "Content-Edited",
                ShortContent = "ShortContenr-Edited",
                HotelDataId  = context.Hotels.FirstOrDefault().Id,
            };

            // Act
            var result = await specialOffersService.EditAsync(model);

            // Assert
            Assert.True(result, errorMessagePrefix + " " + "Returns false.");
        }
예제 #5
0
        public async Task EditAsync_WithCorrectData_ShouldSuccessfullyEdit()
        {
            var errorMessagePrefix = "SpecialOffersService EditAsync() method does not work properly.";

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

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

            var specialOffer = context.SpecialOffers.First();

            var model = new EditSpecialOfferViewModel
            {
                Id           = specialOffer.Id,
                Title        = "Title1-Edited",
                Content      = "Content1-Edited",
                ShortContent = "ShortContenr1-Edited",
                HotelDataId  = context.Hotels.FirstOrDefault().Id,
            };

            // Act
            await specialOffersService.EditAsync(model);

            var actualResult   = specialOfferRepository.All().First();
            var expectedResult = model;

            // Assert
            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.");
        }