Skip to content

Commit 370fdff

Browse files
For null string values for candidate and party, set them to an empty string (#313)
Created C# unit test
1 parent 5591045 commit 370fdff

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

bindings/netstandard/ElectionGuard/ElectionGuard.Encryption.Tests/TestElection.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,36 @@ public void Test_Can_Create_Context_Config()
1919
Assert.IsTrue(result.AllowedOverVotes);
2020
}
2121

22+
[Test]
23+
public void Test_Can_Create_Party()
24+
{
25+
var candidateName = new Language("father time", "en");
26+
var candidate = new Candidate(
27+
"2022-holidays",
28+
new InternationalizedText(new[] { candidateName }),
29+
"new-years-id",
30+
null,
31+
false);
32+
33+
34+
var partyName = new Language("new years", "en");
35+
var party = new ElectionGuard.Party(
36+
"new-years-id",
37+
new InternationalizedText(new[] { partyName }),
38+
"ny",
39+
null,
40+
null);
41+
42+
// Assert
43+
Assert.IsNotNull(candidate);
44+
Assert.IsNotNull(party);
45+
}
46+
47+
48+
49+
50+
51+
2252
[Test]
2353
public void Test_Can_Deserialize_Ciphertext_Election_Context()
2454
{

bindings/netstandard/ElectionGuard/ElectionGuard.Encryption/Manifest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ public unsafe Party(
824824
string abbreviation, string color, string logoUri)
825825
{
826826
var status = NativeInterface.Party.New(
827-
objectId, name.Handle, abbreviation, color, logoUri, out Handle);
827+
objectId, name.Handle, abbreviation, color ?? string.Empty, logoUri ?? string.Empty, out Handle);
828828
if (status != Status.ELECTIONGUARD_STATUS_SUCCESS)
829829
{
830830
throw new ElectionGuardException($"Party Error Status: {status}");
@@ -1009,7 +1009,7 @@ public unsafe Candidate(
10091009
string partyId, string imageUri, bool isWriteIn)
10101010
{
10111011
var status = NativeInterface.Candidate.New(
1012-
objectId, name.Handle, partyId, imageUri, isWriteIn, out Handle);
1012+
objectId, name.Handle, partyId, imageUri ?? string.Empty, isWriteIn, out Handle);
10131013
if (status != Status.ELECTIONGUARD_STATUS_SUCCESS)
10141014
{
10151015
throw new ElectionGuardException($"Candidate Error Status: {status}");

0 commit comments

Comments
 (0)