Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Code review.
  • Loading branch information
DmitryLukyanov committed Jan 16, 2023
commit 308349b19a58712a28e43534bc264991c61a8a79
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace MongoDB.Driver.Encryption
/// <summary>
/// Represents the result of a create encrypted collection.
/// </summary>
public class CreateEncryptedCollectionResult
public sealed class CreateEncryptedCollectionResult
{
private readonly BsonDocument _encryptedFields;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public MongoEncryptionCreateCollectionException(Exception innerException, BsonDo
protected MongoEncryptionCreateCollectionException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
_encryptedFields = (BsonDocument)info.GetValue("_encryptedFields", typeof(BsonDocument));
_encryptedFields = (BsonDocument)info.GetValue(nameof(_encryptedFields), typeof(BsonDocument));
}

/// <summary>
Expand All @@ -63,7 +63,7 @@ protected MongoEncryptionCreateCollectionException(SerializationInfo info, Strea
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("_encryptedFields", _encryptedFields);
info.AddValue(nameof(_encryptedFields), _encryptedFields);
}
}
}
15 changes: 6 additions & 9 deletions tests/MongoDB.Driver.Tests/Encryption/ClientEncryptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,19 @@ public async Task CreateEncryptedCollection_should_handle_various_encryptedField

using (var subject = CreateSubject())
{
var createCollectionOptions = new CreateCollectionOptions() { EncryptedFields = encryptedFieldsStr != null ? BsonDocument.Parse(encryptedFieldsStr) : null };

if (BsonDocument.TryParse(expectedResult, out var encryptedFields))
{
var createCollectionOptions = new CreateCollectionOptions() { EncryptedFields = encryptedFieldsStr != null ? BsonDocument.Parse(encryptedFieldsStr) : null };
var effectiveEncryptedFields = subject.CreateEncryptedCollection(database, collectionName, createCollectionOptions, kmsProvider, dataKeyOptions);
effectiveEncryptedFields.EncryptedFields.WithComparer(new EncryptedFieldsComparer()).Should().Be(encryptedFields.DeepClone());
var createCollectionResult = subject.CreateEncryptedCollection(database, collectionName, createCollectionOptions, kmsProvider, dataKeyOptions);
createCollectionResult.EncryptedFields.WithComparer(new EncryptedFieldsComparer()).Should().Be(encryptedFields.DeepClone());

createCollectionOptions = new CreateCollectionOptions() { EncryptedFields = encryptedFieldsStr != null ? BsonDocument.Parse(encryptedFieldsStr) : null };
effectiveEncryptedFields = await subject.CreateEncryptedCollectionAsync(database, collectionName, createCollectionOptions, kmsProvider, dataKeyOptions);
effectiveEncryptedFields.EncryptedFields.WithComparer(new EncryptedFieldsComparer()).Should().Be(encryptedFields.DeepClone());
createCollectionResult = await subject.CreateEncryptedCollectionAsync(database, collectionName, createCollectionOptions, kmsProvider, dataKeyOptions);
createCollectionResult.EncryptedFields.WithComparer(new EncryptedFieldsComparer()).Should().Be(encryptedFields.DeepClone());
}
else
{
var createCollectionOptions = new CreateCollectionOptions() { EncryptedFields = encryptedFieldsStr != null ? BsonDocument.Parse(encryptedFieldsStr) : null };
AssertInvalidOperationException(Record.Exception(() => subject.CreateEncryptedCollection(database, collectionName, createCollectionOptions, kmsProvider, dataKeyOptions)), expectedResult);

createCollectionOptions = new CreateCollectionOptions() { EncryptedFields = encryptedFieldsStr != null ? BsonDocument.Parse(encryptedFieldsStr) : null };
AssertInvalidOperationException(await Record.ExceptionAsync(() => subject.CreateEncryptedCollectionAsync(database, collectionName, createCollectionOptions, kmsProvider, dataKeyOptions)), expectedResult);
}
}
Expand Down