public async Task GetPreferredShippingAddress_CustomerDoesNotExist_ThrowCustomerNotFoundException( [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock, GetPreferredAddressQueryHandler sut, GetPreferredAddressQuery query ) { //Arrange query.AddressType = "Shipping"; customerRepoMock.Setup(_ => _.GetBySpecAsync( It.IsAny <GetCustomerAddressesSpecification>(), It.IsAny <CancellationToken>() )) .ReturnsAsync((Entities.StoreCustomer)null); //Act Func <Task> func = async() => await sut.Handle(query, CancellationToken.None); //Assert await func.Should().ThrowAsync <CustomerNotFoundException>(); customerRepoMock.Verify(x => x.GetBySpecAsync( It.IsAny <GetCustomerAddressesSpecification>(), It.IsAny <CancellationToken>() )); }
public async Task GetPreferredShippingAddress_NoAddressFound_ReturnAddress( [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock, GetPreferredAddressQueryHandler sut, GetPreferredAddressQuery query, Entities.StoreCustomer customer ) { //Arrange query.AddressType = "Shipping"; customerRepoMock.Setup(_ => _.GetBySpecAsync( It.IsAny <GetCustomerAddressesSpecification>(), It.IsAny <CancellationToken>() )) .ReturnsAsync(customer); //Act var result = await sut.Handle(query, CancellationToken.None); //Assert result.Should().BeNull(); customerRepoMock.Verify(x => x.GetBySpecAsync( It.IsAny <GetCustomerAddressesSpecification>(), It.IsAny <CancellationToken>() )); }
public async Task GetPreferredBillingAddress_HomeAddressExists_ReturnAddress( [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock, GetPreferredAddressQueryHandler sut, GetPreferredAddressQuery query, Entities.IndividualCustomer customer, Entities.Address address ) { //Arrange query.AddressType = "Billing"; customer.AddAddress( new Entities.CustomerAddress( "Home", address ) ); customerRepoMock.Setup(_ => _.GetBySpecAsync( It.IsAny <GetCustomerAddressesSpecification>(), It.IsAny <CancellationToken>() )) .ReturnsAsync(customer); //Act var result = await sut.Handle(query, CancellationToken.None); //Assert result.Should().BeEquivalentTo( address, opt => opt.Excluding(_ => _.SelectedMemberPath.EndsWith("Id", StringComparison.InvariantCultureIgnoreCase)) ); customerRepoMock.Verify(x => x.GetBySpecAsync( It.IsAny <GetCustomerAddressesSpecification>(), It.IsAny <CancellationToken>() )); }