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 async Task UpdateTypeAddEnumValueToFieldDefinition() { var rand = TestingUtility.RandomInt(); var newEnumValue = new EnumValue() { Key = $"enum-key-{rand}", Label = $"enum-label-{rand}" }; await WithUpdateableType(client, async type => { Assert.NotEmpty(type.FieldDefinitions); var enumField = type.FieldDefinitions.FirstOrDefault(field => field.Type.GetType() == typeof(EnumFieldType)); Assert.NotNull(enumField); var updateActions = new List <UpdateAction <Type> >(); var addEnumValueToFieldAction = new AddEnumToFieldDefinitionUpdateAction { Value = newEnumValue, FieldName = enumField.Name }; updateActions.Add(addEnumValueToFieldAction); var updatedType = await client .ExecuteAsync(new UpdateByIdCommand <Type>(type, updateActions)); var updatedEnumField = updatedType.FieldDefinitions.FirstOrDefault(field => field.Type.GetType() == typeof(EnumFieldType))?.Type as EnumFieldType; Assert.NotNull(updatedEnumField); Assert.Contains(updatedEnumField.Values, value => value.Key == newEnumValue.Key && value.Label == newEnumValue.Label); return(updatedType); }); }