Пример #1
0
        public async Task AddMovie_AllPropertiesAreMissing_SavesDataCorrectly()
        {
            // Arrange

            // Using fake URL to prevent requests to Kinopoisk if stub is misconfigured.
            var movieUri = new Uri("https://www.kinopoisk-test.ru/film/111543/");

            var movieInfo = new MovieInfoModel
            {
                Title    = "Темный рыцарь",
                MovieUri = movieUri,
            };

            var serviceProvider = await BootstrapTests(seedData : true, StubClock(new DateTimeOffset(2020, 04, 26, 12, 55, 35, TimeSpan.FromHours(3))));

            var target = serviceProvider.GetRequiredService <IMoviesToSeeService>();

            // Act

            var newMovieId = await target.AddMovie(movieInfo, CancellationToken.None);

            // Assert

            var expectedMovie = new MovieToSeeModel
            {
                Id = newMovieId,
                TimestampOfAddingToSeeList = new DateTimeOffset(2020, 04, 26, 12, 55, 35, TimeSpan.FromHours(3)),
                MovieInfo = movieInfo,
            };

            var storedMovie = target.GetAllMovies().SingleOrDefault(m => m.MovieInfo.MovieUri == movieUri);

            storedMovie.Should().BeEquivalentTo(expectedMovie);
        }
        public MovieToSeeViewModel(MovieToSeeModel movie)
        {
            _ = movie ?? throw new ArgumentNullException(nameof(movie));

            Id = movie.Id;
            TimestampOfAddingToSeeList = movie.TimestampOfAddingToSeeList;
            MovieInfo = new MovieInfoViewModel(movie.MovieInfo);
        }
Пример #3
0
        private static MovieId GetMovieId(IServiceProvider serviceProvider, MovieToSeeModel movie)
        {
            var target = serviceProvider.GetRequiredService <IMoviesToSeeService>();

            return(target
                   .GetAllMovies()
                   .Single(m => m.MovieInfo.MovieUri == movie.MovieInfo.MovieUri).Id);
        }
Пример #4
0
        public async Task <MovieId> AddMovie(MovieInfoModel movieInfo, CancellationToken cancellationToken)
        {
            logger.LogInformation("Adding movie to see '{SourceMovieUri}' ...", movieInfo.MovieUri);

            var movieToSee = new MovieToSeeModel
            {
                TimestampOfAddingToSeeList = clock.Now,
                MovieInfo = movieInfo,
            };

            return(await repository.AddMovie(movieToSee, cancellationToken));
        }
        public async Task <MovieId> AddMovie(MovieToSeeModel movie, CancellationToken cancellationToken)
        {
            var document = movie.ToDocument();

            document.Id = idGenerator.GenerateId();

            var insertOptions = new InsertOneOptions
            {
                BypassDocumentValidation = false,
            };

            await collection.InsertOneAsync(document, insertOptions, cancellationToken);

            return(document.Id.ToMovieId());
        }
        public async Task MoveToMoviesToSee(MovieId movieId, CancellationToken cancellationToken)
        {
            logger.LogInformation("Moving movie {MovieId} to movies to see ...", movieId);

            var movieToGet = await moviesToGetRepository.GetMovie(movieId, cancellationToken);

            var movieToSee = new MovieToSeeModel
            {
                TimestampOfAddingToSeeList = clock.Now,
                MovieInfo = movieToGet.MovieInfo,
            };

            await moviesToSeeRepository.AddMovie(movieToSee, cancellationToken);

            await moviesToGetRepository.DeleteMovie(movieId, cancellationToken);
        }
Пример #7
0
        public async Task AddMovie_AllPropertiesAreFilled_SavesDataCorrectly()
        {
            // Arrange

            // Using fake URL to prevent requests to Kinopoisk if stub is misconfigured.
            var movieUri = new Uri("https://www.kinopoisk-test.ru/film/111543/");

            var movieInfo = new MovieInfoModel
            {
                Title             = "Темный рыцарь",
                Year              = 2008,
                MovieUri          = movieUri,
                PosterUri         = new Uri("https://st.kp.yandex.net/images/film_iphone/iphone360_111543.jpg"),
                Directors         = new[] { "Кристофер Нолан" },
                Cast              = new[] { "Кристиан Бэйл", "Хит Леджер", "Аарон Экхарт", "Мэгги Джилленхол", "Гари Олдман", },
                Rating            = new MovieRatingModel(8.499M, 463508),
                Duration          = TimeSpan.FromMinutes(152),
                Genres            = new[] { "фантастика", "боевик", "триллер", "криминал", "драма", },
                Countries         = new[] { "США", "Великобритания", },
                SummaryParagraphs = new[] { "Бэтмен поднимает ставки в войне с криминалом..." },
            };

            var serviceProvider = await BootstrapTests(seedData : true, StubClock(new DateTimeOffset(2020, 04, 26, 12, 55, 35, TimeSpan.FromHours(3))));

            var target = serviceProvider.GetRequiredService <IMoviesToSeeService>();

            // Act

            var newMovieId = await target.AddMovie(movieInfo, CancellationToken.None);

            // Assert

            var expectedMovie = new MovieToSeeModel
            {
                Id = newMovieId,
                TimestampOfAddingToSeeList = new DateTimeOffset(2020, 04, 26, 12, 55, 35, TimeSpan.FromHours(3)),
                MovieInfo = movieInfo,
            };

            var storedMovie = target.GetAllMovies().SingleOrDefault(m => m.MovieInfo.MovieUri == movieUri);

            storedMovie.Should().BeEquivalentTo(expectedMovie);
        }
 public static MovieToSeeDocument ToDocument(this MovieToSeeModel model)
 {
     return(new MovieToSeeDocument
     {
         Id = model.Id != null ? new ObjectId(model.Id.Value) : default,