Пример #1
0
        public async Task GetRoomTypeByNamec_WithExistentName_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "RoomTypesService GetRoomTypeByName() method does not work properly.";

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

            var roomTypeRepository = new EfDeletableEntityRepository <RoomType>(context);
            var roomTypesService   = this.GetRoomTypesService(roomTypeRepository, context);

            var roomTypeName = roomTypeRepository.All().First().Name;

            // Act
            var actualResult   = roomTypesService.GetRoomTypeByName(roomTypeName);
            var expectedResult = await roomTypeRepository
                                 .All()
                                 .SingleOrDefaultAsync(x => x.Name == roomTypeName);

            // Assert
            Assert.True(expectedResult.Id == actualResult.Id, errorMessagePrefix + " " + "Id is not returned properly.");
            Assert.True(expectedResult.Name == actualResult.Name, errorMessagePrefix + " " + "Name is not returned properly.");
            Assert.True(expectedResult.Price == actualResult.Price, errorMessagePrefix + " " + "Price is not returned properly.");
            Assert.True(expectedResult.CapacityAdults == actualResult.CapacityAdults, errorMessagePrefix + " " + "Capacity Adults is not returned properly.");
            Assert.True(expectedResult.CapacityKids == actualResult.CapacityKids, errorMessagePrefix + " " + "Capacity Kids is not returned properly.");
            Assert.True(expectedResult.Image == actualResult.Image, errorMessagePrefix + " " + "Image is not returned properly.");
            Assert.True(expectedResult.Description == actualResult.Description, errorMessagePrefix + " " + "Description is not returned properly.");
        }
Пример #2
0
        public async Task AddRoomTypeAsync_WithIncorrectProperty_ShouldThrowArgumentNullException()
        {
            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var seeder  = new RoomTypesServiceTestsSeeder();
            await seeder.SeedRoomTypeAsync(context);

            var roomTypeRepository = new EfDeletableEntityRepository <RoomType>(context);
            var roomTypesService   = this.GetRoomTypesService(roomTypeRepository, context);

            var roomTypeModel = new RoomType
            {
                Name           = null,
                Price          = 100,
                CapacityAdults = 1,
                CapacityKids   = 0,
                Image          = "test1.jpg",
                Description    = null,
            };

            // Act

            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await roomTypesService.AddRoomTypeAsync(roomTypeModel);
            });
        }
Пример #3
0
        public async Task DeleteByIdAsync_WithExistentId_ShouldSuccessfullyDelete()
        {
            var errorMessagePrefix = "RoomTypesService DeleteByIdAsync() method does not work properly.";

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

            var roomTypeRepository = new EfDeletableEntityRepository <RoomType>(context);
            var roomTypesService   = this.GetRoomTypesService(roomTypeRepository, context);

            var roomTypeId = roomTypeRepository.All().First().Id;

            // Act
            var roomTypesCount = roomTypeRepository.All().Count();
            await roomTypesService.DeleteByIdAsync(roomTypeId);

            var actualResult   = roomTypeRepository.All().Count();
            var expectedResult = roomTypesCount - 1;

            // Assert
            Assert.True(actualResult == expectedResult, errorMessagePrefix + " " + "Room types count is not reduced.");
        }
Пример #4
0
        public async Task GetAllRoomTypesAsyn_ShouldReturnCorrectCount()
        {
            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var seeder  = new RoomTypesServiceTestsSeeder();
            await seeder.SeedRoomTypeAsync(context);

            var roomTypeRepository = new EfDeletableEntityRepository <RoomType>(context);
            var roomTypesService   = this.GetRoomTypesService(roomTypeRepository, context);

            // Act
            var actualResult   = roomTypesService.GetAllRoomTypes <DetailsRoomTypeViewModel>().ToList();
            var expectedResult = new DetailsRoomTypeViewModel[]
            {
                new DetailsRoomTypeViewModel
                {
                    Id             = roomTypeRepository.All().First().Id,
                    Name           = roomTypeRepository.All().First().Name,
                    CapacityAdults = roomTypeRepository.All().First().CapacityAdults,
                    CapacityKids   = roomTypeRepository.All().First().CapacityKids,
                    Image          = roomTypeRepository.All().First().Image,
                    Description    = roomTypeRepository.All().First().Description,
                },
            };

            Assert.Equal(expectedResult.Length, actualResult.Count());
        }
Пример #5
0
        public async Task EditAsync_WithCorrectData_ShouldReturnCorrectResult()
        {
            var errorMessage = "RoomTypesService EditAsync() method does not work properly.";

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

            var roomTypeRepository = new EfDeletableEntityRepository <RoomType>(context);
            var roomTypesService   = this.GetRoomTypesService(roomTypeRepository, context);

            var roomType = context.RoomTypes.First();

            var model = new EditRoomTypeViewModel
            {
                Id             = roomType.Id,
                Name           = "Test-1",
                Price          = 100,
                CapacityAdults = 1,
                CapacityKids   = 0,
                Image          = "test1.jpg",
                Description    = "Description1",
            };

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

            // Assert
            Assert.True(result, errorMessage + " " + "Returns false.");
        }
