public async Task TestBlockUser()
        {
            //Arrange
            var owner = EntitiesCreationService.GetOwner("BlockerOwner");

            owner.HashedPassword = "******";
            var user = EntitiesCreationService.GetUser("BlockingUser");

            user.HashedPassword = "******";
            user = await accountsRepository.AddAsync(user);

            owner = await accountsRepository.AddAsync(owner);

            try
            {
                //Act
                await accountsService.BanUser(owner.AccountId, user.UserName);

                //Assert
                var blockedUserOwners = blockedUsersRepository.BlokedUserOwners(user.AccountId);
                Assert.Contains(blockedUserOwners, buo => buo.OwnerId == owner.AccountId && buo.AccountId == user.AccountId);
            }
            finally
            {
                //Clean
                accountsRepository.Remove(user);
                accountsRepository.Remove(owner);
            }
        }
Ejemplo n.º 2
0
        public async Task GetAllOrdersForRegularUserTest()
        {
            //Arrange
            var newOrder = await GetNewAddedEntity();

            var secondOrder = EntitiesCreationService.GetOrder();

            secondOrder.CustomerId   = newOrder.CustomerId;
            secondOrder.RestaurantId = newOrder.RestaurantId;
            var addedSecondOrder = await repository.AddAsync(secondOrder);

            try
            {
                //Act
                var foundOrders = repository.GetAllOrdersForRegularUser((int)newOrder.CustomerId);

                //Assert
                Assert.Contains(foundOrders, fo => fo.EntityId == newOrder.EntityId);
                Assert.Contains(foundOrders, fo => fo.EntityId == addedSecondOrder.EntityId);
            }
            finally
            {
                //Clean
                CleaningDb(newOrder);
                CleaningDb(addedSecondOrder);
            }
        }
        public async Task GetOwnersRestaurantsTest()
        {
            //Arrange
            var restaurant = await GetNewAddedEntity();

            var secondRestaurant = EntitiesCreationService.GetRestaurant();

            secondRestaurant.OwnerId = restaurant.OwnerId;
            var addedSecondRestaurant = await repository.AddAsync(secondRestaurant);

            try
            {
                //Act
                var restaurants = repository.GetOwnersRestaurants(restaurant.OwnerId);

                //Assert
                Assert.Contains(restaurants, r => r.RestaurantId == restaurant.RestaurantId);
                Assert.Contains(restaurants, r => r.RestaurantId == addedSecondRestaurant.RestaurantId);
            }
            finally
            {
                //Clean
                CleaningDb(restaurant);
                CleaningDb(secondRestaurant);
            }
        }
Ejemplo n.º 4
0
        public async Task GetAllMealsForRestaurantTest()
        {
            //Arrange
            var meal = await GetNewAddedEntity();

            var secondMeal = EntitiesCreationService.GetMeal();

            secondMeal.RestaurantId = meal.RestaurantId;
            var seccondAddedMeal = await repository.AddAsync(secondMeal);

            try
            {
                //Act
                var meals = repository.GetAllMealsForRestaurant(meal.RestaurantId);

                //Assert
                Assert.Contains(meals, m => m.EntityId == meal.EntityId);
                Assert.Contains(meals, m => m.EntityId == seccondAddedMeal.EntityId);
            }
            finally
            {
                //Clean
                CleaningDb(meal);
            }
        }
Ejemplo n.º 5
0
        private async Task <Meal> GetNewMeal()
        {
            var restaurant = await GetRestaurant();

            var meal = EntitiesCreationService.GetMeal();

            meal.RestaurantId = restaurant.RestaurantId;
            return(meal);
        }
        public async Task UpdateStausTestPositive(AccountRoles accountRole, OrderStatuses previousOrderStatus, OrderStatuses nextStatus)
        {
            //Arrange
            var owner = EntitiesCreationService.GetOwner();

            owner.HashedPassword = "******";
            var restaurant = EntitiesCreationService.GetRestaurant();

            owner.Restaurants = new List <Restaurant>()
            {
                restaurant
            };
            owner = await accountsRepository.AddAsync(owner);


            var account = EntitiesCreationService.GetOwner();

            account.HashedPassword = "******";
            account.Role           = accountRole;

            var order = EntitiesCreationService.GetOrder();

            var orderStatus = EntitiesCreationService.GetOrderStatus();

            orderStatus.Status  = previousOrderStatus;
            order.OrderStatuses = new List <OrderStatus>()
            {
                orderStatus
            };
            order.RestaurantId = owner.Restaurants[0].RestaurantId;
            account.Orders     = new List <Order>()
            {
                order
            };

            account = await accountsRepository.AddAsync(account);

            try
            {
                //Act
                await orderService.UpdateStaus(account.AccountId, account.Orders[0].EntityId, nextStatus);

                //Assert
                var statuses = ordersStatusRepository.GetAllStatusesForOrder(account.Orders[0].EntityId);
                Assert.Contains(statuses, s => s.Status == nextStatus);

                var orders = ordersRepository.GetAllOrdersForRegularUser(account.EntityId);
                Assert.Equal(orders[0].LatestOrderStatus, nextStatus);
            }
            finally
            {
                //Clear
                accountsRepository.Remove(account);
                accountsRepository.Remove(owner);
            }
        }
