diff --git a/src/.editorconfig b/src/.editorconfig index d0b1d62e..2487950d 100644 --- a/src/.editorconfig +++ b/src/.editorconfig @@ -54,6 +54,7 @@ csharp_style_prefer_null_check_over_type_check=true:error csharp_prefer_simple_default_expression=true:error csharp_style_inlined_variable_declaration=true:error dotnet_style_allow_multiple_blank_lines_experimental=false:error +csharp_style_prefer_primary_constructors=true:error csharp_new_line_before_open_brace=all csharp_new_line_before_else=true diff --git a/src/AutoTests.Framework.Components/Application/ComponentReference.cs b/src/AutoTests.Framework.Components/Application/ComponentReference.cs index 3edcdd5a..09fe9d45 100644 --- a/src/AutoTests.Framework.Components/Application/ComponentReference.cs +++ b/src/AutoTests.Framework.Components/Application/ComponentReference.cs @@ -2,17 +2,8 @@ namespace AutoTests.Framework.Components.Application; -public sealed class ComponentReference +public sealed class ComponentReference(ComponentService componentService, string path) { - private readonly ComponentService componentService; - private readonly string path; - - public ComponentReference(ComponentService componentService, string path) - { - this.componentService = componentService; - this.path = path; - } - public T GetComponent() where T : class { diff --git a/src/AutoTests.Framework.Components/Attributes/RouteAttribute.cs b/src/AutoTests.Framework.Components/Attributes/RouteAttribute.cs index 321dda74..4ca571be 100644 --- a/src/AutoTests.Framework.Components/Attributes/RouteAttribute.cs +++ b/src/AutoTests.Framework.Components/Attributes/RouteAttribute.cs @@ -3,12 +3,7 @@ namespace AutoTests.Framework.Components.Attributes; [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)] -public sealed class RouteAttribute : Attribute +public sealed class RouteAttribute(string name) : Attribute { - public string Name { get; } - - public RouteAttribute(string name) - { - Name = name; - } + public string Name { get; } = name; } diff --git a/src/AutoTests.Framework.Components/Attributes/SelectorAttribute.cs b/src/AutoTests.Framework.Components/Attributes/SelectorAttribute.cs index cccd5313..524689b0 100644 --- a/src/AutoTests.Framework.Components/Attributes/SelectorAttribute.cs +++ b/src/AutoTests.Framework.Components/Attributes/SelectorAttribute.cs @@ -3,12 +3,7 @@ namespace AutoTests.Framework.Components.Attributes; [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)] -public sealed class SelectorAttribute : Attribute +public sealed class SelectorAttribute(string name) : Attribute { - public string Value { get; } - - public SelectorAttribute(string name) - { - Value = name; - } + public string Value { get; } = name; } diff --git a/src/AutoTests.Framework.Components/ComponentsSpecflowHooks.cs b/src/AutoTests.Framework.Components/ComponentsSpecflowHooks.cs index 78f7e3ba..195542ba 100644 --- a/src/AutoTests.Framework.Components/ComponentsSpecflowHooks.cs +++ b/src/AutoTests.Framework.Components/ComponentsSpecflowHooks.cs @@ -6,15 +6,8 @@ namespace AutoTests.Framework.Components; [Binding] -public sealed class ComponentsSpecflowHooks +public sealed class ComponentsSpecflowHooks(ComponentService componentService) { - private readonly ComponentService componentService; - - public ComponentsSpecflowHooks(ComponentService componentService) - { - this.componentService = componentService; - } - [StepArgumentTransformation] public ComponentReference TransformComponentReference(string path) { diff --git a/src/AutoTests.Framework.Components/ComponentsSteps.cs b/src/AutoTests.Framework.Components/ComponentsSteps.cs index b64c5c6c..5c911269 100644 --- a/src/AutoTests.Framework.Components/ComponentsSteps.cs +++ b/src/AutoTests.Framework.Components/ComponentsSteps.cs @@ -11,15 +11,8 @@ namespace AutoTests.Framework.Components; [Binding] -public sealed class ComponentsSteps +public sealed class ComponentsSteps(ComponentService componentService) { - private readonly ComponentService componentService; - - public ComponentsSteps(ComponentService componentService) - { - this.componentService = componentService; - } - [When(@"click on '([^']*)'")] public async Task WhenClickOn(ComponentReference componentReference) { diff --git a/src/AutoTests.Framework.Components/Services/ComponentService.cs b/src/AutoTests.Framework.Components/Services/ComponentService.cs index 5a267eb5..c2b0af5d 100644 --- a/src/AutoTests.Framework.Components/Services/ComponentService.cs +++ b/src/AutoTests.Framework.Components/Services/ComponentService.cs @@ -6,14 +6,9 @@ namespace AutoTests.Framework.Components.Services; -public sealed class ComponentService +public sealed class ComponentService(IApplication application) { - private readonly IApplication application; - - public ComponentService(IApplication application) - { - this.application = application; - } + private readonly IApplication application = application; public T GetComponent(string path) where T : class diff --git a/src/AutoTests.Framework.Playwright/Components/TrivialButton.cs b/src/AutoTests.Framework.Playwright/Components/TrivialButton.cs index ab4a9c25..8eea41e7 100644 --- a/src/AutoTests.Framework.Playwright/Components/TrivialButton.cs +++ b/src/AutoTests.Framework.Playwright/Components/TrivialButton.cs @@ -6,25 +6,17 @@ namespace AutoTests.Framework.Playwright.Components; -public sealed class TrivialButton : IClick, IVisible, IEnabled +public sealed class TrivialButton(IPage page) : IClick, IVisible, IEnabled { - private readonly IPage page; - [FromSelector] public string? Locator { get; set; } - public TrivialButton(IPage page) - { - this.page = page; - } - public async Task ClickAsync() { if (Locator == null) { throw new Exception("Locator is required"); } - await page.ClickAsync(Locator); } diff --git a/src/AutoTests.Framework.Playwright/Components/TrivialInput.cs b/src/AutoTests.Framework.Playwright/Components/TrivialInput.cs index a648e562..6eac68fa 100644 --- a/src/AutoTests.Framework.Playwright/Components/TrivialInput.cs +++ b/src/AutoTests.Framework.Playwright/Components/TrivialInput.cs @@ -7,18 +7,11 @@ namespace AutoTests.Framework.Playwright.Components; -public sealed class TrivialInput : ISetValue, IGetValue, IVisible, IEnabled +public sealed class TrivialInput(IPage page) : ISetValue, IGetValue, IVisible, IEnabled { - private readonly IPage page; - [FromSelector] public string? Locator { get; set; } - public TrivialInput(IPage page) - { - this.page = page; - } - public async Task GetValueAsync() { if (Locator == null) diff --git a/src/AutoTests.Framework.Playwright/Components/TrivialLabel.cs b/src/AutoTests.Framework.Playwright/Components/TrivialLabel.cs index 0cf94079..2a9a7ba8 100644 --- a/src/AutoTests.Framework.Playwright/Components/TrivialLabel.cs +++ b/src/AutoTests.Framework.Playwright/Components/TrivialLabel.cs @@ -6,18 +6,11 @@ namespace AutoTests.Framework.Playwright.Components; -public sealed class TrivialLabel : IGetValue, IVisible +public sealed class TrivialLabel(IPage page) : IGetValue, IVisible { - private readonly IPage page; - [FromSelector] public string? Locator { get; set; } - public TrivialLabel(IPage page) - { - this.page = page; - } - public async Task GetValueAsync() { if (Locator == null) diff --git a/src/AutoTests.Framework.Playwright/NavigationSteps.cs b/src/AutoTests.Framework.Playwright/NavigationSteps.cs index 7b926005..98631155 100644 --- a/src/AutoTests.Framework.Playwright/NavigationSteps.cs +++ b/src/AutoTests.Framework.Playwright/NavigationSteps.cs @@ -6,15 +6,8 @@ namespace AutoTests.Framework.Playwright; [Binding] -public sealed class NavigationSteps +public sealed class NavigationSteps(IPage page) { - private readonly IPage page; - - public NavigationSteps(IPage page) - { - this.page = page; - } - [Given(@"navigate to '([^']*)'")] public async Task GivenNavigateTo(ArgumentExpression expression) { diff --git a/src/AutoTests.Framework.Tests/Components/Steps.cs b/src/AutoTests.Framework.Tests/Components/Steps.cs index e83f3500..acfe565d 100644 --- a/src/AutoTests.Framework.Tests/Components/Steps.cs +++ b/src/AutoTests.Framework.Tests/Components/Steps.cs @@ -5,15 +5,8 @@ namespace AutoTests.Framework.Tests.Components; [Binding] -internal sealed class Steps +internal sealed class Steps(Application application) { - private readonly Application application; - - public Steps(Application application) - { - this.application = application; - } - [Then(@"check component test 1")] public void ThenCheckComponentTest1() { diff --git a/src/AutoTests.Framework.Tests/Data/Steps.cs b/src/AutoTests.Framework.Tests/Data/Steps.cs index 81e5634d..24d262d4 100644 --- a/src/AutoTests.Framework.Tests/Data/Steps.cs +++ b/src/AutoTests.Framework.Tests/Data/Steps.cs @@ -5,15 +5,8 @@ namespace AutoTests.Framework.Tests.Data; [Binding] -public sealed class Steps +public sealed class Steps(DataService service) { - private readonly DataService service; - - public Steps(DataService service) - { - this.service = service; - } - [Then(@"test data step 1")] public void ThenTestDataStep() { diff --git a/src/AutoTests.Framework.Tests/Models/TestModel1.cs b/src/AutoTests.Framework.Tests/Models/TestModel1.cs index da034afd..c9b2b54f 100644 --- a/src/AutoTests.Framework.Tests/Models/TestModel1.cs +++ b/src/AutoTests.Framework.Tests/Models/TestModel1.cs @@ -1,13 +1,7 @@ namespace AutoTests.Framework.Tests.Models; -internal sealed class TestModel1 +internal sealed class TestModel1(int x, string y) { - public int X { get; } - public string Y { get; } - - public TestModel1(int x, string y) - { - X = x; - Y = y; - } + public int X { get; } = x; + public string Y { get; } = y; } diff --git a/src/AutoTests.Framework/Data/DataService.cs b/src/AutoTests.Framework/Data/DataService.cs index d1e21d73..d4a4293c 100644 --- a/src/AutoTests.Framework/Data/DataService.cs +++ b/src/AutoTests.Framework/Data/DataService.cs @@ -1,11 +1,6 @@ namespace AutoTests.Framework.Data; -public sealed class DataService +public sealed class DataService(dynamic data) { - public dynamic Data { get; } - - public DataService(dynamic data) - { - Data = data; - } + public dynamic Data { get; } = data; } diff --git a/src/AutoTests.Framework/Expressions/ArgumentExpression.cs b/src/AutoTests.Framework/Expressions/ArgumentExpression.cs index 1c5ff828..67e6a55f 100644 --- a/src/AutoTests.Framework/Expressions/ArgumentExpression.cs +++ b/src/AutoTests.Framework/Expressions/ArgumentExpression.cs @@ -2,17 +2,8 @@ namespace AutoTests.Framework.Expressions; -public sealed class ArgumentExpression +public sealed class ArgumentExpression(IExpressionService expressionService, string text) { - private readonly IExpressionService expressionService; - private readonly string text; - - public ArgumentExpression(IExpressionService expressionService, string text) - { - this.expressionService = expressionService; - this.text = text; - } - public async Task ExecuteAsync() { return await expressionService.ExecuteAsync(text); diff --git a/src/AutoTests.Framework/Expressions/ExpressionEnvironment.cs b/src/AutoTests.Framework/Expressions/ExpressionEnvironment.cs index 7fa54746..623d7f48 100644 --- a/src/AutoTests.Framework/Expressions/ExpressionEnvironment.cs +++ b/src/AutoTests.Framework/Expressions/ExpressionEnvironment.cs @@ -2,12 +2,7 @@ namespace AutoTests.Framework.Expressions; -public class ExpressionEnvironment +public class ExpressionEnvironment(DataService dataService) { - public dynamic Data { get; } - - public ExpressionEnvironment(DataService dataService) - { - Data = dataService.Data; - } + public dynamic Data { get; } = dataService.Data; } diff --git a/src/AutoTests.Framework/Expressions/ExpressionSpecflowHooks.cs b/src/AutoTests.Framework/Expressions/ExpressionSpecflowHooks.cs index 0799bc6b..7ac2a740 100644 --- a/src/AutoTests.Framework/Expressions/ExpressionSpecflowHooks.cs +++ b/src/AutoTests.Framework/Expressions/ExpressionSpecflowHooks.cs @@ -4,15 +4,8 @@ namespace AutoTests.Framework.Expressions; [Binding] -public sealed class ExpressionSpecflowHooks +public sealed class ExpressionSpecflowHooks(IExpressionService expressionService) { - private readonly IExpressionService expressionService; - - public ExpressionSpecflowHooks(IExpressionService expressionService) - { - this.expressionService = expressionService; - } - [StepArgumentTransformation] public ArgumentExpression TransformExpression(string text) { diff --git a/src/AutoTests.Framework/Expressions/RoslynCSharpExpressionService.cs b/src/AutoTests.Framework/Expressions/RoslynCSharpExpressionService.cs index 40b356e6..5139dceb 100644 --- a/src/AutoTests.Framework/Expressions/RoslynCSharpExpressionService.cs +++ b/src/AutoTests.Framework/Expressions/RoslynCSharpExpressionService.cs @@ -5,16 +5,9 @@ namespace AutoTests.Framework.Expressions; -internal sealed class RoslynCSharpExpressionService : IExpressionService +internal sealed class RoslynCSharpExpressionService(ExpressionEnvironment expressionEnvironment) : IExpressionService { - private readonly ExpressionEnvironment expressionEnvironment; - private readonly ScriptOptions scriptOptions; - - public RoslynCSharpExpressionService(ExpressionEnvironment expressionEnvironment) - { - this.expressionEnvironment = expressionEnvironment; - scriptOptions = ScriptOptions.Default.AddReferences("Microsoft.CSharp"); - } + private readonly ScriptOptions scriptOptions = ScriptOptions.Default.AddReferences("Microsoft.CSharp"); public async Task ExecuteAsync(string text) { diff --git a/src/AutoTests.Framework/Models/ExpressionSpecflowHooks.cs b/src/AutoTests.Framework/Models/ExpressionSpecflowHooks.cs index 1487a612..cf9ea03d 100644 --- a/src/AutoTests.Framework/Models/ExpressionSpecflowHooks.cs +++ b/src/AutoTests.Framework/Models/ExpressionSpecflowHooks.cs @@ -6,15 +6,8 @@ namespace AutoTests.Framework.Models; [Binding] -public sealed class ModelsSpecflowHooks +public sealed class ModelsSpecflowHooks(IExpressionService expressionService) { - private readonly IExpressionService expressionService; - - public ModelsSpecflowHooks(IExpressionService expressionService) - { - this.expressionService = expressionService; - } - [StepArgumentTransformation] public IModel TransformModel(Table table) { diff --git a/src/AutoTests.Framework/Models/Model.cs b/src/AutoTests.Framework/Models/Model.cs index 11b23481..1d3f7cfb 100644 --- a/src/AutoTests.Framework/Models/Model.cs +++ b/src/AutoTests.Framework/Models/Model.cs @@ -9,22 +9,13 @@ namespace AutoTests.Framework.Models; -internal sealed class Model : IModel +internal sealed class Model(IExpressionService expressionService, Table table) : IModel { private static readonly JsonSerializerOptions jsonSerializerOptions = new() { NumberHandling = JsonNumberHandling.AllowReadingFromString }; - private readonly IExpressionService expressionService; - private readonly Table table; - - public Model(IExpressionService expressionService, Table table) - { - this.expressionService = expressionService; - this.table = table; - } - public async Task GetValueAsync() { var properties = table.Rows.ToDictionary(x => x["Name"], x => x["Value"]); @@ -58,11 +49,7 @@ private async Task ConvertToObject(IEnumerable(Dictionary properties) { var jsonModel = JsonSerializer.Serialize(properties); - var result = JsonSerializer.Deserialize(jsonModel, jsonSerializerOptions); - if (result == null) - { - throw new Exception($"Unable to serialize {typeof(T).FullName}"); - } + var result = JsonSerializer.Deserialize(jsonModel, jsonSerializerOptions) ?? throw new Exception($"Unable to serialize {typeof(T).FullName}"); return result; } }