Ejemplo n.º 1
0
        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,
            });
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        public Task CreateTheater(Theater theater)
        {
            if (theater == null)
            {
                throw new ArgumentNullException(nameof(theater));
            }

            TheaterDocument document = Translate(theater);

            return(_client.CreateDocumentAsync(_collection.Uri.Value, document));
        }
Ejemplo n.º 4
0
 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,
            });
 }