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)); }
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, }); }
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);