public User DispatchCommand(string[] commandParameters) { string command = commandParameters[0].ToLower(); User user = new User(); switch (command) { case "return": user = ReturnCommand.Execute(commandParameters); Console.WriteLine("Welcome back"); break; case "login": user = LogInCommand.Execute(commandParameters, user); break; case "registeruser": user = RegisterUserCommand.Execute(commandParameters); break; default: throw new InvalidOperationException($"LogInCommand {command} not valid!"); break; } return(user); }
// MvvmCross Lifecycle public override void Prepare(ApplicationUserModel parameter) { if (parameter != null) { Email.Value = parameter.Email; Password.Value = parameter.Password; Task.Run(async() => { await Task.Delay(5000); LogInCommand?.Execute(null); }); } }
public void ExecuteShouldThrowExceptionWhenNoPassPassed() { // Arrange var state = new Mock <ISessionState>(); var builder = new Mock <IStringBuilderWrapper>(); var service = new Mock <IUserService>(); var command = new LogInCommand(state.Object, builder.Object, service.Object); state.SetupGet(m => m.IsLogged).Returns(false); var parameters = new string[] { "username", "" }; var result = command.Execute(parameters); }
public void ExecuteShouldReturnMessageWhenCommandExecuteSuccessfully() { // Arrange var state = new Mock <ISessionState>(); var builder = new Mock <IStringBuilderWrapper>(); var service = new Mock <IUserService>(); var command = new LogInCommand(state.Object, builder.Object, service.Object); state.SetupGet(m => m.IsLogged).Returns(false); var parameters = new string[] { "username", "12345" }; //Assert+Act Assert.AreEqual("User username succesfully logged. Your role is -1", command.Execute(parameters)); }
public void ExecuteShouldReturnMessageWhenAlreadyLogged() { // Arrange var state = new Mock <ISessionState>(); var builder = new Mock <IStringBuilderWrapper>(); var service = new Mock <IUserService>(); var command = new LogInCommand(state.Object, builder.Object, service.Object); state.SetupGet(m => m.IsLogged).Returns(true); var parameters = new string[] { "UserName", "12345" }; //Assert + Act Assert.AreEqual("You are already logged.", command.Execute(parameters)); }
private static void Bot_OnCallbackQuery(object sender, CallbackQueryEventArgs e) { var buttonText = e.CallbackQuery.Data; botClient.OnMessage -= Bot_OnMessage; botClient.OnCallbackQuery -= Bot_OnCallbackQuery; switch (buttonText) { case "Зарегистрироваться": var registrate = new RegistrateCommand(); registrate.Execute(e.CallbackQuery.Message, botClient); break; case "Войти в аккаунт": var logIn = new LogInCommand(); logIn.Execute(e.CallbackQuery.Message, botClient); botClient.SendTextMessageAsync(e.CallbackQuery.Message.Chat.Id, "Метод закончил выполнение"); break; } botClient.SendTextMessageAsync(e.CallbackQuery.Message.Chat.Id, "Оброботчик событий работает"); botClient.OnMessage += Bot_OnMessage; botClient.OnCallbackQuery += Bot_OnCallbackQuery; }
public string DispatchCommand(string[] commandParameters, Session session) { string command = commandParameters[0].ToLower(); string result = ""; switch (command) { case "login": result = LogInCommand.Execute(commandParameters, session); break; case "logout": result = LogoutCommand.Execute(session); break; case "exit": result = ExitCommand.Execute(); break; case "registeruser": result = RegisterUserCommand.Execute(commandParameters); break; case "uploadpicture": result = UploadPictureCommand.Execute(commandParameters); break; case "sharealbum": result = ShareAlbumCommand.Execute(commandParameters); break; case "listfriends": result = PrintFriendsListCommand.Execute(session); break; case "acceptfriend": result = AcceptFriendCommand.Execute(commandParameters, session); break; case "addfriend": result = AddFriendCommand.Execute(commandParameters, session); break; case "addtagto": result = AddTagToCommand.Execute(commandParameters); break; case "createalbum": result = CreateAlbumCommand.Execute(commandParameters, session); break; case "addtown": result = AddTownCommand.Execute(commandParameters); break; case "modifyuser": result = ModifyUserCommand.Execute(commandParameters, session); break; case "addtag": result = AddTagCommand.Execute(commandParameters); break; case "deleteuser": result = DeleteUser.Execute(session); break; default: throw new InvalidOperationException($"Command {command} not valid!"); } return(result); }
public string Dispatch(string input) { string[] arguments = input.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); string commandName = arguments.Length > 0 ? arguments[0] : string.Empty; arguments = arguments.Skip(1).ToArray(); switch (commandName) { case "RegisterUser": RegisterUserCommand register = new RegisterUserCommand(authenticationManager); return(register.Execute(arguments)); case "Login": LogInCommand login = new LogInCommand(authenticationManager); return(login.Execute(arguments)); case "Logout": LogOutCommand logout = new LogOutCommand(authenticationManager); return(logout.Execute(arguments)); case "DeleteUser": DeleteUserCommand delete = new DeleteUserCommand(authenticationManager); return(delete.Execute(arguments)); case "CreateEvent": CreateEventCommand createEvent = new CreateEventCommand(authenticationManager); return(createEvent.Execute(arguments)); case "CreateTeam": CreateTeamCommand createTeam = new CreateTeamCommand(authenticationManager); return(createTeam.Execute(arguments)); case "InviteToTeam": InviteToTeamCommand inviteToTeam = new InviteToTeamCommand(authenticationManager); return(inviteToTeam.Execute(arguments)); case "AcceptInvite": AcceptInviteCommand acceptInvite = new AcceptInviteCommand(authenticationManager); return(acceptInvite.Execute(arguments)); case "DeclineInvite": DeclineInviteCommand declineInvite = new DeclineInviteCommand(authenticationManager); return(declineInvite.Execute(arguments)); case "KickMember": KickMemberCommand kickMember = new KickMemberCommand(authenticationManager); return(kickMember.Execute(arguments)); case "Disband": DisbandCommand disband = new DisbandCommand(authenticationManager); return(disband.Execute(arguments)); case "AddTeamTo": AddTeamToCommand addTeamToCommand = new AddTeamToCommand(authenticationManager); return(addTeamToCommand.Execute(arguments)); case "ShowEvent": ShowEventCommand showEvent = new ShowEventCommand(authenticationManager); return(showEvent.Execute(arguments)); case "ShowTeam": ShowTeamCommand showTeam = new ShowTeamCommand(authenticationManager); return(showTeam.Execute(arguments)); case "Exit": ExitCommand exitCommand = new ExitCommand(); return(exitCommand.Execute(arguments)); default: throw new NotSupportedException($"Command {commandName} is not supported!"); } }
public string DispatchCommand(string[] commandParameters) { var command = commandParameters[0]; if (loggedInUserCommands.Contains(command) && Session.User == null) { throw new InvalidOperationException("Invalid credentials!"); } var args = commandParameters.Skip(1).ToArray(); var returnValue = ""; switch (command) { case "Login": returnValue = LogInCommand.Execute(args); break; case "RegisterUser": returnValue = RegisterUserCommand.Execute(args); break; case "ListFriends": returnValue = PrintFriendsListCommand.Execute(args); break; case "Logout": returnValue = LogOutCommand.Execute(args); break; case "AddTown": returnValue = AddTownCommand.Execute(args); break; case "ModifyUser": returnValue = ModifyUserCommand.Execute(args); break; case "DeleteUser": returnValue = DeleteUser.Execute(args); break; case "AddTag": returnValue = AddTagCommand.Execute(args); break; case "CreateAlbum": returnValue = CreateAlbumCommand.Execute(args); break; case "AddTagTo": returnValue = AddTagToCommand.Execute(args); break; case "AddFriend": returnValue = AddFriendCommand.Execute(args); break; case "AcceptFriend": returnValue = AcceptFriendCommand.Execute(args); break; case "ShareAlbum": returnValue = ShareAlbumCommand.Execute(args); break; case "UploadPicture": returnValue = UploadPictureCommand.Execute(args); break; case "Exit": returnValue = ExitCommand.Execute(); break; default: throw new InvalidOperationException($"Command {command} not valid!"); } return(returnValue); }