public async void 年度一覧の表示() { // Arrange var mockUseCase = new Mock <ISeasonUseCase>(); var seasons = new List <Season> { new Season( "2020年度", new DateTime(2020, 4, 1), new DateTime(2021, 3, 31), new DateTime(2020, 3, 31), new TeamRegistrationFee(5000), new PlayerRegistrationFee(500), new PlayerTradeFee(200) ), new Season( "2021年度", new DateTime(2021, 4, 1), new DateTime(2022, 3, 31), new DateTime(2021, 3, 31), new TeamRegistrationFee(5000), new PlayerRegistrationFee(500), new PlayerTradeFee(200) ), new Season( "2022年度", new DateTime(2022, 4, 1), new DateTime(2023, 3, 31), new DateTime(2022, 3, 31), new TeamRegistrationFee(5000), new PlayerRegistrationFee(500), new PlayerTradeFee(200) ), new Season( "2023年度", new DateTime(2023, 4, 1), new DateTime(2024, 3, 31), new DateTime(2023, 3, 31), new TeamRegistrationFee(5000), new PlayerRegistrationFee(500), new PlayerTradeFee(200) ) }; mockUseCase.Setup(m => m.GetSeasons()) .ReturnsAsync(seasons) .Verifiable(); var controller = new SeasonsController(mockUseCase.Object); // Act var result = await controller.Index(); // Assert mockUseCase.Verify(); var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <IndexViewModel>(viewResult.ViewData.Model); Assert.Equal(4, model.Seasons.Count); }
public async Task Index_ShouldReturnSeasonsIndexView() { // Arrange var seasonsIndexViewModel = A.Fake <ISeasonsIndexViewModel>(); var seasonsDetailsViewModel = A.Fake <ISeasonsDetailsViewModel>(); var seasonRepository = A.Fake <ISeasonRepository>(); var seasons = new List <Season>(); A.CallTo(() => seasonRepository.GetSeasonsAsync()).Returns(seasons); var sharedRepository = A.Fake <ISharedRepository>(); var testController = new SeasonsController(seasonsIndexViewModel, seasonsDetailsViewModel, seasonRepository, sharedRepository); // Act var result = await testController.Index(); // Assert A.CallTo(() => seasonRepository.GetSeasonsAsync()).MustHaveHappenedOnceExactly(); seasonsIndexViewModel.Seasons.ShouldBe(seasons); result.ShouldBeOfType <ViewResult>(); ((ViewResult)result).Model.ShouldBe(seasonsIndexViewModel); }