Beispiel #1
0
        public void CreateAsync_Purschase_Insert_IntegrationWithLibrary_Valid()
        {
            var key = FakeHelper.Key;

            var message = PurchaseMessageMock.Get(key);

            var settings = Settings.Empty;

            settings.Preferences.TryAdd(Preferences.IntegrationWithLibrary, "true");

            var(dto, proxy) = CreateAsync(message, settings);
            dto.Should().NotBeNull();

            var entity = Db.Orders.FirstOrDefault(x => x.Number == Fake.GetOrderNumber(key));

            entity.Should().NotBeNull();

            var expected = OrderMock.GetByPurchase(key);

            expected.Id          = entity.Id;
            expected.Customer.Id = entity.Customer.Id;
            expected.Items[0].Id = entity.Items[0].Id;

            entity.Should().BeEquivalentToEntity(expected);

            var dtoExpected = ShippingDtoMessageMock.Get(key);

            dtoExpected.OrderId = entity.Id;
            dto.Should().BeEquivalentToMessage(dtoExpected);

            var proxyExpectd = DropCopyNumberMessageMock.Get(key);

            proxy.Should().BeEquivalentToMessage(proxyExpectd);
        }
Beispiel #2
0
        public void InsertOrder()
        {
            var result = new ResponseBase <bool>();
            var data   = new OrderModel();

            try
            {
                data = new OrderModel()
                {
                    OrdenDate = Convert.ToDateTime("1999-01-01"),
                    Status    = "1",
                    Comments  = "prueba",
                    CustId    = 1,
                    IdEstado  = 1,
                    LItems    = new System.Collections.Generic.List <ItemModel>(),
                    Price     = 1000
                };
                for (var x = 0; x < 10; ++x)
                {
                    data.LItems.Add(new ItemModel()
                    {
                        ItemId = x
                    });
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }

            result = new OrderMock().InsertOrder(data).Result;
            Assert.IsTrue(result.Code == Status.Ok, result.Message);
        }
Beispiel #3
0
        public void CreateAsync_Purschase_Insert_Valid()
        {
            var key = FakeHelper.Key;

            var message = PurchaseMessageMock.Get(key);

            var(dto, proxy) = CreateAsync(message);
            dto.Should().NotBeNull();

            var entity = Db.Orders.FirstOrDefault(x => x.Number == Fake.GetOrderNumber(key));

            entity.Should().NotBeNull();

            var expected = OrderMock.GetByPurchase(key);

            expected.Id          = entity.Id;
            expected.Customer.Id = entity.Customer.Id;
            expected.Items[0].Id = entity.Items[0].Id;

            entity.Should().BeEquivalentToEntity(expected);

            var dtoExpected = ShippingDtoMessageMock.Get(key);

            dtoExpected.OrderId = entity.Id;
            dto.Should().BeEquivalentToMessage(dtoExpected);
        }
Beispiel #4
0
        public void CreateAsync_Purschase_Update_Customer_NotAccepted()
        {
            var key   = FakeHelper.Key;
            var order = OrderMock.GetByPurchase(key);

            MockRepository.Add(order);

            var message = PurchaseMessageMock.Get(key);
            var key2    = FakeHelper.Key;

            message.CustomerName = Fake.GetCustomerName(key2);
            message.CustomerId   = FakeHelper.GetId(key2).ToString();

            var(dto, proxy) = CreateAsync(message);
            dto.Should().NotBeNull();

            var entity = Db.Orders.FirstOrDefault(x => x.Number == Fake.GetOrderNumber(key));

            entity.Should().NotBeNull();

            var expected = OrderMock.GetByPurchase(key);

            expected.UpdatedAt   = DateTime.UtcNow;
            expected.Items[0].Id = entity.Items[0].Id;
            entity.Should().BeEquivalentToEntity(expected);

            var dtoExpected = ShippingDtoMessageMock.Get(key);

            dtoExpected.OrderId = entity.Id;
            dto.Should().BeEquivalentToMessage(dtoExpected);
        }
Beispiel #5
0
        public void Handle_PurchaseBookCommand_Default()
        {
            // arrange
            var key = MockBuilder.Key;

            var command = PurchaseBookCommandMock.Get(key);

            // act
            var result = Handle(command);

            // assert
            result.Should().BeTrue();

            var orders = MockRepository.Query <Order>()
                         .Include(x => x.Items)
                         .Include(x => x.Customer)
                         .ToList();
            var orderExpected = OrderMock.Get(key);

            orders.Should().BeEquivalentToEntity(MockBuilder.List(orderExpected));

            var publishShippingEventCommands        = Bus.GetAllSent <PublishShippingEventCommand>(ContextNames.Queue.Bookstore);
            var publishShippingEventCommandExpected = PublishShippingEventCommandMock.Get(key);

            publishShippingEventCommandExpected.OrderId = orders[0].Id;
            publishShippingEventCommands.Should().BeEquivalentToMessage(MockBuilder.List(publishShippingEventCommandExpected));

            var dropCopyNumberEvents        = Bus.GetAllPublished <DropCopyNumberEvent>(ContextNames.Exchange.Bookstore);
            var dropCopyNumberEventExpected = DropCopyNumberEventMock.Get(key);

            dropCopyNumberEvents.Should().BeEquivalentToMessage(MockBuilder.List(dropCopyNumberEventExpected));
        }
Beispiel #6
0
        public void Handle_PurchaseBookCommand_Customer_Not_Exists()
        {
            // arrange
            var key = MockBuilder.Key;

            var command = PurchaseBookCommandMock.Get(key);

            // act
            var result = Handle(command);

            // assert
            result.Should().BeTrue();

            var customers        = MockRepository.Query <Customer>().ToList();
            var customerExpected = CustomerMock.Get(key);

            customers.Should().BeEquivalentToEntity(MockBuilder.List(customerExpected));

            var orders = MockRepository.Query <Order>()
                         .Include(x => x.Items)
                         .Include(x => x.Customer)
                         .ToList();
            var orderExpected = OrderMock.Get(key);

            orderExpected.Customer = customerExpected;
            orders.Should().BeEquivalentToEntity(MockBuilder.List(orderExpected));
        }
Beispiel #7
0
        public void GetItemFromOrder()
        {
            var idOrden = 1L;

            var result = new OrderMock().GetItemFromOrder(idOrden).Result;

            Assert.IsTrue(result.Code == Status.Ok || result.Code == Status.NotFound, result.Message);
        }
Beispiel #8
0
        public void GetOrders()
        {
            var custId = 1L;

            var result = new OrderMock().GetOrders(custId).Result;

            Assert.IsTrue(result.Code == Status.Ok || result.Code == Status.NotFound, result.Message);
        }
Beispiel #9
0
        public void ActualizaEstadoOrder()
        {
            var idOrden  = 1;
            var idEstado = 1;

            var result = new OrderMock().ActualizaEstadoOrder(idOrden, idEstado).Result;

            Assert.IsTrue(result.Code == Status.Ok || result.Code == Status.NotFound, result.Message);
        }
Beispiel #10
0
        public void CreateShippingAsync_Dto_Valid()
        {
            var key = FakeHelper.Key;

            var order = OrderMock.Get(key);

            MockRepository.Add(order);

            var message = ShippingDtoMessageMock.Get(key);

            var dto = CreateShippingAsync(message);

            dto.Should().NotBeNull();

            var dtoExpected = ShippingDtoMock.Get(key);

            dto.Should().BeEquivalentToMessage(dtoExpected);
        }
Beispiel #11
0
        public void Handle_PublishShippingEventCommand_Default()
        {
            // arrange
            var key = MockBuilder.Key;

            var order = OrderMock.Get(key);

            MockRepository.Add(order);

            MockRepository.Commit();

            var command = PublishShippingEventCommandMock.Get(key);

            // act
            var result = Handle(command);

            // assert
            result.Should().BeTrue();

            var events        = Bus.GetAllPublished <CreateShippingEvent>(ContextNames.Exchange.Bookstore);
            var eventExpected = CreateShippingEventMock.Get(key);

            events.Should().BeEquivalentToMessage(MockBuilder.List(eventExpected));
        }