public void TestConstructWithValidApiVersion() { try { var v1 = new NuGetApi((NuGetApi.Version) 1); var v2 = new NuGetApi((NuGetApi.Version) 2); var v3 = new NuGetApi((NuGetApi.Version) 3); Assert.IsTrue(true); } catch (Exception) { Assert.IsTrue(false); } }
public void TestConstructWithInvalidApiVersion() { var exceptionsThrown = 0; for (int i = 0; i < 5; i++) { try { var v = new NuGetApi((NuGetApi.Version) i); } catch (Exception) { exceptionsThrown += 1; } } Assert.AreEqual(exceptionsThrown, 2); }
public NuGetApi(NuGetApi.Version version) { switch (version) { case NuGetApi.Version.V1: _url = "https://www.nuget.org/api/v1/"; break; case NuGetApi.Version.V2: _url = "https://www.nuget.org/api/v2/"; break; case NuGetApi.Version.V3: _url = "https://www.nuget.org/api/v2/"; break; default: throw new Exception("Invalid API version " + version.ToString()); } }