Skip to content

Commit

Permalink
Add unit test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Eastrall committed May 12, 2023
1 parent ebbaf6e commit 9e15a88
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public void PropertyShouldHaveEncryptionAnnotationsTest()
Name = name,
NameAsBytes = name,
ExtraData = bytes,
ExtraDataAsBytes = bytes
ExtraDataAsBytes = bytes,
EmptyString = ""
};

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

context.Users.Add(user);
context.SaveChanges();
Expand All @@ -66,6 +68,7 @@ public void PropertyShouldHaveEncryptionAnnotationsTest()
Assert.Equal(name, u.NameAsBytes);
Assert.Equal(bytes, u.ExtraData);
Assert.Equal(bytes, u.ExtraDataAsBytes);
Assert.Null(u.EmptyString);
}
}

Expand Down Expand Up @@ -106,6 +109,9 @@ private class UserEntity

// Encrypted as raw byte array.
public byte[] ExtraDataAsBytes { get; set; }

// Encrypt as Base64 string, but will be empty.
public string EmptyString { get; set; }
}

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

modelBuilder.UseEncryption(_encryptionProvider);
}
Expand Down

0 comments on commit 9e15a88

Please sign in to comment.