Skip to content

Commit

Permalink
fixup: error asserts
Browse files Browse the repository at this point in the history
Signed-off-by: Todd Baert <[email protected]>
  • Loading branch information
toddbaert committed Jul 4, 2024
1 parent edd04f0 commit a8b55a0
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;
using System.ComponentModel;
using System.Reflection;
using System.Threading.Tasks;
using OpenFeature.Constant;
using OpenFeature.Model;
Expand Down Expand Up @@ -245,7 +244,7 @@ public void Thenthedefaultstringvalueshouldbereturned()
public void Giventhereasonshouldindicateanerrorandtheerrorcodeshouldindicateamissingflagwith(string errorCode)
{
Assert.Equal(Reason.Error.ToString(), notFoundDetails.Reason);
Assert.Contains(errorCode, notFoundDetails.ErrorMessage);
Assert.Contains(errorCode, GetErrorTypeDescription(notFoundDetails.ErrorType));
}

[When(@"a string flag with key ""(.*)"" is evaluated as an integer, with details and a default value (.*)")]
Expand All @@ -266,7 +265,15 @@ public void Thenthedefaultintegervalueshouldbereturned()
public void Giventhereasonshouldindicateanerrorandtheerrorcodeshouldindicateatypemismatchwith(string errorCode)
{
Assert.Equal(Reason.Error.ToString(), typeErrorDetails.Reason);
Assert.Contains(errorCode, this.typeErrorDetails.ErrorMessage);
Assert.Contains(errorCode, GetErrorTypeDescription(typeErrorDetails.ErrorType));
}

// convenience method to get the enum description.
private string GetErrorTypeDescription(Enum value)
{
FieldInfo info = value.GetType().GetField(value.ToString());
DescriptionAttribute[] attributes = (DescriptionAttribute[])info.GetCustomAttributes(typeof(DescriptionAttribute));
return attributes[0].Description;
}
}
}

0 comments on commit a8b55a0

Please sign in to comment.