public CommandProcessor() { var addUsers = new AddUserCommand(); var listUsers = new ListUsersCommand(); this.commands.Add(addUsers.Number, addUsers); this.commands.Add(listUsers.Number, listUsers); }
public void ListUsersCommand_Verify_1() { Mock <IIrbisConnection> mock = GetConnectionMock(); IIrbisConnection connection = mock.Object; ListUsersCommand command = new ListUsersCommand(connection); Assert.IsTrue(command.Verify(false)); }
public void ListUsersCommand_Construciton_1() { Mock <IIrbisConnection> mock = GetConnectionMock(); IIrbisConnection connection = mock.Object; ListUsersCommand command = new ListUsersCommand(connection); Assert.AreSame(connection, command.Connection); }
public CommandProcessor() { //создаем хранилище, с которым будут работать команды. var store = new UserStore(new InMemoryDatabaseService()); var addUsers = new AddUserCommand(store); var listUsers = new ListUsersCommand(store); this.commands.Add(addUsers.Number, addUsers); this.commands.Add(listUsers.Number, listUsers); }
private static void Main() { // Inversion of Control var dbEntity = new Dictionary <int, IDbEntity>(); var dbServices = new InMemoryDatabaseService(dbEntity); var userStore = new UserStore(dbServices); var addUsers = new AddUserCommand(userStore); var listUsers = new ListUsersCommand(userStore); var commandProcessor = new CommandProcessor(addUsers, listUsers); var manager = new CommandManager(commandProcessor); manager.Start(); }
public void ExecuteShouldThrowExceptionWhenNoParamsPassed() { // Arrange var state = new Mock <ISessionState>(); var builder = new Mock <IStringBuilderWrapper>(); var service = new Mock <IUserService>(); var command = new ListUsersCommand(state.Object, builder.Object, service.Object); state.SetupGet(m => m.IsLogged).Returns(true); state.SetupGet(m => m.RoleId).Returns(1); var parameters = new string[] { }; var result = command.Execute(parameters); }
public void ExecuteShouldReturnMessageWhenNotCorrectUserLogged() { // Arrange var state = new Mock <ISessionState>(); var builder = new Mock <IStringBuilderWrapper>(); var service = new Mock <IUserService>(); var command = new ListUsersCommand(state.Object, builder.Object, service.Object); state.SetupGet(m => m.IsLogged).Returns(true); state.SetupGet(m => m.RoleId).Returns(2); var parameters = new string[] { "2" }; Assert.AreEqual("This command is available only to users with role Admin", 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 ListUsersCommand(state.Object, builder.Object, service.Object); state.SetupGet(m => m.IsLogged).Returns(false); state.SetupGet(m => m.RoleId).Returns(1); var parameters = new string[] { "2" }; //Assert + Act Assert.AreEqual("Please log before using commands", command.Execute(parameters)); }
private static void Main() { // Inversion of Control var dataService = new InDatabaseUserService(new InMemoryDatabaseService()); var userStore = new UserStore(dataService); var addUsers = new AddUserCommand(userStore); var listUsers = new ListUsersCommand(userStore); var commands = new Dictionary <int, ICommand>(); commands.Add(addUsers.Number, addUsers); commands.Add(listUsers.Number, listUsers); var commandManager = new CommandProcessor(commands); var manager = new CommandManager(commandManager); manager.Start(); }