[Category("nugetory.Integration.PackageDetailsControllerDelete"), Test]//, Timeout(1000)] public void PackageDetailsControllerDeleteApiKeyFailTest() { ClearAllPackages(); LoadAllPackages(); long originalCount = PackageDAO.Count().Result; ValidateAuthenticationAttribute.ApiKey = Path.GetRandomFileName().Replace(".", ""); HttpClient.ApiKey = null; const string suffix = "/Packages(Id='{0}',Version='{1}')"; Package pkgV000 = PackageDAO.Read(NugetSamplePackages.nugetoryV000.Title, NugetSamplePackages.nugetoryV000.Version).Result; string urlSuffix = string.Format(suffix, pkgV000.Title, pkgV000.Version); string url = InvokeUrl + urlSuffix; HttpStatusCode resultCode = HttpClient.Invoke(url, "DELETE"); Assert.AreEqual(HttpStatusCode.Unauthorized, resultCode); Assert.AreEqual(originalCount, PackageDAO.Count().Result); HttpClient.ApiKey = Path.GetRandomFileName().Replace(".", ""); Assert.AreNotEqual(ValidateAuthenticationAttribute.ApiKey, HttpClient.ApiKey); resultCode = HttpClient.Invoke(url, "DELETE"); Assert.AreEqual(HttpStatusCode.Unauthorized, resultCode); Assert.AreEqual(originalCount, PackageDAO.Count().Result); }
public void PackageDownloadControllerGetTest() { const string suffix = "/package/{0}/{1}"; string responseData; Package pkgV000 = PackageDAO.Read(NugetSamplePackages.nugetoryV000.Title, NugetSamplePackages.nugetoryV000.Version).Result; string pkgV000File; using (StreamReader sr = new StreamReader(FileStore.GetFile(pkgV000.Id, pkgV000.PackageHash))) pkgV000File = sr.ReadToEnd(); string url = InvokeUrl + string.Format(suffix, pkgV000.Title, pkgV000.Version); HttpClient.Invoke(url, "GET", out responseData); Assert.AreEqual(pkgV000File, responseData); Package pkgV003 = PackageDAO.Read(NugetSamplePackages.nugetoryV003.Title, NugetSamplePackages.nugetoryV003.Version).Result; string pkgV003File; using (StreamReader sr = new StreamReader(FileStore.GetFile(pkgV003.Id, pkgV003.PackageHash))) pkgV003File = sr.ReadToEnd(); url = InvokeUrl + string.Format(suffix, pkgV003.Title, pkgV003.Version); HttpClient.Invoke(url, "GET", out responseData); Assert.AreEqual(pkgV003File, responseData); }
private static void ClearAllPackages() { List <Package> packages = PackageDAO.Read(p => true).Result; packages.ForEach(p => { PackageDAO.Delete(p.Id); FileStore.DeleteFile(p.Id); }); }
public void OneTimeTearDown() { List <Package> packages = PackageDAO.Read(p => true).Result; packages.ForEach(p => { PackageDAO.Delete(p.Id); FileStore.DeleteFile(p.Id); }); }
[Category("nugetory.Integration.FindPackageControllerGet"), Test]//, Timeout(1000)] public void FindPackageControllerGetTest() { string responseData; Package pkgV003 = PackageDAO.Read(NugetSamplePackages.nugetoryV003.Title, NugetSamplePackages.nugetoryV003.Version).Result; string url = InvokeUrl + GetQuery("IsLatestVersion", "", pkgV003.Title, ""); HttpClient.Invoke(url, "GET", out responseData); string result = GetFindPackageResult(url, new List <Package> { pkgV003 }, true); Assert.AreEqual(result, responseData); }
public static HttpResponseMessage Delete(HttpRequestMessage request, string id, string version) { Package package = PackageDAO.Read(id, version).Result; if (package == null) { throw new PackageNotFoundException(); } if (!FileStore.DeleteFile(package.Id)) { throw new InternalServerErrorException(); } if (!PackageDAO.Delete(package.Id).Result) { throw new InternalServerErrorException(); } return(request.CreateResponse(HttpStatusCode.OK)); }
public void PackageDetailsControllerGetTest() { const string suffix = "/Packages(Id='{0}',Version='{1}')"; string responseData; Package pkgV000 = PackageDAO.Read(NugetSamplePackages.nugetoryV000.Title, NugetSamplePackages.nugetoryV000.Version).Result; string urlSuffix = string.Format(suffix, pkgV000.Title, pkgV000.Version); string url = InvokeUrl + urlSuffix; HttpClient.Invoke(url, "GET", out responseData); Uri uri = new Uri(InvokeUrl + EscapeSuffix(urlSuffix)); string expected = GetDetailsResult(pkgV000, uri); Assert.AreEqual(expected, responseData); }
public static HttpResponseMessage BuildResponse(HttpRequestMessage request, string id, string version) { Package package = PackageDAO.Read(id, version).Result; if (package == null) { throw new PackageNotFoundException(); } HttpResponseMessage res = request.CreateResponse(HttpStatusCode.OK); res.Content = new StringContent(GetDetails(request, package)); res.Content.Headers.Remove("Content-Type"); res.Content.Headers.Add("Content-Type", "application/atom+xml;type=entry;charset=utf-8"); res.Headers.Add("DataServiceVersion", "2.0;"); return(res); }
public static HttpResponseMessage Download(HttpRequestMessage request, string id, string version) { Package package = PackageDAO.Read(id, version).Result; if (package == null) { throw new PackageNotFoundException(); } Stream fileStream = FileStore.GetFile(package.Id, package.PackageHash); HttpResponseMessage res = request.CreateResponse(HttpStatusCode.OK); res.Content = new StreamContent(fileStream); res.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); return(res); }
public void PackageDetailsControllerDeleteNoApiKeySuccessTest() { ClearAllPackages(); LoadAllPackages(); long originalCount = PackageDAO.Count().Result; ValidateAuthenticationAttribute.ApiKey = null; HttpClient.ApiKey = null; const string suffix = "/Packages(Id='{0}',Version='{1}')"; Package pkgV000 = PackageDAO.Read(NugetSamplePackages.nugetoryV000.Title, NugetSamplePackages.nugetoryV000.Version).Result; string urlSuffix = string.Format(suffix, pkgV000.Title, pkgV000.Version); string url = InvokeUrl + urlSuffix; HttpStatusCode resultCode = HttpClient.Invoke(url, "DELETE"); Assert.AreEqual(HttpStatusCode.OK, resultCode); Assert.AreEqual(originalCount - 1, PackageDAO.Count().Result); }
public void SearchControllerGetTest() { string responseData; string targetFramework = ""; Package pkgV003 = PackageDAO.Read(NugetSamplePackages.nugetoryV003.Title, NugetSamplePackages.nugetoryV003.Version).Result; if (pkgV003.FrameworkAssemblies != null && pkgV003.FrameworkAssemblies.Any()) { targetFramework = pkgV003.FrameworkAssemblies[0].TargetFramework; } string url = InvokeUrl + GetQuery("IsLatestVersion", "", pkgV003.Title, targetFramework, "false", "0", "1"); HttpClient.Invoke(url, "GET", out responseData); string result = GetSearchResult(new List <Package> { pkgV003 }); Assert.AreEqual(result, responseData); }