public static void UnregisteredType_CannotWriteResult(JsonSerializerSettings serializerSettings) { var repo = new HalRepository(ImmutableDictionary <Type, ITransformationInstructions> .Empty, new ServiceCollection().BuildServiceProvider()); var sut = new HalJsonOutputFormatter(serializerSettings, ArrayPool <char> .Shared, new MvcOptions(), repo); var context = new OutputFormatterWriteContext(new DefaultHttpContext(), (_, _) => new StreamWriter(Stream.Null), typeof(Unregistered), new Unregistered()); Assert.False(sut.CanWriteResult(context)); }
public static void RegisteredType_CanWriteResult(JsonSerializerSettings serializerSettings) { var map = new Dictionary <Type, ITransformationInstructions> { [typeof(Registered)] = new TransformationMap.Builder <Registered>(_ => Const(new Uri("about:blank", Absolute))), }; var repo = new HalRepository(map, new ServiceCollection().BuildServiceProvider()); var sut = new HalJsonOutputFormatter(serializerSettings, ArrayPool <char> .Shared, new MvcOptions(), repo); var context = new OutputFormatterWriteContext(new DefaultHttpContext(), (_, _) => new StreamWriter(Stream.Null), typeof(Registered), new Registered()); Assert.True(sut.CanWriteResult(context)); }
public void CanConvertAnyType( [Values( typeof(object), typeof(IResource), typeof(Resource), typeof(Resource <object>), typeof(List <object>))] Type type) { var formatter = new HalJsonOutputFormatter( new JsonSerializerSettings(), ArrayPool <char> .Shared, new HalOptions()); var writeContext = new OutputFormatterWriteContext( new DefaultHttpContext(), (s, e) => null, type, null); bool canWrite = formatter.CanWriteResult(writeContext); Assert.IsTrue(canWrite); }