public async Task <ActionResult <BudgetAccountModel> > BudgetAccountAsync(int accountingNumber, string accountNumber, DateTimeOffset?statusDate = null) { if (string.IsNullOrWhiteSpace(accountNumber)) { throw new IntranetExceptionBuilder(ErrorCode.ValueCannotBeNullOrWhiteSpace, nameof(accountNumber)) .WithValidatingType(typeof(string)) .WithValidatingField(nameof(accountNumber)) .Build(); } IGetBudgetAccountQuery query = new GetBudgetAccountQuery { AccountingNumber = accountingNumber, AccountNumber = accountNumber, StatusDate = statusDate?.LocalDateTime.Date ?? DateTime.Today }; IBudgetAccount budgetAccount = await _queryBus.QueryAsync <IGetBudgetAccountQuery, IBudgetAccount>(query); if (budgetAccount == null) { throw new IntranetExceptionBuilder(ErrorCode.ValueShouldBeKnown, nameof(accountNumber)) .WithValidatingType(typeof(string)) .WithValidatingField(nameof(accountNumber)) .Build(); } BudgetAccountModel budgetAccountModel = _accountingModelConverter.Convert <IBudgetAccount, BudgetAccountModel>(budgetAccount); return(Ok(budgetAccountModel)); }
public async Task BudgetAccountAsync_WhenBudgetAccountWasReturnedFromQueryBus_ReturnsOkObjectResultWhereValueIsBudgetAccountModelMatchingBudgetAccountFromQueryBus() { string accountNumber = _fixture.Create <string>(); IBudgetAccount budgetAccount = _fixture.BuildBudgetAccountMock(accountNumber: accountNumber).Object; Controller sut = CreateSut(budgetAccount: budgetAccount); OkObjectResult result = (OkObjectResult)(await sut.BudgetAccountAsync(_fixture.Create <int>(), _fixture.Create <string>())).Result; BudgetAccountModel budgetAccountModel = (BudgetAccountModel)result.Value; Assert.That(budgetAccountModel, Is.Not.Null); Assert.That(budgetAccountModel.AccountNumber, Is.EqualTo(accountNumber)); }