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 UpdateUser(User newUser, string ipAddressToCompare) { var originalUser = FindUserById(newUser.Id); if (IsTheRightUser(originalUser, ipAddressToCompare)) { FoodChoiceRepository.Update(originalUser, newUser); } }
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" } } } } }; }
public void AddUser(User user) { #if DEBUG FoodChoiceRepository.Add(user); #else if (!UserAlreadyRegisteredToday(user.IpAddress)) { FoodChoiceRepository.Add(user); } #endif }
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; }
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); }
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; }
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 }; }
// 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; }
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)); }
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 Update(User originalUser, User newUser) { // all fields are not updated originalUser.AvailableSeats = newUser.AvailableSeats; originalUser.DepartureTime = newUser.DepartureTime; originalUser.Choices = newUser.Choices; TataboufContext.SaveChanges(); }
public void Delete(User user) { TataboufContext.Users.Remove(user); TataboufContext.SaveChanges(); }
public void Add(User user) { TataboufContext.Users.Add(user); TataboufContext.SaveChanges(); }
private static bool IsTheRightUser(User user, string ipAddressToCompare) { return (user != null && user.IpAddress == ipAddressToCompare); }