Ejemplo n.º 7
0
        private async Task <Restaurant> GetRestaurant()
        {
            var owner = await GetOwner();

            var restaurnt = EntitiesCreationService.GetRestaurant();

            restaurnt.OwnerId = owner.AccountId;

            return(await restaurantsRepository.AddAsync(restaurnt));
        }
Ejemplo n.º 8
0
        private async Task <Order> GetNewOrder()
        {
            var user = await GetUser();

            var restaurant = await GetRestaurant();

            var order = EntitiesCreationService.GetOrder();

            order.RestaurantId = restaurant.EntityId;
            order.CustomerId   = user.EntityId;
            return(order);
        }
        public async Task UpdateStausTestNegative(AccountRoles accountRole, OrderStatuses previousOrderStatus, OrderStatuses nextStatus)
        {
            //Arrange
            var owner = EntitiesCreationService.GetOwner();

            owner.HashedPassword = "******";
            var restaurant = EntitiesCreationService.GetRestaurant();

            owner.Restaurants = new List <Restaurant>()
            {
                restaurant
            };
            owner = await accountsRepository.AddAsync(owner);


            var account = EntitiesCreationService.GetOwner();

            account.HashedPassword = "******";
            account.Role           = accountRole;

            var order = EntitiesCreationService.GetOrder();

            var orderStatus = EntitiesCreationService.GetOrderStatus();

            orderStatus.Status  = previousOrderStatus;
            order.OrderStatuses = new List <OrderStatus>()
            {
                orderStatus
            };
            order.RestaurantId = owner.Restaurants[0].RestaurantId;
            account.Orders     = new List <Order>()
            {
                order
            };

            account = await accountsRepository.AddAsync(account);

            try
            {
                //Act
                //Assert
                await Assert.ThrowsAnyAsync <Exception>(async() => await orderService.UpdateStaus(account.AccountId, account.Orders[0].EntityId, nextStatus));
            }
            finally
            {
                //Clear
                accountsRepository.Remove(account);
            }
        }
Ejemplo n.º 10
0
        private async Task <Account> GetOwner()
        {
            var owner = EntitiesCreationService.GetOwner();

            return(await accountsRepository.AddAccount(owner, "password"));
        }
        public async Task TestGetAllAvailableRestaurantsForUser()
        {
            //Arrange
            var owner1 = EntitiesCreationService.GetOwner("BlockerOwner1");

            owner1.HashedPassword = "******";
            var restaurant1Owner1 = EntitiesCreationService.GetRestaurant();
            var restaurant2Owner1 = EntitiesCreationService.GetRestaurant();

            owner1.Restaurants = new List <Restaurant>()
            {
                restaurant1Owner1, restaurant2Owner1
            };
            var owner2 = EntitiesCreationService.GetOwner("BlockerOwner2");

            owner2.HashedPassword = "******";
            var restaurant1Owner2 = EntitiesCreationService.GetRestaurant();
            var restaurant2Owner2 = EntitiesCreationService.GetRestaurant();

            owner2.Restaurants = new List <Restaurant>()
            {
                restaurant1Owner2, restaurant2Owner2
            };

            var user1 = EntitiesCreationService.GetUser("BlockingUser1");

            user1.HashedPassword = "******";

            var user2 = EntitiesCreationService.GetUser("BlockingUser2");

            user2.HashedPassword = "******";

            user1 = await accountsRepository.AddAsync(user1);

            user2 = await accountsRepository.AddAsync(user2);

            owner1 = await accountsRepository.AddAsync(owner1);

            owner2 = await accountsRepository.AddAsync(owner2);

            await accountsService.BanUser(owner1.AccountId, user1.UserName);

            await accountsService.BanUser(owner2.AccountId, user2.UserName);

            try
            {
                //Act
                var firstRestaurants  = accountsService.GetAllAvailableRestaurantsForUser(user1.AccountId);
                var secondRestaurants = accountsService.GetAllAvailableRestaurantsForUser(user2.AccountId);

                //Assert
                Assert.DoesNotContain(firstRestaurants,
                                      fr => fr.EntityId == owner1.Restaurants[0].EntityId ||
                                      fr.EntityId == owner1.Restaurants[1].EntityId);

                Assert.DoesNotContain(secondRestaurants,
                                      sr => sr.EntityId == owner2.Restaurants[0].EntityId ||
                                      sr.EntityId == owner2.Restaurants[1].EntityId);

                Assert.Contains(firstRestaurants,
                                fr => fr.EntityId == owner2.Restaurants[0].EntityId ||
                                fr.EntityId == owner2.Restaurants[1].EntityId);

                Assert.Contains(secondRestaurants,
                                sr => sr.EntityId == owner1.Restaurants[0].EntityId ||
                                sr.EntityId == owner1.Restaurants[1].EntityId);
            }
            finally
            {
                //Clean
                accountsRepository.Remove(user1);
                accountsRepository.Remove(owner1);
                accountsRepository.Remove(user2);
                accountsRepository.Remove(owner2);
            }
        }