public void GivenICreateEntityEachAssociatedWithEntity(int numTargetEntities, string targetEntityName, int numSourceEntities, string referenceOppositeName, string association) { _initialAssociation = association; var sharedReferences = new Dictionary <string, ICollection <Guid> >() { { referenceOppositeName + "Id", new List <Guid>() } }; var targetEntityFactory = new EntityFactory(targetEntityName); var sourceEntityName = targetEntityFactory.Construct().References.FirstOrDefault(x => x.OppositeName == referenceOppositeName)?.EntityName; var sourceEntityFactory = new EntityFactory(sourceEntityName); for (var i = 0; i < numSourceEntities; i++) { var entity = sourceEntityFactory.Construct(); entity.Configure(BaseEntity.ConfigureOptions.CREATE_ATTRIBUTES_AND_REFERENCES); entity.Save(); sharedReferences[referenceOppositeName + "Id"].Add(entity.Id); _sourceEntities.Add(entity); } for (var i = 0; i < numTargetEntities; i++) { var entity = targetEntityFactory.Construct(); entity.Configure(BaseEntity.ConfigureOptions.CREATE_ATTRIBUTES_AND_REFERENCES); entity.SetReferences(sharedReferences); entity.Save(); _targetEntities.Add(entity); } }
public BaseEntity ApplyDetails(string entityName, bool isValid) { var entityFactory = new EntityFactory(entityName); var entity = entityFactory.Construct(isValid); entity.Configure(BaseEntity.ConfigureOptions.CREATE_ATTRIBUTES_AND_REFERENCES); CreateDetailSection(entityName, entity).Apply(); return(entity); }
private List <BaseEntity> CreateReferencedEntities(EntityFactory entityFactory, int numEntities) { // get the list of entities we will be creating var entityList = entityFactory.Construct(numEntities); //iterate overall of our references and recursively create them. foreach (var entity in entityList) { foreach (var reference in entity.References) { var referenceIdName = reference.OppositeName + "Id"; // check if the reference has already been filled out if (!entity.ReferenceIdDictionary.ContainsKey(referenceIdName)) { //ignore self references if (!reference.Optional) { var createdEntity = CreateEntities(new EntityFactory(reference.EntityName, entityFactory.GetFixedString()), 1); var referenceDictionary = new Dictionary <string, ICollection <Guid> >() { { referenceIdName, new List <Guid> { createdEntity[0].Id } } }; //add the created entity to our dictionary for the child entity for all entities in the list if (reference.Type == ReferenceType.ONE && reference.OppositeType == ReferenceType.ONE) { // if one-to-one each reference must be unique entityList.FirstOrDefault(x => x == entity).SetReferences(referenceDictionary); entityList.FirstOrDefault(x => x == entity).ReferenceIdDictionary[referenceIdName] = createdEntity[0].Id; entityList.FirstOrDefault(x => x == entity).ParentEntities.Add(createdEntity[0]); } else { // if one-to-many or many-to-many entities can share a reference. entityList.ForEach(x => x.SetReferences(referenceDictionary)); entityList.ForEach(x => x.ReferenceIdDictionary[referenceIdName] = createdEntity[0].Id); entityList.ForEach(x => x.ParentEntities.Add(createdEntity[0])); } } } } } return(entityList); }
public void IVerifyAWarningForLiveValidators(ValidatorType validator, string attribute, ValidatorActionType validatorType) { var factory = new EntityFactory(_entityName); var entity = factory.Construct(); var invalidAttribute = entity.GetInvalidAttribute(attribute, validator.ToString().ToLower().Capitalize()); var createPageDetailsSection = EntityDetailUtils.GetEntityDetailsSection(_entityName, _contextConfiguration); createPageDetailsSection.SetInputElement(attribute, invalidAttribute); switch (validatorType) { case ValidatorActionType.ON_SUBMIT: _createPage.SubmitButton.Click(); break; case ValidatorActionType.LIVE: createPageDetailsSection.GetInputElement(attribute).SendKeys(Keys.Tab); break; } var errors = createPageDetailsSection.GetErrorMessagesForAttribute(attribute); switch (validator) { case ValidatorType.LENGTH: //(int min, int max) attributeLengthMinMax = entity.GetLengthValidatorMinMax(attribute); //Assert.Contains($"The length of this field is not less than {attributeLengthMinMax.max}. Actual Length: {attributeLengthMinMax.max + 1}", errors); (_, int max) = entity.GetLengthValidatorMinMax(attribute); Assert.Contains($"The length of this field is not less than {max}. Actual Length: {max + 1}", errors); break; case ValidatorType.EMAIL: Assert.Contains($"The value is not a valid email", errors); break; case ValidatorType.NUMERIC: Assert.Contains("You can only use numbers in this field", errors); break; case ValidatorType.REQUIRED: Assert.Contains("This field is required", errors); break; default: throw new Exception($"{validator} is not a valid validator"); } }
public void GraphqlBatchUpdateEntities(EntityFactory entityFactory, int numEntities) { var entity = entityFactory.Construct(); var entityProperties = entity.GetType().GetProperties(); if (entityProperties.Any(x => x.PropertyType.IsEnum) || entity.HasFile) { throw new SkipException("Batch update is currently not supported on entities with enum or file"); } var entityList = entityFactory.ConstructAndSave(_output, numEntities); //setup the rest client var client = new RestClient { BaseUrl = new Uri($"{_configure.BaseUrl}/api/graphql") }; //setup the request var request = new RestRequest { Method = Method.POST, RequestFormat = DataFormat.Json }; //get the authorization token and adds the token to the request var loginToken = new LoginToken(_configure.BaseUrl, _configure.SuperUsername, _configure.SuperPassword); var authorizationToken = $"{loginToken.TokenType} {loginToken.AccessToken}"; request.AddHeader("Authorization", authorizationToken); request.AddHeader("Content-Type", "application/json"); request.AddHeader("Accept", "*\\*"); // form the query to update the entity var updateQuery = QueryBuilder.BatchUpdateEntityQueryBuilder(entityList); request.AddParameter("text/json", updateQuery, ParameterType.RequestBody); // mass update all entities in the list in a single request and check status code is ok RequestHelpers.ValidateResponse(client, Method.POST, request, HttpStatusCode.OK); }