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

Issue # 94 - Added a new binding and unit test to assert if the auto-… #161

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using Capgemini.PowerApps.SpecFlowBindings.Extensions;
using FluentAssertions;
using Microsoft.Dynamics365.UIAutomation.Api.UCI;
Expand Down Expand Up @@ -492,6 +493,78 @@ public static void ThenTheStatusOfTheRecordIs(string status)
XrmApp.Entity.GetFormState().Should().BeEquivalentTo(status);
}

/// <summary>
/// Asserts that auto-number field has value in given format or not. The input format copies those defined by the https://learn.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/create-auto-number-attributes?view=op-9-1#autonumberformat-options.
/// </summary>
/// <param name="formatToMatch">The format to match with</param>
/// <param name="fieldName">The name of the field.</param>
/// <param name="fieldLocation">The location of the field.</param>
[Then(@"I can see a value with the format '(.*)' in the '(.*)' auto-number (field|header field)")]
public void ThenICanSeeAValueWithTheFormatInTheAuto_NumberFieldHeaderField(string formatToMatch, string fieldName, string fieldLocation)
{
string[] inputFormatElements = formatToMatch.Split('-');
var fieldValue = fieldLocation == "field" ? XrmApp.Entity.GetValue(fieldName) : XrmApp.Entity.GetHeaderValue(fieldName);
string[] inputValueElements = fieldValue.Split('-');
string patternNotMatched = string.Empty;
string notAllPatternsExists = string.Empty;
int minLength;
if (inputFormatElements.Length > 0 && inputValueElements.Length > 0 && inputFormatElements.Length == inputValueElements.Length)
{
for (int i = 0; i < inputFormatElements.Length; i++)
{
switch (inputFormatElements[i])
{
case string _ when inputFormatElements[i].Contains("SEQNUM"):
minLength = int.Parse(Regex.Match(inputFormatElements[i], @"\d+").Value);
Regex regexToMatchSeqNum = new Regex(@"^\d{" + minLength + ",}");
if (!regexToMatchSeqNum.IsMatch(inputValueElements[i]))
{
patternNotMatched += " SEQNUM,";
}

break;
case string _ when inputFormatElements[i].Contains("RANDSTRING"):
minLength = int.Parse(Regex.Match(inputFormatElements[i], @"\d+").Value);
Regex regexToMatchRandString = new Regex(@"^[a-zA-Z0-9]{" + minLength + ",}");
if (!regexToMatchRandString.IsMatch(inputValueElements[i]))
{
patternNotMatched += " RANDSTRING,";
}

break;
case string _ when inputFormatElements[i].Contains("DATETIMEUTC"):
string dateTimeFormat = inputFormatElements[i].Split(':').GetValue(1).ToString().Trim('}');
try
{
var parsedDate = DateTime.ParseExact(inputValueElements[i], dateTimeFormat, CultureInfo.InvariantCulture);
}
catch (FormatException)
{
patternNotMatched += " DATETIMEUTC,";
}

break;
default:
patternNotMatched += (inputValueElements[i] == inputFormatElements[i]) ? null : " Static Characters,";
break;
}
}
}
else
{
notAllPatternsExists += "The no. of input pattern and that are in auto-number field value does not match.";
}

if (!patternNotMatched.IsEmptyValue())
{
throw new Exception("The auto-number field value does not match the following pattern/s - " + patternNotMatched.Trim(','));
}
else if (!notAllPatternsExists.IsEmptyValue())
{
throw new Exception(notAllPatternsExists);
}
}

