public void RegisterSupplierTest()
        {
            Supplier supplier3 = new Supplier
            {
                SupplierId = 3,
                Name       = "Luis",
                LastName   = "Perez",
                Email      = "*****@*****.**",
                Phone      = "9456789",
                Age        = 45,
                Gender     = "Masculino",
                UsuarioId  = 1,
                LocationId = 1,
                Country    = "Peru",
                State      = "Lima",
                City       = "Lima",
                Address    = "Lima av. 25",
                Contraseña = "456789"
            };


            mockRepository.Setup(x => x.RegisterSupplier(supplier3))
            .Returns(true);

            var handler = new RegisterSupplierHandler(mockRepository.Object);

            RegisterSupplier ru = new RegisterSupplier(supplier3);

            var res = handler.Handle(ru, ct);

            Assert.IsTrue(res.Result);
        }
Beispiel #2
0
        public async Task RegisterSupplier_Success()
        {
            //arrange
            var command = new RegisterSupplier()
            {
                Name = "Pvc Foil supplier",
                SuppliableArticleIds = new List <Guid> {
                    Material2Foil.Id
                },
                PrimaryContactFirstName   = "John",
                PrimaryContactLastName    = "Smith",
                PrimaryContactPhone       = "381111111111",
                PrimaryContactEmail       = "*****@*****.**",
                ShippingAddressLine1      = "2 Paper st.",
                ShippingAddressLine2      = "2 Apt.",
                ShippingAddressCity       = "Kyiv",
                ShippingAddressProvince   = "Kyiv",
                ShippingAddressCountry    = "Ukraine",
                ShippingAddressPostalCode = "37008",
                InitiatorId = GlobalAdmin.Id
            };
            var handler = new RegisterSupplierHandler(EntityRepository, EventTransmitter);

            //act
            await handler.HandleAsync(command);

            //assert
            var entities = GetRecordedEntities <Supplier>(EntityRepository, nameof(EntityRepository.AddAsync));

            Assert.That(entities.Count, Is.EqualTo(1));
            Assert.That(entities[0].Name, Is.EqualTo(command.Name));
            Assert.That(entities[0].SuppliableArticles.Count, Is.EqualTo(1));
            Assert.That(entities[0].SuppliableArticles.Single(), Is.EqualTo(Material2Foil));
            Assert.That(entities[0].PrimaryContact.FirstName, Is.EqualTo(command.PrimaryContactFirstName));
            Assert.That(entities[0].PrimaryContact.LastName, Is.EqualTo(command.PrimaryContactLastName));
            Assert.That(entities[0].PrimaryContact.PhoneNumber, Is.EqualTo(command.PrimaryContactPhone));
            Assert.That(entities[0].PrimaryContact.Email, Is.EqualTo(command.PrimaryContactEmail));
            Assert.That(entities[0].ShippingAddress.AddressLine1, Is.EqualTo(command.ShippingAddressLine1));
            Assert.That(entities[0].ShippingAddress.AddressLine2, Is.EqualTo(command.ShippingAddressLine2));
            Assert.That(entities[0].ShippingAddress.City, Is.EqualTo(command.ShippingAddressCity));
            Assert.That(entities[0].ShippingAddress.Province, Is.EqualTo(command.ShippingAddressProvince));
            Assert.That(entities[0].ShippingAddress.Country, Is.EqualTo(command.ShippingAddressCountry));
            Assert.That(entities[0].ShippingAddress.PostalCode, Is.EqualTo(command.ShippingAddressPostalCode));

            var events = GetRecordedEvents <DomainEvent <Supplier> >();

            Assert.That(events.Count, Is.EqualTo(1));
            Assert.That(events[0].Trigger, Is.EqualTo(Trigger.Added));
            Assert.That(events[0].Entity, Is.EqualTo(entities[0]));
            Assert.That(events[0].RaisedBy, Is.EqualTo(command.InitiatorId));
        }