public void ReturnBranchIndexView() { var mockBranchService = new Mock <ILibraryBranch>(); mockBranchService.Setup(r => r.GetAll()).Returns(GetAllBranches()); //Arrange var controller = new BranchController(mockBranchService.Object); //Act var result = controller.Index(); Assert.IsType <ViewResult>(result); }
public void Return_BranchIndexModel() { var mockBranchService = new Mock <ILibraryBranchService>(); mockBranchService.Setup(r => r.GetAll()).Returns(GetAllBranches()); var controller = new BranchController(mockBranchService.Object); var result = controller.Index(); var viewResult = result.Should().BeOfType <ViewResult>(); viewResult.Subject.Model.Should().BeOfType <BranchIndexModel>(); }
public void Should_Return_Type_BranchIndexModel() { var mockBranchService = new Mock <ILibraryBranch>(); var mockbranch = new Mock <IWebHostEnvironment>(); mockBranchService.Setup(r => r.GetAll()).Returns(GetAllBranches()); var controller = new BranchController(mockBranchService.Object, mockbranch.Object); var result = controller.Index(); var viewResult = result.Should().BeOfType <ViewResult>(); viewResult.Subject.Model.Should().BeOfType <branchIndexModel>(); }
public void Return_Branch_Index_View() { var mockBranchService = new Mock <ILibraryBranchService>(); mockBranchService.Setup(r => r.GetAll()).Returns(GetAllBranches()); var controller = new BranchController(mockBranchService.Object); var result = controller.Index(); var viewResult = result.Should().BeOfType <ViewResult>(); var viewModel = viewResult.Subject.ViewData.Model.Should().BeAssignableTo <BranchIndexModel>(); viewModel.Subject.Branches.Count().Should().Be(3); }
public void IndexExceptionCase() { #region mockBranchRepository = new Mock <IBranchRepository>(); // Prepare the return data for GetAllQuotation() method. var branchList = new List <ViewBranches>(); branchList.Add(new ViewBranches { Branch_Id = 1, Branch_Name = "Theni" }); // Mock up the GetAllQuotation() repository method with expected return values. mockBranchRepository.Setup(m => m.GetAllUserBranch()).Returns(branchList); // Prepare the return data for the GetAddressList() method. var countrylist = new List <CountryList>(); countrylist.Add(new CountryList { ID = 1, Country_Name = "India" }); mockBranchRepository.Setup(m => m.GetAddresscountryList()).Returns(countrylist); var statelist = new List <StateList>(); statelist.Add(new StateList { ID = 1, State_Name = "Tamil Nadu" }); mockBranchRepository.Setup(m => m.GetAddressstateList()).Returns(statelist); var citylist = new List <CityList>(); citylist.Add(new CityList { ID = 1, City_Name = "Madurai" }); mockBranchRepository.Setup(m => m.GetAddresscityList()).Returns(citylist); branchController = new BranchController(mockBranchRepository.Object); #endregion // Now invoke the Index action. var actionResult = branchController.Index() as ViewResult; // Validate the expected result. ViewResult expectedResult = new ViewResult(); Assert.IsNotNull("Error", actionResult.ViewName); }
public void Index_Action_method_Should_Return_ListOfBranches() { // Arrange ---intializing the classes needed, and Setup up Mock var mockbranchservice = new Mock <ILibraryBranch>(); var mockbranch = new Mock <IWebHostEnvironment>(); mockbranchservice.Setup(x => x.GetAll()).Returns(GetAllBranches()); var controller = new BranchController(mockbranchservice.Object, mockbranch.Object); //Act --- Calling on the method to be tested var result = controller.Index(); //Assert --- i.e we need to start testing d outcome var viewresult = result.Should().BeOfType <ViewResult>(); var viewmodel = viewresult.Subject.ViewData.Model.Should().BeAssignableTo <branchIndexModel>(); viewmodel.Subject.Branches.Count().Should().Be(3); }
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 <ViewBranches> branchList = new List <ViewBranches>(); branchList.Add(new ViewBranches { Branch_Id = 4, Branch_Name = "kakathopu", Address1 = "no:201,bagavath singh street", Country_Name = "India", State_Name = "Tamil Nadu", City_Name = "Madurai" }); // Mock up the GetAllQuotation() repository method with expected return values. mockBranchRepository.Setup(m => m.GetAllUserBranch()).Returns(branchList); //mockCountryRespository.Setup(m => m.GetAddresscountryList()).Returns(branchList); // Prepare the return data for the GetAddressList() method. var countrylist = new List <CountryList>(); countrylist.Add(new CountryList { ID = 1, Country_Name = "India" }); mockBranchRepository.Setup(m => m.GetAddresscountryList()).Returns(countrylist); //var branchList1 = new List<BranchList>(); //branchList1.Add(new BranchList { BranchId = 1, BranchName = "MADURAI MAIN" }); var statelist = new List <StateList>(); statelist.Add(new StateList { ID = 1, State_Name = "Tamil Nadu" }); mockBranchRepository.Setup(m => m.GetAddressstateList()).Returns(statelist); var citylist = new List <CityList>(); citylist.Add(new CityList { ID = 1, City_Name = "Madurai" }); mockBranchRepository.Setup(m => m.GetAddresscityList()).Returns(citylist); //var country=new List<coun> // Mock up the GetAddressList() repository method with expected return value. //mockBranchRepository.Setup(m => m.GetAddressList()).Returns(branchList); #endregion // Now invoke the Index action. var actionResult = branchController.Index() as ViewResult; // Validate the expected result. ViewResult expectedResult = new ViewResult(); Assert.IsNotNull(actionResult); }