Skip to content

Commit 9e15a88

Browse files
committed
Add unit test case
1 parent ebbaf6e commit 9e15a88

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

test/EntityFrameworkCore.DataEncryption.Test/PropertyBuilderExtensionsTest.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public void PropertyShouldHaveEncryptionAnnotationsTest()
3636
Name = name,
3737
NameAsBytes = name,
3838
ExtraData = bytes,
39-
ExtraDataAsBytes = bytes
39+
ExtraDataAsBytes = bytes,
40+
EmptyString = ""
4041
};
4142

4243
using var contextFactory = new DatabaseContextFactory();
@@ -52,6 +53,7 @@ public void PropertyShouldHaveEncryptionAnnotationsTest()
5253
AssertPropertyAnnotations(entityType.GetProperty(nameof(UserEntity.ExtraData)), true, StorageFormat.Base64);
5354
AssertPropertyAnnotations(entityType.GetProperty(nameof(UserEntity.ExtraDataAsBytes)), true, StorageFormat.Binary);
5455
AssertPropertyAnnotations(entityType.GetProperty(nameof(UserEntity.Id)), false, StorageFormat.Default);
56+
AssertPropertyAnnotations(entityType.GetProperty(nameof(UserEntity.EmptyString)), true, StorageFormat.Base64);
5557

5658
context.Users.Add(user);
5759
context.SaveChanges();
@@ -66,6 +68,7 @@ public void PropertyShouldHaveEncryptionAnnotationsTest()
6668
Assert.Equal(name, u.NameAsBytes);
6769
Assert.Equal(bytes, u.ExtraData);
6870
Assert.Equal(bytes, u.ExtraDataAsBytes);
71+
Assert.Null(u.EmptyString);
6972
}
7073
}
7174

@@ -106,6 +109,9 @@ private class UserEntity
106109

107110
// Encrypted as raw byte array.
108111
public byte[] ExtraDataAsBytes { get; set; }
112+
113+
// Encrypt as Base64 string, but will be empty.
114+
public string EmptyString { get; set; }
109115
}
110116

111117
private class FluentDbContext : DbContext
@@ -134,6 +140,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
134140
userEntityBuilder.Property(x => x.NameAsBytes).IsRequired().HasColumnType("BLOB").IsEncrypted(StorageFormat.Binary);
135141
userEntityBuilder.Property(x => x.ExtraData).IsRequired().HasColumnType("TEXT").IsEncrypted(StorageFormat.Base64);
136142
userEntityBuilder.Property(x => x.ExtraDataAsBytes).IsRequired().HasColumnType("BLOB").IsEncrypted(StorageFormat.Binary);
143+
userEntityBuilder.Property(x => x.EmptyString).IsRequired(false).HasColumnType("TEXT").IsEncrypted(StorageFormat.Base64);
137144

138145
modelBuilder.UseEncryption(_encryptionProvider);
139146
}

0 commit comments

Comments
 (0)