public async Task AddTable_InInvalidRestaurant_ShouldNotCreate()
        {
            var context = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.tableService = new TableService(context);
            await SeedData(context);

            AddTableBindingModel model = new AddTableBindingModel
            {
                SeatsCount = 5
            };

            RestaurantServiceModel restaurant = new RestaurantServiceModel
            {
                Id            = "3",
                Address       = "Ivan Vazov",
                AverageRating = 10,
                Name          = "Happy",
                PhoneNumber   = "08888888888",
                Photo         = "src/happy-photo.jpg",
                CityId        = "1"
            };

            await Assert.ThrowsAsync <ArgumentNullException>(() => tableService.AddTable(model, restaurant));
        }
        public async Task GetRestaurantTables_WithData_ShouldReturnCorrectResults()
        {
            string errorMessagePrefix = "Table service GetAllProducts() method does not work properly.";

            var context = ReserveTableDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.tableService = new TableService(context);

            RestaurantServiceModel restaurant = new RestaurantServiceModel
            {
                Id            = "1",
                Address       = "Ivan Vazov",
                AverageRating = 10,
                Name          = "Happy",
                PhoneNumber   = "08888888888",
                Photo         = "src/happy-photo.jpg",
                CityId        = "1"
            };

            var tables = await this.tableService.GetRestaurantTables(restaurant);

            List <TableServiceModel> actualResults   = tables.ToList();
            List <TableServiceModel> expectedResults = GetTableData().To <TableServiceModel>().ToList();

            for (int i = 0; i < expectedResults.Count; i++)
            {
                var expectedEntry = expectedResults[i];
                var actualEntry   = actualResults[i];

                Assert.True(expectedEntry.SeatsCount == actualEntry.SeatsCount, errorMessagePrefix + " " + "Seats count is not returned properly.");
                Assert.True(expectedEntry.RestaurantId == actualEntry.RestaurantId, errorMessagePrefix + " " + "Restaurant Id is not returned properly.");
            }
        }
Esempio n. 3
0
        public async Task GetMyReservations_WithData_ShouldReturnCorrectResults()
        {
            string errorMessage = "ReservationService GetMyReservations() method does not work properly.";

            var context = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.reservationService = new ReservationService(context);
            await SeedData(context);

            List <ReservationServiceModel> expectedResults = GetReservationData().To <ReservationServiceModel>().ToList();
            var reservations = await reservationService.GetMyReservations("pesho");

            List <ReservationServiceModel> actualResults = reservations.ToList();

            for (int i = 0; i < expectedResults.Count; i++)
            {
                var actualResult   = actualResults[i];
                var expectedResult = expectedResults[i];

                Assert.True(actualResult.RestaurantId == expectedResult.RestaurantId, errorMessage + " " + "Restaurant Id is not returned properly.");
                Assert.True(actualResult.SeatsCount == expectedResult.SeatsCount, errorMessage + " " + "Seats Count is not returned properly.");
                Assert.True(actualResult.IsCancelled == expectedResult.IsCancelled, errorMessage + " " + "Is Cancelled is not returned properly.");
                Assert.True(actualResult.TableId == expectedResult.TableId, errorMessage + " " + "Table Id is not returned properly.");
                Assert.True(actualResult.ForDate == expectedResult.ForDate, errorMessage + " " + "For Date is not returned properly.");
            }
        }
        public async Task GetRestaurantById_WithData_ShouldReturnCorrectResult()
        {
            var context = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.restaurantService = new RestaurantService(context);
            await SeedData(context);

            var restaurantId   = "1";
            var expectedResult = new RestaurantServiceModel
            {
                Id          = "1",
                Name        = "Ego",
                Address     = "Egos Address",
                CityId      = "1",
                PhoneNumber = "0888888888",
                Photo       = "/src/ego-photo.jpg"
            };

            var actualResult = await restaurantService.GetRestaurantById(restaurantId);

            Assert.Equal(expectedResult.Name, actualResult.Name);
            Assert.Equal(expectedResult.Address, actualResult.Address);
            Assert.Equal(expectedResult.CityId, actualResult.CityId);
            Assert.Equal(expectedResult.PhoneNumber, actualResult.PhoneNumber);
            Assert.Equal(expectedResult.Photo, actualResult.Photo);
        }
        public async Task AddTable_WithCorrectData_ShouldCreateSucessfully()
        {
            var errorMessage = "Table service AddTable() method is not working correctly.";
            var context      = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.tableService = new TableService(context);
            await SeedData(context);

            AddTableBindingModel model = new AddTableBindingModel
            {
                SeatsCount = 5
            };

            RestaurantServiceModel restaurant = new RestaurantServiceModel
            {
                Id            = "1",
                Address       = "Ivan Vazov",
                AverageRating = 10,
                Name          = "Happy",
                PhoneNumber   = "08888888888",
                Photo         = "src/happy-photo.jpg",
                CityId        = "1"
            };

            var actualResult = await this.tableService.AddTable(model, restaurant);

            Assert.True(actualResult, errorMessage);
        }
