Ejemplo n.º 1
0
        public async Task Is_invalid_when_associated_orders_exist_async()
        {
            var productID      = 1;
            var orderDataProxy = new Mock <IOrderDataProxy>();

            orderDataProxy.Setup(p => p.GetByProductAsync(productID))
            .Returns(Task.FromResult(Enumerable.OfType <Order>(new[] { new Order() })));
            var rule = new CanDeleteProductRule(productID, orderDataProxy.Object);
            await rule.ValidateAsync();

            rule.IsValid.ShouldBe(false);
            rule.ErrorMessage.ShouldNotBe(null);
        }
Ejemplo n.º 2
0
        public async Task Is_valid_when_no_associated_orders_exist_async()
        {
            var productID      = 1;
            var orderDataProxy = new Mock <IOrderDataProxy>();

            orderDataProxy.Setup(p => p.GetByProductAsync(productID))
            .Returns(Task.FromResult(Enumerable.Empty <Order>()));
            var orderService = new OrderService(orderDataProxy.Object, Mock.Of <IOrderItemService>(), Mock.Of <ITransactionContext>());
            var rule         = new CanDeleteProductRule(productID, orderService);
            await rule.ValidateAsync();

            rule.IsValid.ShouldBe(true);
            rule.ErrorMessage.ShouldBe(null);
        }