Esempio n. 1
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.");
        }
Esempio n. 2
0
        public async Task EditAsync_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 = context.SpecialOffers.First();

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

            // Act

            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await specialOffersService.EditAsync(model);
            });
        }
Esempio n. 3
0
        public async Task EditAsync_WithNonExistentId_ShouldThrowArgumentNullException()
        {
            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var seeder  = new SpecialOffersServiceTestsSeeder();
            await seeder.SeedHotelAsync(context);

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

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

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

            // Act

            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await specialOffersService.EditAsync(model);
            });
        }
Esempio n. 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.");
        }
Esempio n. 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.");
        }
Esempio n. 6
0
        public async Task <bool> EditAsync(EditSpecialOfferViewModel specialOfferEditViewModel)
        {
            var specialOffer = this.specialOfferRepository.All().FirstOrDefault(r => r.Id == specialOfferEditViewModel.Id);

            if (specialOffer == null)
            {
                throw new ArgumentNullException(string.Format(string.Format(ServicesDataConstants.InvalidSpecialOfferIdErrorMessage, specialOfferEditViewModel.Id)));
            }

            if (specialOfferEditViewModel.Title == null || specialOfferEditViewModel.Content == null || specialOffer.ShortContent == null)
            {
                throw new ArgumentNullException(string.Format(ServicesDataConstants.InvalidPropertyNameErrorMessage));
            }

            specialOffer.Title        = specialOfferEditViewModel.Title;
            specialOffer.Content      = specialOfferEditViewModel.Content;
            specialOffer.ShortContent = specialOfferEditViewModel.ShortContent;

            this.specialOfferRepository.Update(specialOffer);

            var result = await this.specialOfferRepository.SaveChangesAsync();

            return(result > 0);
        }
Esempio n. 7
0
        public async Task <IActionResult> Edit(EditSpecialOfferViewModel specialOfferEditView)
        {
            await this.specialOffersService.EditAsync(specialOfferEditView);

            return(this.Redirect($"/Administration/SpecialOffers/All"));
        }