Example #1
0
        public async Task Should_NewProductFetched_OnSingleDispatch_DispatchCreate()
        {
            //arrange
            var newProductFetched = new NewProductFetchedIntegrationEvent
            {
                ExternalSourceName = "Fake",
                Id             = Guid.NewGuid().ToString(),
                Description    = "FakeDescription",
                Height         = 1,
                Length         = 2,
                Name           = "FakeName",
                Price          = 3,
                Weight         = 4,
                Width          = 5,
                BarCode        = "fakeBarCode",
                CategoryId     = 6,
                IsAvailable    = true,
                ManufacturerId = 7,
                StockQuantity  = 8
            };

            //act
            await _handler.Handle(newProductFetched);

            //assert
            var createCommands = _pendingCommands.GetCreateCommands();
            var updateCommands = _pendingCommands.GetUpdateCommands();

            createCommands.CreateProductCommands.Should().HaveCount(1);
            updateCommands.UpdateProductCommands.Should().HaveCount(0);
        }
Example #2
0
        public async Task FetchAndPublishAsync(CancellationToken cancellationToken)
        {
            var products = await _adapter.GetProductsAsync();

            if (products?.Data is null)
            {
                throw new FetchFailedException();
            }

            if (products.PageSize == 0)
            {
                throw new ZeroProductsFetchedException();
            }

            foreach (var product in products.Data)
            {
                var @event = new NewProductFetchedIntegrationEvent(product.Name,
                                                                   product.ManufacturerId,
                                                                   product.BarCode,
                                                                   product.StockQuantity,
                                                                   product.Price,
                                                                   product.Description,
                                                                   product.Length,
                                                                   product.Width,
                                                                   product.Height,
                                                                   product.Weight,
                                                                   product.CategoryId,
                                                                   product.Id,
                                                                   GlobalConstants.SmartStoreExternalSourceName
                                                                   );

                _bus.Publish(@event);
            }
        }