public async Task Handle_ExistingCustomerAndAddress_DeleteCustomerAddress( [Frozen] Entities.Customer customer, [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock, DeleteCustomerAddressCommandHandler sut, DeleteCustomerAddressCommand command, Entities.Address address ) { //Arrange customer.AddAddress( new Entities.CustomerAddress( command.AddressType, address ) ); customerRepoMock.Setup(x => x.GetBySpecAsync( It.IsAny <GetCustomerSpecification>(), It.IsAny <CancellationToken>() )) .ReturnsAsync(customer); //Act var result = await sut.Handle(command, CancellationToken.None); //Assert result.Should().NotBeNull(); customerRepoMock.Verify(x => x.UpdateAsync( It.IsAny <Entities.Customer>(), It.IsAny <CancellationToken>() )); }
public void Handle_AddressDoesNotExist_ThrowArgumentNullException( DeleteCustomerAddressCommandHandler sut, DeleteCustomerAddressCommand command ) { //Act Func <Task> func = async() => await sut.Handle(command, CancellationToken.None); //Assert func.Should().Throw <ArgumentNullException>() .WithMessage("Value cannot be null. (Parameter 'customerAddress')"); }
public async Task <IHttpActionResult> Delete(Guid customerAddressId) { DeleteCustomerAddressCommand command = new DeleteCustomerAddressCommand { UserId = UserId, CustomerAddressId = customerAddressId }; var commandResponse = await Bus.Send <DeleteCustomerAddressCommand, DeleteCustomerAddressCommandResponse>(command); var response = new ResponseModel { Message = "حذف آدرس با موفقیت انجام شد", Success = true, ResponseData = commandResponse }; return(Ok(response)); }
public async Task <DeleteCustomerAddressCommandResponse> Handle(DeleteCustomerAddressCommand command) { var customer = await _repository.AsQuery().SingleOrDefaultAsync(p => p.UserId == command.UserId); if (customer == null) { throw new DomainException("مشتری یافت نشد"); } _personDomainService.AddressIsDefaultAddress(customer, command.CustomerAddressId); var address = customer.CustomerAddresses.SingleOrDefault(p => p.Id == command.CustomerAddressId); if (address == null) { throw new DomainException("ادرس یافت نشد"); } customer.CustomerAddresses.Remove(address); return(new DeleteCustomerAddressCommandResponse()); }
public void Handle_CustomerDoesNotExist_ThrowArgumentNullException( [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock, DeleteCustomerAddressCommandHandler sut, DeleteCustomerAddressCommand command ) { // Arrange customerRepoMock.Setup(x => x.GetBySpecAsync( It.IsAny <GetCustomerSpecification>(), It.IsAny <CancellationToken>() )) .ReturnsAsync((Entities.Customer)null); //Act Func <Task> func = async() => await sut.Handle(command, CancellationToken.None); //Assert func.Should().Throw <ArgumentNullException>() .WithMessage("Value cannot be null. (Parameter 'customer')"); }