public void saveBranchException() { string submit = "Save"; HttpPostedFileBase file = null; { Branch branch = new Branch(); { branch.Branch_Code = "3"; branch.Address1 = "hhggh"; } // Mock up the AddNewBranch() repository method with expected return values. int countryId = 1; int stateId = 1; mockBranchRepository.Setup(m => m.AddNewBranch(branch)).Returns(false); mockBranchRepository.Setup(m => m.FindCodeForCountryId(countryId)).Returns("IN"); mockBranchRepository.Setup(m => m.FindCodeForStateId(stateId)).Returns("TN"); var branchlist = new BranchViewModels(); { branch.Branch_Code = "kalai"; branch.Branch_Name = "kakathopu"; branch.Country_ID = countryId; branch.State_ID = stateId; } branchlist.Branch = branch; var countrylist = new List <CountryList>(); countrylist.Add(new CountryList { ID = 1, Country_Name = "India" }); mockBranchRepository.Setup(m => m.FindCodeForCountryId(countryId)).Returns("IN"); var statelist = new List <StateList>(); statelist.Add(new StateList { ID = 1, State_Name = "Tamil Nadu" }); mockBranchRepository.Setup(m => m.FindCodeForStateId(stateId)).Returns("TN"); var actionResult = branchController.Index(submit, branchlist, file); // Validate the expected result. ViewResult expectedResult = new ViewResult(); Assert.IsNotNull(actionResult); //Assert.IsTrue(true, branchlist,(actionResult)); //branchList, (actionResult.Model as BranchViewModels).BranchList); } }
public void Editbranch() { string submit = "Update"; HttpPostedFileBase file = null; Branch branch = new Branch(); { branch.Branch_Name = "salai"; branch.Address1 = "no 90 kamrajar salai"; } // Mock up the EditBranch() repository method with expected return values. int countryId = 1; int stateId = 1; mockBranchRepository.Setup(m => m.EditBranch(branch)).Returns(true); mockBranchRepository.Setup(m => m.FindCodeForCountryId(countryId)).Returns("IN"); mockBranchRepository.Setup(m => m.FindCodeForStateId(stateId)).Returns("TN"); //mockCountryRespository.Setup(m => m.GetAddresscountryList()).Returns(branchList); var branchlist = new BranchViewModels(); { branch.Branch_Id = 4; branch.Branch_Name = "kakathopu"; branch.Country_ID = countryId; } branchlist.Branch = branch; var countrylist = new List <CountryList>(); countrylist.Add(new CountryList { ID = 1, Country_Name = "India" }); mockBranchRepository.Setup(m => m.FindCodeForCountryId(countryId)).Returns("IN"); var statelist = new List <StateList>(); statelist.Add(new StateList { ID = 1, State_Name = "Tamil Nadu" }); mockBranchRepository.Setup(m => m.FindCodeForStateId(stateId)).Returns("TN"); //var citylist = new List<CityList>(); //citylist.Add(new CityList { ID = 1, City_Name = "Madurai" }); //mockBranchRepository.Setup(m => m.GetAddresscityList()).Returns(citylist); // Now invoke the Index action. var actionResult = branchController.Index(submit, branchlist, file); // Validate the expected result. ViewResult expectedResult = new ViewResult(); Assert.IsNotNull(actionResult); //Assert.IsTrue(actionResult.Model is BranchViewModels) }
public void saveBranch() { string submit = "Save"; HttpPostedFileBase file = null; //BranchViewModels model= ; /* * 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 AddNewBranch() method. Branch branch = new Branch(); { branch.Branch_Name = "salai"; branch.Address1 = "hhggh"; } // Mock up the AddNewBranch() repository method with expected return values. int countryId = 1; int stateId = 1; mockBranchRepository.Setup(m => m.AddNewBranch(branch)).Returns(true); mockBranchRepository.Setup(m => m.FindCodeForCountryId(countryId)).Returns("IN"); mockBranchRepository.Setup(m => m.FindCodeForStateId(stateId)).Returns("TN"); //mockCountryRespository.Setup(m => m.GetAddresscountryList()).Returns(branchList); var branchlist = new BranchViewModels(); { branch.Branch_Id = 4; branch.Branch_Name = "kakathopu"; branch.Country_ID = countryId; branch.State_ID = stateId; } branchlist.Branch = branch; var countrylist = new List <CountryList>(); countrylist.Add(new CountryList { ID = 1, Country_Name = "India" }); mockBranchRepository.Setup(m => m.FindCodeForCountryId(countryId)).Returns("IN"); var statelist = new List <StateList>(); statelist.Add(new StateList { ID = 1, State_Name = "Tamil Nadu" }); mockBranchRepository.Setup(m => m.FindCodeForStateId(stateId)).Returns("TN"); //mockBranchRepository.Setup(m => m.AddNewBranch(branchlist.Branch=)).Returns(model); // Prepare the return data for the GetAddressList() method. //var countrylist = new List<CountryList>(); //countrylist.Add(new CountryList { ID = 1, Country_Name = "India" }); #endregion // Now invoke the Index action. var actionResult = branchController.Index(submit, branchlist, file); // Validate the expected result. ViewResult expectedResult = new ViewResult(); Assert.IsNotNull(actionResult); //(branchList, (actionResult.Model as BranchViewModels).BranchList); //Assert.AreEqual(countrylist, (actionResult.Model as BranchViewModels).CountryList); //Assert.AreEqual(statelist, (actionResult.Model as BranchViewModels).StateList); //Assert.AreEqual(citylist, (actionResult.Model as BranchViewModels).CityList); //Assert.AreEqual(branchList, (actionResult.Model as PurchaseViewModels).BranchList); }