コード例 #1
0
        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));
        }
コード例 #2
0
 public void UpdateUser(User newUser, string ipAddressToCompare)
 {
     var originalUser = FindUserById(newUser.Id);
     if (IsTheRightUser(originalUser, ipAddressToCompare))
     {
         FoodChoiceRepository.Update(originalUser, newUser);
     }
 }
コード例 #3
0
ファイル: BaseTest.cs プロジェクト: lionelarmanet/Tatabouf
        public virtual void Initialize()
        {
            _user = new User
            {
                Id = 1,
                Name = "lionel",
                IpAddress = "192.168.0.1"
            };

            _userChoices = new List<User>
            {
                new User
                {
                    Id = 1,
                    Name = "Lionel",
                    AvailableSeats = 3,
                    IpAddress = "192.168.0.1",
                    Choices = new List<Choice>
                    {
                        new Choice
                        {
                            Place = new Place
                            {
                                Label = "Carrefour",
                                InputType = false
                            }
                        }
                    }
                },
                new User
                {
                    Id = 2,
                    Name = "Michel",
                    AvailableSeats = 1,
                    IpAddress = "192.168.0.5",
                    Choices = new List<Choice>
                    {
                        new Choice
                        {
                            Place = new Place
                            {
                                Label = "Carrefour"
                            }
                        },
                        new Choice
                        {
                            Place = new Place
                            {
                                Label = "Quick"
                            }
                        }
                    }
                }
            };
        }
コード例 #4
0
 public void AddUser(User user)
 {
     #if DEBUG
     FoodChoiceRepository.Add(user);
     #else
     if (!UserAlreadyRegisteredToday(user.IpAddress))
     {
         FoodChoiceRepository.Add(user);
     }
     #endif
 }
コード例 #5
0
 public bool ControlCheckBoxes(User user, out string errorMessage)
 {
     var choicesCount = user.Choices.Count();
     if (choicesCount == 0)
     {
         errorMessage = "Merci de cocher au moins une case !";
         return false;
     }
     errorMessage = string.Empty;
     return true;
 }
コード例 #6
0
        public void ControlCheckBoxes_NoChoiceMade()
        {
            var errorMessage = string.Empty;
            var user = new User
            {
                Choices = new List<Choice>()
            };

            var service = new ValidationService();
            var result = service.ControlCheckBoxes(user, out errorMessage);

            Assert.IsFalse(result);
            Assert.AreEqual("Merci de cocher au moins une case !", errorMessage);
        }
コード例 #7
0
 public bool DoAllControls(User user, IEnumerable<User> userChoices, out string errorMessage)
 {
     var error = string.Empty;
     if (!ControlCheckBoxes(user, out error))
     {
         errorMessage = error;
         return false;
     }
     if (!ControlSameNameExists(user.Name, userChoices, out error))
     {
         errorMessage = error;
         return false;
     }
     errorMessage = error;
     return true;
 }
コード例 #8
0
ファイル: Converter.cs プロジェクト: lionelarmanet/Tatabouf
        public static UserModel UserToFoodChoiceModel(User userChoice)
        {
            var choiceModels = userChoice.Choices.Select(c => new ChoiceModel
            {
                UserId = c.UserId,
                PlaceId = c.PlaceId,
                Other = c.OtherIdea
            }).ToList();

            return new UserModel
            {
                Id = userChoice.Id,
                Name = userChoice.Name,
                NumberOfAvailableSeats = userChoice.AvailableSeats,
                IP = userChoice.IpAddress,
                DepartureTime = userChoice.DepartureTime,
                ChoiceModels = choiceModels
            };
        }
コード例 #9
0
        // Try to prevent hacks from GDE ;)
        public void RemoveInvalidEntry(User user, IEnumerable<Place> places)
        {
            var validatedChoices = new List<Choice>();

            foreach (var userChoice in user.Choices)
            {
                // check if place id use the right input type
                var validPlace = places.Where(p => p.Id == userChoice.PlaceId
                                                && ((p.InputType && !string.IsNullOrEmpty(userChoice.OtherIdea)) // input text
                                                || (!p.InputType && string.IsNullOrEmpty(userChoice.OtherIdea)))) // checkbox
                                                .SingleOrDefault();

                if (validPlace != null)
                {
                    validatedChoices.Add(userChoice);
                }
            }
            user.Choices = validatedChoices;
        }
コード例 #10
0
        public void ControlCheckBoxes_IMadeChoices()
        {
            var errorMessage = string.Empty;
            var user = new User
            {
                AvailableSeats = 2,
                Choices = new List<Choice>
                {
                    new Choice { Place = new Place { Label = "Carrefour"} },
                    new Choice { Place = new Place { Label = "Quick"} },
                    new Choice { Place = new Place { Label = "Autre"} },
                }
            };

            var service = new ValidationService();
            var result = service.ControlCheckBoxes(user, out errorMessage);

            Assert.IsTrue(result);
            Assert.IsTrue(string.IsNullOrEmpty(errorMessage));
        }
コード例 #11
0
        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));
        }
コード例 #12
0
 public void Update(User originalUser, User newUser)
 {
     // all fields are not updated
     originalUser.AvailableSeats = newUser.AvailableSeats;
     originalUser.DepartureTime = newUser.DepartureTime;
     originalUser.Choices = newUser.Choices;
     TataboufContext.SaveChanges();
 }
コード例 #13
0
 public void Delete(User user)
 {
     TataboufContext.Users.Remove(user);
     TataboufContext.SaveChanges();
 }
コード例 #14
0
 public void Add(User user)
 {
     TataboufContext.Users.Add(user);
     TataboufContext.SaveChanges();
 }
コード例 #15
0
 private static bool IsTheRightUser(User user, string ipAddressToCompare)
 {
     return (user != null && user.IpAddress == ipAddressToCompare);
 }