public void Should_convert_from_core_acknowledged_result_when_original_models_exists(long? modifiedCount)
        {
            var core = new BulkWriteOperationResult.Acknowledged(
                requestCount: 1,
                matchedCount: 2,
                deletedCount: 3,
                insertedCount: 4,
                modifiedCount: modifiedCount,
                processedRequests: new[] { new InsertRequest(new BsonDocument("b", 1)) },
                upserts: new List<BulkWriteOperationUpsert>());

            var models = new[] 
            {
                new InsertOneModel<BsonDocument>(new BsonDocument("a", 1))
            };
            var mapped = BulkWriteResult<BsonDocument>.FromCore(core, models);

            mapped.ProcessedRequests[0].Should().BeSameAs(models[0]);

            mapped.IsAcknowledged.Should().BeTrue();
            mapped.RequestCount.Should().Be(core.RequestCount);
            mapped.MatchedCount.Should().Be(core.MatchedCount);
            mapped.DeletedCount.Should().Be(core.DeletedCount);
            mapped.InsertedCount.Should().Be(core.InsertedCount);
            mapped.IsModifiedCountAvailable.Should().Be(core.IsModifiedCountAvailable);
            if(mapped.IsModifiedCountAvailable)
            {
                mapped.ModifiedCount.Should().Be(core.ModifiedCount);
            }
            mapped.Upserts.Count.Should().Be(core.Upserts.Count);
        }
        public void Constructor_should_work()
        {
            var processedRequests = new WriteRequest[0];
            var upserts = new BulkWriteOperationUpsert[0];
            var result = new BulkWriteOperationResult.Acknowledged(1, 2, 3, 4, 5, processedRequests, upserts);
            var writeErrors = new BulkWriteOperationError[0];
            var writeConcernError = new BulkWriteConcernError(1, "message", new BsonDocument("x", 1));
            var unprocessedRequests = new WriteRequest[0];
            var subject = new BulkWriteOperationException(result, writeErrors, writeConcernError, unprocessedRequests);

            subject.Result.Should().BeSameAs(result);
            subject.UnprocessedRequests.Should().BeSameAs(unprocessedRequests);
            subject.WriteConcernError.Should().BeSameAs(writeConcernError);
            subject.WriteErrors.Should().BeSameAs(writeErrors);
        }
        public void Constructor_should_work()
        {
            var processedRequests   = new WriteRequest[0];
            var upserts             = new BulkWriteOperationUpsert[0];
            var result              = new BulkWriteOperationResult.Acknowledged(1, 2, 3, 4, 5, processedRequests, upserts);
            var writeErrors         = new BulkWriteOperationError[0];
            var writeConcernError   = new BulkWriteConcernError(1, "message", new BsonDocument("x", 1));
            var unprocessedRequests = new WriteRequest[0];
            var subject             = new BulkWriteOperationException(result, writeErrors, writeConcernError, unprocessedRequests);

            subject.Result.Should().BeSameAs(result);
            subject.UnprocessedRequests.Should().BeSameAs(unprocessedRequests);
            subject.WriteConcernError.Should().BeSameAs(writeConcernError);
            subject.WriteErrors.Should().BeSameAs(writeErrors);
        }
        public void Serialization_should_drop_custom_fields()
        {
            var processedRequests = new WriteRequest[0];
            var upserts = new BulkWriteOperationUpsert[0];
            var result = new BulkWriteOperationResult.Acknowledged(1, 2, 3, 4, 5, processedRequests, upserts);
            var writeErrors = new BulkWriteOperationError[0];
            var writeConcernError = new BulkWriteConcernError(1, "message", new BsonDocument("x", 1));
            var unprocessedRequests = new WriteRequest[0];
            var subject = new BulkWriteOperationException(result, writeErrors, writeConcernError, unprocessedRequests);

            var formatter = new BinaryFormatter();
            using (var stream = new MemoryStream())
            {
                formatter.Serialize(stream, subject);
                stream.Position = 0;
                var rehydrated = (BulkWriteOperationException)formatter.Deserialize(stream);

                rehydrated.Result.Should().BeNull();
                rehydrated.UnprocessedRequests.Should().BeNull();
                rehydrated.WriteConcernError.Should().BeNull();
                rehydrated.WriteErrors.Should().BeNull();
            }
        }
        public void Serialization_should_drop_custom_fields()
        {
            var processedRequests   = new WriteRequest[0];
            var upserts             = new BulkWriteOperationUpsert[0];
            var result              = new BulkWriteOperationResult.Acknowledged(1, 2, 3, 4, 5, processedRequests, upserts);
            var writeErrors         = new BulkWriteOperationError[0];
            var writeConcernError   = new BulkWriteConcernError(1, "message", new BsonDocument("x", 1));
            var unprocessedRequests = new WriteRequest[0];
            var subject             = new BulkWriteOperationException(result, writeErrors, writeConcernError, unprocessedRequests);

            var formatter = new BinaryFormatter();

            using (var stream = new MemoryStream())
            {
                formatter.Serialize(stream, subject);
                stream.Position = 0;
                var rehydrated = (BulkWriteOperationException)formatter.Deserialize(stream);

                rehydrated.Result.Should().BeNull();
                rehydrated.UnprocessedRequests.Should().BeNull();
                rehydrated.WriteConcernError.Should().BeNull();
                rehydrated.WriteErrors.Should().BeNull();
            }
        }