public async Task FindTheater_restores_read_model_entity_correctly( Theater theater) { // Arrange theater.ETag = default; IDocumentClient client = DocumentClient; var sut = new CosmosDbTheaterRepository(client, Collection); await sut.CreateTheater(theater); // Act Theater actual = await sut.FindTheater(theater.Id); // Assert IQueryable <TheaterDocument> query = from d in client.CreateDocumentQuery <TheaterDocument>() where d.Discriminator == nameof(TheaterDocument) && d.Id == theater.Id select d; TheaterDocument document = await query.SingleOrDefault(); actual.Should().BeEquivalentTo(new { document.Id, document.ETag, document.Name, document.SeatRowCount, document.SeatColumnCount, document.CreatedAt, }); }
private async Task <Theater> FindTheaterImpl(Guid theaterId) { TheaterDocument document = await _client .CreateDocumentQuery <TheaterDocument>(_collection.Uri.Value) .Where(d => d.Id == theaterId) .AsDocumentQuery() .SingleOrDefault(); return(Translate(document)); }
public Task CreateTheater(Theater theater) { if (theater == null) { throw new ArgumentNullException(nameof(theater)); } TheaterDocument document = Translate(theater); return(_client.CreateDocumentAsync(_collection.Uri.Value, document)); }
private static Theater Translate(TheaterDocument document) { return(document == null ? default : new Theater { Id = document.Id, ETag = document.ETag, Name = document.Name, SeatRowCount = document.SeatRowCount, SeatColumnCount = document.SeatColumnCount, CreatedAt = document.CreatedAt, }); }