public void it_should_create_a_type_description() { var result = DescriptionContext.ForType(ApiDocumentation, typeof(int), Builder).BuildTypeDescription(); result.Label.Should().Be("int"); result.Description.Should().BeNull(); }
internal static bool VersionsByMediaType(this IApiVersionReader reader) { var context = new DescriptionContext(); reader.AddParameters(context); return(context.HasMediaTypeApiVersion); }
internal static string GetMediaTypeVersionParameter(this IApiVersionReader reader) { var context = new DescriptionContext(); reader.AddParameters(context); return(context.ParameterName); }
/// <summary> /// Записывает информацию о запускаемом приложении (лого). /// Информация содержит имя приложения, версию и авторские права. /// </summary> void WriteLogo(DescriptionContext context) { WriteText(context, appInfo.Title); WriteText(context, " v" + appInfo.Version, true); WriteText(context, appInfo.Description, true); WriteText(context, appInfo.Copyright, true); context.WriteLine(); }
public void it_should_create_a_type_description() { var result = DescriptionContext.ForType(ApiDocumentation, typeof(Person), Builder).BuildTypeDescription(); result.Label.Should().Be("Person"); result.Description.Should().Be(typeof(Person).FullName); result.SupportedProperties.Should().HaveCount(4); }
public void it_should_create_a_resource_description() { var context = DescriptionContext.ForType(ApiDocumentation, typeof(int), Builder); var result = context.BuildTypeDescription(); result = context.TypeDescriptionBuilder.SubClass(context, result); result.IsCollection().Should().BeFalse(); result.Should().BeAssignableTo <IClass>(); }
/// <summary> /// Пишет информацию об использовании приложения в указанный <paramref name="writer"/>. /// </summary> /// <param name="writer">Объект для вывода информации об использовании приложения.</param> public void Print(TextWriter writer) { var context = new DescriptionContext(appInfo, modelType, writer); if (showLogo) { WriteLogo(context); } new SyntaxWriter(context).Write(); context.WriteLine(2); new DetailsWriter(context).Write(); }
/// <summary> /// Пишет непустой текст в контекст описания. /// </summary> /// <param name="context">Контекст описания модели.</param> /// <param name="text">Текст.</param> /// <param name="newline">Флаг, равный true, если нужно добавить перевод строки после записи текста.</param> /// <remarks>Если строка для вывода пустая, то флаг <paramref name="newline"/> игнорируется.</remarks> static void WriteText(DescriptionContext context, string text, bool newline = false) { if (string.IsNullOrWhiteSpace(text)) { return; } context.Writer.Write(text); if (newline) { context.WriteLine(); } }
/// <summary>Accepts the specified visitor.</summary> /// <param name="attributes">The attributes to be visited.</param> /// <param name="memberType">Type of the member.</param> /// <param name="visitor">The visitor.</param> /// <param name="templateMapping">Template mapping to be amended by visitor.</param> /// <param name="descriptionContext">Description context.</param> public static void Accept( this IEnumerable <ServerBehaviorAttribute> attributes, Type memberType, IServerBehaviorAttributeVisitor visitor, IIriTemplateMapping templateMapping, DescriptionContext descriptionContext) { foreach (var attribute in attributes) { attribute.GetType().GetMethod("Accept", BindingFlags.Instance | BindingFlags.Public) .MakeGenericMethod(memberType).Invoke(attribute, new object[] { visitor, templateMapping, descriptionContext }); } }
/// <summary>Accepts the specified visitor.</summary> /// <param name="attributes">The attributes to be visited.</param> /// <param name="memberType">Type of the member.</param> /// <param name="visitor">The visitor.</param> /// <param name="templateMapping">Template mapping to be amended by visitor.</param> /// <param name="descriptionContext">Description context.</param> public static void Accept( this IEnumerable<ServerBehaviorAttribute> attributes, Type memberType, IServerBehaviorAttributeVisitor visitor, IIriTemplateMapping templateMapping, DescriptionContext descriptionContext) { foreach (var attribute in attributes) { attribute.GetType().GetMethod("Accept", BindingFlags.Instance | BindingFlags.Public) .MakeGenericMethod(memberType).Invoke(attribute, new object[] { visitor, templateMapping, descriptionContext }); } }
public void it_should_determine_property_owning_an_operation() { var apiDescriptionBuilder = new ApiDescriptionBuilder <TestController>( _descriptionBuilder, _xmlDocProvider.Object, new[] { _typeDescriptionBuilder.Object }, new IServerBehaviorAttributeVisitor[0], _namedGraphSelectorFactory.Object); var operationOwner = apiDescriptionBuilder.DetermineOperationOwner( typeof(TestController).GetMethod("SetRoles").ToOperationInfo("http://temp.uri/", Verb.POST), DescriptionContext.ForType(_apiDocumentation.Object, typeof(Person), _typeDescriptionBuilder.Object), new Mock <IClass>(MockBehavior.Strict).Object); operationOwner.Should().BeAssignableTo <ISupportedProperty>(); operationOwner.Id.ToString().Should().Be("urn:hydra:" + typeof(Person).FullName + ".Roles"); }
private static IClass CreateDescription(Mock <IEntityContext> entityContext, DescriptionContext context, out bool requiresRdf) { var result = new Mock <IClass>(MockBehavior.Strict); result.SetupGet(instance => instance.Context).Returns(entityContext.Object); result.SetupGet(instance => instance.Id).Returns(new EntityId(String.Format("urn:net:" + context.Type.FullName))); result.SetupSet(instance => instance.Label = It.IsAny <string>()); result.SetupSet(instance => instance.Description = It.IsAny <string>()); result.SetupGet(instance => instance.MediaTypes).Returns(new List <string>()); if (context.Type == typeof(Person)) { result.SetupGet(instance => instance.SupportedProperties).Returns(new ISupportedProperty[0]); result.SetupGet(instance => instance.SupportedOperations).Returns(new List <IOperation>()); } context.Describe(result.Object, requiresRdf = false); return(result.Object); }
public void it_should_create_a_LastName_property_description() { var result = DescriptionContext.ForType(ApiDocumentation, typeof(Person), Builder).BuildTypeDescription(); var property = result.SupportedProperties.FirstOrDefault(item => (item.Property != null) && (item.Property.Label == "LastName")); property.Should().NotBeNull(); property.Readable.Should().BeTrue(); property.Writeable.Should().BeTrue(); property.Required.Should().BeFalse(); property.Property.Description.Should().Be(typeof(Person) + ".LastName"); property.Property.Domain.Should().Contain(@class => @class.Id.Uri.AbsoluteUri.Contains(typeof(Person).FullName)); property.Property.Range.Should().HaveCount(1); property.Property.Range.First().Should().BeAssignableTo <IClass>(); XsdUriParser.Types.Values.Any(iri => iri.AbsoluteUri == ((IClass)property.Property.Range.First()).Id.Uri.AbsoluteUri).Should().BeTrue(); result.SubClassOf.OfType <IRestriction>().Any(restriction => (restriction.OnProperty.Id.Uri.AbsoluteUri == property.Property.Id.Uri.AbsoluteUri) && (restriction.MaxCardinality == 1)).Should().BeTrue(); }
public void it_should_create_a_Roles_property_description() { var result = DescriptionContext.ForType(ApiDocumentation, typeof(Person), Builder).BuildTypeDescription(); var property = result.SupportedProperties.FirstOrDefault(item => (item.Property != null) && (item.Property.Label == "Roles")); property.Should().NotBeNull(); property.Readable.Should().BeTrue(); property.Writeable.Should().BeTrue(); property.Required.Should().BeFalse(); property.Property.Description.Should().Be(typeof(Person) + ".Roles"); property.Property.Domain.Should().Contain(@class => @class.Id.Uri.AbsoluteUri.Contains(typeof(Person).FullName)); property.Property.Range.Should().HaveCount(1); property.Property.Range.First().Should().BeAssignableTo <IClass>(); var range = (IClass)property.Property.Range.First(); range.SubClassOf.FirstOrDefault(item => item.IsClass(new Uri(EntityConverter.Hydra.AbsoluteUri + "Collection"))).Should().NotBeNull(); var restriction = range.SubClassOf.Where(item => item.Is(Owl.Restriction)).Cast <IRestriction>().FirstOrDefault(); restriction.Should().NotBeNull(); XsdUriParser.Types.Values.Any(iri => iri.AbsoluteUri == restriction.AllValuesFrom.Id.Uri.AbsoluteUri).Should().BeTrue(); restriction.OnProperty.Id.Uri.AbsoluteUri.Should().Be(EntityConverter.Hydra.AbsoluteUri + "member"); restriction.MaxCardinality.Should().NotBe(1); }
/// <summary>Accepts the specified visitor.</summary> /// <typeparam name="T">Type of member visited.</typeparam> /// <param name="visitor">The visitor.</param> /// <param name="templateMapping">Template mapping to be amended by visitor.</param> /// <param name="descriptionContext">Description context.</param> public abstract void Accept <T>(IServerBehaviorAttributeVisitor visitor, IIriTemplateMapping templateMapping, DescriptionContext descriptionContext);
public DescriptionContext description() { DescriptionContext _localctx = new DescriptionContext(Context, State); EnterRule(_localctx, 76, RULE_description); int _la; try { EnterOuterAlt(_localctx, 1); { State = 1286; k_description(); State = 1290; ErrorHandler.Sync(this); _la = TokenStream.La(1); while (_la==SCOL) { { { State = 1287; descparam(); } } State = 1292; ErrorHandler.Sync(this); _la = TokenStream.La(1); } State = 1293; Match(COL); State = 1294; text(); State = 1295; Match(CRLF); } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return _localctx; }
/// <summary> /// 初始化一个<see cref="DomainObjectBase{TObject}"/>类型的实例 /// </summary> protected DomainObjectBase() { _validationContext = new ValidationContext <TObject>(AssignableType(this)); _descriptionContext = new DescriptionContext(); _changeTrackingContext = new ChangeTrackingContext(); }
/// <inheritdoc /> public void Visit <T>(LinqServerBehaviorAttribute behaviorAttribute, IIriTemplateMapping templateMapping, DescriptionContext descriptionContext) { IClass range = null; Uri uri = null; switch (behaviorAttribute.Operation) { case LinqOperations.Filter: range = (descriptionContext.ContainsType(typeof(string)) ? descriptionContext[typeof(string)] : descriptionContext.TypeDescriptionBuilder.BuildTypeDescription(descriptionContext.ForType(typeof(string)))); uri = new Uri(OData + "$filter"); break; case LinqOperations.Skip: uri = new Uri(OData + "$skip"); break; case LinqOperations.Take: uri = new Uri(OData + "$top"); break; } if (range == null) { range = (descriptionContext.ContainsType(typeof(T)) ? descriptionContext[typeof(T)] : descriptionContext.TypeDescriptionBuilder.BuildTypeDescription(descriptionContext.ForType(typeof(T)))); } templateMapping.Property = templateMapping.Context.Create <Rdfs.IProperty>(uri); templateMapping.Property.Range.Add(range); }
/// <inheritdoc /> public override void Accept <T>(IServerBehaviorAttributeVisitor visitor, IIriTemplateMapping templateMapping, DescriptionContext descriptionContext) { if (visitor == null) { throw new ArgumentNullException("visitor"); } if (templateMapping == null) { throw new ArgumentNullException("templateMapping"); } visitor.Visit <T>(this, templateMapping, descriptionContext); }