Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧Refactor unit test assertions #724

Merged
merged 10 commits into from
Sep 4, 2023
2 changes: 1 addition & 1 deletion Testing/AvaloniaTesting/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace AvaloniaTesting;
/// <summary>
/// The main application.
/// </summary>
public partial class App : Application
public class App : Application
{
/// <summary>
/// Initializes the application.
Expand Down
2 changes: 1 addition & 1 deletion Testing/AvaloniaTesting/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.With(new Win32PlatformOptions()
.With(new Win32PlatformOptions
{
RenderingMode = new[] { Win32RenderingMode.Wgl },
})
Expand Down
1 change: 0 additions & 1 deletion Testing/AvaloniaTesting/RenderControl.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) KinsonDigital. All rights reserved.
// </copyright>

using Avalonia.Controls;

Check warning on line 5 in Testing/AvaloniaTesting/RenderControl.axaml.cs

View workflow job for this annotation

GitHub Actions / Build Avalonia Testing App / Building AvaloniaTesting Project

Check warning on line 5 in Testing/AvaloniaTesting/RenderControl.axaml.cs

View workflow job for this annotation

GitHub Actions / Build Avalonia Testing App / Building AvaloniaTesting Project


namespace AvaloniaTesting;

Expand Down Expand Up @@ -53,5 +53,4 @@
this.glControl.RenderPosition = new Vector2((float)args.NewSize.Width / 2f, (float)args.NewSize.Height / 2f);
};
}
}

Check warning on line 56 in Testing/AvaloniaTesting/RenderControl.axaml.cs

View workflow job for this annotation

GitHub Actions / Build Avalonia Testing App / Building AvaloniaTesting Project


2 changes: 1 addition & 1 deletion Testing/AvaloniaTesting/ViewLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Copyright (c) KinsonDigital. All rights reserved.
// </copyright>

using System;

Check warning on line 5 in Testing/AvaloniaTesting/ViewLocator.cs

View workflow job for this annotation

GitHub Actions / Build Avalonia Testing App / Building AvaloniaTesting Project

Check warning on line 5 in Testing/AvaloniaTesting/ViewLocator.cs

View workflow job for this annotation

GitHub Actions / Build Avalonia Testing App / Building AvaloniaTesting Project

using Avalonia.Controls;

Check warning on line 6 in Testing/AvaloniaTesting/ViewLocator.cs

View workflow job for this annotation

GitHub Actions / Build Avalonia Testing App / Building AvaloniaTesting Project

using Avalonia.Controls.Templates;

Check warning on line 7 in Testing/AvaloniaTesting/ViewLocator.cs

View workflow job for this annotation

GitHub Actions / Build Avalonia Testing App / Building AvaloniaTesting Project

using AvaloniaTesting.ViewModels;

Check warning on line 8 in Testing/AvaloniaTesting/ViewLocator.cs

View workflow job for this annotation

GitHub Actions / Build Avalonia Testing App / Building AvaloniaTesting Project


namespace AvaloniaTesting;

Expand All @@ -21,7 +21,7 @@

if (type != null)
{
return (Control)Activator.CreateInstance(type)!;
return (Control)Activator.CreateInstance(type) !;

Check warning on line 24 in Testing/AvaloniaTesting/ViewLocator.cs

View workflow job for this annotation

GitHub Actions / Build Avalonia Testing App / Building AvaloniaTesting Project

}

