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

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

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

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

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

            this.PrepareTempData();

            controller.TempData = this.tempData.Object;

            //Act
            var result = controller.Edit(this.GetEditStationFormModel());

            //Assert
            result.Should().BeOfType <RedirectToActionResult>();
            this.customMessage.Should().Be(string.Format(WebConstants.Message.EntityEdited, nameof(WebConstants.Entity.Station)));
        }
Ejemplo n.º 2
0
        public void Post_Edit_WithInvalidModelStateShouldReturnView()
        {
            //Arrange
            var controller = new AdminStationsController(this.townService.Object, this.stationService.Object);

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

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

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

            //Act
            var result = controller.Edit(this.GetEditStationFormModel());

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

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

            form.IsEdit.Should().BeTrue();
            form.Name.Should().Be(StationName);
            form.Phone.Should().Be(StationPhone);
            form.TownId.Should().Be(StationTownId);
        }
Ejemplo n.º 3
0
        public void Post_Edit_WhenNoChangesWereFoundShouldReturnView()
        {
            //Arrange
            var controller = new AdminStationsController(this.townService.Object, this.stationService.Object);

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

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

            this.PrepareTempData();

            controller.TempData = this.tempData.Object;

            //Act
            var result = controller.Edit(this.GetEditStationFormModel());

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

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

            form.Id.Should().Be(EditStationId);
            form.Name.Should().Be(StationName);
            form.Phone.Should().Be(StationPhone);
            form.TownId.Should().Be(StationTownId);
            form.IsEdit.Should().BeTrue();
            this.customMessage.Should().Be(WebConstants.Message.NoChangesFound);
        }
Ejemplo n.º 4
0
        public void Post_Edit_WithNonExistingStationShouldRedirectToAllTowns()
        {
            //Arrange
            var controller = new AdminStationsController(null, this.stationService.Object);

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

            this.PrepareTempData();

            controller.TempData = this.tempData.Object;

            //Act
            var result = controller.Edit(this.GetEditStationFormModel());

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

            model.Url.Should().Be(WebConstants.Routing.AdminAllTownsUrl);
            this.customMessage.Should().Be(string.Format(WebConstants.Message.NonExistingEntity, nameof(WebConstants.Entity.Station), EditStationId));
        }
Ejemplo n.º 5
0
        public void Get_Edit_WithInvalidStationIdShouldRedirectToAllStations()
        {
            //Arrange
            AdminStationEditServiceModel station = null;
            var controller = new AdminStationsController(null, this.stationService.Object);

            this.stationService.Setup(s => s.GetStationToEdit(It.IsAny <int>()))
            .Returns(station);

            this.PrepareTempData();

            controller.TempData = this.tempData.Object;

            //Act
            var result = controller.Edit(EditStationId);

            //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.NonExistingEntity, nameof(WebConstants.Entity.Station), EditStationId));
        }
Ejemplo n.º 6
0
        public void Get_Edit_WithValidStationIdShouldReturnView()
        {
            //Arrange
            var controller = new AdminStationsController(this.townService.Object, this.stationService.Object);

            this.stationService.Setup(s => s.GetStationToEdit(It.IsAny <int>()))
            .Returns(this.GetStationToEdit());

            //Act
            var result = controller.Edit(EditStationId);

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

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

            form.Id.Should().Be(EditStationId);
            form.Name.Should().Be(StationName);
            form.Phone.Should().Be(StationPhone);
            form.TownId.Should().Be(StationTownId);
            form.IsEdit.Should().BeTrue();
        }