Esempio n. 6
0
        public async Task GetRestaurantsInCity_WithDataAlphabeticallyDescending_ShouldReturnCorrectResults()
        {
            string errorMessagePrefix = "CityService GetRestaurantsInCity() method does not work properly.";

            var context = ReserveTableDbContextInMemoryFactory.InitializeContext();

            await Seed(context);

            this.cityService = new CityService(context);

            var restaurantInPlovdiv = new RestaurantServiceModel
            {
                Id            = "1",
                Name          = "Happy",
                Address       = "Ivan Vazov",
                AverageRating = 10,
                CityId        = "1",
                PhoneNumber   = "0888888888",
                Photo         = "/src/Happy.jpg"
            };

            var restaurantInPlovdiv2 = new RestaurantServiceModel
            {
                Id            = "3",
                Name          = "KFC",
                Address       = "Vasil Levski",
                AverageRating = 7,
                CityId        = "1",
                PhoneNumber   = "0888888899",
                Photo         = "/src/KFC.jpg"
            };

            var restaurantsInCity = await this.cityService.GetRestaurantsInCity("Plovdiv", "alphabetically-z-to-a");

            List <RestaurantServiceModel> actualResults   = restaurantsInCity.ToList();
            List <RestaurantServiceModel> expectedResults = new List <RestaurantServiceModel>
            {
                restaurantInPlovdiv,
                restaurantInPlovdiv2
            }
            .OrderByDescending(r => r.Name)
            .ToList();

            for (int i = 0; i < expectedResults.Count; i++)
            {
                var expectedEntry = expectedResults[i];
                var actualEntry   = actualResults[i];

                Assert.True(expectedEntry.Name == actualEntry.Name, errorMessagePrefix + " " + "Name is not returned properly.");
                Assert.True(expectedEntry.Address == actualEntry.Address, errorMessagePrefix + " " + "Address is not returned properly.");
                Assert.True(expectedEntry.PhoneNumber == actualEntry.PhoneNumber, errorMessagePrefix + " " + "Phone Number is not returned properly.");
                Assert.True(expectedEntry.CityId == actualEntry.CityId, errorMessagePrefix + " " + "City Id is not returned properly.");
                Assert.True(expectedEntry.AverageRating == actualEntry.AverageRating, errorMessagePrefix + " " + "Average Rating is not returned properly.");
                Assert.True(expectedEntry.Photo == actualEntry.Photo, errorMessagePrefix + " " + "Photo is not returned properly.");
            }
        }
Esempio n. 7
0
        public async Task GetReservationById_WithInvalidId_ShouldThrowArgumentNullException()
        {
            var context = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.reservationService = new ReservationService(context);
            await SeedData(context);

            string reservationId = "2";
            await Assert.ThrowsAsync <ArgumentNullException>(() => reservationService.GetReservationById(reservationId));
        }
        public async Task SetNewRating_WithInvalidRating_ShouldThrowArgumentException(double rating)
        {
            var context = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.restaurantService = new RestaurantService(context);
            await SeedData(context);

            var restaurantId = "1";

            await Assert.ThrowsAsync <ArgumentException>(() => restaurantService.SetNewRating(restaurantId, rating));
        }
