Exemplo n.º 1
0
            public void Test_SubCategoryControl_Create_Is_Not_Valid()
            {
                var dataSubCategories = new List <SubCategory>
                {
                    new TestSubCategory {
                        Id = 1, SubCategoryName = new DomainEntityTypeString {
                            Value = "ABC"
                        }
                    },
                    new TestSubCategory {
                        Id = 2, SubCategoryName = new DomainEntityTypeString {
                            Value = "ZZZ"
                        }
                    },
                    new TestSubCategory {
                        Id = 3, SubCategoryName = new DomainEntityTypeString {
                            Value = "MMM"
                        }
                    },
                }.AsQueryable();

                G_mockSubCategoriesService.Setup(s => s.GetAll()).Returns(dataSubCategories);

                //var sc = new Moq.Mock<SubCategory>();

                var sc = new TestSubCategory();

                G_mockSubCategoriesService.Setup(s => s.CreateServiceEntity()).Returns(sc);


                var si = new Moq.Mock <SubCategoryClassItem>();

                G_mockSubCategoryClassItemService.Setup(s => s.CreateServiceEntity()).Returns(si.Object);



                var _ServiceHandlerFactory = new TestServiceHandlerFactory();

                var _Filter = new TestFilterFactory();

                var _rule = new TestRulesFactory();

                var common = new CommonInfo();

                var controller =
                    new SubCategoryController(G_mockCategoriesService.Object
                                              , G_mockSubCategoriesService.Object
                                              , G_mockSubCategoryTypesService.Object
                                              , G_mockSubCategoryItemsService.Object
                                              , _ServiceHandlerFactory
                                              , G_mockSubCategoryClassItemService.Object
                                              , _Filter
                                              , _rule
                                              , common
                                              , G_UnitOfWork
                                              );

                SetWebControllerInstance.Initialize(controller);


                var res = controller.GetAvailableCategory(1, 1);

                dynamic attr = new ExpandoObject();
                //  attr.propList = new List<PropListKeyPair>();
                //  attr.Filter = new List<FilterKeyPair>();

                var Model = new SubCategoryModel
                {
                    SubCategoryName
                        = new DomainEntityTypeString {
                        Value = string.Empty, Attributes = null
                        }
                    ,
                    CategoryId =
                        new DomainEntityTypeInt
                    {
                        Value        = int.MaxValue
                        , Attributes = attr
                    }
                    , CategoryTypeId = new DomainEntityTypeInt {
                        Value = int.MaxValue
                    }
                };

                controller.Create(Model);

                var isTrue = controller.ModelState
                             .SelectMany(c => c.Value.Errors)
                             .Any(a => a.ErrorMessage.Contains("SubCategoryName"));


                Assert.IsTrue(!isTrue, "Failed to throw exception.");
            }