public void Registration() { ImportContext context = new ImportContext(); ThingImporter importer = new ThingImporter(); context.Register(importer); Assert.AreSame(importer, context.FindImporter(typeof(Thing))); }
public void RegistrationIsPerContext() { ImportContext context = new ImportContext(); ThingImporter exporter = new ThingImporter(); context.Register(exporter); context = new ImportContext(); Assert.AreNotSame(exporter, context.FindImporter(typeof(Thing))); }
private static object Import(bool hasValue, string input) { JsonReader reader = JsonText.CreateReader(input); ImportContext context = JsonConvert.CreateImportContext(); ThingImporter thingImporter = new ThingImporter(); context.Register(thingImporter); NullableImporter importer = new NullableImporter(typeof(Thing?)); object thing = importer.Import(context, reader); Assert.AreEqual(hasValue, thingImporter.ImportCalled); if (hasValue) { Assert.IsInstanceOfType(typeof(Thing), thing); } else { Assert.IsNull(thing); } Assert.IsTrue(reader.EOF, "Reader must be at EOF."); return(thing); }
private static object Import(bool hasValue, string input) { JsonReader reader = JsonText.CreateReader(input); ImportContext context = JsonConvert.CreateImportContext(); ThingImporter thingImporter = new ThingImporter(); context.Register(thingImporter); NullableImporter importer = new NullableImporter(typeof(Thing?)); object thing = importer.Import(context, reader); Assert.AreEqual(hasValue, thingImporter.ImportCalled); if (hasValue) Assert.IsInstanceOfType(typeof(Thing), thing); else Assert.IsNull(thing); Assert.IsTrue(reader.EOF, "Reader must be at EOF."); return thing; }