Esempio n. 9
0
        public async Task GetCityByName_WithExistentName_ShouldReturnCorrectResults()
        {
            var context = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.cityService = new CityService(context);
            await Seed(context);

            var expectedResult = "1";
            var actualResult   = await cityService.GetCityByName("Plovdiv");

            Assert.Equal(expectedResult, actualResult);
        }
        public async Task SetNewRating_InNotExistantRestaurant_ShouldThrowArgumentNullException()
        {
            var context = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.restaurantService = new RestaurantService(context);
            await SeedData(context);

            var    restaurantId = "10";
            double rating       = 10;

            await Assert.ThrowsAsync <ArgumentNullException>(() => restaurantService.SetNewRating(restaurantId, rating));
        }
Esempio n. 11
0
        public async Task GetCityByName_WithNotExistentName_ShouldReturnNull()
        {
            var errorMessage = "CityService GetCityByName() method does not work properly.";
            var context      = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.cityService = new CityService(context);
            await Seed(context);

            var actualResult = await cityService.GetCityByName("Vidin");

            Assert.True(actualResult == null, errorMessage);
        }
        public async Task GetRestaurantById_WithNotExistentRestaurant_ShouldReturnNull()
        {
            string errorMessage = "RestaurantService GetRestaurantById() method does not work properly.";
            var    context      = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.restaurantService = new RestaurantService(context);
            await SeedData(context);

            var restaurantId = "10";
            var actualResult = await this.restaurantService.GetRestaurantById(restaurantId);

            Assert.True(actualResult == null, errorMessage);
        }
Esempio n. 13
0
        public async Task AddCity_WithInvalidName_ShouldThrowArgumentException(string cityName)
        {
            var context = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.cityService = new CityService(context);

            CityServiceModel city = new CityServiceModel
            {
                Name  = cityName,
                Photo = "/src/varna.jpg",
            };

            await Assert.ThrowsAsync <ArgumentException>(() => this.cityService.AddCity(city));
        }
Esempio n. 14
0
        public async Task GetRestaurantsInCity_WithZeroData_ShouldReturnEmptyResults()
        {
            string errorMessage = "CityService GetRestaurantsInCity() method does not work properly.";

            var context = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.cityService = new CityService(context);

            var restaurantsInCity = await this.cityService.GetRestaurantsInCity("Plovdiv");

            List <RestaurantServiceModel> actualResults = restaurantsInCity.ToList();

            Assert.True(actualResults.Count == 0, errorMessage);
        }
Esempio n. 15
0
        public async Task CancelReservation_WithData_ShouldReturnTrue()
        {
            string errorMessage = "ReservationService CancelReservation() method does not work properly.";

            var context = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.reservationService = new ReservationService(context);
            await SeedData(context);

            string reservationId = "1";
            var    actualResult  = await reservationService.CancelReservation(reservationId);

            Assert.True(actualResult, errorMessage);
        }
        public async Task GetUserById_WithNonExistentId_ShouldReturnNull()
        {
            string errorMessage = "UserService GetById() method does not work properly.";

            var context = ReserveTableDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.userService = new UserService(context);

            ReserveTableUserServiceModel actualData = await this.userService.GetUserById("invalid");

            Assert.True(actualData == null, errorMessage);
        }
Esempio n. 17
0
        public async Task Create_WithNoComment_ShouldThrowArgumentException()
        {
            var context = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.reviewService = new ReviewService(context);

            ReviewServiceModel review = new ReviewServiceModel
            {
                Date    = DateTime.Now,
                Comment = string.Empty,
                Rate    = 9,
            };

            await Assert.ThrowsAsync <ArgumentException>(() => this.reviewService.Create(review));
        }
Esempio n. 18
0
        public async Task IsDateValid_WithInvalidData_ShouldReturnFalse()
        {
            string errorMessage = "ReservationService IsDateValid() method does not work properly.";

            var context = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.reservationService = new ReservationService(context);
            await SeedData(context);

            DateTime invalidDateTime = DateTime.Now.AddDays(-1);

            var actualResult = await reservationService.IsDateValid(invalidDateTime);

            Assert.False(actualResult, errorMessage);
        }
        public async Task GetRestaurantByNameAndCity_WithInvalidData_ShouldReturnNull()
        {
            string errorMessage = "RestaurantService GetRestaurantByNameAndCity() method does not work properly.";
            var    context      = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.restaurantService = new RestaurantService(context);
            await SeedData(context);

            string city       = "Plovdiv";
            string restaurant = "Happy";

            RestaurantServiceModel actualResult = await restaurantService.GetRestaurantByNameAndCity(city, restaurant);

            Assert.True(actualResult == null, errorMessage);
        }
