public async Task ThenTheAccountDetailsAreReturned() { var expectedAccountInformation = new AccountDetailViewModelBuilder().Build(); var accountHref = $"/api/accounts/2385"; AccountApiClient.Setup(x => x.GetResource <AccountDetailViewModel>(accountHref)).ReturnsAsync(expectedAccountInformation); var result = await AccountGateway.GetAccount(accountHref); result.Should().Be(expectedAccountInformation); AccountApiClient.Verify(x => x.GetResource <AccountDetailViewModel>(accountHref), Times.Once); }
public LoginMessages.Response Handle(LoginMessages.Request request) { // Validate request try { Validator.Validate(request); } catch (LoginValidationException ex) { var errorResponse = new LoginMessages.Response() { Success = false, Exception = ex }; return(errorResponse); } // Authenticate Account Account account; try { account = AccountGateway.GetAccount(request.Username); if (account == null) { throw LoginException.Create(LoginExceptions.IncorrectCredentials); } if (account.Password != request.Password) { throw LoginException.Create(LoginExceptions.IncorrectCredentials); } } catch (LoginException ex) { var errorResponse = new LoginMessages.Response() { Success = false, Exception = ex }; return(errorResponse); } var sessionString = SessionCreator.CreateSession(); var session = new Session { Id = sessionString, PlayerId = account.PlayerId, GameId = null }; try { SessionGateway.CreateSession(session); } catch (Exception e) { var message = e.Message; var errorResponse = new LoginMessages.Response() { Success = false, Exception = new Exception("Could not create a session! Error: " + message) }; return(errorResponse); } var response = new LoginMessages.Response() { Success = true, Session = sessionString, Exception = null }; return(response); }
public CreateAccountMessages.Response Handle(CreateAccountMessages.Request request) { // Validate request try { Validator.Validate(request); } catch (CreateAccountValidationException ex) { var errorResponse = new CreateAccountMessages.Response() { Success = false, Exception = ex }; return(errorResponse); } // Check for duplicate usernames var accountExists = AccountGateway.GetAccount(request.Username); if (accountExists != null) { var errorResponse = new CreateAccountMessages.Response() { Success = false, Exception = new CreateAccountException(CreateAccountException.GetMessage(CreateAccountExceptions.UsernameAlreadyExists, request)) }; return(errorResponse); } // Store in Gateway int accountId; try { var validatedAccount = new Account() { Username = request.Username, Password = request.Password }; accountId = AccountGateway.CreateAccount(validatedAccount); } catch (AccountGatewayException ex) { var errorResponse = new CreateAccountMessages.Response() { Success = false, Exception = ex }; return(errorResponse); } // Create associated Player try { var player = new Player() { AccountId = accountId, DisplayName = request.Username, }; PlayerGateway.CreatePlayer(player); } catch (PlayerGatewayException ex) { var errorResponse = new CreateAccountMessages.Response() { Success = false, Exception = ex }; return(errorResponse); } var response = new CreateAccountMessages.Response() { Success = true, Exception = null }; return(response); }