Beispiel #1
0
        public async Task ShouldUpdateProductAsExpired()
        {
            // given
            Product product = new Filler <Product>().Create();

            var productExpirationEvent = new ProductExpirationEvent
            {
                ProductId      = product.Id,
                ExpirationDate = product.ExpirationDate
            };

            CancellationToken cancellationToken = new CancellationToken();

            Message message = new Message
            {
                Body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(productExpirationEvent)),
                ScheduledEnqueueTimeUtc = product.ExpirationDate.ToUniversalTime()
            };

            this.storageBroker.Setup(broker => broker.GetProductByIdAsync(product.Id))
            .ReturnsAsync(product);

            // when
            var productService = new ProductEventService(this.eventsBroker.Object, this.storageBroker.Object);
            await productService.ExpireProductAsync(message, cancellationToken);

            // then
            this.storageBroker.Verify(broker => broker.UpdateProductAsync(It.Is <Product>(
                                                                              storageProduct => storageProduct.Id == product.Id &&
                                                                              storageProduct.Condition == ProductCondition.Expired &&
                                                                              storageProduct.ExpirationDate == product.ExpirationDate)), Times.Once);
        }
Beispiel #2
0
        public async Task ShouldNotUpdateProductAsExpiredIfProductWasRemoved()
        {
            // given
            Product noProduct = null;
            var     productExpirationEvent = new Filler <ProductExpirationEvent>().Create();

            CancellationToken cancellationToken = new CancellationToken();

            Message message = new Message
            {
                Body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(productExpirationEvent)),
                ScheduledEnqueueTimeUtc = DateTime.Now
            };

            this.storageBroker.Setup(broker => broker.GetProductByIdAsync(productExpirationEvent.ProductId))
            .ReturnsAsync(noProduct);

            // when
            var productService = new ProductEventService(this.eventsBroker.Object, this.storageBroker.Object);
            await productService.ExpireProductAsync(message, cancellationToken);

            // then
            this.storageBroker.Verify(broker => broker.UpdateProductAsync(It.IsAny <Product>()), Times.Never);
        }