Beispiel #1
0
        public ActionResult <GetAccountModel> GetAccount([FromRoute] string loginName)
        {
            AccountReadModel account  = _query.Query <AccountReadModel, string>(loginName);
            GetEmailResponse response = _query.Query <GetEmailResponse, string>(account.LoginName);

            return(Json(new GetAccountModel(account.LoginName, response.Email)));
        }
Beispiel #2
0
        public async void UserCreationProcessTests()
        {
            // Setup
            InMemoryAccountsRepository inMemoryAccountsRepository = new InMemoryAccountsRepository();

            Bootstrap.Run(new string[0], builder =>
            {
                builder.RegisterInstance(inMemoryAccountsRepository).AsImplementedInterfaces().SingleInstance();
            }, "IntegrationTesting");

            Guid             userId           = Guid.NewGuid();
            AccountPostModel accountPostModel = CreatePostAccountModel(userId);

            // Act
            HttpResponseHeaders responseMessageHeaders;

            using (Response <string> response = await RestClient.For <IAccountsApi>(Url).PostAccount(accountPostModel))
            {
                Assert.True(response.ResponseMessage.IsSuccessStatusCode);
                responseMessageHeaders = response.ResponseMessage.Headers;
                Assert.True(responseMessageHeaders.Location.IsAbsoluteUri);
            }

            using (Response <string> response = await RestClient.For <IConfirmationApi>(responseMessageHeaders.Location)
                                                .PutConfirmation(new ConfirmationPutModel {
                Confirmed = true
            }))
            {
                Assert.True(response.ResponseMessage.IsSuccessStatusCode);
            }

            using (Response <AccountReadModel> response = await RestClient.For <IAccountsApi>(Url).GetAccount(userId))
            {
                Assert.True(response.ResponseMessage.IsSuccessStatusCode);
                AccountReadModel accountReadModel = response.GetContent();
                Assert.Equal(accountPostModel.LoginName, accountReadModel.LoginName);
                Assert.Equal(accountPostModel.Name, accountReadModel.Name);
                Assert.Equal(accountPostModel.Surname, accountReadModel.Surname);
            }
        }
        public async Task Handle(RegisterUserCommand command)
        {
            AccountReadModel accountReadModel = await _query.Query <Task <AccountReadModel>, string>(command.LoginName);

            if (accountReadModel != null)
            {
                throw new LoginNameAlreadyUsedException(command.LoginName);
            }

            if (await _sagaRepository.Get <UserRegistrationSagaData>(x => x.LoginName == command.LoginName) != null)
            {
                throw new LoginNameAlreadyUsedException(command.LoginName);
            }

            UserRegistrationSaga     saga = new UserRegistrationSaga(_commandBus, _passwordHasher);
            UserRegistrationSagaData data = new UserRegistrationSagaData {
                Id = command.Id
            };
            await saga.RaiseEvent(data, saga.RegisterUserCommand, command);

            await _sagaRepository.Save(data.Id, data);
        }
        public async Task <ActionResult <AccountReadModel> > GetAccount([FromRoute] Guid id)
        {
            AccountReadModel account = await _query.Query <Task <AccountReadModel>, Guid>(id);

            return(Content(JsonSerializer.Serialize(account)));
        }