public void CanProcess_Should_not_match_model_is_null()
        {
            // given
            var processor = new RdfResponseProcessorTestable(new ISerializer[0]);

            // when
            var match = processor.CanProcess(new MediaRange(RdfSerialization.RdfXml.MediaType), null, new NancyContext());

            // then
            Assert.That(match.ModelResult, Is.EqualTo(MatchResult.NoMatch));
        }
        public void Should_not_allow_processing_when_no_compatible_serializer_is_available()
        {
            // given
            var serializers = new ISerializer[0];
            var processor   = new RdfResponseProcessorTestable(serializers);

            // when
            var match = processor.CanProcess(new MediaRange(RdfSerialization.RdfXml.MediaType), new object(), new NancyContext());

            // then
            Assert.That(match.ModelResult, Is.EqualTo(MatchResult.DontCare));
            Assert.That(match.RequestedContentTypeResult, Is.EqualTo(MatchResult.NoMatch));
        }
        public void Should_not_match_wildcard_when_not_set_up()
        {
            // given
            var serializer = A.Fake <RdfSerializer>();

            A.CallTo(() => serializer.CanSerialize(A <MediaRange> .Ignored)).Returns(true);
            var processor = new RdfResponseProcessorTestable(new[] { serializer });

            // when
            var match = processor.CanProcess(new MediaRange("*/*"), new object(), new NancyContext());

            // then
            Assert.That(match.ModelResult, Is.EqualTo(MatchResult.DontCare));
            Assert.That(match.RequestedContentTypeResult, Is.EqualTo(MatchResult.NoMatch));
        }
        public void Should_pass_SiteBase_from_context_to_serializtion()
        {
            // given
            var serializer = A.Fake <IRdfSerializer>();

            A.CallTo(() => serializer.CanSerialize(A <MediaRange> .Ignored)).Returns(true);
            var processor = new RdfResponseProcessorTestable(new[] { serializer });

            // when
            var response = processor.Process(new MediaRange("application/rdf+xml"), new object(), NancyContext);

            response.Contents(new MemoryStream());

            // then
            A.CallTo(() => serializer.Serialize(
                         A <MediaRange> .That.Matches(mr => mr == RdfSerialization.RdfXml.MediaType),
                         A <WrappedModel> .That.Matches(wm => wm.BaseUrl == new Uri(NancyContext.Request.Url.SiteBase)),
                         A <MemoryStream> ._)).MustHaveHappened();
        }
        public void Should_pass_actual_requested()
        {
            // given
            var contentType = new MediaRange("application/rdf+xml;profile=testprofile");
            var serializer  = A.Fake <IRdfSerializer>();

            A.CallTo(() => serializer.CanSerialize(A <MediaRange> .Ignored)).Returns(true);
            var processor = new RdfResponseProcessorTestable(new[] { serializer });

            // when
            var response = processor.Process(new MediaRange(contentType), new object(), NancyContext);

            response.Contents(new MemoryStream());

            // then
            A.CallTo(() => serializer.Serialize(
                         A <MediaRange> .That.Matches(mr => mr.Equals(contentType)),
                         A <WrappedModel> ._,
                         A <MemoryStream> ._)).MustHaveHappened();
        }
        public void WhenProcessingRdfModel()
        {
            var processor = new RdfResponseProcessorTestable(new[] { this.serializer });

            this.response = processor.Process(this.mediaRange, new object(), new NancyContext());
        }