public async void Execute_WithNullUsername_NotSuccessful()
        {
            // arrange
            RegisterUserModel registrationModel = new RegisterUserModel { Username = null };
            var command = this.commandRepository.RegisterNewUser(registrationModel);

            // act
            var commandResult = await this.CommandExecutor.ExecuteAsync(command);

            // assert
            CommandAssert.IsFailure(commandResult);
        }
        public async void Execute_WithValidModel_NotSuccessful()
        {
            // arrange
            RegisterUserModel registrationModel = new RegisterUserModel { Username = "******" };
            var existingUser = new User { Name = registrationModel.Username };
            this.userAccessMock.Setup(x => x.TryGetByName(registrationModel.Username)).Returns(new Maybe<User>(existingUser));
            var command = this.commandRepository.RegisterNewUser(registrationModel);

            // act
            var commandResult = await this.CommandExecutor.ExecuteAsync(command);

            // assert
            CommandAssert.IsFailure(commandResult);
        }
Exemplo n.º 3
0
        public async Task<HttpResponseMessage> RegisterIfUnknown(RegisterUserModel registrationModel)
        {
            HttpResponseMessage response;
            if (registrationModel == null)
            {
                response = this.CreateErrorResponse("The registrationModel is not set.", HttpStatusCode.BadRequest);
                return response;
            }

            var registerNewUserCommand = this.commandRepository.RegisterNewUserIfUnknown(registrationModel);
            var commandResult = await this.commandExecutor.ExecuteAsync(registerNewUserCommand);

            response = this.CreateResponseFromCommandResult(commandResult);
            return response;
        }
        public async void Execute_WithValidModel_Successful()
        {
            // arrange
            RegisterUserModel registrationModel = new RegisterUserModel { Username = "******" };
            this.userAccessMock.Setup(x => x.TryGetByName(registrationModel.Username)).Returns(Maybe<User>.Empty);
            this.userAccessMock.Setup(x => x.Add(registrationModel.Username)).Returns(new User { Name = registrationModel.Username });
            var command = this.commandRepository.RegisterNewUser(registrationModel);

            // act
            var commandResult = await this.CommandExecutor.ExecuteAsync(command);

            // assert
            CommandAssert.IsSuccessful(commandResult);
            Assert.AreEqual(registrationModel.Username, commandResult.SuccessData.Name);
        }
Exemplo n.º 5
0
        public async void RegisterIfUnknown_WithValidModel_ReturnsOk()
        {
            // arrange
            this.commandRepositoryMock
                .Setup(x => x.RegisterNewUserIfUnknown(It.IsNotNull<RegisterUserModel>()))
                .Returns(this.CreateCommandMock(new CommandResult<UserModel>(true, new UserModel())));
            RegisterUserModel registrationModel = new RegisterUserModel();

            // act
            var response = await this.controller.RegisterIfUnknown(registrationModel);

            // assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            UserModel createdUser;
            Assert.IsTrue(response.TryGetContentValue(out createdUser));
        }
Exemplo n.º 6
0
 public CommandBase<UserModel> RegisterNewUserIfUnknown(RegisterUserModel registrationModel)
 {
     var command = this.commandFactory.CreateCommand<RegisterNewUserIfUnknownCommand, UserModel>();
     command.Initialize(registrationModel);
     return command;
 }