コード例 #1
0
        public void TownStations_WithExistingTownAndNoStationsShouldReturnCountZero()
        {
            //Arrange
            var controller = new AdminTownsController(this.townService.Object);

            this.townService.Setup(t => t.TownExists(It.IsAny <int>()))
            .Returns(true);

            this.townService.Setup(t => t.TownStations(It.IsAny <int>()))
            .Returns(new List <AdminTownStationsServiceModel>());

            //Act
            var result = controller.TownStations(TownId);

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

            model.As <IEnumerable <AdminTownStationsServiceModel> >().Should().HaveCount(0);
        }
コード例 #2
0
        public void TownStations_ShouldRedirectToAllTownsForNonExistingTown()
        {
            //Arrange
            var controller = new AdminTownsController(this.townService.Object);

            this.townService.Setup(t => t.TownExists(It.IsAny <int>()))
            .Returns(false);

            this.PrepareTempData();

            controller.TempData = this.tempData.Object;

            //Act
            var result = controller.TownStations(TownId);

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

            model.ActionName.Should().Be(WebConstants.Action.AdminAllTowns);
            this.customMessage.Should().Be(string.Format(WebConstants.Message.NonExistingEntity, nameof(WebConstants.Entity.Town), TownId));
        }