コード例 #1
0
        public void Should_build_a_new_product_from_ProductViewData()
        {
            var orders = new List<int>();
            var expectedProduct = new Product();

            var contributor1 = new MockProductBuilderContributor(2, ctx =>
            {
                ctx.ProductViewData.ShouldBeTheSameAs(productViewData);
                orders.Add(2);
            });
            var contributor2 = new MockProductBuilderContributor(1, ctx =>
            {
                ctx.ProductViewData.ShouldBeTheSameAs(productViewData);
                orders.Add(1);
                ctx.SetProduct(expectedProduct);
            });

            IProductBuilder productBuilder = new ProductBuilder(new[]{ contributor1, contributor2 });

            var product = productBuilder.ProductFromProductViewData(productViewData, modelStateDictionary, new MockHttpRequest());

            product.ShouldBeTheSameAs(expectedProduct);

            orders[0].ShouldEqual(1);
            orders[1].ShouldEqual(2);
        }
コード例 #2
0
        public void Should_not_process_contributor_if_ModelStateDictionary_is_invalid()
        {
            var contributor1 = new MockProductBuilderContributor(1, ctx => ctx.ModelStateDictionary.AddModelError("x", "message"));
            var contributor2 = new MockProductBuilderContributor(2, ctx => Assert.Fail("contributor2 should not be invoked"));

            IProductBuilder productBuilder = new ProductBuilder(new[] { contributor1, contributor2 });

            var product = productBuilder.ProductFromProductViewData(productViewData, modelStateDictionary, new MockHttpRequest());
        }