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(); }
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>(); }
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"); }
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); }
/// <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); }