/// <summary> /// Visits the <paramref name="statement"/>. /// </summary> /// <param name="statement"></param> protected virtual void VisitExtendStatement(ExtendStatement statement) { VisitElementTypeIdentifierPath(statement.MessageType); foreach (var item in statement.Items) { switch (item) { case NormalFieldStatement normalField: VisitNormalFieldStatement(normalField); break; case GroupFieldStatement groupField: VisitGroupFieldStatement(groupField); break; case EmptyStatement emptyStatement: VisitEmptyStatement(emptyStatement); break; case null: throw ReportUnexpectedAlternative <IExtendBodyItem>(); default: throw ReportUnexpectedAlternative(item); } } }
public void VerifySingleFieldFieldsWithSingleOption(ElementTypeIdentifierPath messageType, string fieldName , OptionIdentifierPath optionName) { const LabelKind label = LabelKind.Required; IVariant fieldType = Variant.Create(ProtoType.Double); IVariant optionConst = Constant.Create(true); IEnumerable <FieldOption> GetFieldOptions() => GetRange( new FieldOption { Name = optionName, Value = optionConst } ); IEnumerable <NormalFieldStatement> GetNormalFields() { var fieldNumber = FieldNumber; yield return(new NormalFieldStatement { Name = fieldName, Label = label, FieldType = fieldType, Number = fieldNumber, Options = GetFieldOptions().ToList() }); } ExpectedTopLevel = new ExtendStatement { MessageType = messageType, Items = GetNormalFields().ToList <IExtendBodyItem>() }; }
public void VerifyFromZeroGroups(ElementTypeIdentifierPath messageType, LabelKind label , string[] groupNames, long fieldNumber) { IEnumerable <IExtendBodyItem> GetStatementItems() => groupNames.Select <string, IExtendBodyItem>( x => new GroupFieldStatement { Name = x, Label = label, Number = fieldNumber } ); ExpectedTopLevel = new ExtendStatement { MessageType = messageType, Items = GetStatementItems().ToList() }; }
public void VerifyFromZeroFieldsWithOrWithoutOptions(ElementTypeIdentifierPath messageType , string[] fieldNames, OptionIdentifierPath[] optionNames) { const LabelKind label = LabelKind.Required; IVariant fieldType = Variant.Create(ProtoType.Double); IVariant optionConst = Constant.Create(true); IEnumerable <FieldOption> GetFieldOptions() => optionNames.Select( x => new FieldOption { Name = x, Value = optionConst } ); IEnumerable <NormalFieldStatement> GetNormalFields() { foreach (var fieldName in fieldNames) { var fieldNumber = FieldNumber; yield return(new NormalFieldStatement { Name = fieldName, Label = label, FieldType = fieldType, Number = fieldNumber, Options = GetFieldOptions().ToList() }); } } ExpectedTopLevel = new ExtendStatement { MessageType = messageType, Items = GetNormalFields().ToList <IExtendBodyItem>() }; }
public void VerifyEmptyBody(ElementTypeIdentifierPath messageType) { ExpectedTopLevel = new ExtendStatement { MessageType = messageType }; }
public void VerifyExtendStatementWithEmptyStatement(ElementTypeIdentifierPath messageType) { ExpectedTopLevel = new ExtendStatement { MessageType = messageType, Items = { NewEmptyStatement } }; }