Пример #6
0
        public async Task GetAllRoomTypesCountAsync_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "RoomTypesService GetAllRoomTypesCountAsync() method does not work properly.";

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

            var roomTypeRepository = new EfDeletableEntityRepository <RoomType>(context);
            var roomTypesService   = this.GetRoomTypesService(roomTypeRepository, context);

            // Act
            var actualResult = await roomTypesService.GetAllRoomTypesCountAsync();

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

            // Assert
            Assert.True(actualResult == expectedResult, errorMessagePrefix + " " + "RoomTypesService GetAllRoomTypesCountAsync() method does not work properly.");
        }
Пример #7
0
        public async Task DeleteByIdAsync_WithExistentId_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "RoomTypeService DeleteByIdAsync() method does not work properly.";

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

            var roomTypeRepository = new EfDeletableEntityRepository <RoomType>(context);
            var roomTypesService   = this.GetRoomTypesService(roomTypeRepository, context);

            var roomTypeId = roomTypeRepository.All().First().Id;

            // Act
            var result = await roomTypesService.DeleteByIdAsync(roomTypeId);

            // Assert
            Assert.True(result, errorMessagePrefix + " " + "Returns false.");
        }
Пример #8
0
        public async Task EditAsync_WithCorrectData_ShouldSuccessfullyEdit()
        {
            var errorMessagePrefix = "RoomTypeService EditAsync() method does not work properly.";

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

            var roomTypeRepository = new EfDeletableEntityRepository <RoomType>(context);
            var roomTypesService   = this.GetRoomTypesService(roomTypeRepository, context);

            var roomType = context.RoomTypes.First();

            var model = new EditRoomTypeViewModel
            {
                Id             = roomType.Id,
                Name           = "Test-2-Edited",
                Price          = 130,
                CapacityAdults = 1,
                CapacityKids   = 0,
                Image          = "test2-edited.jpg",
                Description    = "Description2-edited",
            };

            // Act
            await roomTypesService.EditAsync(model);

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

            // Assert
            Assert.True(expectedResult.Name == actualResult.Name, errorMessagePrefix + " " + "Name is not returned properly.");
            Assert.True(expectedResult.Price == actualResult.Price, errorMessagePrefix + " " + "Price is not returned properly.");
            Assert.True(expectedResult.CapacityAdults == actualResult.CapacityAdults, errorMessagePrefix + " " + "Capacity Adults is not returned properly.");
            Assert.True(expectedResult.CapacityKids == actualResult.CapacityKids, errorMessagePrefix + " " + "Capacity Kids is not returned properly.");
            Assert.True(expectedResult.Image == actualResult.Image, errorMessagePrefix + " " + "Image is not returned properly.");
            Assert.True(expectedResult.Description == actualResult.Description, errorMessagePrefix + " " + "Description is not returned properly.");
        }
Пример #9
0
        public async Task GetAllRoomTypesAsyn_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "RoomTypesService GetAllRoomTypesAsyn() method does not work properly.";

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

            var roomTypeRepository = new EfDeletableEntityRepository <RoomType>(context);
            var roomTypesService   = this.GetRoomTypesService(roomTypeRepository, context);

            // Act
            var actualResult   = roomTypesService.GetAllRoomTypes <DetailsRoomTypeViewModel>().ToList();
            var expectedResult = new DetailsRoomTypeViewModel[]
            {
                new DetailsRoomTypeViewModel
                {
                    Id             = roomTypeRepository.All().First().Id,
                    Name           = roomTypeRepository.All().First().Name,
                    CapacityAdults = roomTypeRepository.All().First().CapacityAdults,
                    CapacityKids   = roomTypeRepository.All().First().CapacityKids,
                    Image          = roomTypeRepository.All().First().Image,
                    Description    = roomTypeRepository.All().First().Description,
                    Price          = roomTypeRepository.All().First().Price,
                },
            };

            Assert.True(expectedResult[0].Id == actualResult[0].Id, errorMessagePrefix + " " + "Id is not returned properly.");
            Assert.True(expectedResult[0].Name == actualResult[0].Name, errorMessagePrefix + " " + "Name is not returned properly.");
            Assert.True(expectedResult[0].Price == actualResult[0].Price, errorMessagePrefix + " " + "Price is not returned properly.");
            Assert.True(expectedResult[0].CapacityAdults == actualResult[0].CapacityAdults, errorMessagePrefix + " " + "Capacity Adults is not returned properly.");
            Assert.True(expectedResult[0].CapacityKids == actualResult[0].CapacityKids, errorMessagePrefix + " " + "Capacity Kids is not returned properly.");
            Assert.True(expectedResult[0].Image == actualResult[0].Image, errorMessagePrefix + " " + "Image is not returned properly.");
            Assert.True(expectedResult[0].Description == actualResult[0].Description, errorMessagePrefix + " " + "Description is not returned properly.");
        }