public void UpdateCategoryByKeySetExternalIdAndExpandParent() { IClient commerceToolsClient = this.categoryFixture.GetService <IClient>(); Category category = this.categoryFixture.CreateCategory(this.categoryFixture.GetCategoryDraftWithParent()); string externalId = TestingUtility.RandomString(10); //expansions List <Expansion <Category> > expansions = new List <Expansion <Category> >(); ReferenceExpansion <Category> expand = new ReferenceExpansion <Category>(c => c.Parent); expansions.Add(expand); //updateActions List <UpdateAction <Category> > updateActions = new List <UpdateAction <Category> >(); SetExternalIdUpdateAction setKeyAction = new SetExternalIdUpdateAction() { ExternalId = externalId }; updateActions.Add(setKeyAction); Category retrievedCategory = commerceToolsClient.ExecuteAsync(new UpdateByKeyCommand <Category>(category.Key, category.Version, updateActions, expansions)).Result; this.categoryFixture.CategoriesToDelete.Add(retrievedCategory); Assert.Equal(externalId, retrievedCategory.ExternalId); Assert.NotNull(retrievedCategory.Parent.Obj); }
public void AssertEventually(Action runnableBlock, int maxWaitTimeSecond = 180, int waitBeforeRetryMilliseconds = 100) { var maxWaitTime = TimeSpan.FromSeconds(maxWaitTimeSecond); var waitBeforeRetry = TimeSpan.FromMilliseconds(waitBeforeRetryMilliseconds); TestingUtility.AssertEventually(maxWaitTime, waitBeforeRetry, runnableBlock); }
public CategoryDraft GetCategoryDraft() { CategoryDraft categoryDraft = new CategoryDraft(); string categoryName = TestingUtility.RandomString(10); LocalizedString localizedStringName = new LocalizedString(); localizedStringName.Add("en", categoryName); categoryDraft.Name = localizedStringName; string slug = TestingUtility.RandomString(10); LocalizedString localizedStringSlug = new LocalizedString(); localizedStringSlug.Add("en", slug); categoryDraft.Slug = localizedStringSlug; categoryDraft.Key = TestingUtility.RandomString(10); categoryDraft.OrderHint = TestingUtility.RandomSortOrder(); return(categoryDraft); }
/// <summary> /// Update Category set random Key and return updated instance /// </summary> /// <param name="category"></param> /// <returns>Updated Category with newer version and updated random Key</returns> public Category UpdateCategorySetRandomKey(Category category) { IClient commerceToolsClient = this.GetService <IClient>(); List <UpdateAction <Category> > updateActions = new List <UpdateAction <Category> >(); SetKeyUpdateAction setKeyAction = new SetKeyUpdateAction() { Key = TestingUtility.RandomString(10) }; updateActions.Add(setKeyAction); Category updatedCategory = commerceToolsClient .ExecuteAsync(new UpdateByIdCommand <Category>(new Guid(category.Id), category.Version, updateActions)) .Result; return(updatedCategory); }
public void UpdateTypeByIdAddFieldDefinition() { IClient commerceToolsClient = this.typeFixture.GetService <IClient>(); Type type = this.typeFixture.CreateType(); List <UpdateAction <Type> > updateActions = new List <UpdateAction <Type> >(); string newKey = TestingUtility.RandomString(10); AddFieldDefinitionUpdateAction addFieldDefinitionUpdateAction = new AddFieldDefinitionUpdateAction() { FieldDefinition = this.typeFixture.CreateNewStringFieldDefinition() }; updateActions.Add(addFieldDefinitionUpdateAction); Type retrievedType = commerceToolsClient.ExecuteAsync(new UpdateByIdCommand <Type>(new Guid(type.Id), type.Version, updateActions)).Result; this.typeFixture.TypesToDelete.Add(retrievedType); Assert.Equal(type.FieldDefinitions.Count + 1, retrievedType.FieldDefinitions.Count); }
public void UpdateTypeByIdChangeKey() { IClient commerceToolsClient = this.typeFixture.GetService <IClient>(); Type type = this.typeFixture.CreateType(); List <UpdateAction <Type> > updateActions = new List <UpdateAction <Type> >(); string newKey = TestingUtility.RandomString(10); ChangeKeyUpdateAction changeKeyUpdateAction = new ChangeKeyUpdateAction() { Key = newKey }; updateActions.Add(changeKeyUpdateAction); Type retrievedType = commerceToolsClient.ExecuteAsync(new UpdateByIdCommand <Type>(new Guid(type.Id), type.Version, updateActions)).Result; this.typeFixture.TypesToDelete.Add(retrievedType); Assert.Equal(newKey, retrievedType.Key); }
public void UpdateCategoryByKeySetExternalId() { IClient commerceToolsClient = this.categoryFixture.GetService <IClient>(); Category category = this.categoryFixture.CreateCategory(); string externalId = TestingUtility.RandomString(10); List <UpdateAction <Category> > updateActions = new List <UpdateAction <Category> >(); SetExternalIdUpdateAction setKeyAction = new SetExternalIdUpdateAction() { ExternalId = externalId }; updateActions.Add(setKeyAction); Category retrievedCategory = commerceToolsClient.ExecuteAsync(new UpdateByKeyCommand <Category>(category.Key, category.Version, updateActions)).Result; this.categoryFixture.CategoriesToDelete.Add(retrievedCategory); Assert.Equal(externalId, retrievedCategory.ExternalId); }
public void UpdateCategoryByKeyChangeSlug() { IClient commerceToolsClient = this.categoryFixture.GetService <IClient>(); Category category = this.categoryFixture.CreateCategory(); var slug = TestingUtility.RandomString(10); var updateActions = new List <UpdateAction <Category> >(); var changeSlugAction = new ChangeSlugUpdateAction { Slug = new LocalizedString() { { "en", slug } } }; updateActions.Add(changeSlugAction); var retrievedCategory = commerceToolsClient.ExecuteAsync(new UpdateByKeyCommand <Category>(category.Key, category.Version, updateActions)).Result; this.categoryFixture.CategoriesToDelete.Add(retrievedCategory); Assert.Equal(slug, retrievedCategory.Slug["en"]); }
public void UpdateTypeByKeyChangeName() { IClient commerceToolsClient = this.typeFixture.GetService <IClient>(); Type type = this.typeFixture.CreateType(); List <UpdateAction <Type> > updateActions = new List <UpdateAction <Type> >(); string newName = TestingUtility.RandomString(10); ChangeNameUpdateAction changeNameUpdateAction = new ChangeNameUpdateAction() { Name = new LocalizedString() { { "en", newName } } }; updateActions.Add(changeNameUpdateAction); Type retrievedType = commerceToolsClient.ExecuteAsync(new UpdateByKeyCommand <Type>(type.Key, type.Version, updateActions)).Result; this.typeFixture.TypesToDelete.Add(retrievedType); Assert.Equal(newName, retrievedType.Name["en"]); }
public void UpdateTypeByIdAddEnumToFieldDefinition() { IClient commerceToolsClient = this.typeFixture.GetService <IClient>(); Type type = this.typeFixture.CreateType(); List <UpdateAction <Type> > updateActions = new List <UpdateAction <Type> >(); string newKey = TestingUtility.RandomString(10); AddEnumToFieldDefinitionUpdateAction addEnumToFieldDefinitionUpdateAction = new AddEnumToFieldDefinitionUpdateAction() { FieldName = "enum-field", Value = new EnumValue() { Key = "new-enum-key", Label = "new-enum-label" } }; updateActions.Add(addEnumToFieldDefinitionUpdateAction); Type retrievedType = commerceToolsClient.ExecuteAsync(new UpdateByIdCommand <Type>(new Guid(type.Id), type.Version, updateActions)).Result; this.typeFixture.TypesToDelete.Add(retrievedType); Assert.Equal(type.GetFieldDefinition("enum-field").Type.ToEnumFieldType().Values.Count + 1, retrievedType.GetFieldDefinition("enum-field").Type.ToEnumFieldType().Values.Count); }
public void UpdateCategoryByKeyChangeName() { IClient commerceToolsClient = this.categoryFixture.GetService <IClient>(); Category category = this.categoryFixture.CreateCategory(); string name = TestingUtility.RandomString(10); List <UpdateAction <Category> > updateActions = new List <UpdateAction <Category> >(); ChangeNameUpdateAction changeNameUpdateAction = new ChangeNameUpdateAction() { Name = new LocalizedString() { { "en", name } } }; updateActions.Add(changeNameUpdateAction); Category retrievedCategory = commerceToolsClient.ExecuteAsync(new UpdateByKeyCommand <Category>(category.Key, category.Version, updateActions)).Result; this.categoryFixture.CategoriesToDelete.Add(retrievedCategory); Assert.Equal(name, retrievedCategory.Name["en"]); }
public void UpdateCategoryByIdSetKey() { IClient commerceToolsClient = this.categoryFixture.GetService <IClient>(); Category category = this.categoryFixture.CreateCategory(); string newKey = TestingUtility.RandomString(10); List <UpdateAction <Category> > updateActions = new List <UpdateAction <Category> >(); SetKeyUpdateAction setKeyAction = new SetKeyUpdateAction() { Key = newKey }; updateActions.Add(setKeyAction); Category retrievedCategory = commerceToolsClient.ExecuteAsync(new UpdateByIdCommand <Category>(new Guid(category.Id), category.Version, updateActions)).Result; // The retrieved category has to be deleted and not the created category. // The retrieved category will have version 2 and the created category will have version 1. // Only the latest version can be deleted. this.categoryFixture.CategoriesToDelete.Add(retrievedCategory); Assert.Equal(newKey, retrievedCategory.Key); }
public ProductTypeDraft CreateProductTypeDraft() { ProductTypeDraft productTypeDraft = new ProductTypeDraft(); productTypeDraft.Key = TestingUtility.RandomString(10); productTypeDraft.Name = TestingUtility.RandomString(10); productTypeDraft.Description = TestingUtility.RandomString(10); productTypeDraft.Attributes = new List <AttributeDefinitionDraft>(); productTypeDraft.Attributes.Add(this.CreateTextAttributeDefinitionDraft()); productTypeDraft.Attributes.Add(this.CreateLocalizedTextAttributeDefinitionDraft()); productTypeDraft.Attributes.Add(this.CreateBooleanAttributeDefinitionDraft()); productTypeDraft.Attributes.Add(this.CreateNumberAttributeDefinitionDraft()); productTypeDraft.Attributes.Add(this.CreateDateAttributeDefinitionDraft()); productTypeDraft.Attributes.Add(this.CreateDateTimeAttributeDefinitionDraft()); productTypeDraft.Attributes.Add(this.CreateTimeAttributeDefinitionDraft()); productTypeDraft.Attributes.Add(this.CreateMoneyAttributeDefinitionDraft()); productTypeDraft.Attributes.Add(this.CreateReferenceAttributeDefinitionDraft()); productTypeDraft.Attributes.Add(this.CreateSetAttributeDefinitionDraft()); productTypeDraft.Attributes.Add(this.CreateEnumAttributeDefinitionDraft()); productTypeDraft.Attributes.Add(this.CreateLocalizedEnumAttributeDefinitionDraft()); return(productTypeDraft); }