From 31d8694833105d2f722eec1909213145816e3186 Mon Sep 17 00:00:00 2001 From: Vladimir Semenovich Date: Thu, 24 Feb 2022 18:52:37 +0300 Subject: [PATCH 1/5] fix: 'sequence contains no elements' exception while aggregating through empty collection on error message --- .../Bindings/DropdownBinding.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Behavioral.Automation/Bindings/DropdownBinding.cs b/src/Behavioral.Automation/Bindings/DropdownBinding.cs index 1becbf42..6b4ed226 100644 --- a/src/Behavioral.Automation/Bindings/DropdownBinding.cs +++ b/src/Behavioral.Automation/Bindings/DropdownBinding.cs @@ -51,7 +51,7 @@ public void CheckDropdownContainsItems( Assert.ShouldBecome( () => wrapper.Items.Contains(value), !behavior.Contains("not"), - $"{wrapper.Caption} items are {wrapper.Items.Aggregate((x, y) => $"{x}, {y}")}"); + GenerateErrorMessage(wrapper.Caption, wrapper.Items)); } [Given("the (.*?) (contains|not contains) the following values:")] @@ -62,12 +62,12 @@ public void CheckDropdownContainsMultipleItems([NotNull] IDropdownWrapper wrappe Assert.ShouldBecome(()=> table.Rows.Any(),true, new AssertionBehavior(AssertionType.Immediate, false), "Please provide data in the table"); - var dropdownItems = wrapper.Items; + var dropdownItems = wrapper.Items.ToArray(); foreach (var row in table.Rows) { var value = row.Values.FirstOrDefault(); Assert.ShouldBecome(()=>dropdownItems.Contains(value), !behavior.Contains("not"), - $"{wrapper.Caption} items are {dropdownItems.Aggregate((x, y) => $"{x}, {y}")}"); + GenerateErrorMessage(wrapper.Caption, dropdownItems)); } } @@ -80,7 +80,7 @@ public void CheckAllItemsContainString( Assert.ShouldBecome(() => wrapper.Stale, false, $"{wrapper.Caption} is stale"); var items = wrapper.Items; Assert.ShouldBecome(() => wrapper.Items.All(x => x.ToLower().Contains(value.ToLower().Trim())), - !behavior.Contains("not"), $"{wrapper.Caption} items are {items.Aggregate((x, y) => $"{x}, {y}")}"); + !behavior.Contains("not"), GenerateErrorMessage(wrapper.Caption, items)); } [Given("user selected \"(.*?)\" in (.*?)")] @@ -143,7 +143,7 @@ private void CheckDropdownValueCollectionEnabled([NotNull] string behavior, [Then("no values should be selected in (.*?):")] public void CheckMultiSelectDropdownHasNoValuesSelected([NotNull] IMultiSelectDropdownWrapper wrapper) { - Assert.ShouldBecome(() => !wrapper.SelectedValuesTexts.Any(), true, $"{wrapper.Caption} has the following values : {wrapper.SelectedValuesTexts.Aggregate((x, y) => $"{x}, {y}")}"); + Assert.ShouldBecome(() => !wrapper.SelectedValuesTexts.Any(), true, GenerateErrorMessage(wrapper.Caption, wrapper.SelectedValuesTexts)); } [Given("(.*?) selected value (is|is not|become|become not) empty")] @@ -164,6 +164,15 @@ private void CheckDropdownElements([NotNull] IEnumerable actualValues, [ $"Expected one of the {valueType} to be {expectedValue} but was {actualValue}"); } } + + /// + /// Method that returns error message with elements aggregation + /// + /// wrapper caption + /// collection of dropdown elements in string form + /// + private string GenerateErrorMessage(string caption, IEnumerable items) + => $"'{caption}' items are: {(items.Any() ? items.Aggregate((x, y) => $"{x}, {y}") : "'none'")}"; } } From ab49226fc6e067ed5291ec858f1034ac4c6388c8 Mon Sep 17 00:00:00 2001 From: Vladimir Semenovich Date: Thu, 24 Feb 2022 19:03:43 +0300 Subject: [PATCH 2/5] refactor: generateerrormessage method changed to address null values --- src/Behavioral.Automation/Bindings/DropdownBinding.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Behavioral.Automation/Bindings/DropdownBinding.cs b/src/Behavioral.Automation/Bindings/DropdownBinding.cs index 6b4ed226..57cefe8f 100644 --- a/src/Behavioral.Automation/Bindings/DropdownBinding.cs +++ b/src/Behavioral.Automation/Bindings/DropdownBinding.cs @@ -172,7 +172,12 @@ private void CheckDropdownElements([NotNull] IEnumerable actualValues, [ /// collection of dropdown elements in string form /// private string GenerateErrorMessage(string caption, IEnumerable items) - => $"'{caption}' items are: {(items.Any() ? items.Aggregate((x, y) => $"{x}, {y}") : "'none'")}"; + { + if (items == null || !items.Any()) + return $"'{caption}' is empty"; + + return $"'{caption}' items are: {items.Aggregate((x, y) => $"{x}, {y}")}"; + } } } From 1f032f5694cd6026c6ece7de4b05cbed6f5bb689 Mon Sep 17 00:00:00 2001 From: Vladimir Semenovich Date: Fri, 25 Feb 2022 11:12:17 +0300 Subject: [PATCH 3/5] feat: add version record to changelog.md --- CHANGELOG.md | 4 ++++ src/Behavioral.Automation/Behavioral.Automation.csproj | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8f3d347..5f8bfbac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ 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.8.6] - 2022-01-25 +### Fixed +- Error when calling Aggregate() to generate message for DropdownWrapper + [1.8.5] - 2022-01-27 ### Changed - Bindings code refactoring diff --git a/src/Behavioral.Automation/Behavioral.Automation.csproj b/src/Behavioral.Automation/Behavioral.Automation.csproj index 9c0a50c8..fec60278 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.8.5 + 1.8.6 https://github.com/quantori/Behavioral.Automation true true From 382fe1b1a74c27643c6a5f05215b47e9a6d9f341 Mon Sep 17 00:00:00 2001 From: Vladimir Semenovich Date: Fri, 25 Feb 2022 11:34:34 +0300 Subject: [PATCH 4/5] feat: move message generator to PrintValuesHelper.cs and modify it to extension method --- .../Bindings/DropdownBinding.cs | 23 ++++--------------- .../Services/PrintValuesHelper.cs | 17 ++++++++++++++ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/Behavioral.Automation/Bindings/DropdownBinding.cs b/src/Behavioral.Automation/Bindings/DropdownBinding.cs index f6cb0813..5d919cc5 100644 --- a/src/Behavioral.Automation/Bindings/DropdownBinding.cs +++ b/src/Behavioral.Automation/Bindings/DropdownBinding.cs @@ -4,6 +4,7 @@ using Behavioral.Automation.Elements; using Behavioral.Automation.FluentAssertions; using Behavioral.Automation.Model; +using Behavioral.Automation.Services; using JetBrains.Annotations; using TechTalk.SpecFlow; @@ -92,7 +93,7 @@ public void CheckDropdownContainsItems( Assert.ShouldBecome( () => wrapper.Items.Contains(value), !behavior.Contains("not"), - GenerateErrorMessage(wrapper.Caption, wrapper.Items)); + wrapper.Items.CreateDropdownErrorMessage(wrapper.Caption)); } /// @@ -119,7 +120,7 @@ public void CheckDropdownContainsMultipleItems([NotNull] IDropdownWrapper wrappe { var value = row.Values.FirstOrDefault(); Assert.ShouldBecome(()=>dropdownItems.Contains(value), !behavior.Contains("not"), - GenerateErrorMessage(wrapper.Caption, dropdownItems)); + dropdownItems.CreateDropdownErrorMessage(wrapper.Caption)); } } @@ -140,7 +141,7 @@ public void CheckAllItemsContainString( Assert.ShouldBecome(() => wrapper.Stale, false, $"{wrapper.Caption} is stale"); var items = wrapper.Items; Assert.ShouldBecome(() => wrapper.Items.All(x => x.ToLower().Contains(value.ToLower().Trim())), - !behavior.Contains("not"), GenerateErrorMessage(wrapper.Caption, items)); + !behavior.Contains("not"), items.CreateDropdownErrorMessage(wrapper.Caption)); } /// @@ -258,7 +259,7 @@ private void CheckDropdownValueCollectionEnabled([NotNull] string behavior, [Then("no values should be selected in (.*?):")] public void CheckMultiSelectDropdownHasNoValuesSelected([NotNull] IMultiSelectDropdownWrapper wrapper) { - Assert.ShouldBecome(() => !wrapper.SelectedValuesTexts.Any(), true, GenerateErrorMessage(wrapper.Caption, wrapper.SelectedValuesTexts)); + Assert.ShouldBecome(() => !wrapper.SelectedValuesTexts.Any(), true, wrapper.SelectedValuesTexts.CreateDropdownErrorMessage(wrapper.Caption)); } /// @@ -296,20 +297,6 @@ public void ClearSelectedValues([NotNull] IMultiSelectDropdownWrapper wrapper) { wrapper.ClearSelectedValues(); } - - /// - /// Method that returns error message with elements aggregation - /// - /// wrapper caption - /// collection of dropdown elements in string form - /// - private string GenerateErrorMessage(string caption, IEnumerable items) - { - if (items == null || !items.Any()) - return $"'{caption}' is empty"; - - return $"'{caption}' items are: {items.Aggregate((x, y) => $"{x}, {y}")}"; - } } } diff --git a/src/Behavioral.Automation/Services/PrintValuesHelper.cs b/src/Behavioral.Automation/Services/PrintValuesHelper.cs index cb76133e..b35978b1 100644 --- a/src/Behavioral.Automation/Services/PrintValuesHelper.cs +++ b/src/Behavioral.Automation/Services/PrintValuesHelper.cs @@ -17,5 +17,22 @@ public static string GetPrintableValues([NotNull] this IEnumerable + /// Method that returns error message with elements aggregation + /// + /// wrapper caption + /// collection of dropdown elements in string form + /// Error message with actual collection items + public static string CreateDropdownErrorMessage(this IEnumerable items, string caption) + { + caption ??= "Collection"; + if (items == null || !items.Any()) + return $"'{caption}' is empty"; + + return $"Actual '{caption}' items are: {items.Aggregate((x, y) => $"{x}, {y}")}"; + } } } From 8a6a6ee6eaf2a86752dd819e54d47c3f1103a54e Mon Sep 17 00:00:00 2001 From: Vladimir Semenovich Date: Fri, 25 Feb 2022 11:41:08 +0300 Subject: [PATCH 5/5] fix: remove empty lines --- src/Behavioral.Automation/Services/PrintValuesHelper.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Behavioral.Automation/Services/PrintValuesHelper.cs b/src/Behavioral.Automation/Services/PrintValuesHelper.cs index b35978b1..ecfd6309 100644 --- a/src/Behavioral.Automation/Services/PrintValuesHelper.cs +++ b/src/Behavioral.Automation/Services/PrintValuesHelper.cs @@ -17,8 +17,6 @@ public static string GetPrintableValues([NotNull] this IEnumerable /// Method that returns error message with elements aggregation