public void Post_Add_WithNonExistingEndStationShouldRedirectToAllRoutes() { //Arrange var controller = new RoutesController(null, null, this.fixture.UserManagerMockInstance.Object, this.companyService.Object, this.stationService.Object); this.companyService.Setup(c => c.IsApproved(It.IsAny <string>())) .Returns(true); this.companyService.Setup(c => c.IsBlocked(It.IsAny <string>())) .Returns(false); this.stationService.Setup(s => s.StationExist(It.IsAny <int>())) .Returns(false); this.PrepareTempData(); controller.TempData = this.tempData.Object; //Act var result = controller.Add(this.GetRouteFormModel()); //Assert this.AssertRedirectToCompanyRoutes(result); this.customMessage.Should().Be(WebConstants.Message.InvalidStation); }
public void Get_Add_WithValidDataShouldReturnAddRoutesFormView() { //Arrange var controller = new RoutesController(null, this.townService.Object, this.fixture.UserManagerMockInstance.Object, this.companyService.Object, null); this.companyService.Setup(c => c.IsApproved(It.IsAny <string>())) .Returns(true); this.companyService.Setup(c => c.IsBlocked(It.IsAny <string>())) .Returns(false); this.townService.Setup(t => t.GetTownsWithStations()) .Returns(this.GetTownsStations()); //Act var result = controller.Add(); //Assert result.Should().BeOfType <ViewResult>(); var model = result.As <ViewResult>().Model; model.Should().BeOfType <RouteFormModel>(); var form = model.As <RouteFormModel>(); form.TownsStations.Should().HaveCount(TownsCount); }
public void TestGetAdd() { // Arrange var controller = new RoutesController(new RouteLogic(new RouteRepositoryStub()), new StationLogic(new StationRepositoryStub())); // ACt var result = (ViewResult)controller.Add(); // Assert Assert.AreEqual("", result.ViewName); }
public void TestPostAddValidationError() { // Arrange var controller = new RoutesController(new RouteLogic(new RouteRepositoryStub()), new StationLogic(new StationRepositoryStub())); controller.ViewData.ModelState.AddModelError("RouteName", "Route name should be provided!"); var NewRoute = new Route(); // ACt var result = (ViewResult)controller.Add(NewRoute); // Assert Assert.AreEqual("", result.ViewName); }
public void TestPostAddDBError() { // Arrange var controller = new RoutesController(new RouteLogic(new RouteRepositoryStub()), new StationLogic(new StationRepositoryStub())); var NewRoute = new Route { RouteID = 0, RouteName = null }; // ACt var result = (ViewResult)controller.Add(NewRoute); // Assert Assert.AreEqual("", result.ViewName); }
public void TestPostAdd() { // Arrange var controller = new RoutesController(new RouteLogic(new RouteRepositoryStub()), new StationLogic(new StationRepositoryStub())); var NewRoute = new Route { RouteID = 4, RouteName = "R4" }; // ACt var result = (RedirectToRouteResult)controller.Add(NewRoute); // Assert Assert.AreEqual("", result.RouteName); Assert.AreEqual("Index", result.RouteValues.Values.First()); }
public void Post_Add_WithNotApprovedCompanyShouldRedirectToAllRoutes() { //Arrange var controller = new RoutesController(null, null, this.fixture.UserManagerMockInstance.Object, this.companyService.Object, null); this.companyService.Setup(c => c.IsApproved(It.IsAny <string>())) .Returns(false); this.PrepareTempData(); controller.TempData = this.tempData.Object; //Act var result = controller.Add(); //Assert this.AssertRedirectToCompanyRoutes(result); this.customMessage.Should().Be(WebConstants.Message.CompanyNotApproved); }
public void Post_Add_WithInvalidModelStateDuplicatedRouteShouldReturnRouteAddFormView() { //Arrange var controller = new RoutesController(this.routeService.Object, this.townService.Object, this.fixture.UserManagerMockInstance.Object, this.companyService.Object, this.stationService.Object); this.companyService.Setup(c => c.IsApproved(It.IsAny <string>())) .Returns(true); this.companyService.Setup(c => c.IsBlocked(It.IsAny <string>())) .Returns(false); this.stationService.Setup(s => s.StationExist(It.IsAny <int>())) .Returns(true); this.routeService.Setup(r => r.Add(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <TimeSpan>(), It.IsAny <TimeSpan>(), It.IsAny <BusType>(), It.IsAny <decimal>(), It.IsAny <string>())) .Returns(false); this.townService.Setup(t => t.GetTownsWithStations()) .Returns(this.GetTownsStations()); this.PrepareTempData(); controller.TempData = this.tempData.Object; controller.ModelState.AddModelError(string.Empty, "Error"); //Act var result = controller.Add(this.GetRouteFormModel()); //Assert result.Should().BeOfType <ViewResult>(); result.As <ViewResult>().ViewData.ModelState.Root.Errors.Should().HaveCount(1); result.As <ViewResult>().ViewData.ModelState.Root.Errors.Any(e => e.ErrorMessage == WebConstants.Message.CompanyRouteDuplication); var viewResult = result.As <ViewResult>().Model; viewResult.Should().BeOfType <RouteFormModel>(); var form = viewResult.As <RouteFormModel>(); this.AssertRouteFormModelProperties(StartStation, EndStation, form, viewResult); form.IsEdit.Should().BeFalse(); }
public void Post_Add_WithEqualStartAndEndStationsShouldReturnRouteAddFormView() { const int WrongStartStation = 15; //Arrange var form = this.GetRouteFormModel(); form.StartStation = WrongStartStation; form.EndStation = WrongStartStation; var controller = new RoutesController(null, this.townService.Object, this.fixture.UserManagerMockInstance.Object, this.companyService.Object, this.stationService.Object); this.companyService.Setup(c => c.IsApproved(It.IsAny <string>())) .Returns(true); this.companyService.Setup(c => c.IsBlocked(It.IsAny <string>())) .Returns(false); this.stationService.Setup(s => s.StationExist(It.IsAny <int>())) .Returns(true); this.townService.Setup(t => t.GetTownsWithStations()) .Returns(this.GetTownsStations()); this.PrepareTempData(); controller.TempData = this.tempData.Object; //Act var result = controller.Add(form); //Assert result.Should().BeOfType <ViewResult>(); result.As <ViewResult>().ViewData.ModelState.Root.Errors.Should().HaveCount(1); result.As <ViewResult>().ViewData.ModelState.Root.Errors.Any(e => e.ErrorMessage == WebConstants.Message.StartStationEqualToEndStation); var viewResult = result.As <ViewResult>().Model; this.AssertRouteFormModelProperties(WrongStartStation, WrongStartStation, form, viewResult); }
public void Post_Add_WithValidDataShouldRedirectToAllRoutes() { //Arrange var controller = new RoutesController(this.routeService.Object, this.townService.Object, this.fixture.UserManagerMockInstance.Object, this.companyService.Object, this.stationService.Object); this.companyService.Setup(c => c.IsApproved(It.IsAny <string>())) .Returns(true); this.companyService.Setup(c => c.IsBlocked(It.IsAny <string>())) .Returns(false); this.stationService.Setup(s => s.StationExist(It.IsAny <int>())) .Returns(true); this.routeService.Setup(r => r.Add(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <TimeSpan>(), It.IsAny <TimeSpan>(), It.IsAny <BusType>(), It.IsAny <decimal>(), It.IsAny <string>())) .Returns(true); this.townService.Setup(t => t.GetTownsWithStations()) .Returns(this.GetTownsStations()); this.townService.Setup(t => t.GetTownNameByStationId(It.IsAny <int>())) .Returns(StartTownName); this.townService.SetupSequence(t => t.GetTownNameByStationId(It.IsAny <int>())) .Returns(StartTownName) .Returns(EndTownName); this.PrepareTempData(); controller.TempData = this.tempData.Object; //Act var result = controller.Add(this.GetRouteFormModel()); //Assert this.AssertRedirectToCompanyRoutes(result); this.customMessage.Should().Be(string.Format(WebConstants.Message.RouteAdded, StartTownName, EndTownName)); }