public async System.Threading.Tasks.Task TestLocation() { string initialName = randomNewUserName("Application Initial Name ", 6); string changedName = randomNewUserName("Application Changed Name ", 6); string service = "Application"; DateTimeOffset dto = DateTimeOffset.Now; // login as default and get account for current user var loginUser1 = randomNewUserName("TestAccountUser", 6); var strId = await LoginAndRegisterAsNewUser(loginUser1); User user = await GetCurrentUser(); Account currentAccount = await GetAccountForCurrentUser(); // C - Create var request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service + "/Equipment Notification"); Application viewmodel_application = SecurityHelper.CreateNewApplication(currentAccount); string[] stringsToMatch = new string[65]; for (int i = 0; i < stringsToMatch.Length; i++) { stringsToMatch[i] = RandomTextString(20, i); } viewmodel_application.EquipmentLocation = new Location() { Address = new CustomAddress() { StreetLine1 = stringsToMatch[1], StreetLine2 = stringsToMatch[2], StreetLine3 = stringsToMatch[3], City = stringsToMatch[4], Province = stringsToMatch[5], Postalcode = stringsToMatch[6], Country = stringsToMatch[7] }, PrivateDwelling = true, SettingDescription = stringsToMatch[8] }; var jsonString = JsonConvert.SerializeObject(viewmodel_application); request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json"); var response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // parse as JSON. jsonString = await response.Content.ReadAsStringAsync(); Application responseViewModel = JsonConvert.DeserializeObject <Application>(jsonString); Assert.Equal("Testing", responseViewModel.mainbusinessfocus); Assert.Equal("Automated Testing", responseViewModel.manufacturingprocessdescription); Guid id = new Guid(responseViewModel.id); //return; // R - Read request = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); jsonString = await response.Content.ReadAsStringAsync(); responseViewModel = JsonConvert.DeserializeObject <Application>(jsonString); Assert.Equal("Testing", responseViewModel.mainbusinessfocus); Assert.Equal("Automated Testing", responseViewModel.manufacturingprocessdescription); CheckAddress(responseViewModel.EquipmentLocation.Address, stringsToMatch[1], stringsToMatch[2], stringsToMatch[3], stringsToMatch[4], stringsToMatch[5], stringsToMatch[6], stringsToMatch[7] ); Assert.True(responseViewModel.EquipmentLocation.PrivateDwelling); Assert.Equal(stringsToMatch[8], responseViewModel.EquipmentLocation.SettingDescription); // U - Update viewmodel_application = new Application() { mainbusinessfocus = changedName }; // test update with existing addresses for (int i = 0; i < stringsToMatch.Length; i++) { stringsToMatch[i] = RandomTextString(20, i); } viewmodel_application.EquipmentLocation = new Location() { Id = responseViewModel.EquipmentLocation.Id, Address = new CustomAddress() { Id = responseViewModel.EquipmentLocation.Address.Id, StreetLine1 = stringsToMatch[1], StreetLine2 = stringsToMatch[2], StreetLine3 = stringsToMatch[3], City = stringsToMatch[4], Province = stringsToMatch[5], Postalcode = stringsToMatch[6], Country = stringsToMatch[7] }, PrivateDwelling = false, SettingDescription = stringsToMatch[8] }; request = new HttpRequestMessage(HttpMethod.Put, "/api/" + service + "/" + id) { Content = new StringContent(JsonConvert.SerializeObject(viewmodel_application), Encoding.UTF8, "application/json") }; response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // verify that the update persisted. request = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); jsonString = await response.Content.ReadAsStringAsync(); responseViewModel = JsonConvert.DeserializeObject <Application>(jsonString); Assert.Equal(changedName, responseViewModel.mainbusinessfocus); CheckAddress(responseViewModel.EquipmentLocation.Address, stringsToMatch[1], stringsToMatch[2], stringsToMatch[3], stringsToMatch[4], stringsToMatch[5], stringsToMatch[6], stringsToMatch[7] ); Assert.False(responseViewModel.EquipmentLocation.PrivateDwelling); Assert.Equal(stringsToMatch[8], responseViewModel.EquipmentLocation.SettingDescription); // U - Update viewmodel_application = new Application() { mainbusinessfocus = changedName }; // test update with new addresses for (int i = 0; i < stringsToMatch.Length; i++) { stringsToMatch[i] = RandomTextString(20, i); } viewmodel_application.EquipmentLocation = new Location() { Address = new CustomAddress() { StreetLine1 = stringsToMatch[1], StreetLine2 = stringsToMatch[2], StreetLine3 = stringsToMatch[3], City = stringsToMatch[4], Province = stringsToMatch[5], Postalcode = stringsToMatch[6], Country = stringsToMatch[7] }, PrivateDwelling = false, SettingDescription = stringsToMatch[8] }; request = new HttpRequestMessage(HttpMethod.Put, "/api/" + service + "/" + id) { Content = new StringContent(JsonConvert.SerializeObject(viewmodel_application), Encoding.UTF8, "application/json") }; response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // verify that the update persisted. request = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id); response = await _client.SendAsync(request); jsonString = await response.Content.ReadAsStringAsync(); response.EnsureSuccessStatusCode(); responseViewModel = JsonConvert.DeserializeObject <Application>(jsonString); Assert.Equal(changedName, responseViewModel.mainbusinessfocus); CheckAddress(responseViewModel.EquipmentLocation.Address, stringsToMatch[1], stringsToMatch[2], stringsToMatch[3], stringsToMatch[4], stringsToMatch[5], stringsToMatch[6], stringsToMatch[7] ); Assert.False(responseViewModel.EquipmentLocation.PrivateDwelling); Assert.Equal(stringsToMatch[8], responseViewModel.EquipmentLocation.SettingDescription); // D - Delete request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service + "/" + id + "/delete"); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // second delete should return a 404. request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service + "/" + id + "/delete"); response = await _client.SendAsync(request); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); // should get a 404 if we try a get now. request = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id); response = await _client.SendAsync(request); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); // logout and cleanup (deletes the account and contact created above ^^^) await LogoutAndCleanupTestUser(strId); }
public async System.Threading.Tasks.Task Test25MbUploadFile() { // Create application string initialName = randomNewUserName("Application Initial Name ", 6); string changedName = randomNewUserName("Application Changed Name ", 6); string service = "Application"; // login as default and get account for current user string loginUser = randomNewUserName("TestAppUser_", 6); var strId = await LoginAndRegisterAsNewUser(loginUser); User user = await GetCurrentUser(); Account currentAccount = await GetAccountForCurrentUser(); var request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service + "/Waiver"); Application viewmodel_application = SecurityHelper.CreateNewApplication(currentAccount); var jsonString = JsonConvert.SerializeObject(viewmodel_application); request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json"); var response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); jsonString = await response.Content.ReadAsStringAsync(); Application responseViewModel = JsonConvert.DeserializeObject <Application>(jsonString); Assert.Equal("Testing", responseViewModel.mainbusinessfocus); Assert.Equal("Automated Testing", responseViewModel.manufacturingprocessdescription); Guid id = new Guid(responseViewModel.id); request = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); jsonString = await response.Content.ReadAsStringAsync(); responseViewModel = JsonConvert.DeserializeObject <Application>(jsonString); Assert.Equal("Testing", responseViewModel.mainbusinessfocus); Assert.True(responseViewModel.applicant != null); Assert.Equal(currentAccount.id, responseViewModel.applicant.id); // Test upload, get, delete attachment string documentType = "Licence Application Main"; using (var formData = new MultipartFormDataContent()) { // Upload var fileContent = new ByteArrayContent(new byte[25 * 1024 * 1024]); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") { Name = "file", FileName = "test.pdf" }; formData.Add(fileContent); formData.Add(new StringContent(documentType, Encoding.UTF8, "application/json"), "documentType"); response = _client.PostAsync($"/api/file/{id}/attachments/incident", formData).Result; Assert.Equal(HttpStatusCode.OK, response.StatusCode); } // Get request = new HttpRequestMessage(HttpMethod.Get, $"/api/file/{id}/attachments/incident/{documentType}"); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); jsonString = await response.Content.ReadAsStringAsync(); var files = JsonConvert.DeserializeObject <List <FileSystemItem> >(jsonString); files.ForEach(async file => { // Delete request = new HttpRequestMessage(HttpMethod.Delete, $"/api/file/{id}/attachments/incident?serverRelativeUrl={Uri.EscapeDataString(file.serverrelativeurl)}&documentType={documentType}"); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); }); request = new HttpRequestMessage(HttpMethod.Get, $"/api/file/{id}/attachments/incident/{documentType}"); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); jsonString = await response.Content.ReadAsStringAsync(); files = JsonConvert.DeserializeObject <List <FileSystemItem> >(jsonString); Assert.Empty(files); await LogoutAndCleanupTestUser(strId); }
public async System.Threading.Tasks.Task TestUserCanAccessApplicationForTheirAccount() { string initialName = randomNewUserName("Application Shared ", 6); string service = "Application"; // login as default and get account for current user string loginUser1 = randomNewUserName("TestAppUser", 6); string loginAccount = randomNewUserName(loginUser1, 6); string loginUser2 = loginUser1 + "-2"; loginUser1 = loginUser1 + "-1"; var strId1 = await LoginAndRegisterAsNewUser(loginUser1, loginAccount); User user1 = await GetCurrentUser(); Account currentAccount1 = await GetAccountForCurrentUser(); // C - Create var request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service + "/Waiver"); Application viewmodel_application = SecurityHelper.CreateNewApplication(currentAccount1); var jsonString = JsonConvert.SerializeObject(viewmodel_application); request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json"); var response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // parse as JSON. jsonString = await response.Content.ReadAsStringAsync(); Application responseViewModel = JsonConvert.DeserializeObject <Application>(jsonString); // name should match. Assert.Equal("Testing", responseViewModel.mainbusinessfocus); Assert.Equal("Automated Testing", responseViewModel.manufacturingprocessdescription); Guid id = new Guid(responseViewModel.id); // R - Read request = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); jsonString = await response.Content.ReadAsStringAsync(); responseViewModel = JsonConvert.DeserializeObject <Application>(jsonString); Assert.Equal(currentAccount1.id, responseViewModel.applicant.id); await Logout(); // register and login as a second user var strId2 = await LoginAndRegisterAsNewUser(loginUser2, loginAccount); User user2 = await GetCurrentUser(); Account currentAccount2 = await GetAccountForCurrentUser(); // same account as user 1 Assert.Equal(currentAccount2.id, currentAccount1.id); // R - Read (should be able to access by user) request = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // logout and cleanup (deletes the account and contact created above ^^^) await LogoutAndCleanupTestUser(strId2); // log back in as first user await Login(loginUser1); // R - Read - still has access to application request = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); jsonString = await response.Content.ReadAsStringAsync(); responseViewModel = JsonConvert.DeserializeObject <Application>(jsonString); Assert.Equal(currentAccount1.id, responseViewModel.applicant.id); // D - Delete request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service + "/" + id + "/delete"); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // should get a 404 if we try a get now. request = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id); response = await _client.SendAsync(request); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); // logout and cleanup (deletes the account and contact created above ^^^) await LogoutAndCleanupTestUser(strId1); //await Logout(); }
public async System.Threading.Tasks.Task TestFileListing() { string initialName = randomNewUserName("First InitialName", 6); string changedName = randomNewUserName("First ChangedName", 6); string service = "Application"; // Login as default user var loginUser = randomNewUserName("NewLoginUser", 6); var strId = await LoginAndRegisterAsNewUser(loginUser); User user = await GetCurrentUser(); Account currentAccount = await GetAccountForCurrentUser(); // C - Create var request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service + "/Waiver"); Application viewmodel_application = SecurityHelper.CreateNewApplication(currentAccount); var jsonString = JsonConvert.SerializeObject(viewmodel_application); request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json"); var response = await _client.SendAsync(request); jsonString = await response.Content.ReadAsStringAsync(); response.EnsureSuccessStatusCode(); // parse as JSON. Application responseViewModel = JsonConvert.DeserializeObject <Application>(jsonString); //Assert.Equal("Applying Person", responseViewModel.applyingPerson); Assert.Equal("Testing", responseViewModel.mainbusinessfocus); Assert.Equal("Automated Testing", responseViewModel.manufacturingprocessdescription); Guid id = new Guid(responseViewModel.id); // Attach a file string testData = "This is just a test."; byte[] bytes = Encoding.ASCII.GetBytes(testData); string documentType = "Test Document Type"; // Create random filename var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; var stringChars = new char[9]; var random = new Random(); for (int i = 0; i < stringChars.Length; i++) { stringChars[i] = chars[random.Next(chars.Length)]; } var randomString = new String(stringChars); string filename = randomString + ".txt"; MultipartFormDataContent multiPartContent = new MultipartFormDataContent("----TestBoundary"); var fileContent = new MultipartContent { new ByteArrayContent(bytes) }; fileContent.Headers.ContentType = new MediaTypeHeaderValue("text/plain"); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data"); fileContent.Headers.ContentDisposition.Name = "File"; fileContent.Headers.ContentDisposition.FileName = filename; multiPartContent.Add(fileContent); multiPartContent.Add(new StringContent(documentType), "documentType"); // form input string accountId = user.accountid; // create a new request object for the upload, as we will be using multipart form submission. var requestMessage = new HttpRequestMessage(HttpMethod.Post, $"/api/file/{ id }/attachments/incident"); requestMessage.Content = multiPartContent; var uploadResponse = await _client.SendAsync(requestMessage); uploadResponse.EnsureSuccessStatusCode(); // Cleanup request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service + "/" + id + "/delete"); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // should get a 404 if we try a get now. request = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id); response = await _client.SendAsync(request); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); await LogoutAndCleanupTestUser(strId); }
public async System.Threading.Tasks.Task TestCRUD() { string initialName = randomNewUserName("Application Initial Name ", 6); string changedName = randomNewUserName("Application Changed Name ", 6); string service = "Application"; // login as default and get account for current user var loginUser1 = randomNewUserName("TestAccountUser", 6); var strId = await LoginAndRegisterAsNewUser(loginUser1); User user = await GetCurrentUser(); Account currentAccount = await GetAccountForCurrentUser(); // C - Create var request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service + "/Waiver"); Application viewmodel_application = SecurityHelper.CreateNewApplication(currentAccount); var jsonString = JsonConvert.SerializeObject(viewmodel_application); request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json"); var response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // parse as JSON. jsonString = await response.Content.ReadAsStringAsync(); Application responseViewModel = JsonConvert.DeserializeObject <Application>(jsonString); Assert.Equal("Testing", responseViewModel.mainbusinessfocus); Assert.Equal("Automated Testing", responseViewModel.manufacturingprocessdescription); Guid id = new Guid(responseViewModel.id); //return; // R - Read request = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); jsonString = await response.Content.ReadAsStringAsync(); responseViewModel = JsonConvert.DeserializeObject <Application>(jsonString); Assert.Equal("Testing", responseViewModel.mainbusinessfocus); Assert.Equal("Automated Testing", responseViewModel.manufacturingprocessdescription); Assert.True(responseViewModel.applicant != null); Assert.Equal(currentAccount.id, responseViewModel.applicant.id); // U - Update viewmodel_application = new Application(); viewmodel_application.mainbusinessfocus = changedName; request = new HttpRequestMessage(HttpMethod.Put, "/api/" + service + "/" + id) { Content = new StringContent(JsonConvert.SerializeObject(viewmodel_application), Encoding.UTF8, "application/json") }; response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // verify that the update persisted. request = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); jsonString = await response.Content.ReadAsStringAsync(); responseViewModel = JsonConvert.DeserializeObject <Application>(jsonString); Assert.Equal(changedName, responseViewModel.mainbusinessfocus); // D - Delete request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service + "/" + id + "/delete"); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // second delete should return a 404. request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service + "/" + id + "/delete"); response = await _client.SendAsync(request); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); // should get a 404 if we try a get now. request = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id); response = await _client.SendAsync(request); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); // logout and cleanup (deletes the account and contact created above ^^^) await LogoutAndCleanupTestUser(strId); }
public async System.Threading.Tasks.Task TestDashboard() { string initialName = randomNewUserName("Application Initial Name ", 6); string changedName = randomNewUserName("Application Changed Name ", 6); string service = "Application"; // login as default and get account for current user var loginUser1 = randomNewUserName("TestAccountUser", 6); var strId = await LoginAndRegisterAsNewUser(loginUser1); User user = await GetCurrentUser(); Account currentAccount = await GetAccountForCurrentUser(); // C - Create var request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service + "/Waiver"); Application viewmodel_application = SecurityHelper.CreateNewApplication(currentAccount); var jsonString = JsonConvert.SerializeObject(viewmodel_application); request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json"); var response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // parse as JSON. jsonString = await response.Content.ReadAsStringAsync(); Application responseViewModel = JsonConvert.DeserializeObject <Application>(jsonString); Assert.Equal("Testing", responseViewModel.mainbusinessfocus); Assert.Equal("Automated Testing", responseViewModel.manufacturingprocessdescription); Guid id = new Guid(responseViewModel.id); // verify that item is now available on the dashboard. request = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/current"); request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json"); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // parse as JSON. jsonString = await response.Content.ReadAsStringAsync(); List <Application> dashboardItems = JsonConvert.DeserializeObject <List <Application> >(jsonString); bool found = false; // verify that the item was present foreach (var item in dashboardItems) { if (item.id == responseViewModel.id) { found = true; } } Assert.True(found); // D - Delete request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service + "/" + id + "/delete"); response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); // second delete should return a 404. request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service + "/" + id + "/delete"); response = await _client.SendAsync(request); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); // should get a 404 if we try a get now. request = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id); response = await _client.SendAsync(request); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); // logout and cleanup (deletes the account and contact created above ^^^) await LogoutAndCleanupTestUser(strId); }