Esempio n. 20
0
        public async Task Create_WithInvalidRate_ShouldThrowArgumentException(double rate)
        {
            var context = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.reviewService = new ReviewService(context);

            ReviewServiceModel review = new ReviewServiceModel
            {
                Date    = DateTime.Now,
                Comment = "Good",
                Rate    = rate,
            };

            await Assert.ThrowsAsync <ArgumentException>(() => this.reviewService.Create(review));
        }
        public async Task SetNewRating_WithData_ShouldReturnCorrectResult()
        {
            string errorMessage = "RestaurantService SetNewRating() method does not work properly.";
            var    context      = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.restaurantService = new RestaurantService(context);
            await SeedData(context);

            var    restaurantId = "1";
            double rating       = 10;

            var actualResult = await restaurantService.SetNewRating(restaurantId, rating);

            Assert.True(actualResult, errorMessage);
        }
Esempio n. 22
0
        public async Task MakeReservation_WithNoAvailableTables_ShouldReturnNull()
        {
            string errorMessage = "ReservationService MakeReservation() method does not work properly.";

            var context = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.reservationService = new ReservationService(context);
            await SeedData(context);

            CreateReservationBindingModel reservationBindingModel = new CreateReservationBindingModel
            {
                Date       = "09/08/2019 20:00:00",
                SeatsCount = 4,
                Restaurant = "Happy"
            };

            ReserveTableUserServiceModel user = new ReserveTableUserServiceModel
            {
                Id       = "1",
                Email    = "*****@*****.**",
                UserName = "******"
            };

            RestaurantServiceModel restaurant = new RestaurantServiceModel
            {
                Id            = "1",
                Address       = "New Street",
                AverageRating = 10,
                CityId        = "1",
                Name          = "Happy",
                PhoneNumber   = "0888888888",
                Photo         = "/src/happy.jpg",
                Tables        = new List <TableServiceModel>()
                {
                    new TableServiceModel
                    {
                        Id           = "1",
                        SeatsCount   = 2,
                        RestaurantId = "1",
                        Reservations = new List <ReservationServiceModel>()
                    }
                }
            };

            var actualResult = await reservationService.MakeReservation(reservationBindingModel, user, restaurant);

            Assert.True(actualResult == null, errorMessage);
        }
Esempio n. 23
0
        public async Task GetReservationById_WithData_ShouldReturnCorrectResults()
        {
            string errorMessage = "ReservationService GetReservationById() method does not work properly.";
            var    context      = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.reservationService = new ReservationService(context);
            await SeedData(context);

            string reservationId = "1";
            var    actualResult  = await reservationService.GetReservationById(reservationId);

            ReservationServiceModel expectedResult = new ReservationServiceModel
            {
                Id           = "1",
                ForDate      = new DateTime(2019, 9, 5, 20, 0, 0),
                RestaurantId = "1",
                IsCancelled  = false,
                SeatsCount   = 2,
                TableId      = "1",
                UserId       = "1",
                Restaurant   = new RestaurantServiceModel
                {
                    Id            = "1",
                    Address       = "New Street",
                    AverageRating = 10,
                    CityId        = "1",
                    Name          = "Happy",
                    PhoneNumber   = "0888888888",
                    Photo         = "/src/happy.jpg",
                    Tables        = new List <TableServiceModel>()
                    {
                        new TableServiceModel
                        {
                            Id           = "1",
                            SeatsCount   = 2,
                            RestaurantId = "1"
                        }
                    }
                }
            };

            Assert.True(actualResult.RestaurantId == expectedResult.RestaurantId, errorMessage + " " + "Restaurant Id is not returned properly.");
            Assert.True(actualResult.SeatsCount == expectedResult.SeatsCount, errorMessage + " " + "Seats Count is not returned properly.");
            Assert.True(actualResult.IsCancelled == expectedResult.IsCancelled, errorMessage + " " + "Is Cancelled is not returned properly.");
            Assert.True(actualResult.TableId == expectedResult.TableId, errorMessage + " " + "Table Id is not returned properly.");
            Assert.True(actualResult.ForDate == expectedResult.ForDate, errorMessage + " " + "For Date is not returned properly.");
        }
        public async Task GetUserByUsername_WithExistentUsername_ShouldReturnCorrectResult()
        {
            string errorMessagePrefix = "UserService GetUserByUsername() method does not work properly.";

            var context = ReserveTableDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.userService = new UserService(context);

            ReserveTableUserServiceModel expectedData = context.Users.First().To <ReserveTableUserServiceModel>();
            ReserveTableUserServiceModel actualData   = await this.userService.GetUserByUsername(expectedData.UserName);

            Assert.True(expectedData.Id == actualData.Id, errorMessagePrefix + " " + "Id is not returned properly.");
            Assert.True(expectedData.UserName == actualData.UserName, errorMessagePrefix + " " + "UserName is not returned properly.");
            Assert.True(expectedData.Email == actualData.Email, errorMessagePrefix + " " + "Price is not returned properly.");
        }
