[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 static void UploadAllPackages(PackageDAO packageDAO, string invokeUrl) { NugetPackage packageV000 = NugetSamplePackages.nugetoryV000; byte[] request = Convert.FromBase64String(packageV000.Base64Post); HttpStatusCode responseCode = HttpClient.Invoke(invokeUrl, "PUT", request, packageV000.ContentType, packageV000.ContentLength); Assert.AreEqual(HttpStatusCode.Created, responseCode); Assert.AreEqual(1, packageDAO.Count().Result); NugetPackage packageV001 = NugetSamplePackages.nugetoryV001; request = Convert.FromBase64String(packageV001.Base64Post); responseCode = HttpClient.Invoke(invokeUrl, "PUT", request, packageV001.ContentType, packageV001.ContentLength); Assert.AreEqual(HttpStatusCode.Created, responseCode); Assert.AreEqual(2, packageDAO.Count().Result); NugetPackage packageV002 = NugetSamplePackages.nugetoryV002; request = Convert.FromBase64String(packageV002.Base64Post); responseCode = HttpClient.Invoke(invokeUrl, "PUT", request, packageV002.ContentType, packageV002.ContentLength); Assert.AreEqual(HttpStatusCode.Created, responseCode); Assert.AreEqual(3, packageDAO.Count().Result); NugetPackage packageV003 = NugetSamplePackages.nugetoryV003; request = Convert.FromBase64String(packageV003.Base64Post); responseCode = HttpClient.Invoke(invokeUrl, "PUT", request, packageV003.ContentType, packageV003.ContentLength); Assert.AreEqual(HttpStatusCode.Created, responseCode); Assert.AreEqual(4, packageDAO.Count().Result); NugetPackage bookstoreV000 = NugetSamplePackages.bookstoreV000; request = Convert.FromBase64String(bookstoreV000.Base64Post); responseCode = HttpClient.Invoke(invokeUrl, "PUT", request, bookstoreV000.ContentType, bookstoreV000.ContentLength); Assert.AreEqual(HttpStatusCode.Created, responseCode); Assert.AreEqual(5, packageDAO.Count().Result); NugetPackage bookstoreV001 = NugetSamplePackages.bookstoreV001; request = Convert.FromBase64String(bookstoreV001.Base64Post); responseCode = HttpClient.Invoke(invokeUrl, "PUT", request, bookstoreV001.ContentType, bookstoreV001.ContentLength); Assert.AreEqual(HttpStatusCode.Created, responseCode); Assert.AreEqual(6, packageDAO.Count().Result); }
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); }