public void ValidateSku_When_not_uniqe_Then_fails()
        {
            var validator = new ProductRequestCustomValidator();
            var request   = ProductCreateRequestBuilder.Create()
                            .WithProduct(ProductDtoBuilder.Create()
                                         .WithVariant(ProductVariantDtoBuilder.Create()
                                                      .WithSku("001")
                                                      .Build())
                                         .WithVariant(ProductVariantDtoBuilder.Create()
                                                      .WithSku("000")
                                                      .Build())
                                         .Build())
                            .Build();

            var errors = new ArgumentErrorsCollection();

            var dbContextMock = GetDbContextMock();

            validator.ValidateSkus(dbContextMock.Object, request, errors);

            dbContextMock.VerifyGet(c => c.Products, Times.AtLeast(request.Product.Variants.Count));

            Assert.IsNotEmpty(errors);
            Assert.IsTrue(errors.HasArgument("Product.Variants.Sku"), errors[0].ArgumentName);
        }
        public void ValidateRequestCustom_When_newIds_Then_success_validation()
        {
            ProductCreateRequest request = ProductCreateRequestBuilder.Create()
                                           .WithProduct(ProductDtoBuilder.Create()
                                                        .WithName("TEST")
                                                        .WithCategoryId(1)
                                                        .WithDescription("TEST DESCRIPTION")
                                                        .WithOption(ProductOptionDtoBuilder.Create()
                                                                    .WithIndex(1)
                                                                    .WithName("TEST")
                                                                    .Build())
                                                        .WithVariant(ProductVariantDtoBuilder.Create()
                                                                     .WithPrice(10)
                                                                     .WithQuantity(10)
                                                                     .WithOptionValue(ProductVariantOptionValueDtoBuilder.Create()
                                                                                      .WithIndex(1)
                                                                                      .WithValue("TEST")
                                                                                      .Build())
                                                                     .Build())
                                                        .Build())
                                           .Build();

            SetupMocks(request);

            CommandMock.Object.ValidateRequestCustom();

            ValidatorMock.Verify(s => s.ValidateNewIds(It.IsAny <IDbContext>(),
                                                       It.IsAny <ProductCreateRequest>(),
                                                       It.IsAny <ArgumentErrorsCollection>()),
                                 Times.Once);
        }
        public void Execute_When_correct_request_Then_validates_Then_calls_execute()
        {
            var request = ProductCreateRequestBuilder.Create()
                          .WithProduct(ProductDtoBuilder.Create()
                                       .WithName("TEST")
                                       .WithCategoryId(1)
                                       .WithDescription("TEST DESCRIPTION")
                                       .WithOption(ProductOptionDtoBuilder.Create()
                                                   .WithIndex(1)
                                                   .WithName("TEST")
                                                   .Build())
                                       .WithVariant(ProductVariantDtoBuilder.Create()
                                                    .WithPrice(10)
                                                    .WithQuantity(10)
                                                    .WithOptionValue(ProductVariantOptionValueDtoBuilder.Create()
                                                                     .WithIndex(1)
                                                                     .WithValue("TEST")
                                                                     .Build())
                                                    .Build())
                                       .Build())
                          .Build();

            SetupMocks(request);

            CommandMock.Setup(c => c.ValidateRequestCustom());

            CommandMock.Object.Execute(request);

            CommandMock.Protected().Verify("ValidateRequest", Times.Once());
            CommandMock.Verify(c => c.ValidateRequestCustom(), Times.Once);
        }
        public void ValidateSku_When_unique_Then_passes()
        {
            var validator = new ProductRequestCustomValidator();

            var request = ProductCreateRequestBuilder.Create().WithProduct(
                ProductDtoBuilder.Create().WithVariant(
                    ProductVariantDtoBuilder.Create().WithSku("001")
                    .Build())
                .Build())
                          .Build();

            var errors = new ArgumentErrorsCollection();

            var dbContextMock = GetDbContextMock();

            validator.ValidateSkus(dbContextMock.Object, request, errors);

            dbContextMock.VerifyGet(c => c.Products, Times.Once);

            Assert.IsEmpty(errors);
        }