public async Task RegisterCustomer_Success() { var command = new RegisterCustomer() { Name = "Customer Buyer", Type = CustomerType.RetailOutlet, PrimaryContactFirstName = "Sam", PrimaryContactLastName = "Gold", PrimaryContactPhone = "380000000000", PrimaryContactEmail = "*****@*****.**", ShippingAddressLine1 = "1 Paper st.", ShippingAddressLine2 = "1 Apt.", ShippingAddressCity = "Kyiv", ShippingAddressProvince = "Kyiv", ShippingAddressCountry = "Ukraine", ShippingAddressPostalCode = "37007", InitiatorId = GlobalAdmin.Id }; var handler = new RegisterCustomerHandler(EntityRepository, EventTransmitter); await handler.HandleAsync(command); Assert.That(CallsTo(EntityRepository, nameof(EntityRepository.AddAsync)), Is.EqualTo(1)); var entity = GetRecordedEntities <Customer>(EntityRepository, nameof(EntityRepository.AddAsync)).Single(); Assert.That(entity.Name, Is.EqualTo(command.Name)); Assert.That(entity.CustomerType, Is.EqualTo(command.Type)); Assert.That(entity.PrimaryContact.FirstName, Is.EqualTo(command.PrimaryContactFirstName)); Assert.That(entity.PrimaryContact.LastName, Is.EqualTo(command.PrimaryContactLastName)); Assert.That(entity.PrimaryContact.PhoneNumber, Is.EqualTo(command.PrimaryContactPhone)); Assert.That(entity.PrimaryContact.Email, Is.EqualTo(command.PrimaryContactEmail)); Assert.That(entity.ShippingAddress.AddressLine1, Is.EqualTo(command.ShippingAddressLine1)); Assert.That(entity.ShippingAddress.AddressLine2, Is.EqualTo(command.ShippingAddressLine2)); Assert.That(entity.ShippingAddress.City, Is.EqualTo(command.ShippingAddressCity)); Assert.That(entity.ShippingAddress.Province, Is.EqualTo(command.ShippingAddressProvince)); Assert.That(entity.ShippingAddress.Country, Is.EqualTo(command.ShippingAddressCountry)); Assert.That(entity.ShippingAddress.PostalCode, Is.EqualTo(command.ShippingAddressPostalCode)); var events = GetRecordedEvents <DomainEvent <Customer> >(); Assert.That(events.Count, Is.EqualTo(1)); Assert.That(events[0].Entity, Is.EqualTo(entity)); Assert.That(events[0].Trigger, Is.EqualTo(Trigger.Added)); Assert.That(events[0].RaisedBy, Is.EqualTo(command.InitiatorId)); }
public async Task Should_Handle_Register_Customer_Command() { //arrange var cmd = _fixture.Create <RegisterCustomer>(); var sut = new RegisterCustomerHandler(_repository, _mediator); Customer newCustomer = null; _repository .When(x => x.Create(Arg.Any <Customer>(), _none)) .Do(x => newCustomer = x.Arg <Customer>()); //act await sut.Handle(cmd, _none); //assert newCustomer.Should().NotBeNull(); newCustomer.Address.Should().BeEquivalentTo(new { cmd.CountryCode, cmd.ZipCode, cmd.City, cmd.Street, cmd.House, cmd.Apartment }); newCustomer.Contact.Should().BeEquivalentTo(new { cmd.Title, cmd.FirstName, cmd.MiddleName, cmd.LastName, }); await _repository.Received().Create(newCustomer, _none); await _mediator.ReceivedWithAnyArgs().Publish <CustomerRegistered>(null, _none); }
public void RegisterCustomerTest() { Customer customer3 = new Customer { CustomerId = 3, Country = "Perú", Email = "*****@*****.**" }; mockRepository.Setup(x => x.RegisterCustomer(customer3)) .Returns(true); var handler = new RegisterCustomerHandler(mockRepository.Object); RegisterCustomer rc = new RegisterCustomer(customer3); var res = handler.Handle(rc, ct); Assert.IsTrue(res.Result); Assert.IsTrue(true); }