Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Feb 27, 2024
1 parent 322fc06 commit 0ffd351
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void W_OpenDefault_NonWindows()
var result = WindowsOpenDesktopApp.OpenDefault(["any value"], OSPlatform.Linux);
Assert.IsNull(result);
}

[TestMethod]
public void W_OpenDefault2_NonWindows()
{
Expand All @@ -82,6 +82,20 @@ public void W_OpenDefault2_NonWindows()
return;
}

var result = WindowsOpenDesktopApp.OpenDefault(["any value"], OSPlatform.Windows);

Assert.IsTrue(result);
}

[TestMethod]
public void W_OpenDefault3_NonWindows()
{
if ( new AppSettings().IsWindows )
{
Assert.Inconclusive("This test if for Unix Only");
return;
}

var result = WindowsOpenDesktopApp.OpenDefault(["any value"]);

Console.WriteLine(result);
Expand Down Expand Up @@ -121,7 +135,7 @@ public void W_OpenApplicationAtUrl_NonWindows()
"app", OSPlatform.Linux);
Assert.IsNull(result);
}

[TestMethod]
[ExpectedException(typeof(Win32Exception))]
public void W_OpenApplicationAtUrl2_NonWindows()
Expand All @@ -132,6 +146,21 @@ public void W_OpenApplicationAtUrl2_NonWindows()
return;
}

// ExpectedException = Win32Exception
WindowsOpenDesktopApp.OpenApplicationAtUrl(["any value"],
"/not_found_849539453", OSPlatform.Windows);
}

[TestMethod]
[ExpectedException(typeof(Win32Exception))]
public void W_OpenApplicationAtUrl3_NonWindows()
{
if ( new AppSettings().IsWindows )
{
Assert.Inconclusive("This test if for Unix Only");
return;
}

WindowsOpenDesktopApp.OpenApplicationAtUrl(new List<string> { "any value" },
"app");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,61 @@ public void Test_GetDisplayName_ReturnsEmptyString_ForNullableEnumWithNullDispla
// Assert
Assert.AreEqual(null, result);
}

public enum TestType
{
[Display(Name = "First Display Name")] FirstValue,

[Display(Name = "Second Display Name")]
SecondValue
}

[TestMethod]
public void GetDisplayName_WithValidEnumValue_ReturnsCorrectDisplayName()
{
// Arrange
var enumValue = TestType.FirstValue;

// Act
var displayName = EnumHelper.GetDisplayName(enumValue);

// Assert
Assert.AreEqual("First Display Name", displayName);
}

[TestMethod]
public void GetDisplayName_WithNullEnumValue_ReturnsNull()
{
// Arrange & Act
var displayName = EnumHelper.GetDisplayName(null!);

// Assert
Assert.IsNull(displayName);
}

[TestMethod]
public void GetDisplayName_WithInvalidEnumValue_ReturnsNull()
{
// Arrange
var enumValue = ( TestType )100; // An invalid value

// Act
var displayName = EnumHelper.GetDisplayName(enumValue);

// Assert
Assert.IsNull(displayName);
}

[TestMethod]
public void GetDisplayName_WithEnumValueWithoutDisplayAttribute_ReturnsNull()
{
// Arrange
var enumValue = TestType.SecondValue;

// Act
var displayName = EnumHelper.GetDisplayName(enumValue);

// Assert
Assert.AreEqual("Second Display Name", displayName);
}
}

0 comments on commit 0ffd351

Please sign in to comment.