예제 #1
0
        public void DetailsViewNullValue()
        {
            //Act
            RedirectToRouteResult result = songController.Details(null) as RedirectToRouteResult;
            var resArray = result.RouteValues.ToArray();

            //Assert
            Assert.AreEqual("Error", resArray[0].Value);
        }
        public async Task SongController_GetDetails_ShouldReturnBadRequestWhenSongDoesNotExist()
        {
            //Arrenge
            var adminSongService = this.GetAdminSongServiceBaseMock();

            adminSongService
            .Setup(s => s.DetailsAsync(It.IsAny <int>()))
            .ReturnsAsync((AdminSongDetailsServiceModel)null);

            var controller = new SongsController(null, adminSongService.Object);
            //Act
            var result = await controller.Details(10);

            //Assert
            result.Should().BeOfType <BadRequestResult>();
        }
        public async Task SongController_GetDetails_ShouldReturnViewWithViewModel()
        {
            //Arrenge
            const int     SongId       = 10;
            const string  SongName     = "TestSong";
            const double  SongDuration = 2;
            const decimal SongPrice    = 5;
            const string  SongArtist   = "TestArtist";


            var adminSongService = this.GetAdminSongServiceBaseMock();

            adminSongService
            .Setup(s => s.DetailsAsync(It.IsAny <int>()))
            .ReturnsAsync(new AdminSongDetailsServiceModel
            {
                Id       = SongId,
                Name     = SongName,
                Duration = SongDuration,
                Price    = SongPrice,
                Artist   = SongArtist,
                Ganre    = Ganre.Blues
            });

            var controller = new SongsController(null, adminSongService.Object);
            //Act
            var result = await controller.Details(SongId);

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

            model.Should().BeOfType <AdminSongDetailsServiceModel>();

            var formModel = model.As <AdminSongDetailsServiceModel>();

            formModel.Id.Should().Be(SongId);
            formModel.Name.Should().Be(SongName);
            formModel.Duration.Should().Be(SongDuration);
            formModel.Price.Should().Be(SongPrice);
            formModel.Artist.Should().Be(SongArtist);
            formModel.Ganre.Should().Be(Ganre.Blues);
        }