Ejemplo n.º 1
0
        public async Task UpsertDocument_TwoNewDocumentsSameIdDifferentEtag_OnlyOneIsStored()
        {
            // Arrange
            var db      = new DocumentDb(location, key, database);
            var id      = Guid.NewGuid();
            var personA = new PersonTest()
            {
                Id       = id,
                PersonId = Guid.NewGuid(),
                Name     = "Barney Rubble",
                Age      = 87
            };
            var personB = new PersonTest()
            {
                Id       = id,
                PersonId = Guid.NewGuid(),
                Name     = "Barney Rubble",
                Age      = 87
            };
            var personAEnvelope = new DocumentBase <PersonTest> {
                VM = personA
            };
            var personBEnvelope = new DocumentBase <PersonTest> {
                VM = personB
            };

            // Act
            var taskForPersonA = db.UpsertDocument(CollectionId, id.ToString(), personAEnvelope);
            var taskForPersonB = db.UpsertDocument(CollectionId, id.ToString(), personBEnvelope);

            // Assert
            //We don't care about exception now we just waiting for tasks to finish
            await Record.ExceptionAsync(() => Task.WhenAll(taskForPersonA, taskForPersonB));

            var persons = await db.Query <PersonTest>(CollectionId, new Dictionary <string, object>()
                                                      { { "Id", personA.Id } });

            persons.Count().Should().Be(1);
        }