private static void SetFieldValue(string fieldName, string fieldValue, string fieldType)
{
switch (fieldType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,10 @@ Scenario: Assert field not editable
Scenario: Assert fields not editable
Then I can not edit the following fields
| Field |
| createdonbehalfby |
| createdonbehalfby |

Scenario: Assert if the auto-number field contains value as per the input pattern/format
When I enter 'Some text' into the 'sb_name' text field on the form
And I save the record
Then I can see a value with the format 'SB-{SEQNUM:4}-{RANDSTRING:6}-{DATETIMEUTC:yyyyMMddhhmm}' in the 'sb_autonumberone' auto-number header field
And I can see a value with the format '{DATETIMEUTC:yyyyddMM}-{SEQNUM:4}' in the 'sb_autonumbertwo' auto-number field
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<AppModuleSiteMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SiteMapUniqueName>sb_MockApp</SiteMapUniqueName>
<EnableCollapsibleGroups>False</EnableCollapsibleGroups>
<ShowHome>True</ShowHome>
<ShowPinned>True</ShowPinned>
<ShowRecents>True</ShowRecents>
<SiteMap IntroducedVersion="7.0.0.0">
<Area Id="area_primary" ResourceId="SitemapDesigner.NewArea" DescriptionResourceId="SitemapDesigner.NewArea" ShowGroups="true" IntroducedVersion="7.0.0.0">
<Titles>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<AppModuleSiteMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SiteMapUniqueName>sb_MockApp</SiteMapUniqueName>
<EnableCollapsibleGroups>False</EnableCollapsibleGroups>
<ShowHome>True</ShowHome>
<ShowPinned>True</ShowPinned>
<ShowRecents>True</ShowRecents>
<SiteMap IntroducedVersion="7.0.0.0">
<Area Id="area_primary" ResourceId="SitemapDesigner.NewArea" DescriptionResourceId="SitemapDesigner.NewArea" ShowGroups="true" IntroducedVersion="7.0.0.0">
<Titles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@
<Name>owningbusinessunit</Name>
<LogicalName>owningbusinessunit</LogicalName>
<RequiredLevel>none</RequiredLevel>
<DisplayMask>ValidForAdvancedFind|ValidForForm|ValidForGrid</DisplayMask>
<ImeMode>auto</ImeMode>
<ValidForUpdateApi>0</ValidForUpdateApi>
<ValidForReadApi>1</ValidForReadApi>
Expand Down Expand Up @@ -564,6 +565,86 @@
<Description description="Contains the id of the process associated with the entity." languagecode="1033" />
</Descriptions>
</attribute>
<attribute PhysicalName="sb_AutonumberOne">
<Type>nvarchar</Type>
<Name>sb_autonumberone</Name>
<LogicalName>sb_autonumberone</LogicalName>
<RequiredLevel>none</RequiredLevel>
<DisplayMask>ReadOnlyInUI|ValidForAdvancedFind|ValidForForm|ValidForGrid</DisplayMask>
<ImeMode>auto</ImeMode>
<ValidForUpdateApi>1</ValidForUpdateApi>
<ValidForReadApi>1</ValidForReadApi>
<ValidForCreateApi>1</ValidForCreateApi>
<IsCustomField>1</IsCustomField>
<IsAuditEnabled>1</IsAuditEnabled>
<IsSecured>0</IsSecured>
<IntroducedVersion>1.0.0.2</IntroducedVersion>
<IsCustomizable>1</IsCustomizable>
<IsRenameable>1</IsRenameable>
<CanModifySearchSettings>1</CanModifySearchSettings>
<CanModifyRequirementLevelSettings>1</CanModifyRequirementLevelSettings>
<CanModifyAdditionalSettings>1</CanModifyAdditionalSettings>
<SourceType>0</SourceType>
<IsGlobalFilterEnabled>0</IsGlobalFilterEnabled>
<IsSortableEnabled>0</IsSortableEnabled>
<CanModifyGlobalFilterSettings>1</CanModifyGlobalFilterSettings>
<CanModifyIsSortableSettings>1</CanModifyIsSortableSettings>
<IsDataSourceSecret>0</IsDataSourceSecret>
<AutoNumberFormat>SB-{SEQNUM:4}-{RANDSTRING:6}-{DATETIMEUTC:yyyyMMddhhmm}</AutoNumberFormat>
<IsSearchable>0</IsSearchable>
<IsFilterable>0</IsFilterable>
<IsRetrievable>0</IsRetrievable>
<IsLocalizable>0</IsLocalizable>
<Format>text</Format>
<MaxLength>100</MaxLength>
<Length>200</Length>
<displaynames>
<displayname description="Auto-number 1" languagecode="1033" />
</displaynames>
<Descriptions>
<Description description="" languagecode="1033" />
</Descriptions>
</attribute>
<attribute PhysicalName="sb_AutonumberTwo">
<Type>nvarchar</Type>
<Name>sb_autonumbertwo</Name>
<LogicalName>sb_autonumbertwo</LogicalName>
<RequiredLevel>none</RequiredLevel>
<DisplayMask>ReadOnlyInUI|ValidForAdvancedFind|ValidForForm|ValidForGrid</DisplayMask>
<ImeMode>auto</ImeMode>
<ValidForUpdateApi>1</ValidForUpdateApi>
<ValidForReadApi>1</ValidForReadApi>
<ValidForCreateApi>1</ValidForCreateApi>
<IsCustomField>1</IsCustomField>
<IsAuditEnabled>1</IsAuditEnabled>
<IsSecured>0</IsSecured>
<IntroducedVersion>1.0.0.2</IntroducedVersion>
<IsCustomizable>1</IsCustomizable>
<IsRenameable>1</IsRenameable>
<CanModifySearchSettings>1</CanModifySearchSettings>
<CanModifyRequirementLevelSettings>1</CanModifyRequirementLevelSettings>
<CanModifyAdditionalSettings>1</CanModifyAdditionalSettings>
<SourceType>0</SourceType>
<IsGlobalFilterEnabled>0</IsGlobalFilterEnabled>
<IsSortableEnabled>0</IsSortableEnabled>
<CanModifyGlobalFilterSettings>1</CanModifyGlobalFilterSettings>
<CanModifyIsSortableSettings>1</CanModifyIsSortableSettings>
<IsDataSourceSecret>0</IsDataSourceSecret>
<AutoNumberFormat>{DATETIMEUTC:yyyyddMM}-{SEQNUM:4}</AutoNumberFormat>
<IsSearchable>0</IsSearchable>
<IsFilterable>0</IsFilterable>
<IsRetrievable>0</IsRetrievable>
<IsLocalizable>0</IsLocalizable>
<Format>text</Format>
<MaxLength>100</MaxLength>
<Length>200</Length>
<displaynames>
<displayname description="Auto-number 2" languagecode="1033" />
</displaynames>
<Descriptions>
<Description description="" languagecode="1033" />
</Descriptions>
</attribute>
<attribute PhysicalName="sb_Choice">
<Type>picklist</Type>
<Name>sb_choice</Name>
Expand Down Expand Up @@ -1910,6 +1991,7 @@
<IsDocumentRecommendationsEnabled>0</IsDocumentRecommendationsEnabled>
<IsBPFEntity>0</IsBPFEntity>
<OwnershipTypeMask>UserOwned</OwnershipTypeMask>
<EntityMask>ActivityPointer</EntityMask>
<IsAuditEnabled>0</IsAuditEnabled>
<IsRetrieveAuditEnabled>0</IsRetrieveAuditEnabled>
<IsRetrieveMultipleAuditEnabled>0</IsRetrieveMultipleAuditEnabled>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
<control id="sb_name" classid="{4273EDBD-AC1D-40d3-9FB2-095C621B552D}" datafieldname="sb_name" />
</cell>
</row>
<row>
<cell id="{611d8d20-211c-8077-0330-3d381e17ee85}" showlabel="true" locklevel="0">
<labels>
<label description="Auto-number 2" languagecode="1033" />
</labels>
<control id="sb_autonumbertwo" classid="{4273EDBD-AC1D-40d3-9FB2-095C621B552D}" datafieldname="sb_autonumbertwo" disabled="false" />
</cell>
</row>
<row>
<cell id="{ee7e9058-7950-4797-b682-01eeee93f0ab}" locklevel="0">
<labels>
Expand Down Expand Up @@ -246,10 +254,11 @@
<label description="" languagecode="1033" />
</labels>
</cell>
<cell id="{6ba2785a-8c2c-4f55-9bce-977862b81864}" showlabel="false">
<cell id="{8d465b85-3ba5-758c-d3b0-6575e13ec6e7}" showlabel="true" locklevel="0">
<labels>
<label description="" languagecode="1033" />
<label description="Auto-number 1" languagecode="1033" />
</labels>
<control id="header_sb_autonumberone" classid="{4273EDBD-AC1D-40d3-9FB2-095C621B552D}" datafieldname="sb_autonumberone" disabled="false" />
</cell>
<cell id="{10fc1664-f736-4dbd-a625-953d789d9146}" locklevel="0">
<labels>
Expand Down Expand Up @@ -359,9 +368,6 @@
</row>
</rows>
</footer>
<DisplayConditions Order="0" FallbackForm="true">
<Everyone />
</DisplayConditions>
<formLibraries>
<Library name="sb_/js/sb_mockrecord.form.js" libraryUniqueId="{14cfe9ba-3f37-439c-b6e6-28bebb4cc0ad}" />
</formLibraries>
Expand All @@ -372,6 +378,39 @@
</Handlers>
</event>
</events>
<Navigation>
<NavBar></NavBar>
<NavBarAreas>
<NavBarArea Id="Info">
<Titles>
<Title LCID="1033" Text="Common" />
</Titles>
</NavBarArea>
<NavBarArea Id="Sales">
<Titles>
<Title LCID="1033" Text="Sales" />
</Titles>
</NavBarArea>
<NavBarArea Id="Service">
<Titles>
<Title LCID="1033" Text="Service" />
</Titles>
</NavBarArea>
<NavBarArea Id="Marketing">
<Titles>
<Title LCID="1033" Text="Marketing" />
</Titles>
</NavBarArea>
<NavBarArea Id="ProcessCenter">
<Titles>
<Title LCID="1033" Text="Process Sessions" />
</Titles>
</NavBarArea>
</NavBarAreas>
</Navigation>
<DisplayConditions Order="0" FallbackForm="true">
<Everyone />
</DisplayConditions>
</form>
<IsCustomizable>1</IsCustomizable>
<CanBeDeleted>1</CanBeDeleted>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
<control id="sb_name" classid="{4273EDBD-AC1D-40d3-9FB2-095C621B552D}" datafieldname="sb_name" />
</cell>
</row>
<row>
<cell id="{611d8d20-211c-8077-0330-3d381e17ee85}" showlabel="true" locklevel="0">
<labels>
<label description="Auto-number 2" languagecode="1033" />
</labels>
<control id="sb_autonumbertwo" classid="{4273EDBD-AC1D-40d3-9FB2-095C621B552D}" datafieldname="sb_autonumbertwo" disabled="false" />
</cell>
</row>
<row>
<cell id="{ee7e9058-7950-4797-b682-01eeee93f0ab}" locklevel="0">
<labels>
Expand Down Expand Up @@ -246,10 +254,11 @@
<label description="" languagecode="1033" />
</labels>
</cell>
<cell id="{6ba2785a-8c2c-4f55-9bce-977862b81864}" showlabel="false">
<cell id="{8d465b85-3ba5-758c-d3b0-6575e13ec6e7}" showlabel="true" locklevel="0">
<labels>
<label description="" languagecode="1033" />
<label description="Auto-number 1" languagecode="1033" />
</labels>
<control id="header_sb_autonumberone" classid="{4273EDBD-AC1D-40d3-9FB2-095C621B552D}" datafieldname="sb_autonumberone" disabled="false" />
</cell>
<cell id="{10fc1664-f736-4dbd-a625-953d789d9146}" locklevel="0">
<labels>
Expand Down Expand Up @@ -359,9 +368,6 @@
</row>
</rows>
</footer>
<DisplayConditions Order="0" FallbackForm="true">
<Everyone />
</DisplayConditions>
<formLibraries>
<Library name="sb_/js/sb_mockrecord.form.js" libraryUniqueId="{14cfe9ba-3f37-439c-b6e6-28bebb4cc0ad}" />
</formLibraries>
Expand All @@ -372,6 +378,39 @@
</Handlers>
</event>
</events>
<Navigation>
<NavBar></NavBar>
<NavBarAreas>
<NavBarArea Id="Info">
<Titles>
<Title LCID="1033" Text="Common" />
</Titles>
</NavBarArea>
<NavBarArea Id="Sales">
<Titles>
<Title LCID="1033" Text="Sales" />
</Titles>
</NavBarArea>
<NavBarArea Id="Service">
<Titles>
<Title LCID="1033" Text="Service" />
</Titles>
</NavBarArea>
<NavBarArea Id="Marketing">
<Titles>
<Title LCID="1033" Text="Marketing" />
</Titles>
</NavBarArea>
<NavBarArea Id="ProcessCenter">
<Titles>
<Title LCID="1033" Text="Process Sessions" />
</Titles>
</NavBarArea>
</NavBarAreas>
</Navigation>
<DisplayConditions Order="0" FallbackForm="true">
<Everyone />
</DisplayConditions>
</form>
<IsCustomizable>1</IsCustomizable>
<CanBeDeleted>1</CanBeDeleted>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@
<Name>owningbusinessunit</Name>
<LogicalName>owningbusinessunit</LogicalName>
<RequiredLevel>none</RequiredLevel>
<DisplayMask>ValidForAdvancedFind|ValidForForm|ValidForGrid</DisplayMask>
<ImeMode>auto</ImeMode>
<ValidForUpdateApi>0</ValidForUpdateApi>
<ValidForReadApi>1</ValidForReadApi>
Expand Down