Esempio n. 1
0
            public void Test_Vaildator_Error(string FieldValue, bool trg)
            {
                var _ServiceHandlerFactory = new TestServiceHandlerFactory();
                var _Filter           = new TestFilterFactory();
                var _testRulesFactory = new TestRulesFactory();
                var _common           = new CommonInfo();

                /*
                 *
                 * (IServiceHandlerFactory ServiceHandlerFactory
                 *          , IFilterFactory FilterFactory
                 *          , IRule RulesFactor
                 *          , ICommonInfo CommonInfo)
                 *
                 */


                var testController =
                    new TestController(_ServiceHandlerFactory
                                       , _Filter
                                       , _testRulesFactory
                                       , _common
                                       );

                SetWebControllerInstance.Initialize(testController);

                var Model = default(IBaseViewModelRule);

                Model = new TestViewModel
                {
                    Name = FieldValue
                };

                if (FieldValue == string.Empty)
                {
                    Model = new TestErrorViewModel
                    {
                        Name = FieldValue
                    }
                }
                ;

                testController.Validate(Model);



                var isTrue = testController.ModelState
                             .SelectMany(c => c.Value.Errors)
                             .Any();

                Assert.AreNotSame(isTrue.ToString(), trg.ToString(), "Validation Test Failed");
            }
Esempio n. 2
0
            //public void Test_Webapi_Parser_Attribute_IsInValid()
            //{

            //    string json3 = @"
            //                    {
            //                    'CategoryId':{'value':'2'}
            //                    ,'CategoryTypeId':'2'
            //                    ,'subCategoryName':'Create Test'
            //                    ,'subCategoryTypeName':'Create Test234'
            //                    }
            //                  ";

            //    var json = JObject.Parse(json3);

            //    test_webapi_parser<SubCategoryViewModel>(json, false);

            //}

            // [Test]
            //public void test_webapi_parser_isValid()
            //{

            // string json3= @"
            //                    {
            //                    'CategoryId':{'value':'2'}
            //                    ,'CategoryTypeId':{'value':'2'}
            //                    ,'subCategoryName':{'value':'Create Test'}
            //                    ,'subCategoryTypeName':'Create Test234'
            //                    }
            //                  ";


            //    var json = JObject.Parse(json3);


            //    dynamic json4 = new JObject();
            //    json4.CategoryId = "2";
            //   // json4.CategoryId.Attributes = new JArray() as dynamic;
            //    json4.CategoryTypeId = "2";
            //    json4.subCategoryName = "Create Test";
            //    json4.subCategoryTypeName = "Create Test234";
            //    //json4.err = "error";

            //    test_webapi_parser<SubCategoryViewModel>(json, false);
            //}

            //  [Test]
            //public void test_webapi_parser_isInValid()
            //{
            //    dynamic json = new JObject();
            //    json.CategoryId = "2";
            //    json.CategoryTypeId = "2";
            //    json.subCategoryName = "Create Test";
            //    json.xsubCategoryTypeName = "Create Test234";

            //    test_webapi_parser<SubCategoryViewModel>(json,true);
            //}


            public void test_webapi_parser <T>(JObject json, bool bBoolean)
                where T : class, IDomainViewModel
            {
                var _ServiceHandlerFactory = new TestServiceHandlerFactory();
                var _Filter           = new TestFilterFactory();
                var _testRulesFactory = new TestRulesFactory();
                var _common           = new CommonInfo();



                var testController =
                    new TestWebController(_ServiceHandlerFactory
                                          , _testRulesFactory
                                          , _Filter
                                          , _common
                                          );

                SetWebControllerInstance.Initialize(testController);


                var res = testController.TestJsonParsing <T>(json);

                Assert.AreEqual(bBoolean, res, "webapi parser failed");
            }
Esempio n. 3
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.");
            }
Esempio n. 4
0
            // [Test]
            public void Test_Ron()
            {
                //Arrange
                Mock <IServiceGenericHandler> mockContainer = new Mock <IServiceGenericHandler>();

                var ta = new List <TestReposAttribute>()
                {
                    new Mock <TestReposAttribute>().Object
                    , new Mock <TestReposAttribute>().Object
                }.AsQueryable();


                var sc = new TestSubCategory();

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


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

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

                var client = new Moq.Mock <Client>();

                G_mockClientsServices.Setup(s => s.CreateServiceEntity()).Returns(client.Object);


                var testController =
                    new SubCategoryWebController(G_mockCategoriesService.Object
                                                 , G_mockSubCategoriesService.Object
                                                 , G_mockSubCategoryTypesService.Object
                                                 //, new TestServiceHandlerFactory()
                                                 , G_mockSubCategoryItemsService.Object
                                                 //, new TestServiceHandlerFactory()
                                                 , G_mockClientsServices.Object
                                                 //  , null

                                                 , G_mockServiceHandlerFactory.Object
                                                 // ,  G_mockFilterFactory.Object
                                                 , G_IRule.Object
                                                 , G_mockFilterFactory.Object
                                                 , G_CommonInfo
                                                 , G_UnitOfWork

                                                 );

                SetWebControllerInstance.Initialize(testController);
                var results = testController.GetAvailableCategory();

                var context3 = results.Content;

                //foreach(var c in ((dynamic)results.Content).Value)
                //{
                //    System.Diagnostics.Debug.WriteLine("");
                //}

                var t = context3;

                if (typeof(IEnumerable).IsAssignableFrom(((dynamic)results.Content).Value.GetType()))
                {
                    //foreach(var c in ((dynamic)results.Content).Value)
                    //{
                    //    System.Diagnostics.Debug.WriteLine("");
                    //}
                }
                else
                {
                }

                ///   var c = typeof(IEnumerable).IsAssignableFrom(((dynamic)results.Content).Value);

                // typeof(IEnumerable).IsAssignableFrom(((dynamic)results.Content).Value.GetType())


                // mockContainer.Setup(s => s.GetData<ITestReposAttribute>()).Returns(ta);


                var f = mockContainer.Object.GetData <ITestReposAttribute>();



                var context = new ReposContext("ReposContext");

                var uow = new UnitOfWork(context);

                var rep = new EfRepository <TestEntity>();

                var _service = new TestServices <TestEntity>(
                    rep, null, null);

                var _handler = new TestServiceHandlerFactory(context);

                var subAttributes = _handler
                                    .Using <IServiceGenericHandler>()
                                    .GetData <ITestReposAttribute>()
                                    .OfType <TestReposAttribute>()
                                    .Any();


                //  CustomerViewModel viewModel = new CustomerViewModel(mockView.Object, mockContainer.Object);
                //   viewModel.CustomersRepository = new CustomersRepository();
                //   viewModel.Customer = new Mock<Customer>().Object;

                //Act
                // viewModel.Save();

                //Assert
                //  Assert.IsTrue(viewModel.CustomersRepository.Count == 1);
            }