public void ParseAPIsJsonDocumentMinimal() { var stream = this.GetType().Assembly.GetManifestResourceStream(this.GetType(), "apis.json"); var rootMap = new VocabTerm<ApisJson>(null); rootMap.MapProperty<string>("name", (s, o) => s.Name = o ); rootMap.MapProperty<string>("url", (s, o) => s.Url = new Uri(o)); var apiMap = new VocabTerm<ApisJsonApi>("apis"); apiMap.MapProperty<string>("name", (s, o) => s.Name = o); apiMap.MapProperty<string>("description", (s, o) => s.Name = o); apiMap.MapProperty<string>("baseUrl", (s, o) => s.BaseUrl = new Uri(o)); rootMap.MapObject<ApisJsonApi>(apiMap, (s) => { if (s.Apis == null) { s.Apis = new List<ApisJsonApi>(); } var api = new ApisJsonApi(); s.Apis.Add(api); return api; }); var apis = new ApisJson(); JsonStreamingParser.ParseStream(stream, apis, rootMap); Assert.Equal("API Evangelist", apis.Name); Assert.Equal(2, apis.Apis.Count()); }
public void ParseAPIsJsonDocument() { var stream = this.GetType().Assembly.GetManifestResourceStream(this.GetType(),"apis.json"); var vocab = ApisJsonVocab.Create(); //new VocabTerm<ApisJson>(null); //vocab.MapProperty<string>("name", (s, o) => { s.Name = o; }); //vocab.MapProperty<string>("url", (s, o) => { s.Url = new Uri(o); }); //vocab.MapProperty<string>("image", (s, o) => { s.Image = new Uri(o); }); //vocab.MapProperty<string>("modified", (s, o) => { s.Modified = DateTime.Parse(o); }); //vocab.MapProperty<string>("created", (s, o) => { s.Created = DateTime.Parse(o); }); //vocab.MapProperty<string>("tags", (s, o) => { // if (s.Tags == null) s.Tags = new List<string>(); // s.Tags.Add(o); }); //vocab.MapProperty<string>("specificationVersion", (s, o) => { s.SpecificationVersion = o; }); //var apivocab = new VocabTerm<ApisJsonApi>("apis"); //apivocab.MapProperty<string>("name", (s, o) => { s.Name = o; }); //apivocab.MapProperty<string>("description", (s, o) => { s.Name = o; }); //apivocab.MapProperty<string>("humanUrl", (s, o) => { s.HumanUrl = new Uri(o); }); //apivocab.MapProperty<string>("baseUrl", (s, o) => { s.BaseUrl = new Uri(o); }); //apivocab.MapProperty<string>("image", (s, o) => { s.Image = new Uri(o); }); //apivocab.MapProperty<string>("tags", (s, o) => { // if (s.Tags == null) s.Tags = new List<string>(); // s.Tags.Add(o); //}); //vocab.MapObject<ApisJsonApi>(apivocab, (s) => //{ // if (s.Apis == null) // { // s.Apis = new List<ApisJsonApi>(); // } // var api = new ApisJsonApi(); // s.Apis.Add(api); // return api; //}); //var propertyTerm = new VocabTerm<ApisJsonProperty>("properties"); //propertyTerm.MapProperty<string>("url", (s, o) => { s.Url = new Uri(o);}); //propertyTerm.MapProperty<string>("type", (s, o) => { s.Type = o;}); //apivocab.MapObject<ApisJsonProperty>(propertyTerm, (s) => //{ // if (s.Properties == null) // { // s.Properties = new List<ApisJsonProperty>(); // } // var property = new ApisJsonProperty(); // s.Properties.Add(property); // return property; //}); var apis = new ApisJson(); JsonStreamingParser.ParseStream(stream, apis, vocab); Assert.Equal("API Evangelist", apis.Name); Assert.Equal(2,apis.Apis.Count()); }