Esempio n. 25
0
        public async Task CheckIfExists_WithNotExistentCity_ShouldReturnFalse()
        {
            string errorMessage = "CityService CheckIfExists() method does not work properly.";
            var    context      = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.cityService = new CityService(context);
            await Seed(context);

            CityServiceModel city = new CityServiceModel
            {
                Name  = "Varna",
                Photo = "/src/varna.jpg"
            };

            var actualResult = await cityService.CheckIfExists(city);

            Assert.False(actualResult, errorMessage);
        }
        public async Task CreateNewRestaurant_InNotExistentCity_ShouldThrowArgumentNullException()
        {
            var context = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.restaurantService = new RestaurantService(context);
            await SeedData(context);

            RestaurantServiceModel restaurant = new RestaurantServiceModel
            {
                Name        = "Happy",
                Address     = "Center",
                CityId      = "2",
                PhoneNumber = "08888888888",
                Photo       = "/src/happy.jpg"
            };

            await Assert.ThrowsAsync <ArgumentNullException>(() => this.restaurantService.CreateNewRestaurant(restaurant));
        }
Esempio n. 27
0
        public async Task AddCity_WithCorrectData_ShouldCreateSucessfully()
        {
            string errorMessage = "CityService AddCity() method does not work properly.";

            var context = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.cityService = new CityService(context);

            CityServiceModel city = new CityServiceModel
            {
                Name  = "Varna",
                Photo = "/src/varna.jpg",
            };

            bool actualResult = await this.cityService.AddCity(city);

            Assert.True(actualResult, errorMessage);
        }
        public async Task CreateNewRestaurant_WithInvalidAddress_ShouldThrowArgumentException(string address)
        {
            var context = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.restaurantService = new RestaurantService(context);
            await SeedData(context);

            RestaurantServiceModel restaurant = new RestaurantServiceModel
            {
                Name        = "Happy",
                Address     = address,
                CityId      = "1",
                PhoneNumber = "08888888888",
                Photo       = "/src/happy.jpg"
            };

            await Assert.ThrowsAsync <ArgumentException>(() => this.restaurantService.CreateNewRestaurant(restaurant));
        }
Esempio n. 29
0
        public async Task Create_WithCorrectData_ShouldCreateSucessfully()
        {
            string errorMessage = "ReviewService Create() method does not work properly.";

            var context = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.reviewService = new ReviewService(context);

            ReviewServiceModel review = new ReviewServiceModel
            {
                Date    = DateTime.Now,
                Comment = "Good",
                Rate    = 9,
            };

            bool actualResult = await this.reviewService.Create(review);

            Assert.True(actualResult, errorMessage);
        }
Esempio n. 30
0
        public async Task GetAllCitiesNames_WithData_ShouldReturnCorrectResults()
        {
            string errorMessage = "CityService GetAllCitiesNames() method does not work properly.";
            var    context      = ReserveTableDbContextInMemoryFactory.InitializeContext();

            this.cityService = new CityService(context);
            await Seed(context);

            var cities = await this.cityService.GetAllCitiesNames();

            List <string> actualResults   = cities.ToList();
            List <string> expectedResults = GetCityData().Select(city => city.Name).ToList();

            for (int i = 0; i < expectedResults.Count; i++)
            {
                var expectedEntry = expectedResults[i];
                var actualEntry   = actualResults[i];

                Assert.True(expectedEntry == actualEntry, errorMessage);
            }
        }