public void FoodChoiceService_AddUser()
        {
            // Arrange
            var repositoryMock = GetRepositoryMock();

            var service = new FoodChoiceService();
            service.FoodChoiceRepository = repositoryMock.Object;

            var user = new User
            {
                Name = "lionel",
                IpAddress = "192.168.0.1",
                AvailableSeats = 2,
                Choices = new List<Choice>
                {
                    new Choice
                    {
                        Place = new Place
                        {
                            Label = "Marie Blachère", InputType = false
                        }
                    }
                }
            };

            // Act
            service.AddUser(user);

            // Assert
            repositoryMock.Verify(r => r.Add(user));
        }
        public void FoodChoiceService_DeleteUser_IpAddressIncorrect()
        {
            const int userId = 1;
            const string ipAddressToCompare = "127.0.0.1";

            var repositoryMock = GetRepositoryMock();

            var service = new FoodChoiceService();
            service.FoodChoiceRepository = repositoryMock.Object;

            service.DeleteUser(userId, ipAddressToCompare);

            repositoryMock.Verify(r => r.FindById(userId));
            repositoryMock.Verify(r => r.Delete(_user), Times.Never);
        }
Пример #3
0
        public override void Initialize()
        {
            // initialize controller with services and fake repository
            controller = new HomeController();
            controller.ValidationService = new ValidationService();

            var foodChoiceService = new FoodChoiceService();
            foodChoiceService.FoodChoiceRepository = GetRepositoryMock().Object;
            controller.FoodChoiceService = foodChoiceService;
        }
        public void FoodChoiceService_UpdateUser_Ok()
        {
            const int userId = 1;
            var userUpdated = new User
            {
                Id = _userId,
                Name = "lionel",
                Choices = new List<Choice> {
                    new Choice { Place = new Place { Id = 1, Label = "Carrefour" } },
                    new Choice { Place = new Place { Id = 1, Label = "Quick" } },
                }
            };

            const string ipAddressToCompare = "192.168.0.1";

            var repositoryMock = GetRepositoryMock();

            var service = new FoodChoiceService();
            service.FoodChoiceRepository = repositoryMock.Object;

            service.UpdateUser(userUpdated, ipAddressToCompare);

            repositoryMock.Verify(r => r.FindById(userId));
            repositoryMock.Verify(r => r.Update(_user, userUpdated));
        }
        public void FoodChoiceService_GetTodayUsersChoices()
        {
            var today = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
            var tomorrow = today.AddDays(1);

            var repositoryMock = GetRepositoryMock();

            var service = new FoodChoiceService();
            service.FoodChoiceRepository = repositoryMock.Object;
            var usersChoices = service.GetTodayUsersChoices();

            repositoryMock.Verify(r => r.GetUsersChoices(today, tomorrow));
        }
        public void FoodChoiceService_GetPlaces()
        {
            var repositoryMock = GetRepositoryMock();

            var service = new FoodChoiceService();
            service.FoodChoiceRepository = repositoryMock.Object;

            service.GetPlaces();
            repositoryMock.Verify(r => r.GetPlaces());
        }
        public void FoodChoiceService_FindUserById()
        {
            const int userId = 1;
            var repositoryMock = GetRepositoryMock();

            var service = new FoodChoiceService();
            service.FoodChoiceRepository = repositoryMock.Object;

            var user = service.FindUserById(userId);

            Assert.IsNotNull(user);
            repositoryMock.Verify(r => r.FindById(userId));
        }