public async Task <IActionResult> ActivateLicense( string customerId, IFormFile licenseFile ) { var uploads = Path.Combine(_environment.WebRootPath, "uploads"); if (!Directory.Exists(uploads)) { Directory.CreateDirectory(uploads); } var file = new FileModel(); if (licenseFile.Length > 0) { using (var fileStream = new FileStream(Path.Combine(uploads, licenseFile.FileName), FileMode.Create)) { await licenseFile.CopyToAsync(fileStream); file.filename = Path.Combine(uploads, licenseFile.FileName); file.contentType = licenseFile.ContentType; } LicenseResponse response = hacarusVisualInspection.ActivateLicense(file, customerId); ViewData["HttpResponse"] = "Status code: " + response.httpResponse.StatusCode; ViewData["StringMessage"] = hacarusVisualInspection.StringMessage; } ViewBag.BearerAvailable = !string.IsNullOrEmpty(bearer); ViewBag.Active = "activateLicense"; return(Index()); }
public async Task <IActionResult> ActivateLicense( IFormFile licenseFile ) { var Uploads = Path.Combine(Environment.WebRootPath, "uploads"); if (!Directory.Exists(Uploads)) { Directory.CreateDirectory(Uploads); } var file = new FileModel(); if (licenseFile.Length > 0) { using (var fileStream = new FileStream(Path.Combine(Uploads, licenseFile.FileName), FileMode.Create)) { await licenseFile.CopyToAsync(fileStream); file.FileName = Path.Combine(Uploads, licenseFile.FileName); file.ContentType = licenseFile.ContentType; } LicenseResponse Result = VisualInspection.ActivateLicense(file); ViewData["HttpResponse"] = "Status code: " + Result.HttpResponse.StatusCode; ViewData["StringMessage"] = Result.HttpResponse.Content; } ViewBag.BearerAvailable = VisualInspection.IsAuthorized; ViewBag.Active = "activateLicense"; return(Index()); }
public void FailedInvalidLicenseFile() { Console.WriteLine("FailedInvalidLicenseFile Start"); var JsonString = File.ReadAllText("../../../Files/ActivateLicenseFailed.txt"); var Client = MockGenerator.MockRestClient <LicenseResponse>(HttpStatusCode.Forbidden, JsonString); HacarusVisualInspection VisualInspection = new HacarusVisualInspection(Client); var LicenseFile = new FileModel("../../../Files/license0", "txt"); LicenseResponse Response = VisualInspection.ActivateLicense(LicenseFile); Assert.IsNotNull(Response); Assert.IsNotNull(Response.HttpResponse); Assert.IsNull(Response.Data); Assert.IsNotNull(Response.Errors); Assert.IsTrue(Response.HttpResponse.StatusCode.Equals(HttpStatusCode.Forbidden)); Assert.IsTrue(Response.Errors.Title.Equals("Invalid license!")); Console.WriteLine("FailedInvalidLicenseFile End"); }
public void Success() { Console.WriteLine("Success Start"); var JsonString = File.ReadAllText("../../../Files/ActivateLicenseSuccess.txt"); var Client = MockGenerator.MockRestClient <LicenseResponse>(HttpStatusCode.OK, JsonString); HacarusVisualInspection VisualInspection = new HacarusVisualInspection(Client); var LicenseFile = new FileModel("../../../Files/license0", "txt"); LicenseResponse Response = VisualInspection.ActivateLicense(LicenseFile); Assert.IsNotNull(Response); Assert.IsNotNull(Response.HttpResponse); Assert.IsNotNull(Response.Data); Assert.IsNull(Response.Errors); Assert.IsTrue(Response.HttpResponse.StatusCode.Equals(HttpStatusCode.OK)); Assert.IsTrue(Response.Data.Status.Equals("ok")); Console.WriteLine("Success End"); }