Example #1
0
            //[Test]
            public void rules_are_executed_with_not_vaild_rules()
            {
                ModelStateDictionary modelState = new ModelStateDictionary();

                var _edit     = new Moq.Mock <SubCategoryEdits>(_Context.Object);
                var x_scRepos = new Mock <EfRepository <SubCategory> >(_Context.Object)
                {
                    CallBase = true
                };

                x_scRepos.Setup(s => s.Add(It.IsAny <SubCategory>()));
                x_scRepos.Setup(s => s.ModifiedEntities).Returns(It.IsAny <EntityRules>());
                //x_scRepos.Setup(s =>
                //  s.RunRules(It.IsAny<ServiceRuleFunc<bool>>(), It.IsAny<ModelStateDictionary>(), It.IsAny<object>())).Returns(true);

                var subCategoryEntity = new TestSubCategory
                {
                    Id = 1
                    ,
                    SubCategoryName = new DomainEntityTypeString {
                        Value = "Default"
                    }
                };

                subCategoryEntity.SubCategoryName.Value = "dd";


                var _service         = new Moq.Mock <SubCategoriesService>();
                var testRulesFactory = new TestRulesFactory();

                _service = new Moq.Mock <SubCategoriesService>(x_scRepos.Object
                                                               , _edit.Object, testRulesFactory)
                {
                    CallBase = true
                };

                _service.Object.Add(subCategoryEntity);


                _service.Object.Verify(modelState);
                //SetEntitiesDefaults(It.IsAny<SubCategory>()
                _service.Verify(mock => _service.Object.RunRules(It.IsAny <ServiceRuleFunc <bool> >(), It.IsAny <ModelStateDictionary>(), It.IsAny <object>()), Times.Once);
                //  SubCategoryRules

                //  MockSubCategoryEdits.Verify(mock => mock.SetEntitiesDefaults(It.IsAny<SubCategory>()), Times.Once);

                //  Assert.IsTrue(modelState.Count == 1, "Model Validation Rule didn't Failed.");
            }
Example #2
0
            //[Test]
            public void Test_Apply_Attribute_Filter_IsValid()
            {
                Assert.False(1 == 1, "Test is Broken");

                var sc = new TestSubCategory();

                FilterParms filterParms = default(FilterParms);

                filterParms.Factory    = new TestFilterFactory();
                filterParms.FilterEnum = EnumTest.TestSubCategoryFilter;

                //  var dynfilter = 3;

                filterParms.ParmInputs = new Dictionary <string, object>
                {
                    { "Filter", sc.CategoryTypeId }
                };

                sc.ApplyFilter(filterParms);
                var bres = sc.CategoryTypeId.HasAttributes(EnumAttributes.filter);

                Assert.IsTrue(bres, "Cannot Find Attributes Filter");
            }
Example #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.");
            }
Example #4
0
            //[Test]
            public void edits_are_executed_()
            {
                Moq.Mock <SubCategoryEdits> _edit;

                Moq.Mock <SubCategoriesService> _service;

                /*
                 * public SubCategoriesService(IRepository<SubCategory> subCategoryRepository
                 *                      , IServiceEntityEdit<SubCategory> Edits
                 *                      )
                 */

                var context = new ReposContext("ReposContext");


                _edit = new Moq.Mock <SubCategoryEdits>(_Context.Object);

                var scRepos = new EfRepository <SubCategory>(G_mockUnitOfWork.Object);

                //var _scRepos = new Mock<EfRepository<SubCategory>>(context); //.Object) { CallBase = true };

                var sc = new TestSubCategory
                {
                    Id = 1,
                    SubCategoryName = new DomainEntityTypeString {
                        Value = "Default"
                    }
                };

                var dataCategories = new List <Category>
                {
                    new TestCategory {
                        CategoryName = new DomainEntityTypeString {
                            Value = "AAA"
                        }
                    },
                    new TestCategory {
                        CategoryName = new DomainEntityTypeString {
                            Value = "BBB"
                        }
                    },
                    new TestCategory {
                        CategoryName = new DomainEntityTypeString {
                            Value = "ZZZ"
                        }
                    }
                }.AsQueryable();

                var mockSet = new Mock <DbSet <SubCategory> >()
                {
                    CallBase = true
                };

                var DB = new TestDbSet <SubCategory>(); //                   DbSet<SubCategory>();

                mockSet.As <IQueryable <SubCategory> >().Setup(m => m.Provider).Returns(dataCategories.Provider);
                mockSet.As <IQueryable <SubCategory> >().Setup(m => m.Expression).Returns(dataCategories.Expression);
                mockSet.As <IQueryable <SubCategory> >().Setup(m => m.ElementType).Returns(dataCategories.ElementType);
                //   mockSet.As<IQueryable<SubCategory>>().Setup(m => m.GetEnumerator()).Returns(o => dataCategories.GetEnumerator());


                //_Context.Setup(m => m.Set<SubCategory>()).Returns(DB);

                var MockDbContext = EntityFrameworkMockHelper.GetMockContext <IDbContext>();

                MockDbContext.CallBase = true;


                MockDbContext.Setup(m => m.Set <SubCategory>()).Returns(DB);

                var _scRepos = new Mock <IRepository <SubCategory> >()
                {
                    CallBase = true
                };

                // var mockSet = new Mock<DbSet<SubCategory>>() { CallBase = true };

                var x_scRepos = new Mock <EfRepository <SubCategory> >(G_mockUnitOfWork.Object)
                {
                    CallBase = true
                };

                x_scRepos.Setup(s => s.Add(It.IsAny <SubCategory>()));
                x_scRepos.Setup(s => s.ModifiedEntities).Returns(It.IsAny <EntityRules>());


                var scReposx = new EfRepository <SubCategory>(G_mockUnitOfWork.Object);

                var testRulesFactory = new TestRulesFactory();

                _service = new Moq.Mock <SubCategoriesService>(x_scRepos.Object //_mockSubCategoryRepository.Object
                                                               , _edit.Object, testRulesFactory)
                {
                    CallBase = true
                };


                var cat = EntitiesUtil.CreateEntity <SubCategory>();


                _edit.Setup(s => s.SetEntitiesDefaults(cat));

                var Model = new SubCategoryModel
                {
                    SubCategoryName
                        = new DomainEntityTypeString {
                        Value = "Defaultx", Attributes = null
                        }
                };

                //   _service.Object.CreateServiceEntity();

                ModelStateDictionary modelState = new ModelStateDictionary();

                //  _service.Object.Save();

                var subCategoryEntity = new TestSubCategory
                {
                    Id = 1
                    ,
                    SubCategoryName = new DomainEntityTypeString {
                        Value = "Default"
                    }
                };



                _service.Object.Add(subCategoryEntity);

                _service.Object.Verify(modelState);

                // _edit.Object.SetEntitiesDefaults(cat);

                //   _edit.Verify(s => s.SetEntitiesDefaults(cat), Times.Once);
            }
Example #5
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);
            }