public async Task ReturnSingleAccountBasedOnIdSuccessfuly() { // Arrange GetAccountQuery query = new GetAccountQuery() { Id = 10 }; // Act var result = await handler.Handle(query, CancellationToken.None); // Assert Assert.Equal(10, result.Id); Assert.IsType <AccountViewModel> (result); }
public async Task Then_The_Api_Is_Called_With_The_Request_And_The_Account_Is_Returned( GetAccountQuery query, GetAccountResponse apiResponse, [Frozen] Mock <IAccountsApiClient <AccountsConfiguration> > apiClient, GetAccountQueryHandler handler ) { apiClient.Setup(x => x.Get <GetAccountResponse>(It.Is <GetAccountRequest>(x => x.HashedAccountId == query.HashedAccountId))).ReturnsAsync(apiResponse); var actual = await handler.Handle(query, CancellationToken.None); actual.Should().BeEquivalentTo(apiResponse); }
public void And_No_Account_Then_Throws_EntityNotFoundException( GetAccountQuery query, [Frozen] ValidationResult validationResult, [Frozen] Mock <IAccountsService> mockService, GetAccountQueryHandler handler) { validationResult.ValidationDictionary.Clear(); mockService .Setup(service => service.GetAccount(It.IsAny <long>())) .ReturnsAsync((Domain.Account.Account)null); var act = new Func <Task>(async() => await handler.Handle(query, CancellationToken.None)); act.Should().Throw <EntityNotFoundException <Domain.Entities.Account> >(); }
public async Task Then_Gets_Account_Details_From_Service( GetAccountQuery query, Domain.Account.Account account, [Frozen] ValidationResult validationResult, [Frozen] Mock <IAccountsService> mockService, GetAccountQueryHandler handler) { validationResult.ValidationDictionary.Clear(); mockService .Setup(service => service.GetAccount(query.Id)) .ReturnsAsync(account); var result = await handler.Handle(query, CancellationToken.None); result.Account.Should().BeEquivalentTo(account); }
public async Task Then_If_NotFound_Response_Then_Null_Returned( GetAccountQuery query, [Frozen] Mock <IAccountsApiClient <AccountsConfiguration> > accountApiClient, GetAccountQueryHandler handler) { //Arrange accountApiClient.Setup(x => x.Get <GetAccountByIdResponse>( It.IsAny <GetAccountByIdRequest>())) .ReturnsAsync((GetAccountByIdResponse)null); //Act var actual = await handler.Handle(query, CancellationToken.None); //Assert actual.AccountId.Should().BeNull(); actual.HashedAccountId.Should().BeNull(); }
public void And_Fails_Validation_Then_Throws_ValidationException( GetAccountQuery query, string propertyName, Domain.Account.Account account, [Frozen] Mock <IValidator <GetAccountQuery> > mockValidator, [Frozen] ValidationResult validationResult, [Frozen] Mock <IAccountsService> mockService, GetAccountQueryHandler handler) { validationResult.AddError(propertyName); mockValidator .Setup(validator => validator.ValidateAsync(It.IsAny <GetAccountQuery>())) .ReturnsAsync(validationResult); var act = new Func <Task>(async() => await handler.Handle(query, CancellationToken.None)); act.Should().Throw <ArgumentException>() .WithMessage($"*{propertyName}*"); }
public async Task Then_The_Query_Is_Handled_And_Data_Returned( GetAccountQuery query, GetAccountByIdResponse apiResponse, [Frozen] Mock <IAccountsApiClient <AccountsConfiguration> > accountsApiClient, GetAccountQueryHandler handler) { //Arrange var expectedGetUrl = new GetAccountByIdRequest(query.AccountId); accountsApiClient .Setup(x => x.Get <GetAccountByIdResponse>( It.Is <GetAccountByIdRequest>(c => c.GetUrl.Equals(expectedGetUrl.GetUrl)))) .ReturnsAsync(apiResponse); //Act var actual = await handler.Handle(query, CancellationToken.None); //Assert actual.Should().BeEquivalentTo(apiResponse); }