From 44e65ce08219059c0e439e54a1dbc4cb18610ff3 Mon Sep 17 00:00:00 2001 From: Shuhan Jin Date: Mon, 6 Nov 2023 18:32:35 +0800 Subject: [PATCH 1/7] feat(AC2and AC3): implement get all company and get company by id --- CompanyApi/Controllers/CompanyController.cs | 22 +++++++++- CompanyApi/CreateCompanyRequest.cs | 7 +++- CompanyApiTest/CompanyApiTest.cs | 46 +++++++++++++++++++++ 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/CompanyApi/Controllers/CompanyController.cs b/CompanyApi/Controllers/CompanyController.cs index 08002a0..6c70e8c 100644 --- a/CompanyApi/Controllers/CompanyController.cs +++ b/CompanyApi/Controllers/CompanyController.cs @@ -22,8 +22,28 @@ public ActionResult Create(CreateCompanyRequest request) [HttpDelete] public void ClearData() - { + { companies.Clear(); } + + [HttpGet] + public ActionResult> GetAll() + { + return companies; + + } + + [HttpGet("{id}")] + public ActionResult Get(string id) + { + var company = companies.FirstOrDefault(cp => cp.Id == id); + + if (company != null) + { + return company; + } + + return NotFound(); + } } } diff --git a/CompanyApi/CreateCompanyRequest.cs b/CompanyApi/CreateCompanyRequest.cs index 7dc7c1c..78bd655 100644 --- a/CompanyApi/CreateCompanyRequest.cs +++ b/CompanyApi/CreateCompanyRequest.cs @@ -2,6 +2,11 @@ { public class CreateCompanyRequest { - public required string Name { get; set; } + public CreateCompanyRequest(string name) + { + Name = name; + } + + public string Name { get; set; } } } diff --git a/CompanyApiTest/CompanyApiTest.cs b/CompanyApiTest/CompanyApiTest.cs index 2f38b90..4e2b83c 100644 --- a/CompanyApiTest/CompanyApiTest.cs +++ b/CompanyApiTest/CompanyApiTest.cs @@ -2,6 +2,8 @@ using Microsoft.AspNetCore.Mvc.Testing; using Newtonsoft.Json; using System.Net; +using System.Net.Http; +using System.Net.Http.Json; using System.Text; namespace CompanyApiTest @@ -84,5 +86,49 @@ private async Task ClearDataAsync() { await httpClient.DeleteAsync("/api/companies"); } + + [Fact] + public async Task Should_return_all_companies_with_status_200_when_GetAll_given_without_company_name() + { + // Given + await ClearDataAsync(); + var companyGiven = new CreateCompanyRequest("BlueSky Digital Media"); + await httpClient.PostAsJsonAsync("api/companies", companyGiven); + + // When + HttpResponseMessage httpResponseMessage = await httpClient.GetAsync("api/companies"); + + // Then + Assert.Equal(HttpStatusCode.OK, httpResponseMessage.StatusCode); //ok = 200 + //Assert.Equal(companyGiven,await httpResponseMessage.Content.ReadFromJsonAsync>()); + + } + + [Fact] + public async Task Should_return_company_name_with_status_200_when_Get_given_company_name_and_company_exist() + { + await ClearDataAsync(); + var companyGiven = new CreateCompanyRequest("BlueSky Digital Media"); + var createResponse = await httpClient.PostAsync( + "/api/companies", + SerializeObjectToContent(companyGiven)); + var company = await createResponse.Content.ReadFromJsonAsync(); + HttpResponseMessage httpResponseMessage = await httpClient.GetAsync("api/companies" + $"/{company?.Id}"); + var companyGet = await httpResponseMessage.Content.ReadFromJsonAsync(); + + // Then + Assert.Equal(company?.Id, companyGet?.Id); + Assert.Equal(HttpStatusCode.OK, httpResponseMessage.StatusCode); + } + + [Fact] + public async Task Should_return_status_404_when_Get_given_company_name_and_company_do_not_exist() + { + await ClearDataAsync(); + + HttpResponseMessage httpResponseMessage = await httpClient.GetAsync("api/companies/blueSky Digital Media"); + + Assert.Equal(HttpStatusCode.NotFound, httpResponseMessage.StatusCode); //NotFound = 404 + } } } \ No newline at end of file From 909b3a5d8ae048b2bc39972f3f546d7c84c839c0 Mon Sep 17 00:00:00 2001 From: Shuhan Jin Date: Mon, 6 Nov 2023 19:35:42 +0800 Subject: [PATCH 2/7] feat(AC2and AC3): obtain company from pageindex and pagesize --- CompanyApi/Controllers/CompanyController.cs | 8 +++++ CompanyApiTest/CompanyApiTest.cs | 34 +++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/CompanyApi/Controllers/CompanyController.cs b/CompanyApi/Controllers/CompanyController.cs index 6c70e8c..f950291 100644 --- a/CompanyApi/Controllers/CompanyController.cs +++ b/CompanyApi/Controllers/CompanyController.cs @@ -45,5 +45,13 @@ public ActionResult Get(string id) return NotFound(); } + + [HttpGet] + public ActionResult> GetCompanies(int pageSize, int pageIndex) + { + var startIndex = (pageIndex - 1) * pageSize; + var companiesPage = companies.Skip(startIndex).Take(pageSize).ToList(); + return Ok(companiesPage); + } } } diff --git a/CompanyApiTest/CompanyApiTest.cs b/CompanyApiTest/CompanyApiTest.cs index 4e2b83c..fe26fc5 100644 --- a/CompanyApiTest/CompanyApiTest.cs +++ b/CompanyApiTest/CompanyApiTest.cs @@ -130,5 +130,39 @@ public async Task Should_return_status_404_when_Get_given_company_name_and_compa Assert.Equal(HttpStatusCode.NotFound, httpResponseMessage.StatusCode); //NotFound = 404 } + + [Fact] + /*public async Task Should_Returns_Correct_PageSize_and_PageIndex_when_GetCompanies_Given_PageSize_and_PageIndex() + { + var companyGiven1 = new CreateCompanyRequest("BlueSky Digital Media"); + var companyGiven2 = new CreateCompanyRequest("Hyperoptics"); + await httpClient.PostAsJsonAsync("api/companies", companyGiven1); + await httpClient.PostAsJsonAsync("api/companies", companyGiven2); + + var response = await httpClient.GetAsync("/api/company?pageIndex=1&pageSize=2"); + response.EnsureSuccessStatusCode(); + var content = await response.Content.ReadAsStringAsync(); + var companies = JsonConvert.DeserializeObject>(content); + + Assert.Equal(2, companies.Count); + + foreach (var company in companies) + { + Assert.NotNull(company.Id); + Assert.NotNull(company.Name); + } + }*/ + + /*[Fact] + public async Task UpdateCompany_ReturnsNoContentStatusCode() + { + var updatedCompany = new Company { Id = 1, Name = "Updated Company A" }; + var jsonContent = JsonConvert.SerializeObject(updatedCompany); + var content = new StringContent(jsonContent, Encoding.UTF8, "application/json"); + + var response = await _client.PutAsync("/api/company/1", content); + + Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); + }*/ } } \ No newline at end of file From e8ef7236dbdf63cc1d855f07b1fd36a3ee211ce3 Mon Sep 17 00:00:00 2001 From: sjin9 Date: Mon, 6 Nov 2023 22:53:26 +0800 Subject: [PATCH 3/7] feat(AC5):update company name by id --- CompanyApi/Controllers/CompanyController.cs | 14 ++++++++ CompanyApiTest/CompanyApiTest.cs | 36 ++++++++++++++------- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/CompanyApi/Controllers/CompanyController.cs b/CompanyApi/Controllers/CompanyController.cs index f950291..4844ac6 100644 --- a/CompanyApi/Controllers/CompanyController.cs +++ b/CompanyApi/Controllers/CompanyController.cs @@ -53,5 +53,19 @@ public ActionResult> GetCompanies(int pageSize, int pageIndex) var companiesPage = companies.Skip(startIndex).Take(pageSize).ToList(); return Ok(companiesPage); } + + [HttpPut("{id}")] + public ActionResult Update(string id, [FromBody] Company updatedCompany) + { + var existingCompany = companies.FirstOrDefault(c => c.Id == id); + if (existingCompany == null) + { + return NotFound(); + } + + existingCompany.Name = updatedCompany.Name; + + return NoContent(); + } } } diff --git a/CompanyApiTest/CompanyApiTest.cs b/CompanyApiTest/CompanyApiTest.cs index fe26fc5..2c8cf99 100644 --- a/CompanyApiTest/CompanyApiTest.cs +++ b/CompanyApiTest/CompanyApiTest.cs @@ -132,7 +132,7 @@ public async Task Should_return_status_404_when_Get_given_company_name_and_compa } [Fact] - /*public async Task Should_Returns_Correct_PageSize_and_PageIndex_when_GetCompanies_Given_PageSize_and_PageIndex() + public async Task Should_Returns_Correct_PageSize_and_PageIndex_when_GetCompanies_Given_PageSize_and_PageIndex() { var companyGiven1 = new CreateCompanyRequest("BlueSky Digital Media"); var companyGiven2 = new CreateCompanyRequest("Hyperoptics"); @@ -140,7 +140,7 @@ public async Task Should_return_status_404_when_Get_given_company_name_and_compa await httpClient.PostAsJsonAsync("api/companies", companyGiven2); var response = await httpClient.GetAsync("/api/company?pageIndex=1&pageSize=2"); - response.EnsureSuccessStatusCode(); + //response.EnsureSuccessStatusCode(); var content = await response.Content.ReadAsStringAsync(); var companies = JsonConvert.DeserializeObject>(content); @@ -151,18 +151,32 @@ public async Task Should_return_status_404_when_Get_given_company_name_and_compa Assert.NotNull(company.Id); Assert.NotNull(company.Name); } - }*/ + } - /*[Fact] - public async Task UpdateCompany_ReturnsNoContentStatusCode() + [Fact] + public async Task Should_return_status_204_When_Update_Given_updated_company_name() { - var updatedCompany = new Company { Id = 1, Name = "Updated Company A" }; - var jsonContent = JsonConvert.SerializeObject(updatedCompany); - var content = new StringContent(jsonContent, Encoding.UTF8, "application/json"); + await ClearDataAsync(); + var companyGiven = new CreateCompanyRequest("BlueSky Digital Media"); + var createResponse = await httpClient.PostAsync( + "/api/companies", + SerializeObjectToContent(companyGiven)); + var company = await createResponse.Content.ReadFromJsonAsync(); + var updatedCompany = new Company("Hyperoptics"); - var response = await _client.PutAsync("/api/company/1", content); + HttpResponseMessage httpResponseMessage = await httpClient.PutAsJsonAsync("api/companies" + $"/{company?.Id}", updatedCompany); - Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); - }*/ + Assert.Equal(HttpStatusCode.NoContent, httpResponseMessage.StatusCode); + } + + [Fact] + public async Task Should_return_status_404_When_Update_Given_unmatched_company_id() + { + var updatedCompany = new Company("Hyperoptics"); + + HttpResponseMessage httpResponseMessage = await httpClient.PutAsJsonAsync("api/companies/1", updatedCompany); + + Assert.Equal(HttpStatusCode.NotFound, httpResponseMessage.StatusCode); + } } } \ No newline at end of file From 593909639befb3188008866cfecf1fa6f2a22269 Mon Sep 17 00:00:00 2001 From: sjin9 Date: Mon, 6 Nov 2023 23:25:58 +0800 Subject: [PATCH 4/7] feat(AC4): get a list of companies by page size and index --- CompanyApi/Controllers/CompanyController.cs | 15 +++++--- CompanyApi/Employee.cs | 6 ++++ CompanyApiTest/CompanyApiTest.cs | 38 +++++++++++++++------ 3 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 CompanyApi/Employee.cs diff --git a/CompanyApi/Controllers/CompanyController.cs b/CompanyApi/Controllers/CompanyController.cs index 4844ac6..fa31e9c 100644 --- a/CompanyApi/Controllers/CompanyController.cs +++ b/CompanyApi/Controllers/CompanyController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using System.Linq; namespace CompanyApi.Controllers { @@ -27,10 +28,16 @@ public void ClearData() } [HttpGet] - public ActionResult> GetAll() + public ActionResult> GetAll([FromQuery] int? pageSize, int? pageIndex) { - return companies; + if (pageSize != null && pageIndex != null) + { + var startIndex = (pageIndex - 1) * pageSize; + var companiesPage = companies.Skip((int)startIndex).Take((int)pageSize).ToList(); + return Ok(companiesPage); + } + return companies; } [HttpGet("{id}")] @@ -46,13 +53,13 @@ public ActionResult Get(string id) return NotFound(); } - [HttpGet] + /*[HttpGet] public ActionResult> GetCompanies(int pageSize, int pageIndex) { var startIndex = (pageIndex - 1) * pageSize; var companiesPage = companies.Skip(startIndex).Take(pageSize).ToList(); return Ok(companiesPage); - } + }*/ [HttpPut("{id}")] public ActionResult Update(string id, [FromBody] Company updatedCompany) diff --git a/CompanyApi/Employee.cs b/CompanyApi/Employee.cs new file mode 100644 index 0000000..ef11e46 --- /dev/null +++ b/CompanyApi/Employee.cs @@ -0,0 +1,6 @@ +namespace CompanyApi +{ + public class Employee + { + } +} diff --git a/CompanyApiTest/CompanyApiTest.cs b/CompanyApiTest/CompanyApiTest.cs index 2c8cf99..79ab822 100644 --- a/CompanyApiTest/CompanyApiTest.cs +++ b/CompanyApiTest/CompanyApiTest.cs @@ -1,4 +1,6 @@ using CompanyApi; +using CompanyApi.Controllers; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Testing; using Newtonsoft.Json; using System.Net; @@ -139,18 +141,34 @@ public async Task Should_Returns_Correct_PageSize_and_PageIndex_when_GetCompanie await httpClient.PostAsJsonAsync("api/companies", companyGiven1); await httpClient.PostAsJsonAsync("api/companies", companyGiven2); - var response = await httpClient.GetAsync("/api/company?pageIndex=1&pageSize=2"); - //response.EnsureSuccessStatusCode(); - var content = await response.Content.ReadAsStringAsync(); - var companies = JsonConvert.DeserializeObject>(content); + var httpResponseMessage = await httpClient.GetAsync("/api/companies?pageIndex=1&pageSize=2"); + List? companies = await httpResponseMessage.Content.ReadFromJsonAsync>(); - Assert.Equal(2, companies.Count); + Assert.Equal(HttpStatusCode.OK, httpResponseMessage.StatusCode); + Assert.Equal("BlueSky Digital Media", companies[0].Name); + Assert.Equal("Hyperoptics", companies[1].Name); + } - foreach (var company in companies) - { - Assert.NotNull(company.Id); - Assert.NotNull(company.Name); - } + [Fact] + public void GetAll_Returns200WithListOfCompanies() + { + // Arrange + var controller = new CompanyController(); + int? pageSize = 10; + int? pageIndex = 1; + + // Act + var response = controller.GetAll(pageSize, pageIndex); + var okResult = Assert.IsType(response.Result); + var companies = Assert.IsType>(okResult.Value); + + // Assert + Assert.Equal(200, okResult.StatusCode); + Assert.NotNull(companies); + + // Add additional assertions based on your requirements + // For example, you can check if the returned list has the expected number of items + Assert.Equal(pageSize, companies.Count); } [Fact] From c8edae597c44401f593572670f189a46a06f5f8f Mon Sep 17 00:00:00 2001 From: sjin9 Date: Mon, 6 Nov 2023 23:53:16 +0800 Subject: [PATCH 5/7] feat(AC6): add employee to a specific company --- CompanyApi/Company.cs | 3 ++ CompanyApi/Controllers/CompanyController.cs | 47 ++++++++++++++++----- CompanyApi/Employee.cs | 12 +++++- CompanyApiTest/CompanyApiTest.cs | 44 +++++++++---------- 4 files changed, 73 insertions(+), 33 deletions(-) diff --git a/CompanyApi/Company.cs b/CompanyApi/Company.cs index 43e7373..f626466 100644 --- a/CompanyApi/Company.cs +++ b/CompanyApi/Company.cs @@ -6,10 +6,13 @@ public Company(string name) { Id = Guid.NewGuid().ToString(); Name = name; + Employees = new List(); } public string Id { get; set; } public string Name { get; set; } + + public List Employees { get; set; } = new List(); } } diff --git a/CompanyApi/Controllers/CompanyController.cs b/CompanyApi/Controllers/CompanyController.cs index fa31e9c..799cd8b 100644 --- a/CompanyApi/Controllers/CompanyController.cs +++ b/CompanyApi/Controllers/CompanyController.cs @@ -43,7 +43,7 @@ public ActionResult> GetAll([FromQuery] int? pageSize, int? pageIn [HttpGet("{id}")] public ActionResult Get(string id) { - var company = companies.FirstOrDefault(cp => cp.Id == id); + var company = companies.Find(cp => cp.Id == id); if (company != null) { @@ -53,18 +53,10 @@ public ActionResult Get(string id) return NotFound(); } - /*[HttpGet] - public ActionResult> GetCompanies(int pageSize, int pageIndex) - { - var startIndex = (pageIndex - 1) * pageSize; - var companiesPage = companies.Skip(startIndex).Take(pageSize).ToList(); - return Ok(companiesPage); - }*/ - [HttpPut("{id}")] public ActionResult Update(string id, [FromBody] Company updatedCompany) { - var existingCompany = companies.FirstOrDefault(c => c.Id == id); + var existingCompany = companies.Find(c => c.Id == id); if (existingCompany == null) { return NotFound(); @@ -74,5 +66,40 @@ public ActionResult Update(string id, [FromBody] Company updatedCompany return NoContent(); } + + [HttpPost("{companyId}/employees")] + public ActionResult AddEmployee(string companyId, [FromBody] Employee employee) + { + var company = companies.Find(c => c.Id == companyId); + if (company == null) + { + return NotFound(); + } + + //employee.Id = Guid.NewGuid().ToString(); + company.Employees.Add(employee); + + return Ok(employee); + } + + /*[HttpDelete("employees/{employeeId}")] + public ActionResult DeleteEmployee(string companyId, string employeeId) + { + var company = companies.Find(c => c.Id == companyId); + if (company == null) + { + return NotFound(); + } + + var employee = company.Employees.FirstOrDefault(e => e.Id == employeeId); + if (employee == null) + { + return NotFound("Employee not found"); + } + + company.Employees.Remove(employee); + + return NoContent(); + }*/ } } diff --git a/CompanyApi/Employee.cs b/CompanyApi/Employee.cs index ef11e46..75b1969 100644 --- a/CompanyApi/Employee.cs +++ b/CompanyApi/Employee.cs @@ -1,6 +1,16 @@ -namespace CompanyApi +using System.Xml.Linq; + +namespace CompanyApi { public class Employee { + public Employee(string name) + { + Id = Guid.NewGuid().ToString(); + Name = name; + } + + public string Id { get; set; } + public string Name { get; set; } } } diff --git a/CompanyApiTest/CompanyApiTest.cs b/CompanyApiTest/CompanyApiTest.cs index 79ab822..ae569ab 100644 --- a/CompanyApiTest/CompanyApiTest.cs +++ b/CompanyApiTest/CompanyApiTest.cs @@ -149,28 +149,6 @@ public async Task Should_Returns_Correct_PageSize_and_PageIndex_when_GetCompanie Assert.Equal("Hyperoptics", companies[1].Name); } - [Fact] - public void GetAll_Returns200WithListOfCompanies() - { - // Arrange - var controller = new CompanyController(); - int? pageSize = 10; - int? pageIndex = 1; - - // Act - var response = controller.GetAll(pageSize, pageIndex); - var okResult = Assert.IsType(response.Result); - var companies = Assert.IsType>(okResult.Value); - - // Assert - Assert.Equal(200, okResult.StatusCode); - Assert.NotNull(companies); - - // Add additional assertions based on your requirements - // For example, you can check if the returned list has the expected number of items - Assert.Equal(pageSize, companies.Count); - } - [Fact] public async Task Should_return_status_204_When_Update_Given_updated_company_name() { @@ -196,5 +174,27 @@ public async Task Should_return_status_404_When_Update_Given_unmatched_company_i Assert.Equal(HttpStatusCode.NotFound, httpResponseMessage.StatusCode); } + + [Fact] + public async Task Should_Add_Employee_to_specific_company_When_AddEmployee_Given_() + { + await ClearDataAsync(); + var companyGiven = new CreateCompanyRequest("BlueSky Digital Media"); + var createResponse = await httpClient.PostAsync( + "/api/companies", + SerializeObjectToContent(companyGiven)); + var company = await createResponse.Content.ReadFromJsonAsync(); + var newEmployee = new Employee("Erika"); + company.Employees.Add(newEmployee); + + var httpResponseMessage = await httpClient.PostAsJsonAsync($"api/companies/{company.Id}/employees", newEmployee); + + Employee? addedEmployee = await httpResponseMessage.Content.ReadFromJsonAsync(); + + Assert.Equal("Erika", addedEmployee.Name); + Assert.Equal(HttpStatusCode.OK, httpResponseMessage.StatusCode); + } + + } } \ No newline at end of file From 048ff1254cd047c5f75aad3d776dca7791d70829 Mon Sep 17 00:00:00 2001 From: sjin9 Date: Tue, 7 Nov 2023 00:18:26 +0800 Subject: [PATCH 6/7] feat(AC7): delete a specific employee of a specific company --- CompanyApi/Controllers/CompanyController.cs | 10 +++--- CompanyApiTest/CompanyApiTest.cs | 38 ++++++++++++++++++++- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/CompanyApi/Controllers/CompanyController.cs b/CompanyApi/Controllers/CompanyController.cs index 799cd8b..e18f7b9 100644 --- a/CompanyApi/Controllers/CompanyController.cs +++ b/CompanyApi/Controllers/CompanyController.cs @@ -82,7 +82,7 @@ public ActionResult AddEmployee(string companyId, [FromBody] Employee e return Ok(employee); } - /*[HttpDelete("employees/{employeeId}")] + [HttpDelete("{companyId}/employees/{employeeId}")] public ActionResult DeleteEmployee(string companyId, string employeeId) { var company = companies.Find(c => c.Id == companyId); @@ -91,15 +91,15 @@ public ActionResult DeleteEmployee(string companyId, string employeeId) return NotFound(); } - var employee = company.Employees.FirstOrDefault(e => e.Id == employeeId); + var employee = company.Employees.Find(e => e.Id == employeeId); if (employee == null) { - return NotFound("Employee not found"); + return NotFound(); } company.Employees.Remove(employee); - return NoContent(); - }*/ + return NoContent(); //bc delete doesnt return anything + } } } diff --git a/CompanyApiTest/CompanyApiTest.cs b/CompanyApiTest/CompanyApiTest.cs index ae569ab..bf16df9 100644 --- a/CompanyApiTest/CompanyApiTest.cs +++ b/CompanyApiTest/CompanyApiTest.cs @@ -185,7 +185,6 @@ public async Task Should_Add_Employee_to_specific_company_When_AddEmployee_Given SerializeObjectToContent(companyGiven)); var company = await createResponse.Content.ReadFromJsonAsync(); var newEmployee = new Employee("Erika"); - company.Employees.Add(newEmployee); var httpResponseMessage = await httpClient.PostAsJsonAsync($"api/companies/{company.Id}/employees", newEmployee); @@ -195,6 +194,43 @@ public async Task Should_Add_Employee_to_specific_company_When_AddEmployee_Given Assert.Equal(HttpStatusCode.OK, httpResponseMessage.StatusCode); } + [Fact] + public async Task Should_delete_specific_employee_when_DeleteEmployee_Given_employeeId_and_companyId() + { + await ClearDataAsync(); + // create a company + var companyGiven = new CreateCompanyRequest("BlueSky Digital Media"); + var createResponse = await httpClient.PostAsync( + "/api/companies", + SerializeObjectToContent(companyGiven)); + var company = await createResponse.Content.ReadFromJsonAsync(); + + //create a employee of this company + var newEmployee = new Employee("Erika"); + company.Employees.Add(newEmployee); + var httpResponseMessage = await httpClient.PostAsJsonAsync($"api/companies/{company.Id}/employees", newEmployee); + Employee? employee = await httpResponseMessage.Content.ReadFromJsonAsync(); + + //delete employee + var response = await httpClient.DeleteAsync($"api/companies/{company.Id}/employees/{employee.Id}"); + + Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); + } + + [Fact] + public async Task Should_return_status_404_when_DeleteEmployee_Given_employeeId_not_valid() + { + await ClearDataAsync(); + var companyGiven = new CreateCompanyRequest("BlueSky Digital Media"); + var createResponse = await httpClient.PostAsync( + "/api/companies", + SerializeObjectToContent(companyGiven)); + var company = await createResponse.Content.ReadFromJsonAsync(); + + var response = await httpClient.DeleteAsync($"api/companies/{company.Id}/employees/1"); + + Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); + } } } \ No newline at end of file From 11c2a2c5b2c35cd47e67afd67f2223495c124d4c Mon Sep 17 00:00:00 2001 From: sjin9 <148843137+sjin9@users.noreply.github.com> Date: Tue, 7 Nov 2023 00:23:43 +0800 Subject: [PATCH 7/7] Update apis.http --- CompanyApi/apis.http | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/CompanyApi/apis.http b/CompanyApi/apis.http index a17fa51..b028c0a 100644 --- a/CompanyApi/apis.http +++ b/CompanyApi/apis.http @@ -58,4 +58,41 @@ Content-Type: application/json; charset=utf-8 ### Case1: Sucess, 204 NO Content ### Case2: 404 Company NOT Found -###################################################################################### \ No newline at end of file +###################################################################################### + +## AC6 add employee to a specific company +PUT https://{{hostname}}:{{port}}/api/Companies/{companyID}/employee +Content-Type: application/json; charset=utf-8 + +Company: +{ + "name": Google +} + +employee: +{ + "name": Eleanor +} +### Response: +### Case1: Sucess, 200 ok, with the employee name +### Case2: 404 Company NOT Found + +###################################################################################### + +## AC7 delete a specific employee from a specific company +PUT https://{{hostname}}:{{port}}/api/Companies/{companyID}/employee/{employeeID} +Content-Type: application/json; charset=utf-8 + +Company: +{ + "name": Google +} + +employee: +{ + "name": Eleanor +} +### Response: +### Case1: success, 204 no content +### Case2: 404 Company NOT Found +### Case3: 404 emloyee NOT Found