public void FullDocumentBeforeChange_get_and_set_should_work( [Values(ChangeStreamFullDocumentBeforeChangeOption.Default, ChangeStreamFullDocumentBeforeChangeOption.WhenAvailable)] ChangeStreamFullDocumentBeforeChangeOption value) { var subject = CreateSubject(); subject.FullDocumentBeforeChange = value; var result = subject.FullDocumentBeforeChange; result.Should().Be(value); }
public void Execute_should_return_expected_results_for_pre_post_images( [Values(false, true)] bool async, [Values(ChangeStreamFullDocumentOption.Default, ChangeStreamFullDocumentOption.Required, ChangeStreamFullDocumentOption.WhenAvailable)] ChangeStreamFullDocumentOption fullDocument, [Values(ChangeStreamFullDocumentBeforeChangeOption.Required, ChangeStreamFullDocumentOption.WhenAvailable)] ChangeStreamFullDocumentBeforeChangeOption fullDocumentBeforeChange) { RequireServer.Check(). ClusterTypes(ClusterType.ReplicaSet). Supports(Feature.ChangeStreamPrePostImages); EnsureDatabaseExists(); DropCollection(); CreateCollection(_collectionNamespace, true); var pipeline = new[] { BsonDocument.Parse("{ $match : { operationType : \"update\" } }") }; var resultSerializer = new ChangeStreamDocumentSerializer <BsonDocument>(BsonDocumentSerializer.Instance); var messageEncoderSettings = new MessageEncoderSettings(); var subject = new ChangeStreamOperation <ChangeStreamDocument <BsonDocument> >(_collectionNamespace, pipeline, resultSerializer, messageEncoderSettings); subject.FullDocument = fullDocument; subject.FullDocumentBeforeChange = fullDocumentBeforeChange; var validateFullDocument = fullDocument != ChangeStreamFullDocumentOption.Default; Insert("{ _id : 1, x : 1 }"); using (var cursor = ExecuteOperation(subject, async)) using (var enumerator = new AsyncCursorEnumerator <ChangeStreamDocument <BsonDocument> >(cursor, CancellationToken.None)) { Update("{ _id : 1 }", "{ $set : { x : 2 } }"); enumerator.MoveNext().Should().BeTrue(); var change = enumerator.Current; change.OperationType.Should().Be(ChangeStreamOperationType.Update); change.CollectionNamespace.Should().Be(_collectionNamespace); change.DocumentKey.Should().Be("{ _id : 1 }"); change.FullDocumentBeforeChange.Should().Be("{ _id : 1, x : 1 }"); change.RenameTo.Should().BeNull(); change.ResumeToken.Should().NotBeNull(); change.UpdateDescription.RemovedFields.Should().BeEmpty(); change.UpdateDescription.UpdatedFields.Should().Be("{ x : 2 }"); if (validateFullDocument) { change.FullDocument.Should().Be("{ _id : 1, x : 2 }"); } } }