public void GivenAUserThatWantsToSeeWhatMoviesAlreadyExist(string typeOfContent) { object request; var config = _container.Resolve <IConfiguration>(); switch (typeOfContent.ToUpperInvariant()) { case "MOVIE": foreach (var videoId in Enumerable.Range(1000000, 10)) { request = RequestGenerator.GetMovieRequest(videoId); Database.AddRequestItem(request as MovieRequest, config); } break; case "SHOW": case "TV EPISODE": foreach (var tvId in Enumerable.Range(10000000, 10)) { request = RequestGenerator.GetTvEpisodeRequest(1000000, tvId); Database.AddRequestItem(request as TvEpisodeRequest, config); } break; default: throw new Exception($"{typeOfContent} is not currently supported."); } ; }
public void ShouldRetrieveAllEpisodesInDatastore() { foreach (var id in Enumerable.Range(1, 10)) { var request = RequestGenerator.GetTvEpisodeRequest(100, id); Database.AddRequestItem(request, _config); } var repository = _fixture.Create <TvEpisodeRepository>(); var(tvShows, tvEpisodes) = repository.GetTvEpisodes(); tvEpisodes .Select(s => s.imdb_id) .Distinct() .Should() .HaveCount(10) .And .BeEquivalentTo(new[] { "tt1", "tt2", "tt3", "tt4", "tt5", "tt6", "tt7", "tt8", "tt9", "tt10" }); tvShows .Select(s => s.imdb_id) .Distinct() .Should() .HaveCount(1) .And .BeEquivalentTo(new[] { "tt100" }); }
public void GivenAVideoAlreadyExistsInTheRecord(string typeOfContent) { object request; switch (typeOfContent.ToUpperInvariant()) { case "MOVIE": request = RequestGenerator.GetMovieRequest(); (request as MovieRequest).Plot = "Original Plot"; Database.AddRequestItem(request as MovieRequest, _container.Resolve <IConfiguration>()); (request as MovieRequest).Plot = "New Plot"; break; case "TV EPISODE": request = RequestGenerator.GetTvEpisodeRequest(); (request as TvEpisodeRequest).EpisodePlot = "Original Plot"; Database.AddRequestItem(request as TvEpisodeRequest, _container.Resolve <IConfiguration>()); (request as TvEpisodeRequest).EpisodePlot = "New Plot"; break; default: throw new Exception($"{typeOfContent} is not currently supported."); } ; _container.RegisterInstanceAs(request, name: "RequestBody"); }
public void ShouldMapTvEpisodeDataModelToViewModel() { _tvRepo.Setup(s => s.UpsertTvEpisode(It.IsAny <TvEpisodeRequest>())) .Returns((CreateSeriesDataModel("tt2222"), CreateEpisodeModel("tt1234"))); var service = _fixture.Create <VideoService>(); var result = service.UpsertTvEpisode(RequestGenerator.GetTvEpisodeRequest()); result.Episode.Should().BeEquivalentTo(new TvEpisode { VideoId = "tt1234", EpisodeName = "title", MpaaRating = "R", Plot = "plot", ReleaseDate = DateTime.MaxValue, Runtime = 120.33M, EpisodeNumber = 1, SeasonNumber = 1 }); result.Series.Should().BeEquivalentTo(new SeriesViewModel { SeriesId = 1, VideoId = "tt2222", Title = "title", Plot = "plot", ReleaseDate = DateTime.MaxValue }); }
public void GivenANewVideo(string typeOfContent) { var request = typeOfContent.ToUpperInvariant() switch { "MOVIE" => RequestGenerator.GetMovieRequest(), "TV EPISODE" => RequestGenerator.GetTvEpisodeRequest(), _ => throw new Exception($"{typeOfContent} is not currently supported.") }; _container.RegisterInstanceAs <object>(request, name: "RequestBody"); }
public void ShouldThrowBadRequestExceptionIfStoredProcedureThrowsValidationError(string property) { var repository = _fixture.Create <TvEpisodeRepository>(); var request = RequestGenerator.GetTvEpisodeRequest(); request.GetType() .GetProperty(property) .SetValue(request, null); Action exception = () => repository.UpsertTvEpisode(request); exception.Should() .Throw <EvoBadRequestException>() .WithMessage($"{property} can not be null."); }
public void ShouldThrowExceptionWhenRequestIsInvalid() { var repository = _fixture.Create <TvEpisodeRepository>(); var request = RequestGenerator.GetTvEpisodeRequest(); request.Actors .First() .Modify(gr => gr.FirstName, null); Action exception = () => repository.UpsertTvEpisode(request); exception.Should() .Throw <EvoException>() .WithMessage(@"Cannot insert the value NULL into column 'first_name', table '@persons'; column does not allow nulls. INSERT fails. The data for table-valued parameter ""@persons"" doesn't conform to the table type of the parameter. SQL Server error is: 515, state: 2 The statement has been terminated."); }
public void ShouldInsertTvEpisodeAndSeries() { var repository = _fixture.Create <TvEpisodeRepository>(); var request = RequestGenerator.GetTvEpisodeRequest(134132, 134133); var(tvShow, tvEpisodes) = repository.UpsertTvEpisode(request); tvShow.Count().Should().Be(1); tvShow.All(a => a.imdb_id == "tt134132").Should().BeTrue(); tvEpisodes.Count().Should().Be(1); tvEpisodes.All(a => a.imdb_id == "tt134133").Should().BeTrue(); var command = @"SELECT COUNT(*) FROM video.vw_tv_series WHERE imdb_id = 'tt134132'"; using var sqlConnection = new SqlConnection(_config.CreateConnectionString()); using var sqlCommand = new SqlCommand(command, sqlConnection); sqlCommand.Connection.Open(); var reader = sqlCommand.ExecuteReader(); reader.Read(); var rowCount = reader.GetInt32(0); sqlCommand.Connection.Close(); rowCount.Should().Be(1); command = @"SELECT COUNT(*) FROM video.vw_tv_episodes WHERE imdb_id = 'tt134133'"; sqlCommand.CommandText = command; sqlCommand.Connection.Open(); reader = sqlCommand.ExecuteReader(); reader.Read(); rowCount = reader.GetInt32(0); sqlCommand.Connection.Close(); rowCount.Should().Be(1); }
public void ShouldReturnAllTvSeriesInDatastore() { foreach (var id in Enumerable.Range(1, 10)) { var request = RequestGenerator.GetTvEpisodeRequest(100 + id, id); Database.AddRequestItem(request, _config); } var repository = _fixture.Create <TvEpisodeRepository>(); var tvSeries = repository.GetTvShows(); tvSeries .Select(s => s.imdb_id) .Distinct() .Should() .BeEquivalentTo(new[] { "tt101", "tt102", "tt103", "tt104", "tt105", "tt106", "tt107", "tt108", "tt109", "tt110" }); }
public void ShouldReturnSpecificTvSeriesInDatastore() { foreach (var id in Enumerable.Range(1, 10)) { var request = RequestGenerator.GetTvEpisodeRequest(100 + id, id); Database.AddRequestItem(request, _config); } var repository = _fixture.Create <TvEpisodeRepository>(); var tvSeries = repository.GetTvShows("tt101"); tvSeries .Select(s => s.imdb_id) .Distinct() .Single() .Should() .Be("tt101"); }
public void GivenAUserThatWantsToSeeAMovieThatAlreadyExists(string typeOfContent) { var config = _container.Resolve <IConfiguration>(); switch (typeOfContent.ToUpperInvariant()) { case "MOVIE": foreach (var videoId in Enumerable.Range(1000000, 10)) { var movieRequest = RequestGenerator.GetMovieRequest(videoId); Database.AddRequestItem(movieRequest as MovieRequest, config); } _container.RegisterInstanceAs <object>("tt1000005", name: "RequestID"); break; case "SHOW": foreach (var tvId in Enumerable.Range(10000000, 10)) { var tvRequest = RequestGenerator.GetTvEpisodeRequest(1000000, tvId); Database.AddRequestItem(tvRequest as TvEpisodeRequest, config); } _container.RegisterInstanceAs <object>("tt1000000", name: "RequestID"); break; case "TV EPISODE": foreach (var tvId in Enumerable.Range(10000000, 10)) { var tvRequest = RequestGenerator.GetTvEpisodeRequest(1000000, tvId); Database.AddRequestItem(tvRequest as TvEpisodeRequest, config); } _container.RegisterInstanceAs <object>("tt10000005", name: "RequestID"); break; default: throw new Exception($"{typeOfContent} is not currently supported."); } ; }