private ParseTestResult <RepositoryDescription> FromJson(string json, Uri documentRoot, bool expectWarnings = false)
            {
                var sink   = new CapturingTraceSink();
                var result = RepositoryDescription.FromJson(
                    JObject.Parse(json),
                    new TraceContext("test", sink),
                    documentRoot);
                var ret = new ParseTestResult <RepositoryDescription>(sink.Events, result);

                if (!expectWarnings)
                {
                    Assert.Empty(ret.GetEventsByMethod("JsonParseWarning"));
                }
                return(ret);
            }
            private void InvalidJsonTest(string json, RepositoryDescription expected, params string[] warnings)
            {
                var result = FromJson(json, expectWarnings: true);

                Assert.Equal(expected, result.Result);

                foreach (var warning in warnings)
                {
                    // Find the matching event
                    var evt = result.FindEvent("JsonParseWarning", new { warning });
                    Assert.NotNull(evt);

                    // Ensure there is a JToken
                    Assert.NotNull(evt.Payload["token"]);
                }
            }
 public void GivenANullTracer_ItThrows()
 {
     Assert.Throws <ArgumentNullException>("trace", () => RepositoryDescription.FromJson(new JObject(), null, new Uri("http://api.nuget.org")));
 }
 public void GivenANullJObject_ItThrows()
 {
     Assert.Throws <ArgumentNullException>("json", () => RepositoryDescription.FromJson(null, new TraceContext("foo", TraceSinks.Null), new Uri("http://api.nuget.org")));
 }