Esempio n. 1
0
        public void Post_Add_WithValidDataShouldRedirectToAllStations()
        {
            //Arrange
            var controller = new AdminStationsController(this.townService.Object, this.stationService.Object);

            this.stationService.Setup(s => s.Add(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>()))
            .Returns(true);

            this.townService.Setup(t => t.GetTownNameById(It.IsAny <int>()))
            .Returns(Town);

            this.PrepareTempData();

            controller.TempData = this.tempData.Object;

            //Act
            var result = controller.Add(this.GetAddStationFormModel());

            //Assert
            result.Should().BeOfType <RedirectToActionResult>();
            var model = result.As <RedirectToActionResult>();

            model.ActionName.Should().Be(WebConstants.Action.AdminAllStations);
            this.customMessage.Should().Be(string.Format(WebConstants.Message.StationCreated, StationName, Town));
        }
Esempio n. 2
0
        public void Post_Add_WithAlreadyExistingStationShouldReturnView()
        {
            //Arrange
            var controller = new AdminStationsController(this.townService.Object, this.stationService.Object);

            this.stationService.Setup(s => s.Add(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>()))
            .Returns(false);

            this.townService.Setup(t => t.GetTownNameById(It.IsAny <int>()))
            .Returns(Town);

            this.PrepareTempData();

            controller.TempData = this.tempData.Object;

            //Act
            var result = controller.Add(this.GetAddStationFormModel());

            //Assert
            result.Should().BeOfType <ViewResult>();
            var model = result.As <ViewResult>().Model;

            model.Should().BeOfType <StationFormModel>();
            var form = model.As <StationFormModel>();

            form.IsEdit.Should().Be(false);
            form.Name.Should().Be(StationName);
            form.Phone.Should().Be(StationPhone);
            form.TownId.Should().Be(StationTownId);
            this.customMessage.Should().Be(string.Format(WebConstants.Message.StationAlreadyExists, form.Name, Town));
        }
Esempio n. 3
0
        public void Get_Add_ShouldReturnView()
        {
            //Arrange
            var controller = new AdminStationsController(this.townService.Object, this.stationService.Object);

            //Act
            var result = controller.Add();

            //Assert
            result.Should().BeOfType <ViewResult>();
            var model = result.As <ViewResult>().Model;

            model.Should().BeOfType <StationFormModel>();
        }
Esempio n. 4
0
        public void Post_Add_WithInvalidModelStateShouldReturnView()
        {
            //Arrange
            var controller = new AdminStationsController(this.townService.Object, this.stationService.Object);

            controller.ModelState.AddModelError(string.Empty, "Error");

            //Act
            var result = controller.Add(this.GetAddStationFormModel());

            //Assert
            result.Should().BeOfType <ViewResult>();
            var model = result.As <ViewResult>().Model;

            model.Should().BeOfType <StationFormModel>();
            var form = model.As <StationFormModel>();

            form.IsEdit.Should().Be(false);
            form.Name.Should().Be(StationName);
            form.Phone.Should().Be(StationPhone);
            form.TownId.Should().Be(StationTownId);
        }