Exemplo n.º 1
0
        public async Task UpsertDocument_UpdateDocument_IsUpdatedCorrectly()
        {
            // Arrange
            var db         = new DocumentDb(location, key, database);
            var documentId = Guid.NewGuid().ToString();
            var person     = new PersonTest
            {
                Id       = Guid.Parse(documentId),
                PersonId = Guid.NewGuid(),
                Name     = "Barney Rubble",
                Age      = 87
            };
            var personEnvelope = new DocumentBase <PersonTest> {
                VM = person
            };
            await db.UpsertDocument(CollectionId, documentId, personEnvelope);

            personEnvelope = await db.ReadDocument <PersonTest>(CollectionId, documentId);

            personEnvelope.VM.Name = "Fred Flintstone";
            personEnvelope.VM.Age  = 88;

            await db.UpsertDocument(CollectionId, documentId, personEnvelope);

            // Assert
            var doc = await db.ReadDocument <PersonTest>(CollectionId, documentId);

            doc.VM.Age.Should().Be(88);
            doc.VM.Name.Should().Be("Fred Flintstone");
            doc.VM.PersonId.Should().Be(person.PersonId);
        }
Exemplo n.º 2
0
        public async Task ReadDocument_DocumentExists_ReturnDocumentIsCorrect()
        {
            // Arrange
            var db         = new DocumentDb(location, key, database);
            var documentId = Guid.NewGuid().ToString();
            var person     = new PersonTest
            {
                PersonId = Guid.NewGuid(),
                Name     = "Barney Rubble",
                Age      = 87
            };
            var personEnvelope = new DocumentBase <PersonTest> {
                VM = person
            };
            await db.UpsertDocument(CollectionId, documentId, personEnvelope);

            // Act
            var doc = await db.ReadDocument <PersonTest>(CollectionId, documentId);

            // Assert
            doc.VM.Age.Should().Be(person.Age);
            doc.VM.Name.Should().Be(person.Name);
            doc.VM.PersonId.Should().Be(person.PersonId);
            doc.ETag.Should().NotBe(string.Empty);
        }
Exemplo n.º 3
0
        public async Task UpsertDocument_NewDocument_IsStoredCorrectly()
        {
            // Arrange
            var db     = new DocumentDb(location, key, database);
            var id     = Guid.NewGuid();
            var person = new PersonTest()
            {
                PersonId = id,
                Name     = "Barney Rubble",
                Age      = 87
            };
            var personEnvelope = new DocumentBase <PersonTest> {
                VM = person, ETag = Guid.NewGuid().ToString()
            };

            // Act
            await db.UpsertDocument(CollectionId, id.ToString(), personEnvelope);

            // Assert
            var doc = await db.ReadDocument <PersonTest>(CollectionId, id.ToString());

            doc.VM.Age.Should().Be(87);
            doc.VM.Name.Should().Be("Barney Rubble");
            doc.VM.PersonId.Should().Be(person.PersonId);
        }
Exemplo n.º 4
0
        public async Task ReadDocument_DocumentNotExists_ReturnsNull()
        {
            // Arrange
            var db         = new DocumentDb(location, key, database);
            var documentId = Guid.NewGuid().ToString();

            // Act
            var doc = await db.ReadDocument <PersonTest>(CollectionId, documentId);

            // Assert
            doc.Should().BeNull();
        }
Exemplo n.º 5
0
        public async Task ReadDocument_DocumentIdIsNull_ThrowsException(string documentId)
        {
            // Arrange
            var db = new DocumentDb(location, key, database);

            // Act
            var ex = await Record.ExceptionAsync(() => db.ReadDocument <PersonTest>(CollectionId, documentId));

            //Assert
            ex.Should().NotBeNull();
            ex.Should().BeOfType <ArgumentNullException>();
        }
Exemplo n.º 6
0
        public async Task UpsertDocument_UpdateDocumentConncurrently_ThrowsException()

        {
            // Arrange
            var db         = new DocumentDb(location, key, database);
            var documentId = Guid.NewGuid().ToString();
            var person     = new PersonTest
            {
                PersonId = Guid.NewGuid(),
                Name     = "Barney Rubble",
                Age      = 87,
            };
            var personEnvelope = new DocumentBase <PersonTest> {
                VM = person
            };
            await db.UpsertDocument(CollectionId, documentId, personEnvelope);

            personEnvelope = await db.ReadDocument <PersonTest>(CollectionId, documentId);

            var newChange = new DocumentBase <PersonTest> {
                VM = person
            };

            newChange.VM.Name = "Change";
            newChange.ETag    = personEnvelope.ETag;

            personEnvelope.VM.Name = "Fred Flintstone";
            personEnvelope.VM.Age  = 88;

            await db.UpsertDocument(CollectionId, documentId, personEnvelope);

            var exception = await Record.ExceptionAsync(() => db.UpsertDocument(CollectionId, documentId, newChange));

            // Assert
            exception.Should().NotBeNull();
            exception.Should().BeOfType <ConcurrencyException>();
            exception.Message.Should().Contain("One of the specified pre-condition is not met");
        }