return new TextBlock { Text = "Not Found: " + name };
Expand Down
4 changes: 2 additions & 2 deletions Testing/VelaptorTests/Content/Fonts/FontTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,9 @@
/// <param name="text">The text to mock the kerning values for.</param>
private void MockGlyphKernings(string text)
{
if (this.glyphMetrics is null || this.glyphMetrics.Count <= 0)
if (this.glyphMetrics.Count <= 0)
{
Assert.True(false, $"Cannot run test with the static class member '{this.glyphMetrics}' being null or empty.");
Assert.Fail($"Cannot run test with the static class member '{this.glyphMetrics}' being null or empty.");

Check warning on line 685 in Testing/VelaptorTests/Content/Fonts/FontTests.cs

View workflow job for this annotation

GitHub Actions / Run Velaptor Tests / Run Unit Tests

Do not use Assert.True(false, message) to fail a test. Use Assert.Fail(message) instead. (https://xunit.net/xunit.analyzers/rules/xUnit2020)
}

// Strip new line and carriage feed characters. This white space characters
Expand Down
10 changes: 5 additions & 5 deletions Testing/VelaptorTests/Helpers/TestDataLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@

if (string.IsNullOrEmpty(fileName))
{
Assert.True(false, $"{loadTestDataPrefix}The parameter '{nameof(fileName)}' must not be null or empty.");
Assert.Fail($"{loadTestDataPrefix}The parameter '{nameof(fileName)}' must not be null or empty.");

Check warning on line 53 in Testing/VelaptorTests/Helpers/TestDataLoader.cs

View workflow job for this annotation

GitHub Actions / Run Velaptor Tests / Run Unit Tests

Do not use Assert.True(false, message) to fail a test. Use Assert.Fail(message) instead. (https://xunit.net/xunit.analyzers/rules/xUnit2020)

Check warning on line 53 in Testing/VelaptorTests/Helpers/TestDataLoader.cs

View workflow job for this annotation

GitHub Actions / Run Velaptor Tests / Run Unit Tests

Do not use Assert.True(false, message) to fail a test. Use Assert.Fail(message) instead. (https://xunit.net/xunit.analyzers/rules/xUnit2020)
}

if (Path.HasExtension(fileName) is false)
{
Assert.True(false, $"{loadTestDataPrefix}The file name '{fileName}' must be a file name with an extension.");
Assert.Fail($"{loadTestDataPrefix}The file name '{fileName}' must be a file name with an extension.");

Check warning on line 58 in Testing/VelaptorTests/Helpers/TestDataLoader.cs

View workflow job for this annotation

GitHub Actions / Run Velaptor Tests / Run Unit Tests

Do not use Assert.True(false, message) to fail a test. Use Assert.Fail(message) instead. (https://xunit.net/xunit.analyzers/rules/xUnit2020)

Check warning on line 58 in Testing/VelaptorTests/Helpers/TestDataLoader.cs

View workflow job for this annotation

GitHub Actions / Run Velaptor Tests / Run Unit Tests

Do not use Assert.True(false, message) to fail a test. Use Assert.Fail(message) instead. (https://xunit.net/xunit.analyzers/rules/xUnit2020)
}

relativeDirPath = relativeDirPath.Replace(WinDirSeparatorChar, CrossPlatDirSeparatorChar);
Expand All @@ -74,14 +74,14 @@

if (Directory.Exists(fullDirPath) is false)
{
Assert.True(false, $"{loadTestDataPrefix}The directory path '{fullDirPath}' does not exist.");
Assert.Fail($"{loadTestDataPrefix}The directory path '{fullDirPath}' does not exist.");

Check warning on line 77 in Testing/VelaptorTests/Helpers/TestDataLoader.cs

View workflow job for this annotation

GitHub Actions / Run Velaptor Tests / Run Unit Tests

Do not use Assert.True(false, message) to fail a test. Use Assert.Fail(message) instead. (https://xunit.net/xunit.analyzers/rules/xUnit2020)

Check warning on line 77 in Testing/VelaptorTests/Helpers/TestDataLoader.cs

View workflow job for this annotation

GitHub Actions / Run Velaptor Tests / Run Unit Tests

Do not use Assert.True(false, message) to fail a test. Use Assert.Fail(message) instead. (https://xunit.net/xunit.analyzers/rules/xUnit2020)
}

var fullTestDataFilePath = $"{fullDirPath}{CrossPlatDirSeparatorChar}{fileName}";

if (File.Exists(fullTestDataFilePath) is false)
{
Assert.True(false, $"{loadTestDataPrefix}The test data file path '{fullTestDataFilePath}' does not exist.");
Assert.Fail($"{loadTestDataPrefix}The test data file path '{fullTestDataFilePath}' does not exist.");

Check warning on line 84 in Testing/VelaptorTests/Helpers/TestDataLoader.cs

View workflow job for this annotation

GitHub Actions / Run Velaptor Tests / Run Unit Tests

Do not use Assert.True(false, message) to fail a test. Use Assert.Fail(message) instead. (https://xunit.net/xunit.analyzers/rules/xUnit2020)
}

var testJSONData = File.ReadAllText(fullTestDataFilePath);
Expand All @@ -90,7 +90,7 @@
{
Error = (_, args) =>
{
Assert.True(false, args.ErrorContext.Error.Message);
Assert.Fail(args.ErrorContext.Error.Message);

Check warning on line 93 in Testing/VelaptorTests/Helpers/TestDataLoader.cs

View workflow job for this annotation

GitHub Actions / Run Velaptor Tests / Run Unit Tests

Do not use Assert.True(false, message) to fail a test. Use Assert.Fail(message) instead. (https://xunit.net/xunit.analyzers/rules/xUnit2020)
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace VelaptorTests.NativeInterop.GLFW;

using System;
using FluentAssertions;
using Helpers;
using Velaptor.NativeInterop.GLFW;
using Xunit;
Expand All @@ -31,8 +32,8 @@ public void Ctor_WhenInvoked_SetsPropertyValues()
var eventArgs = new GlfwErrorEventArgs(GlfwErrorCode.ApiUnavailable, "test-message");

// Assert
Assert.Equal(GlfwErrorCode.ApiUnavailable, eventArgs.ErrorCode);
Assert.Equal("test-message", eventArgs.ErrorMessage);
eventArgs.ErrorCode.Should().Be(GlfwErrorCode.ApiUnavailable);
eventArgs.ErrorMessage.Should().Be("test-message");
}
#endregion
}
Loading
Loading