public void ShouldReturnNoContentWhenSuccessfulUpdate()
        {
            var request = new TvEpisodeRequest()
            {
                VideoId     = "tt1234",
                TvEpisodeId = "tt1233"
            };

            _service.Setup(s => s.UpsertTvEpisode(request))
            .Returns(new TvEpisodeViewModel
            {
                Series = new SeriesViewModel
                {
                    VideoId   = "tt1234",
                    IsUpdated = true
                },
                Episode = new TvEpisode
                {
                    VideoId   = "tt1234",
                    IsUpdated = true
                }.Yield()
            });

            var result = _controller.UpsertTvEpisode(request) as NoContentResult;

            result.Should().NotBeNull();
        }
        public void ShouldReturnCreatedWhenSuccessfulCreation()
        {
            var request = new TvEpisodeRequest()
            {
                VideoId     = "tt1234",
                TvEpisodeId = "tt1233"
            };

            _service.Setup(s => s.UpsertTvEpisode(request))
            .Returns(new TvEpisodeViewModel
            {
                Series = new SeriesViewModel
                {
                    VideoId = "tt1234"
                },
                Episode = new TvEpisode
                {
                    VideoId = "tt1233"
                }.Yield()
            });

            var result = _controller.UpsertTvEpisode(request) as CreatedResult;

            result.Should().NotBe(null);
            result.Location.Should().Be("/videos/tvEpisodes/tt1233");
            (result.Value as TvEpisodeViewModel).Series.VideoId.Should().Be("tt1234");
            (result.Value as TvEpisodeViewModel).Episode.Single().VideoId.Should().Be("tt1233");
        }
Esempio n. 3
0
        UpsertTvEpisode(TvEpisodeRequest tvEpisode)
        {
            using var sqlConnection = new SqlConnection(_configuration.CreateConnectionString());
            var command = tvEpisode.CreateTvEpisodeCommand(sqlConnection);

            return(ReadFromDatabase(command));
        }
Esempio n. 4
0
        public IActionResult UpsertTvEpisode([FromBody] TvEpisodeRequest request)
        {
            var result = _service.UpsertTvEpisode(request);

            return(result.Episode.All(a => a.IsUpdated)
                ? NoContent() as IActionResult
                : Created($"/videos/tvEpisodes/{request.TvEpisodeId}", result) as IActionResult);
        }
Esempio n. 5
0
        public static void AddRequestItem(TvEpisodeRequest request, IConfiguration configuration)
        {
            var connection = configuration.CreateConnectionString();

            using var sqlConnection = new SqlConnection(connection);
            var command = request.CreateTvEpisodeCommand(sqlConnection);

            command.Connection.Open();
            command.ExecuteNonQuery();
            command.Connection.Close();
        }
Esempio n. 6
0
        public TvEpisodeViewModel UpsertTvEpisode(TvEpisodeRequest tvEpisode)
        {
            var(tvShow, tvEpisodeResponse) = _tvEpisodeRepository.UpsertTvEpisode(tvEpisode);

            return(new TvEpisodeViewModel
            {
                Episode = tvEpisodeResponse.GroupBy(
                    key => key.tv_episode_id,
                    (episodeId, tvEpisodes) => _mapper.Map <TvEpisode>(
                        tvEpisodes.Where(w => w.tv_episode_id == episodeId))),
                Series = _mapper.Map <SeriesViewModel>(tvShow)
            });
        }
Esempio n. 7
0
        public static SqlCommand CreateTvEpisodeCommand(
            this TvEpisodeRequest tvEpisode,
            SqlConnection sqlConnection)
        {
            var command = new SqlCommand("[video].[usp_add_tv_episode]", sqlConnection)
            {
                CommandType = CommandType.StoredProcedure
            };

            using var genres = CreateSqlParameter.CreateDataTable(tvEpisode.Genres);
            using var stars  = CreateSqlParameter.CreateDataTable(
                      tvEpisode.Actors
                      .Concat(tvEpisode.Producers)
                      .Concat(tvEpisode.Directors)
                      .Concat(tvEpisode.Writers));
            using var ratings = CreateSqlParameter.CreateDataTable(tvEpisode.Ratings);
            command.Parameters.Add(CreateSqlParameter.CreateParameter("@series_imdb_id", tvEpisode.VideoId));
            command.Parameters.Add(CreateSqlParameter.CreateParameter("@series_title", tvEpisode.Title));
            command.Parameters.Add(CreateSqlParameter.CreateParameter("@mpaa_rating", tvEpisode.MpaaRating));
            command.Parameters.Add(CreateSqlParameter.CreateParameter("@series_plot", tvEpisode.Plot));
            command.Parameters.Add(CreateSqlParameter.CreateParameter("@series_release_date", tvEpisode.ReleaseDate));
            command.Parameters.Add(CreateSqlParameter.CreateParameter("@episode_imdb_id", tvEpisode.TvEpisodeId));
            command.Parameters.Add(CreateSqlParameter.CreateParameter("@runtime",
                                                                      tvEpisode.Runtime.HasValue
                ? tvEpisode.Runtime.Value.ToString()
                : "null"));
            command.Parameters.Add(CreateSqlParameter.CreateParameter("@episode_release_date", tvEpisode.EpisodeReleaseDate));
            command.Parameters.Add(CreateSqlParameter.CreateParameter("@season_number", tvEpisode.SeasonNumber));
            command.Parameters.Add(CreateSqlParameter.CreateParameter("@episode_number", tvEpisode.EpisodeNumber));
            command.Parameters.Add(CreateSqlParameter.CreateParameter("@episode_name", tvEpisode.EpisodeName));
            command.Parameters.Add(CreateSqlParameter.CreateParameter("@plot", tvEpisode.EpisodePlot));
            command.Parameters.Add(CreateSqlParameter.CreateParameter("@resolution", tvEpisode.Resolution));
            command.Parameters.Add(CreateSqlParameter.CreateParameter("@codec", tvEpisode.Codec));
            command.Parameters.Add(CreateSqlParameter.CreateParameter("@extended", tvEpisode.Extended));
            CreateSqlParameter.AddTableParameter("@genres", genres, command);
            CreateSqlParameter.AddTableParameter("@persons", stars, command);
            CreateSqlParameter.AddTableParameter("@ratings", ratings, command);

            return(command);
        }