Beispiel #1
0
        /// <summary>
        /// Creates the operation replacing meta values with defaults.
        /// </summary>
        /// <example>
        /// GET always expects owl:Nothing, PUT always returns owl:Nothing, etc.
        /// </example>
        protected virtual Operation CreateOperation(OperationMeta meta, IriRef modelOrPropertyType)
        {
            switch (meta.Method)
            {
            case HttpMethod.Delete:
                meta.Returns = meta.Returns ?? (IriRef)Owl.Nothing;
                goto case HttpMethod.Head;

            case HttpMethod.Get:
                meta.Returns = modelOrPropertyType;
                goto case HttpMethod.Head;

            case HttpMethod.Head:
            case HttpMethod.Trace:
                meta.Expects = (IriRef)Owl.Nothing;
                break;

            case HttpMethod.Put:
                meta.Expects = modelOrPropertyType;
                meta.Returns = (IriRef?)Owl.Nothing;
                break;
            }

            return(new Operation(meta.Method)
            {
                Title = meta.Title,
                Description = meta.Description,
                Returns = meta.Returns.GetValueOrDefault(modelOrPropertyType),
                Expects = meta.Expects.GetValueOrDefault((IriRef)Owl.Nothing)
            });
        }
Beispiel #2
0
        /// <summary>
        /// Creates the supported operations for supported property.
        /// </summary>
        public IEnumerable <Operation> CreateOperations(PropertyInfo prop, IReadOnlyDictionary <Type, Uri> classIds)
        {
            IriRef mappedType = this.rangeRetrieval.GetRange(prop, classIds) ?? (IriRef)Vocab.Hydra.Resource;

            return(from operation in this.operations
                   where operation.Type == prop.ReflectedType
                   from meta in operation.GetSupportedPropertyOperations(prop)
                   select this.CreateOperation(meta, mappedType));
        }
Beispiel #3
0
        public void Should_be_explicitly_castable_from_string()
        {
            // given
            var expected = new IriRef(TestUri);

            // when
            var iriRef = (IriRef)TestUri;

            // then
            Assert.Equal(expected, iriRef);
        }
Beispiel #4
0
        public void Should_work_with_absolute_Uri_string()
        {
            // given
            const string path = TestUri;

            // when
            var iriRef = new IriRef(path);

            // then
            Assert.Equal(new Uri(path, UriKind.Absolute).ToString(), iriRef.Value);
        }
Beispiel #5
0
        public void Should_work_with_relative_Uri_string()
        {
            // given
            const string path = "/relative/path";

            // when
            var iriRef = new IriRef(path);

            // then
            Assert.Equal(new Uri(path, UriKind.Relative).ToString(), iriRef.Value);
        }
        public void Should_be_explicitly_castable_from_Uri()
        {
            // given
            var expected = new IriRef(TestUri);

            // when
            IriRef iriRef = (IriRef) new Uri(TestUri);

            // then
            Assert.AreEqual(expected, iriRef);
        }
        public void Should_deserialize_compacted_IriRef(string json)
        {
            // given
            dynamic raw    = JsonConvert.DeserializeObject(json);
            var     iriRef = new IriRef(raw.property.ToString());

            // when
            var deserialized = this.serializer.Deserialize <ClassWithSomeUris>((JToken)raw);

            // then
            Assert.Equal(iriRef, deserialized.Property);
        }
        public void Should_deserialize_expanded_IriRef(string json)
        {
            // given
            dynamic raw    = JsonConvert.DeserializeObject(json);
            var     iriRef = new IriRef(raw.property["@id"].ToString());

            // when
            var deserialized = this.serializer.Deserialize <ClassWithSomeUris>((JToken)raw);

            // then
            Assert.That(deserialized.Property, Is.EqualTo(iriRef));
        }
Beispiel #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ApiDocumentation"/> class.
 /// </summary>
 /// <param name="entrypoint">The entrypoint Uri.</param>
 public ApiDocumentation(IriRef entrypoint)
 {
     this.Entrypoint = entrypoint;
 }