private async Task <Movie> FindMovieImpl(Guid movieId)
        {
            MovieDocument document = await _client
                                     .CreateDocumentQuery <MovieDocument>(_collection.Uri.Value)
                                     .Where(d => d.Id == movieId)
                                     .AsDocumentQuery()
                                     .SingleOrDefault();

            return(Translate(document));
        }
        public Task CreateMovie(Movie movie)
        {
            if (movie == null)
            {
                throw new ArgumentNullException(nameof(movie));
            }

            MovieDocument document = Translate(movie);

            return(_client.CreateDocumentAsync(_collection.Uri.Value, document));
        }
Exemplo n.º 3
0
        public async Task CreateMovie_creates_document_correctly(Movie movie)
        {
            // Arrange
            movie.ETag = default;
            IDocumentClient client = DocumentClient;
            var             sut    = new CosmosDbMovieRepository(client, Collection);

            // Act
            await sut.CreateMovie(movie);

            // Assert
            IQueryable <MovieDocument> query =
                from d in client.CreateDocumentQuery <MovieDocument>()
                where
                d.Discriminator == nameof(MovieDocument) &&
                d.Id == movie.Id
                select d;

            MovieDocument actual = await query.SingleOrDefault();

            actual.Should().BeEquivalentTo(new
            {
                movie.Id,
                movie.Title,
                Screenings = from s in movie.Screenings
                             select new
                {
                    s.Id,
                    s.TheaterId,
                    s.TheaterName,
                    s.Seats,
                    s.ScreeningTime,
                    s.DefaultFee,
                    s.ChildrenFee,
                    s.CreatedAt,
                },
                movie.CreatedAt,
            });
        }
Exemplo n.º 4
0
        public async Task given_document_found_then_FindMovie_restores_read_model_entity_correctly(
            Movie movie)
        {
            // Arrange
            var sut = new CosmosDbMovieRepository(DocumentClient, Collection);
            await sut.CreateMovie(movie);

            // Act
            Movie actual = await sut.FindMovie(movie.Id);

            // Assert
            IQueryable <MovieDocument> query =
                from d in DocumentClient.CreateDocumentQuery <MovieDocument>()
                where d.Id == movie.Id
                select d;

            MovieDocument document = await query.SingleOrDefault();

            actual.Should().BeEquivalentTo(new
            {
                document.Id,
                document.ETag,
                document.Title,
                Screenings = from s in document.Screenings
                             select new
                {
                    s.Id,
                    ETag = default(string),
                    s.TheaterId,
                    s.TheaterName,
                    s.Seats,
                    s.ScreeningTime,
                    s.DefaultFee,
                    s.ChildrenFee,
                    s.CreatedAt,
                },
                document.CreatedAt,
            });
        }
 private static Movie Translate(MovieDocument document)
 => _mapper.Map <Movie>(document);