From 93cfa8696515c35ae0fc12f714ed1f3909702a9b Mon Sep 17 00:00:00 2001 From: Sergey Ruzin Date: Mon, 16 May 2022 18:49:12 +0300 Subject: [PATCH] Fixed NullReferenceException when using ComplexBindingBuilder in hooks --- CHANGELOG.md | 4 ++-- .../Behavioral.Automation.csproj | 2 +- .../Services/ComplexBindingBuilder.cs | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 260c9137..ef790454 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,6 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -[1.10.0] - 2022-05-16 +[1.10.2] - 2022-05-16 ### Added -- Added cells representation to the ITableRowWrapper interface. \ No newline at end of file +- Fixed NullReferenceException when using ComplexBindingBuilder in hooks \ No newline at end of file diff --git a/src/Behavioral.Automation/Behavioral.Automation.csproj b/src/Behavioral.Automation/Behavioral.Automation.csproj index 6136556a..6bd4a74f 100644 --- a/src/Behavioral.Automation/Behavioral.Automation.csproj +++ b/src/Behavioral.Automation/Behavioral.Automation.csproj @@ -16,7 +16,7 @@ The whole automation code is divided into the following parts: - UI structure descriptive code - Supportive code Quantori Inc. - 1.10.1 + 1.10.2 https://github.com/quantori/Behavioral.Automation true true diff --git a/src/Behavioral.Automation/Services/ComplexBindingBuilder.cs b/src/Behavioral.Automation/Services/ComplexBindingBuilder.cs index 62cab2e4..a2a3008e 100644 --- a/src/Behavioral.Automation/Services/ComplexBindingBuilder.cs +++ b/src/Behavioral.Automation/Services/ComplexBindingBuilder.cs @@ -73,7 +73,7 @@ public void BuildAction(Action method, params ob private void BuildAction(object[] pars, IEnumerable attributes, string methodName) { - var definitionType = _scenarioContext.StepContext.StepInfo.StepDefinitionType.ToString(); + var definitionType = GetStepDefinitionType().ToString(); var attributeForCurrentStep = attributes.FirstOrDefault(a => a.GetType().Name.StartsWith(definitionType, StringComparison.OrdinalIgnoreCase)); if (attributeForCurrentStep == null) { @@ -99,7 +99,7 @@ private void BuildAction(object[] pars, IEnumerable private void RunAction(string stepExpression) { - switch (_scenarioContext.StepContext.StepInfo.StepDefinitionType) + switch (GetStepDefinitionType()) { case StepDefinitionType.Given: _runner.Given(stepExpression); @@ -115,6 +115,18 @@ private void RunAction(string stepExpression) } } + private StepDefinitionType GetStepDefinitionType() + { + try + { + return _scenarioContext.StepContext.StepInfo.StepDefinitionType; + } + catch (NullReferenceException) + { + return StepDefinitionType.Given; + } + } + private void RunAction(string stepExpression, Table table) { switch (_scenarioContext.StepContext.StepInfo.StepDefinitionType)