public static EntityReference GetLookupValue(CrmTestingContext context, string alias, string targetEntity, IEnumerable <ConditionExpression> addtionalLookupFilters) { Logger.WriteLine($"Getting lookupvalue for entity {targetEntity}"); var result = context.RecordCache.Get(alias); if (result != null) { Logger.WriteLine($"Cached record found"); return(result); } var targetMd = GlobalTestingContext.Metadata.GetEntityMetadata(targetEntity); Logger.WriteLine($"Querying lookup in CRM"); QueryExpression qe = new QueryExpression(targetEntity) { ColumnSet = new ColumnSet(targetMd.PrimaryNameAttribute) }; qe.Criteria.AddCondition(targetMd.PrimaryNameAttribute, ConditionOperator.Equal, alias); if (addtionalLookupFilters != null) { foreach (var filter in addtionalLookupFilters) { qe.Criteria.AddCondition(filter); } } var col = GlobalTestingContext.ConnectionManager.CurrentConnection.RetrieveMultiple(qe); Logger.WriteLine($"Looked for {targetEntity} with {targetMd.PrimaryNameAttribute} is {alias}. Found {col.Entities.Count} records"); return(col.Entities.FirstOrDefault()?.ToEntityReference(targetMd.PrimaryNameAttribute)); }
/// <summary> /// Asserts if an entity has all of the field/value combinations. /// </summary> /// <param name="record"></param> /// <param name="criteria"></param> /// <param name="context"></param> public static void HasProperties(Entity record, Table criteria, CrmTestingContext context) { List <string> errors = new List <string>(); foreach (var row in criteria.Rows) { var actualValue = record.Contains(row[Constants.SpecFlow.TABLE_KEY]) ? record[row[Constants.SpecFlow.TABLE_KEY]] : null; var expectedValue = ObjectConverter.ToCrmObject(record.LogicalName, row[Constants.SpecFlow.TABLE_KEY], row[Constants.SpecFlow.TABLE_VALUE], context); try { AreEqual(actualValue, expectedValue, row[Constants.SpecFlow.TABLE_KEY]); } catch (AssertFailedException ex) { Logger.WriteLine(ex.Message); errors.Add(ex.Message); } } if (errors.Count > 0) { Assert.Fail($"At least one error occured when asseting fields. Errors: {string.Join(Environment.NewLine, errors)}"); } }
public Hooks(SeleniumTestingContext seleniumTestingContext, CrmTestingContext crmContext, FeatureContext featureContext, ScenarioContext scenarioContext) { _seleniumContext = seleniumTestingContext; _crmContext = crmContext; _featureContext = featureContext; _scenarioContext = scenarioContext; }
public static Entity[] GetActivePath(CrmTestingContext crmContext, Entity instance) { var req = new RetrieveActivePathRequest() { ProcessInstanceId = instance.Id }; return(GlobalTestingContext.ConnectionManager.CurrentConnection.Execute <RetrieveActivePathResponse>(req).ProcessStages.Entities.ToArray()); }
public SeleniumTestingContext(CrmTestingContext crmContext) { _crmContext = crmContext; BrowserOptions = new BrowserOptions() { CleanSession = true, StartMaximized = true, UCITestMode = true, }; CurrentApp = HelperMethods.GetAppSettingsValue("AppName", true); }
private static object ParseVirtualType(CrmTestingContext context, AttributeMetadata metadata, string value) { if (metadata.AttributeTypeName == AttributeTypeDisplayName.MultiSelectPicklistType) { return(new OptionSetValueCollection(value.Split(',').Select(v => GetOptionSetValue(metadata, v.Trim(), context)).ToList())); } else { throw new NotImplementedException(string.Format("Virtual type {0} not implemented", metadata.AttributeTypeName.Value)); } }
public SeleniumTestingContext(CrmTestingContext crmContext) { _crmContext = crmContext; BrowserOptions = new BrowserOptions() { CleanSession = true, DriversPath = null, StartMaximized = true, PrivateMode = true, UCITestMode = true, }; CurrentApp = HelperMethods.GetAppSettingsValue("AppName", true); BrowserOptions.Headless = Convert.ToBoolean(HelperMethods.GetAppSettingsValue("Headless", true, "false")); }
private static EntityReference GetLookupValue(CrmTestingContext context, AttributeMetadata metadata, string alias) { var lookupMd = (LookupAttributeMetadata)metadata; foreach (string targetEntity in lookupMd.Targets) { var result = GetLookupValue(context, alias, targetEntity); if (result != null) { return(result); } } throw new TestExecutionException(Constants.ErrorCodes.LOOKUP_NOT_FOUND, alias, string.Join(", ", lookupMd.Targets)); }
public static Entity GetProcessInstanceOfRecord(CrmTestingContext crmContext, EntityReference crmRecord) { if (crmRecord == null) { return(null); } var request = new RetrieveProcessInstancesRequest() { EntityId = crmRecord.Id, EntityLogicalName = crmRecord.LogicalName }; var response = GlobalTestingContext.ConnectionManager.CurrentConnection.Execute <RetrieveProcessInstancesResponse>(request); return(response.Processes.Entities.FirstOrDefault()); }
public static CommandAction GetPreferredCommandActionFromTarget(CrmTestingContext crmContext) { if (crmContext.IsTarget(Constants.SpecFlow.TARGET_API)) { return(CommandAction.PreferApi); } else if (crmContext.IsTarget(Constants.SpecFlow.TARGET_Chrome) || crmContext.IsTarget(Constants.SpecFlow.TARGET_Edge) || crmContext.IsTarget(Constants.SpecFlow.TARGET_Firefox) || crmContext.IsTarget(Constants.SpecFlow.TARGET_InternetExplorer)) { return(CommandAction.ForceBrowser); } else { throw new TestExecutionException(Constants.ErrorCodes.UNKNOWN_TAG); } }
public RecordBuilder(CrmTestingContext context) { _crmContext = context; _defaultData = ReadDefaultData(); }
private static object GetConvertedValue(CrmTestingContext context, AttributeMetadata metadata, string value, ConvertedObjectType objectType) { switch (metadata.AttributeType) { case AttributeTypeCode.Boolean: return(GetTwoOptionValue(metadata, value, context)); case AttributeTypeCode.Double: return(double.Parse(value, NumberFormatInfo.InvariantInfo)); case AttributeTypeCode.Decimal: return(decimal.Parse(value, NumberFormatInfo.InvariantInfo)); case AttributeTypeCode.Integer: return(int.Parse(value, NumberFormatInfo.InvariantInfo)); case AttributeTypeCode.DateTime: return(ParseDateTime(metadata, value)); case AttributeTypeCode.Memo: case AttributeTypeCode.String: return(value); case AttributeTypeCode.Money: if (objectType == ConvertedObjectType.Primitive) { return(decimal.Parse(value, NumberFormatInfo.InvariantInfo)); } else { return(new Money(decimal.Parse(value, NumberFormatInfo.InvariantInfo))); } case AttributeTypeCode.Picklist: case AttributeTypeCode.State: case AttributeTypeCode.Status: var optionSet = GetOptionSetValue(metadata, value, context); if (objectType == ConvertedObjectType.Primitive) { return(optionSet.Value); } else { return(optionSet); } case AttributeTypeCode.Customer: case AttributeTypeCode.Lookup: case AttributeTypeCode.Owner: var lookup = GetLookupValue(context, metadata, value); if (objectType == ConvertedObjectType.Primitive) { return(lookup.Id); } else { return(lookup); } case AttributeTypeCode.Uniqueidentifier: return(GetLookupValue(context, metadata, value).Id); case AttributeTypeCode.Virtual: return(ParseVirtualType(context, metadata, value)); default: throw new NotImplementedException(string.Format("Type {0} not implemented", metadata.AttributeType)); } }
public static object ToCrmObject(string entityName, string attributeName, string value, CrmTestingContext context, ConvertedObjectType objectType = ConvertedObjectType.Default) { Logger.WriteLine($"Converting CRM Object. Entity: {entityName}, Attribute: {attributeName}, Value: {value}, ObjectType: {objectType}"); if (string.IsNullOrWhiteSpace(value)) { return(null); } var metadata = GlobalTestingContext.Metadata.GetAttributeMetadata(entityName, attributeName); object convertedValue = GetConvertedValue(context, metadata, value, objectType); Logger.WriteLine($"ConvertedValue: {HelperMethods.CrmObjectToPrimitive(convertedValue)}"); return(convertedValue); }
/// <summary> /// Gets the TwoOptionValue. /// /// For UI type it will return the same text, but just verifies if the text is a valid option /// For other types it will return a boolean that matches the text /// </summary> /// <param name="metadata"></param> /// <param name="value"></param> /// <param name="context"></param> /// <param name="objectType"></param> /// <returns></returns> private static object GetTwoOptionValue(AttributeMetadata metadata, string value, CrmTestingContext context) { var optionMd = metadata as BooleanAttributeMetadata; if (value.ToLower() == optionMd.OptionSet.TrueOption.Label.GetLabelInLanguage(context.LanguageCode).ToLower()) { return(true); } else if (value.ToLower() == optionMd.OptionSet.FalseOption.Label.GetLabelInLanguage(context.LanguageCode).ToLower()) { return(false); } else { throw new TestExecutionException(Constants.ErrorCodes.OPTION_NOT_FOUND, metadata.LogicalName, value); } }
private static OptionSetValue GetOptionSetValue(AttributeMetadata metadata, string value, CrmTestingContext context) { var optionMd = metadata as EnumAttributeMetadata; var option = optionMd.OptionSet.Options.Where(o => o.Label.IsLabel(context.LanguageCode, value)).FirstOrDefault(); Assert.IsNotNull(option, $"Option {value} not found. AvailaleOptions: { string.Join(", ", optionMd.OptionSet.Options.Select(o => o.Label?.GetLabelInLanguage(context.LanguageCode)))}"); Assert.IsTrue(option.Value.HasValue); return(new OptionSetValue(option.Value.Value)); }
public static EntityReference GetLookupValue(CrmTestingContext context, string alias, string targetEntity) { return(GetLookupValue(context, alias, targetEntity, new ConditionExpression[0])); }
public static SetStateRequest ToSetStateRequest(EntityReference target, string desiredstatus, CrmTestingContext context) { var attributeMd = GlobalTestingContext.Metadata.GetAttributeMetadata(target.LogicalName, Constants.CRM.STATUSCODE) as StatusAttributeMetadata; var optionMd = attributeMd.OptionSet.Options.Where(o => o.Label.IsLabel(context.LanguageCode, desiredstatus)).FirstOrDefault() as StatusOptionMetadata; return(new SetStateRequest() { EntityMoniker = target, State = new OptionSetValue(optionMd.State.Value), Status = new OptionSetValue(optionMd.Value.Value), }); }
public static Entity GetProcessRecord(CrmTestingContext crmContext, EntityReference crmRecord, Guid instanceId) { return(GlobalTestingContext.ConnectionManager.CurrentConnection.Retrieve($"{crmRecord.LogicalName}process", instanceId, new ColumnSet("activestageid"))); }
public static QueryExpression CreateQueryExpressionFromTable(string entityName, Table criteria, CrmTestingContext context) { Logger.WriteLine($"Creating Query for {entityName}"); QueryExpression qe = new QueryExpression(entityName) { ColumnSet = new ColumnSet() }; foreach (var row in criteria.Rows) { var crmValue = ObjectConverter.ToCrmObject(entityName, row[Constants.SpecFlow.TABLE_KEY], row[Constants.SpecFlow.TABLE_VALUE], context, ConvertedObjectType.Primitive); if (crmValue == null) { Logger.WriteLine($"Adding condition {row[Constants.SpecFlow.TABLE_KEY]} IS NULL"); qe.Criteria.AddCondition(row[Constants.SpecFlow.TABLE_KEY], ConditionOperator.Null); } else { Logger.WriteLine($"Adding condition {row[Constants.SpecFlow.TABLE_KEY]} Equals {crmValue}"); qe.Criteria.AddCondition(row[Constants.SpecFlow.TABLE_KEY], ConditionOperator.Equal, crmValue); } } return(qe); }
public TableConverter(CrmTestingContext context) { _context = context; }