public AddFriendCommandResult Handler(AddFriendCommand command) { command.Validate(); if (command.Invalid) { return(new AddFriendCommandResult(false, false, command.Notifications.ToList())); } if (friendRepository.LocationAlreadyExists(Latitude: command.Latitude, Longitude: command.Longitude)) { AddNotification("Location", "Já existe um amigo cadastrado nesta localização."); } if (Invalid) { return(new AddFriendCommandResult(false, false, Notifications.ToList())); } var friend = new Friend(command.Name, new Point(command.Latitude, command.Longitude)); AddNotifications(friend); if (Invalid) { return(new AddFriendCommandResult(false, false, Notifications.ToList())); } friendRepository.Add(friend); return(new AddFriendCommandResult(true, true, new Message() { MessageType = MessageType.Information, Description = "Amigo cadastrado com sucesso!" })); }
public void ShouldReturnValidWhenNotExistNotifications() { var friend = new AddFriendCommand() { Name = "Some Name", Latitude = 0, Longitude = 0 }; friend.Validate(); friend.Valid.Should().BeTrue(); }
public void ShouldReturnNotificationWhenNameIsEmpty() { var expected = new List <Notification>() { new Notification("Name", "Nome não pode ser vazio ou nulo.") }; var friend = new AddFriendCommand() { Name = string.Empty, Latitude = 0, Longitude = 0 }; friend.Validate(); friend.Valid.Should().BeFalse(); friend.Notifications.Should().BeEquivalentTo(expected); }