Esempio n. 1
0
        public async Task CreateAllAsync_ShouldShouldSuccessfullyCreate()
        {
            var errorMessagePrefix = "SpecialOffersService CreateAllAsync() method does not work properly.";

            // 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);

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

            // Assert
            Assert.True(result, errorMessagePrefix + " " + "Returns false.");
        }
Esempio n. 2
0
        public async Task CreateAllAsync_ShouldReturnCorrectResult()
        {
            var errorMessage = "SpecialOffersService CreateAllAsync() method does not work properly.";

            // 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);

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

            await specialOffersService.CreateAllAsync(new List <SpecialOffer> {
                specialOffer
            });

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

            // Assert
            Assert.True(expectedResult.Title == actualResult.Title, errorMessage + " " + "Title is not returned properly.");
            Assert.True(expectedResult.Content == actualResult.Content, errorMessage + " " + "Content is not returned properly.");
            Assert.True(expectedResult.ShortContent == actualResult.ShortContent, errorMessage + " " + "Short content is not returned properly.");
            Assert.True(expectedResult.HotelDataId == actualResult.HotelDataId, errorMessage + " " + "Hotel is not returned properly.");
        }
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);
            });
        }