コード例 #1
0
        public async Task Unit_CreateNewAccount_ExpectAccountInResultAndRepository()
        {
            var newAccountName            = "Johnny";
            AccountCreatorService creator = new AccountCreatorService(_mockLogger.Object, newAccountName, _accountRepo);
            ServiceResult         result  = await creator.CreateAccount();

            result.Should().NotBeNull();
            AccountInsertResultDto newAccount = JsonConvert.DeserializeObject <AccountInsertResultDto>(result.ContentResult);

            newAccount.Should().NotBeNull();
            newAccount.Name.Should().Be(newAccountName);
            newAccount.AccountId.Should().BeGreaterThan(0);
            Account newAccountFromDb = await _accountRepo.GetAsync(newAccount.AccountId);

            newAccountFromDb.Should().NotBeNull();
            newAccountFromDb.Name.Should().Be(newAccount.Name);
            newAccountFromDb.Id.Should().Be(newAccount.AccountId);
        }
コード例 #2
0
        public async Task Integration_CreateNewAccount_ExpectAccountInResultAndRepository()
        {
            var newAccount = new AccountInsertDto {
                Name = "Johnny"
            };
            var content       = JsonConvert.SerializeObject(newAccount);
            var stringContent = new StringContent(content, Encoding.UTF8, "application/json");
            var response      = await _client.PostAsync("/api/account/create", stringContent);

            response.StatusCode.Should().Be(System.Net.HttpStatusCode.Created);
            var responseString = await response.Content.ReadAsStringAsync();

            AccountInsertResultDto account = JsonConvert.DeserializeObject <AccountInsertResultDto>(responseString);

            account.Should().NotBeNull();
            account.Name.Should().Be("Johnny");
            Account accountFromDb = _context.Accounts.Find(account.AccountId);

            accountFromDb.Should().NotBeNull();
            accountFromDb.Name.Should().Be(account.Name);
            accountFromDb.Id.Should().Be(account.AccountId);
        }