예제 #1
0
        public void Index()
        {
            /*
             *  First identify the repository methods which are invoked form Index action. Then Setup the mock
             *  for all the identified methods.
             *
             *  Then invoke the Controller's Index action with necessary input parameters and ensure that you have
             *  invoked the Index action for all the different cases (code blocks) available in that, which should
             *  cover all the blocks/statements in the Index action.
             *
             */
            #region Arrange
            // Prepare the return data for GetAllQuotation() method.

            List <ProductGroup> ProductGroupList = new List <ProductGroup>();
            ProductGroupList.Add(new ProductGroup {
                Product_Group_Id = 4, Product_Group_Name = "Camera", Level = 15
            });

            // Mock up the GetAllQuotation() repository method with expected return values.
            mockProductGroupRepository.Setup(m => m.GetAllProductGroup()).Returns(ProductGroupList);

            #endregion

            // Now invoke the Index action.
            var actionResult = productgroupcontroller.Index("test", "test") as ViewResult;

            // Validate the expected result.
            ViewResult expectedResult = new ViewResult();

            Assert.IsNotNull(actionResult);
        }
예제 #2
0
        public void IndexExceptionCase()
        {
            #region
            mockProductGroupRepository = new Mock <IProductGroupRepository>();

            // Prepare the return data for GetAllQuotation() method.
            var productgroupList = new List <ProductGroup>();
            productgroupList.Add(new ProductGroup {
                Product_Group_Id = 4, Product_Group_Name = "Camera", Level = 15
            });

            // Mock up the GetAllQuotation() repository method with expected return values.
            mockProductGroupRepository.Setup(m => m.GetAllProductGroup()).Returns(productgroupList);

            productgroupcontroller = new ProductGroupController(mockProductGroupRepository.Object);
            #endregion

            // Now invoke the Index action.
            var actionResult = productgroupcontroller.Index("test", "test") as ViewResult;

            // Validate the expected result.
            ViewResult expectedResult = new ViewResult();
            Assert.IsNotNull("Error", actionResult.ViewName);
        }