Ejemplo n.º 1
0
        public void DefaultSerializer()
        {
            const String contentType   = "application/json";
            var          configuration = new SerializationConfiguration();
            var          serializer    = configuration.Create(contentType);

            Assert.IsType <JsonSerializer>(serializer);
        }
Ejemplo n.º 2
0
        public void NotFound()
        {
            const String contentType   = "application/unknow";
            var          configuration = new SerializationConfiguration();
            var          serializer    = configuration.Create(contentType);

            Assert.IsType <NullSerializer>(serializer);
        }
Ejemplo n.º 3
0
        internal static ISerializer CreateSerializer(this IBasicProperties source,
                                                     SerializationConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            return(configuration.Create(source.ContentTypeOrDefault(SerializationConfiguration.DefaultContentType)));
        }
Ejemplo n.º 4
0
        public void CustomMap()
        {
            const String contentType   = "application/dummy";
            var          configuration = new SerializationConfiguration();

            configuration.Map(header => header.MediaType == contentType, new FakeSerializer());
            var serializer = configuration.Create(contentType);

            Assert.IsType <FakeSerializer>(serializer);
        }
Ejemplo n.º 5
0
        public void CustomNegotiation()
        {
            const String contentType   = "application/custom";
            var          configuration = new SerializationConfiguration();

            configuration.Map(_ => _.MediaType == "application/custom", new FakeSerializer());
            var negotiator = new Mock <IContentNegotiator>();
            var @set       = new SortedSet <ContentNegotiator.MediaTypeHeader>();

            @set.Add(ContentNegotiator.MediaTypeHeader.Parse(contentType));
            negotiator.Setup(_ => _.Negotiate(contentType))
            .Returns(@set);
            configuration.NegotiateBy(negotiator.Object);
            var serializer = configuration.Create(contentType);

            Assert.IsType <FakeSerializer>(serializer);
        }