public void DefaultSerializer() { const String contentType = "application/json"; var configuration = new SerializationConfiguration(); var serializer = configuration.Create(contentType); Assert.IsType<JsonSerializer>(serializer); }
public void NotFound() { const String contentType = "application/unknow"; var configuration = new SerializationConfiguration(); var serializer = configuration.Create(contentType); Assert.IsType<NullSerializer>(serializer); }
internal static ISerializer CreateSerializer(this IBasicProperties source, SerializationConfiguration configuration) { if (configuration == null) throw new ArgumentNullException(nameof(configuration)); return configuration.Create(source.ContentTypeOrDefault(SerializationConfiguration.DefaultContentType)); }
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); }
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); }