public void ExecuteAllThreeMethodsOnce_WhenValidParametersArePassed() { //Arrange this.componentsFactoryMock .Setup(x => x.CreateTeam(this.validTeamName)) .Returns(this.teamMock.Object); var sut = new CreateTeamCommand(this.historyEventWriterMock.Object, personsCollectionMock.Object, this.componentsFactoryMock.Object); var parameters = new List <string>() { this.validTeamName }; //Act var returnMessage = sut.Execute(parameters); //Assert this.componentsFactoryMock.Verify(x => x.CreateTeam(this.validTeamName), Times.Once); this.personsCollectionMock.Verify(x => x.AddTeam(teamMock.Object), Times.Once); this.historyEventWriterMock. Verify(x => x.AddHistoryEvent( returnMessage, null, null, teamMock.Object, null ), Times.Once); }
public void Execute_Less_Params_ThrowEx() { var fakeProvider = new FakeTeamProvider(); var listParams = new List <string>(); var sut = new CreateTeamCommand(listParams, fakeProvider); //Act & Assert Assert.ThrowsException <ArgumentException>(() => sut.Execute(), "Parameters count is not valid!"); }
public void ThrowWhen_NoOtherTeams() { //Arrange var fakeProvider = new FakeTeamProvider(); var list = new List <string>(); var sut = new CreateTeamCommand(list, fakeProvider); //Act & Assert Assert.ThrowsException <ArgumentException>(() => sut.Execute()); }
public void ThrowExceptionWithInvalidParameters() { var factoryMock = new Mock <IFactory>(); var dbMock = new Mock <IDataBase>(); var sut = new CreateTeamCommand(factoryMock.Object, dbMock.Object); Assert.ThrowsException <ArgumentException> (() => sut.Execute(new List <string> { })); }
public void ThrowExeptionWhenCommandParametersAreLessThanItShouldCorrectly() { string name = "TeamName"; ITeam team = new Team(name); database.Teams.Add(team); List <string> parameters = new List <string> { }; CreateTeamCommand command = new CreateTeamCommand(parameters); command.Execute(); Assert.IsTrue(database.Teams.Any(x => x.Name == name)); }
public void CreateTeamCommand() { string name = "TeamName"; ITeam team = new Team(name); database.Teams.Add(team); List <string> parameters = new List <string> { name }; CreateTeamCommand command = new CreateTeamCommand(parameters); command.Execute(); Assert.IsTrue(database.Teams.Any(x => x.Name == name)); }
public void ReturnCorrectString() { //Arrange var fakeProvider = new FakeTeamProvider(); var listParams = new List <string>() { "Ducks" }; var sut = new CreateTeamCommand(listParams, fakeProvider); //Act var result = sut.Execute(); //Assert Assert.AreEqual(result, $"Created Team{Environment.NewLine}Ducks" + Commons.CreateTeamText()); }
public void CreateNewTeam_CheckFormattedMessage() { var teamname = "teamX"; var factoryMock = new Mock <IFactory>(); var dbMock = new Mock <IDataBase>(); var teams = new Dictionary <string, ITeam>(); var teamMock = new Mock <ITeam>(); dbMock.Setup(x => x.Teams).Returns(teams); factoryMock.Setup(x => x.CreateTeam(teamname)).Returns(teamMock.Object); var sut = new CreateTeamCommand(factoryMock.Object, dbMock.Object); var parameters = new List <string> { "teamX" }; var message = sut.Execute(parameters); Assert.AreEqual(" Team teamX was created.", message); }
public void ThrowArgumentException_WhenNullPersonIsReturned() { //Arrange this.componentsFactoryMock .Setup(x => x.CreateTeam(this.validTeamName)); var sut = new CreateTeamCommand( this.historyEventWriterMock.Object, personsCollectionMock.Object, this.componentsFactoryMock.Object); var parameters = new List <string>() { this.validTeamName }; //Act, Assert Assert.ThrowsException <ArgumentException>(() => sut.Execute(parameters)); }
public void CreateNewTeam_ChecksCount() { var teamname = "teamX"; var factoryMock = new Mock <IFactory>(); var dbMock = new Mock <IDataBase>(); var teams = new Dictionary <string, ITeam>(); var teamMock = new Mock <ITeam>(); //Mock and Setup the engine and the db dbMock.Setup(x => x.Teams).Returns(teams); factoryMock.Setup(x => x.CreateTeam(teamname)).Returns(teamMock.Object); var sut = new CreateTeamCommand(factoryMock.Object, dbMock.Object); var parameters = new List <string> { "teamX" }; sut.Execute(parameters); Assert.AreEqual(1, teams.Count); }
public void ReturnCorrectMessage_WhenCorrectParametrsArePassed() { //Arrange this.componentsFactoryMock .Setup(x => x.CreateTeam(this.validTeamName)) .Returns(this.teamMock.Object); var sut = new CreateTeamCommand(this.historyEventWriterMock.Object, personsCollectionMock.Object, this.componentsFactoryMock.Object); var parameters = new List <string>() { this.validTeamName }; var expectedReturn = string.Format(CommandsConsts.ObjectCreated, nameof(Team), validTeamName); //Act var actualReturn = sut.Execute(parameters); //Assert Assert.AreEqual(expectedReturn, actualReturn); }
public void CreateTeam_TeamAlreadyExists() { var teamname = "teamX"; //setup key of the dictionary var factoryMock = new Mock <IFactory>(); var dbMock = new Mock <IDataBase>(); var teams = new Dictionary <string, ITeam>(); var teamMock = new Mock <ITeam>(); teams.Add(teamname, teamMock.Object); // add team to the dictionary //Mock and Setup engine and db dbMock.Setup(x => x.Teams).Returns(teams); var sut = new CreateTeamCommand(factoryMock.Object, dbMock.Object); var parameters = new List <string> { "teamX" }; var ex = Assert.ThrowsException <ArgumentException>(() => sut.Execute(parameters)); Assert.AreEqual($" Team with name {teamname} alteady exists", ex.Message); }
public string Dispatch(string input) { string[] args = input.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); string commandName = args.Length > 0 ? args[0] : string.Empty; string[] commandArgs = args.Skip(1).ToArray(); switch (commandName) { case "ShowTeam": ShowTeamCommand showTeamCommand = new ShowTeamCommand(); return(showTeamCommand.Execute(commandArgs)); case "ShowEvent": ShowEventCommand showEventCommand = new ShowEventCommand(); return(showEventCommand.Execute(commandArgs)); case "AddTeamTo": AddTeamToCommand addTeamToCommand = new AddTeamToCommand(this._authManager); return(addTeamToCommand.Execute(commandArgs)); case "Disband": DisbandCommand disbandCommand = new DisbandCommand(this._authManager); return(disbandCommand.Execute(commandArgs)); case "KickMember": KickMemberCommand kickMemberCommand = new KickMemberCommand(this._authManager); return(kickMemberCommand.Execute(commandArgs)); case "AcceptInvite": AcceptInviteCommand acceptInviteCommand = new AcceptInviteCommand(this._authManager); return(acceptInviteCommand.Execute(commandArgs)); case "DeclineInvite": DeclineInviteCommand declineInviteCommand = new DeclineInviteCommand(this._authManager); return(declineInviteCommand.Execute(commandArgs)); case "InviteToTeam": InviteToTeamCommand inviteToTeamCommand = new InviteToTeamCommand(this._authManager); return(inviteToTeamCommand.Execute(commandArgs)); case "CreateTeam": CreateTeamCommand createTeamCommand = new CreateTeamCommand(this._authManager); return(createTeamCommand.Execute(commandArgs)); case "CreateEvent": CreateEventCommand createEventCommand = new CreateEventCommand(this._authManager); return(createEventCommand.Execute(commandArgs)); case "Exit": ExitCommand exitCommand = new ExitCommand(); return(exitCommand.Execute(new string[0])); case "RegisterUser": RegisterUserCommand registerUserCommand = new RegisterUserCommand(_authManager); return(registerUserCommand.Execute(commandArgs)); case "Login": LoginCommand loginCommand = new LoginCommand(this._authManager); return(loginCommand.Execute(commandArgs)); case "Logout": LogoutCommand logoutCommand = new LogoutCommand(this._authManager); return(logoutCommand.Execute(commandArgs)); case "DeleteUser": DeleteUserCommand deleteUserCommand = new DeleteUserCommand(this._authManager); return(deleteUserCommand.Execute(commandArgs)); default: throw new NotSupportedException($"Command {commandName} not supported!"); } }
public string Dispatch(string input) { string result = string.Empty;; string[] inputArgs = input .Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); string commandName = inputArgs.Length > 0 ? inputArgs[0].ToLower() : string.Empty; inputArgs = inputArgs.Skip(1).ToArray(); switch (commandName) { case "registeruser": result = RegisterUserCommand.Execute(inputArgs); break; case "deleteuser": result = DeleteUserCommand.Execute(inputArgs); break; case "login": result = LoginCommand.Execute(inputArgs); break; case "logout": result = LogoutCommand.Execute(inputArgs); break; case "createevent": result = CreateEventInternalCommand.Execute(inputArgs); break; case "createteam": result = CreateTeamCommand.Execute(inputArgs); break; case "showevent": result = ShowEventCommand.Execute(inputArgs); break; case "showteam": result = ShowTeamCommand.Execute(inputArgs); break; case "kickmember": result = KickMemberInternalCommand.Execute(inputArgs); break; case "invitetoteam": result = InviteToTeamCommand.Execute(inputArgs); break; case "acceptinvite": result = AcceptInviteCommand.Execute(inputArgs); break; case "declineinvite": result = DeclineInvitartionCommand.Execute(inputArgs); break; case "disband": result = DisbandCommand.Execute(inputArgs); break; case "addteamto": result = AddTeamToCommand.Execute(inputArgs); break; case "exit": result = ExitCommand.Execute(inputArgs); break; default: throw new NotSupportedException($"Command {commandName} not supported!"); } return(result); }
public string Dispatch(string input) { string result = ""; var commandArgs = Regex.Split(input.Trim(), @"\s"); var command = commandArgs.Length > 0 ? commandArgs[0] : string.Empty; var args = commandArgs.Skip(1).ToArray(); switch (command) { case "Login": result = LoginCommand.Execute(args); break; case "Logout": result = LogoutCommand.Execute(args); break; case "RegisterUser": result = RegisterUserCommand.Execute(args); break; case "DeleteUser": result = DeleteUserCommand.Execute(args); break; case "CreateEvent": result = CreateEventCommand.Execute(args); break; case "CreateTeam": result = CreateTeamCommand.Execute(args); break; case "InviteToTeam": result = InviteToTeamCommand.Execute(args); break; case "AcceptInvite": result = AcceptInviteCommand.Execute(args); break; case "DeclineInvite": result = DeclineInviteCommand.Execute(args); break; case "KickMember": result = KickMemberCommand.Execute(args); break; case "Exit": result = ExitCommand.Execute(args); break; case "Disband": result = DisbandCommand.Execute(args); break; case "AddTeamTo": result = AddTeamToCommand.Execute(args); break; case "ShowTeam": result = ShowTeamCommand.Execute(args); break; case "ShowEvent": result = ShowEventCommand.Execute(args); break; default: throw new NotSupportedException($"Command {command} not supported!"); } return(result); }
public string Dispatch(string input) { string result = string.Empty; string[] inputArgs = input.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); string commandName = inputArgs.Length > 0 ? inputArgs[0] : string.Empty; inputArgs = inputArgs.Skip(1).ToArray(); switch (commandName) { case "RegisterUser": var registerUser = new RegisterUserCommand(); result = registerUser.Execute(inputArgs); break; case "Login": var login = new LoginCommand(); result = login.Execute(inputArgs); break; case "Logout": var logout = new LogoutCommand(); result = logout.Execute(inputArgs); break; case "DeleteUser": var deleteUser = new DeleteUserCommand(); result = deleteUser.Execute(inputArgs); break; case "CreateEvent": var createEvent = new CreateEventCommand(); result = createEvent.Execute(inputArgs); break; case "CreateTeam": var createTeam = new CreateTeamCommand(); result = createTeam.Execute(inputArgs); break; case "InviteToTeam": var inviteToTeam = new InviteToTeamCommand(); result = inviteToTeam.Execute(inputArgs); break; case "AcceptInvite": var acceptInvite = new AcceptInviteCommand(); result = acceptInvite.Execute(inputArgs); break; case "DeclineInvite": var declineInvite = new DeclineInviteCommand(); result = declineInvite.Execute(inputArgs); break; case "KickMember": var kickMember = new KickMemberCommand(); result = kickMember.Execute(inputArgs); break; case "Disband": var disband = new DisbandCommand(); result = disband.Execute(inputArgs); break; case "AddTeamTo": var addTeamTo = new AddTeamToCommand(); result = addTeamTo.Execute(inputArgs); break; case "ShowEvent": var showEvent = new ShowEventCommand(); result = showEvent.Execute(inputArgs); break; case "ShowTeam": var showTeam = new ShowTeamCommand(); result = showTeam.Execute(inputArgs); break; case "Exit": var exit = new ExitCommand(); exit.Execute(inputArgs); break; default: throw new NotSupportedException($"Command {commandName} not supported!"); } return(result); }
public string Dispatch(string input) { string result = string.Empty; string[] inputArgs = input.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); string commandName = inputArgs.Length > 0 ? inputArgs[0] : string.Empty; inputArgs = inputArgs.Skip(1).ToArray(); switch (commandName) { case "RegisterUser": RegisterUserCommand registerCmd = new RegisterUserCommand(); result = registerCmd.Execute(inputArgs); break; case "Login": LoginCommand loginCmd = new LoginCommand(); result = loginCmd.Execute(inputArgs); break; case "Logout": LogoutCommand logoutCmd = new LogoutCommand(); result = logoutCmd.Execute(inputArgs); break; case "DeleteUser": DeleteUserCommand deleteUserCmd = new DeleteUserCommand(); result = deleteUserCmd.Execute(inputArgs); break; //try to make description as a one argument case "CreateEvent": CreateEventCommand createEventCmd = new CreateEventCommand(); result = createEventCmd.Execute(inputArgs); break; case "CreateTeam": CreateTeamCommand createTeamCmd = new CreateTeamCommand(); result = createTeamCmd.Execute(inputArgs); break; case "InviteToTeam": InviteToTeamCommand inviteToTeamCmd = new InviteToTeamCommand(); result = inviteToTeamCmd.Execute(inputArgs); break; case "AcceptInvite": AcceptInviteCommand acceptInviteCmd = new AcceptInviteCommand(); result = acceptInviteCmd.Execute(inputArgs); break; case "DeclineInvite": DeclineInviteCommand declineInviteCmd = new DeclineInviteCommand(); result = declineInviteCmd.Execute(inputArgs); break; case "KickMember": KickMemberCommand kickMemberCmd = new KickMemberCommand(); result = kickMemberCmd.Execute(inputArgs); break; case "Disband": DisbandCommand disbandCmd = new DisbandCommand(); result = disbandCmd.Execute(inputArgs); break; // case "AddTeamTo": // AddTeamToEventCommand addTeamToCmd = new AddTeamToEventCommand(); // result = addTeamToCmd.Execute(inputArgs); // break; case "ShowEvent": ShowEventCommand showEventCmd = new ShowEventCommand(); result = showEventCmd.Execute(inputArgs); break; case "ShowTeam": ShowTeamCommand showTeamCmd = new ShowTeamCommand(); result = showTeamCmd.Execute(inputArgs); break; case "Exit": ExitCommand exitCmd = new ExitCommand(); result = exitCmd.Execute(inputArgs); break; default: result = $"Command {commandName} not supported!"; throw new NotSupportedException(result); } return(result); }
public string Dispatch(string input) { string result = string.Empty; string[] inputArgs = input.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); string commandName = inputArgs.Length > 0 ? inputArgs[0] : string.Empty; inputArgs = inputArgs.Skip(1).ToArray(); switch (commandName.ToLower()) { case "exit": ExitCommand exit = new ExitCommand(); exit.Execute(inputArgs); break; case "registeruser": RegisterUserCommand registerUser = new RegisterUserCommand(); result = registerUser.Execute(inputArgs); break; case "login": LoginCommand loginUser = new LoginCommand(); result = loginUser.Execute(inputArgs); break; case "logout": LogoutCommand logoutUser = new LogoutCommand(); result = logoutUser.Execute(inputArgs); break; case "deleteuser": DeleteUserCommand deleteUser = new DeleteUserCommand(); result = deleteUser.Execute(inputArgs); break; case "createevent": CreateEventCommand createEvent = new CreateEventCommand(); result = createEvent.Execute(inputArgs); break; case "createteam": CreateTeamCommand createTeam = new CreateTeamCommand(); result = createTeam.Execute(inputArgs); break; case "showevent": ShowEventCommand showEvent = new ShowEventCommand(); result = showEvent.Execute(inputArgs); break; case "invitetoteam": InviteToTeamCommand inviteToTeam = new InviteToTeamCommand(); result = inviteToTeam.Execute(inputArgs); break; case "showteam": ShowTeamCommand showTeam = new ShowTeamCommand(); result = showTeam.Execute(inputArgs); break; case "acceptinvite": AcceptInviteCommand acceptInvite = new AcceptInviteCommand(); result = acceptInvite.Execute(inputArgs); break; case "declineinvite": DeclineInviteCommand declineInvite = new DeclineInviteCommand(); result = declineInvite.Execute(inputArgs); break; case "kickmember": KickMemberCommand kickMember = new KickMemberCommand(); result = kickMember.Execute(inputArgs); break; case "disband": DisbandCommand disband = new DisbandCommand(); result = disband.Execute(inputArgs); break; case "addteamto": AddTeamToCommand addTeamTo = new AddTeamToCommand(); result = addTeamTo.Execute(inputArgs); break; default: throw new NotSupportedException($"Command {commandName} not supported!"); } return(result); }
public string Dispatch(string input) { string result = string.Empty; string[] inputArgs = Regex.Split(input.Trim(), @"\s+"); //string[] args = input.Trim().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); string commandName = inputArgs.Length > 0 ? inputArgs[0] : string.Empty; inputArgs = inputArgs.Skip(1).ToArray(); switch (commandName) { // Basic Logic case "RegisterUser": RegisterUserCommand register = new RegisterUserCommand(); result = register.Execute(inputArgs); break; case "Login": LoginCommand login = new LoginCommand(); result = login.Execute(inputArgs); break; case "Logout": LogoutCommand logout = new LogoutCommand(); result = logout.Execute(inputArgs); break; case "DeleteUser": DeleteUserCommand deleteUser = new DeleteUserCommand(); result = deleteUser.Execute(inputArgs); break; case "Exit": ExitCommand exit = new ExitCommand(); result = exit.Execute(inputArgs); break; // Advanced Logic case "CreateEvent": CreateEventCommand createEvent = new CreateEventCommand(); result = createEvent.Execute(inputArgs); break; case "CreateTeam": CreateTeamCommand createTeam = new CreateTeamCommand(); result = createTeam.Execute(inputArgs); break; case "InviteToTeam": InviteToTeamCommand inviteToTeam = new InviteToTeamCommand(); result = inviteToTeam.Execute(inputArgs); break; case "AcceptInvite": AcceptInviteCommand acceptInvite = new AcceptInviteCommand(); result = acceptInvite.Execute(inputArgs); break; case "DeclineInvite": DeclineInviteCommand declineInvite = new DeclineInviteCommand(); result = declineInvite.Execute(inputArgs); break; case "KickMember": KickMemberCommand kickMember = new KickMemberCommand(); result = kickMember.Execute(inputArgs); break; case "Disband": DisbandTeamCommand disband = new DisbandTeamCommand(); result = disband.Execute(inputArgs); break; case "AddTeamTo": AddTeamToCommand addTeamTo = new AddTeamToCommand(); result = addTeamTo.Execute(inputArgs); break; case "ShowEvent": ShowEventCommand showEvent = new ShowEventCommand(); result = showEvent.Execute(inputArgs); break; case "ShowTeam": ShowTeamCommand showTeam = new ShowTeamCommand(); result = showTeam.Execute(inputArgs); break; // Import Data case "ImportUsers": ImportUsersCommand importUsers = new ImportUsersCommand(); result = importUsers.Execute(inputArgs); break; case "ImportTeams": ImportTeamsCommand importTeams = new ImportTeamsCommand(); result = importTeams.Execute(inputArgs); break; // Export Data case "ExportTeam": ExportTeamCommand exportTeam = new ExportTeamCommand(); result = exportTeam.Execute(inputArgs); break; // Basic Logic default: throw new NotSupportedException($"Command {commandName} not supported!"); } return(result); }
public string DispatchCommand(string[] commandParameters) { string commandName = commandParameters[0]; commandParameters = commandParameters.Skip(1).ToArray(); string result = string.Empty; switch (commandName) { case "RegisterUser": RegisterUserCommand registerUser = new RegisterUserCommand(new UserService()); result = registerUser.Execute(commandParameters); break; case "Login": LoginCommand loginCommand = new LoginCommand(new UserService()); result = loginCommand.Execute(commandParameters); break; case "Logout": LogoutCommand logoutCommand = new LogoutCommand(new UserService()); result = logoutCommand.Execute(commandParameters); break; case "DeleteUser": DeleteUserCommand deleteUser = new DeleteUserCommand(new UserService()); result = deleteUser.Execute(commandParameters); break; case "CreateEvent": CreateEventCommand createEvent = new CreateEventCommand(new EventService()); result = createEvent.Execute(commandParameters); break; case "CreateTeam": CreateTeamCommand createTeam = new CreateTeamCommand(new TeamService()); result = createTeam.Execute(commandParameters); break; case "InviteToTeam": InviteToTeamCommand invToTeam = new InviteToTeamCommand(new TeamService(), new UserService()); result = invToTeam.Execute(commandParameters); break; case "AcceptInvite": AcceptInviteCommand acceptInvite = new AcceptInviteCommand(new TeamService(), new UserService()); result = acceptInvite.Execute(commandParameters); break; case "DeclineInvite": DeclineInviteCommand declineInvite = new DeclineInviteCommand(new TeamService(), new UserService()); result = declineInvite.Execute(commandParameters); break; case "KickMember": KickMemberCommand kickMember = new KickMemberCommand(new TeamService(), new UserService()); result = kickMember.Execute(commandParameters); break; case "Disband": DisbandCommand disbandTeam = new DisbandCommand(new TeamService(), new UserService()); result = disbandTeam.Execute(commandParameters); break; case "AddTeamTo": AddTeamToCommand addTeam = new AddTeamToCommand(new EventService(), new TeamService()); result = addTeam.Execute(commandParameters); break; case "ShowEvent": ShowEventCommand showEvent = new ShowEventCommand(new EventService()); result = showEvent.Execute(commandParameters); break; case "ShowTeam": ShowTeamCommand showTeam = new ShowTeamCommand(new TeamService()); result = showTeam.Execute(commandParameters); break; case "ImportUsers": ImportUsersCommand importUsers = new ImportUsersCommand(new UserService()); result = importUsers.Execute(commandParameters); break; case "ImportTeams": ImportTeamsCommand importTeams = new ImportTeamsCommand(new TeamService()); result = importTeams.Execute(commandParameters); break; case "ExportTeam": ExportTeamCommand exportTeam = new ExportTeamCommand(new TeamService()); result = exportTeam.Execute(commandParameters); break; case "Exit": ExitCommand exit = new ExitCommand(); exit.Execute(commandParameters); break; default: throw new NotSupportedException($"Command {commandName} not valid!"); } return(result); }