Skip to content

Commit e65d18f

Browse files
committed
cleaned: TO-DO : req.resp
1 parent 9d46f8a commit e65d18f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+138
-247
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ VisualStudioVersion = 16.0.31005.135
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Api", "Api", "{B55D2BE1-7C69-4EF0-BBB2-F1B8D0F9C8C4}"
77
EndProject
8-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Rest.Api", "src\Api\Coding.Challenge.Api\Rest.Api.csproj", "{5D8B62B2-549D-44B4-BAEA-D95246B461FA}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xero.Demo.Api", "src\Api\Coding.Challenge.Api\Xero.Demo.Api.csproj", "{5D8B62B2-549D-44B4-BAEA-D95246B461FA}"
99
EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Api.Test", "Api.Test", "{84CAFD70-C5BC-45F5-8066-1898CD37ED15}"
1111
EndProject
12-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Rest.Api.Tests", "src\Api.Test\Coding.Challenge.Api.Tests\Rest.Api.Tests.csproj", "{7825EF30-568B-428A-8125-C63AA149B101}"
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xero.Demo.Api.Tests", "src\Api.Test\Coding.Challenge.Api.Tests\Xero.Demo.Api.Tests.csproj", "{7825EF30-568B-428A-8125-C63AA149B101}"
1313
EndProject
1414
Global
1515
GlobalSection(SolutionConfigurationPlatforms) = preSolution

src/Api.Test/Coding.Challenge.Api.Tests/EndpointsTests/IntegrationTests/ProductControllerTest.cs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
using Rest.Api.Tests.EndpointTests.UnitTests.V1.TestData;
2-
using Rest.Api.Tests.Setup;
1+
using Xero.Demo.Api.Tests.EndpointTests.UnitTests.V1.TestData;
2+
using Xero.Demo.Api.Tests.Setup;
33
using Newtonsoft.Json;
44
using System;
55
using System.Collections.Generic;
66
using System.Linq;
77
using System.Net.Http.Json;
88
using System.Threading.Tasks;
99
using Xunit;
10-
using Rest.Api.Domain;
11-
using Rest.Api.Domain.Models;
10+
using Xero.Demo.Api.Domain;
11+
using Xero.Demo.Api.Domain.Models;
1212

13-
namespace Rest.Api.Tests.EndpointTests.IntegrationTests
13+
namespace Xero.Demo.Api.Tests.EndpointTests.IntegrationTests
1414
{
1515
[Trait("Category", "Integration")]
1616
public class ProductControllerTest : IDisposable
@@ -24,7 +24,7 @@ public ProductControllerTest()
2424

2525
[Theory]
2626
[InlineData("en-US", "1")]
27-
[InlineData("en-US", "2")]
27+
//[InlineData("en-US", "2")]
2828
public async Task GetAsync_Returns_200(string culture, string version)
2929
{
3030
// Given
@@ -98,24 +98,6 @@ public async Task PutAsync_Returns_204(string culture, string version)
9898
Assert.Equal(System.Net.HttpStatusCode.NoContent, response.StatusCode);
9999
}
100100

101-
[Theory]
102-
[InlineData("en-US", "1")]
103-
//[InlineData("en-US", "2")]
104-
public async Task DeleteAsync_Returns_204(string culture, string version)
105-
{
106-
// Given
107-
var client = factory.CreateClient();
108-
var addProductResponse = await client.PostAsJsonAsync(string.Format(SampleDataV1.productEndpoint, culture, version), SampleDataV1.Product);
109-
var addedProduct = JsonConvert.DeserializeObject<Product>(await addProductResponse.Content.ReadAsStringAsync());
110-
var id = addedProduct.Id;
111-
112-
// When
113-
var response = await client.DeleteAsync(string.Format(SampleDataV1.productEndpoint, culture, version) + $"/{id}");
114-
115-
// Then
116-
Assert.Equal(System.Net.HttpStatusCode.NoContent, response.StatusCode);
117-
}
118-
119101
public void Dispose()
120102
{
121103
factory = null;

src/Api.Test/Coding.Challenge.Api.Tests/EndpointsTests/UnitTests/V1/Products/CreateTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using Rest.Api.Endpoints.V1.Products;
2-
using Rest.Api.Domain.Models;
1+
using Xero.Demo.Api.Endpoints.V1.Products;
2+
using Xero.Demo.Api.Domain.Models;
33
using Microsoft.AspNetCore.Http;
44
using Microsoft.AspNetCore.Mvc;
55
using Microsoft.EntityFrameworkCore;
@@ -8,10 +8,10 @@
88
using System;
99
using System.Threading.Tasks;
1010
using Xunit;
11-
using Rest.Api.Tests.EndpointTests.UnitTests.V1.TestData;
12-
using Rest.Api.Datastore;
11+
using Xero.Demo.Api.Tests.EndpointTests.UnitTests.V1.TestData;
12+
using Xero.Demo.Api.Datastore;
1313

14-
namespace Rest.Api.Tests.EndpointTests.UnitTests.V1.Products
14+
namespace Xero.Demo.Api.Tests.EndpointTests.UnitTests.V1.Products
1515
{
1616
[Trait("Category", "Unit")]
1717
public class CreateTest : IDisposable

src/Api.Test/Coding.Challenge.Api.Tests/EndpointsTests/UnitTests/V1/Products/DeleteTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using Rest.Api.Endpoints.V1.Products;
2-
using Rest.Api.Tests.EndpointTests.UnitTests.V1.TestData;
3-
using Rest.Api.Domain;
1+
using Xero.Demo.Api.Endpoints.V1.Products;
2+
using Xero.Demo.Api.Tests.EndpointTests.UnitTests.V1.TestData;
3+
using Xero.Demo.Api.Domain;
44
using Microsoft.AspNetCore.Http;
55
using Microsoft.AspNetCore.Mvc;
66
using Microsoft.EntityFrameworkCore;
@@ -9,9 +9,9 @@
99
using System;
1010
using System.Threading.Tasks;
1111
using Xunit;
12-
using Rest.Api.Datastore;
12+
using Xero.Demo.Api.Datastore;
1313

14-
namespace Rest.Api.Tests.EndpointTests.UnitTests.V1.Products
14+
namespace Xero.Demo.Api.Tests.EndpointTests.UnitTests.V1.Products
1515
{
1616
[Trait("Category", "Unit")]
1717
public class DeleteTest : IDisposable
@@ -40,7 +40,7 @@ public async Task DeleteAsync_Deletes_Product_Successfully_With_Valid_Product_Id
4040
};
4141

4242
var product = await moqDatabase.Products.AddAsync(SampleDataV1.Product); //adding the product to be database
43-
await moqDatabase.SaveAsync(); //saving the product to be deleted
43+
await moqDatabase.SaveChangesAsync(); //saving the product to be deleted
4444

4545
//When
4646
var actualResponse = await sut.DeleteAsync(product.Entity.Id) as NoContentResult;

src/Api.Test/Coding.Challenge.Api.Tests/EndpointsTests/UnitTests/V1/Products/ReadTest.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Rest.Api.Endpoints.V1.Products;
2-
using Rest.Api.Domain;
1+
using Xero.Demo.Api.Endpoints.V1.Products;
32
using Microsoft.AspNetCore.Http;
43
using Microsoft.AspNetCore.Mvc;
54
using Microsoft.EntityFrameworkCore;
@@ -9,11 +8,11 @@
98
using System.Collections.Generic;
109
using System.Threading.Tasks;
1110
using Xunit;
12-
using Rest.Api.Domain.Models;
13-
using Rest.Api.Tests.EndpointTests.UnitTests.V1.TestData;
14-
using Rest.Api.Datastore;
11+
using Xero.Demo.Api.Domain.Models;
12+
using Xero.Demo.Api.Tests.EndpointTests.UnitTests.V1.TestData;
13+
using Xero.Demo.Api.Datastore;
1514

16-
namespace Rest.Api.Tests.EndpointTests.UnitTests.V1.Products
15+
namespace Xero.Demo.Api.Tests.EndpointTests.UnitTests.V1.Products
1716
{
1817
[Trait("Category", "Unit")]
1918
public class ReadTest : IDisposable
@@ -52,7 +51,7 @@ public async Task GetAsync_Gets_All_Product_Successfully()
5251
products.Add(SampleDataV1.Product);
5352
products.Add(SampleDataV1.Product);
5453
moqDatabase.Products.AddRange(products); //adding the products to be database
55-
await moqDatabase.SaveAsync(); //saving the product to be deleted
54+
await moqDatabase.SaveChangesAsync(); //saving the product to be deleted
5655

5756
//When
5857
var actualResponse = await sut.GetAsync() as OkObjectResult;
@@ -69,7 +68,7 @@ public async Task GetByIdAsync_Gets_All_Product_Successfully()
6968
{
7069
//Given
7170
var product = await moqDatabase.Products.AddAsync(SampleDataV1.Product); //adding the product to be database
72-
await moqDatabase.SaveAsync(); //saving the product to be deleted
71+
await moqDatabase.SaveChangesAsync(); //saving the product to be deleted
7372

7473
//When
7574
var actualResponse = await sut.GetByIdAsync(product.Entity.Id) as OkObjectResult;

src/Api.Test/Coding.Challenge.Api.Tests/EndpointsTests/UnitTests/V1/Products/UpdateTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using Rest.Api.Endpoints.V1.Products;
2-
using Rest.Api.Tests.EndpointTests.UnitTests.V1.TestData;
3-
using Rest.Api.Domain;
1+
using Xero.Demo.Api.Endpoints.V1.Products;
2+
using Xero.Demo.Api.Tests.EndpointTests.UnitTests.V1.TestData;
3+
using Xero.Demo.Api.Domain;
44
using Microsoft.AspNetCore.Http;
55
using Microsoft.AspNetCore.Mvc;
66
using Microsoft.EntityFrameworkCore;
@@ -9,9 +9,9 @@
99
using System;
1010
using System.Threading.Tasks;
1111
using Xunit;
12-
using Rest.Api.Datastore;
12+
using Xero.Demo.Api.Datastore;
1313

14-
namespace Rest.Api.Tests.EndpointTests.UnitTests.V1.Products
14+
namespace Xero.Demo.Api.Tests.EndpointTests.UnitTests.V1.Products
1515
{
1616
[Trait("Category", "Unit")]
1717
public class UpdateTest : IDisposable
@@ -40,7 +40,7 @@ public async Task PutAsync_Updates_Product_Successfully_With_Valid_Product_Id_an
4040
};
4141

4242
var product = await moqDatabase.Products.AddAsync(SampleDataV1.Product); //adding the product to be database
43-
await moqDatabase.SaveAsync(); //saving the product to be updated
43+
await moqDatabase.SaveChangesAsync(); //saving the product to be updated
4444
product.Entity.Description = SampleDataV1.NewDescription;
4545

4646
//When

src/Api.Test/Coding.Challenge.Api.Tests/EndpointsTests/UnitTests/V1/TestData/SampleData.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using Rest.Api.Domain.Models;
1+
using Xero.Demo.Api.Domain.Models;
22
using System;
33
using System.Collections.Generic;
44

5-
namespace Rest.Api.Tests.EndpointTests.UnitTests.V1.TestData
5+
namespace Xero.Demo.Api.Tests.EndpointTests.UnitTests.V1.TestData
66
{
77
internal class SampleDataV1
88
{

src/Api.Test/Coding.Challenge.Api.Tests/EndpointsTests/UnitTests/V2/Products/CreateTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using Rest.Api.Endpoints.V2.Products;
2-
using Rest.Api.Domain.Models;
1+
using Xero.Demo.Api.Endpoints.V2.Products;
2+
using Xero.Demo.Api.Domain.Models;
33
using Microsoft.AspNetCore.Http;
44
using Microsoft.AspNetCore.Mvc;
55
using Microsoft.EntityFrameworkCore;
@@ -8,10 +8,10 @@
88
using System;
99
using System.Threading.Tasks;
1010
using Xunit;
11-
using Rest.Api.Tests.EndpointTests.UnitTests.V2.TestData;
12-
using Rest.Api.Datastore;
11+
using Xero.Demo.Api.Tests.EndpointTests.UnitTests.V2.TestData;
12+
using Xero.Demo.Api.Datastore;
1313

14-
namespace Rest.Api.Tests.EndpointTests.UnitTests.V2.Products
14+
namespace Xero.Demo.Api.Tests.EndpointTests.UnitTests.V2.Products
1515
{
1616
[Trait("Category", "Unit")]
1717
public class CreateTest : IDisposable

src/Api.Test/Coding.Challenge.Api.Tests/EndpointsTests/UnitTests/V2/TestData/SampleData.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using Rest.Api.Domain.Models;
1+
using Xero.Demo.Api.Domain.Models;
22
using System.Collections.Generic;
33

4-
namespace Rest.Api.Tests.EndpointTests.UnitTests.V2.TestData
4+
namespace Xero.Demo.Api.Tests.EndpointTests.UnitTests.V2.TestData
55
{
66
internal class SampleDataV2
77
{

src/Api.Test/Coding.Challenge.Api.Tests/Setup/SetupStartup.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Rest.Api.Tests.EndpointTests.UnitTests.V1.TestData;
1+
using Xero.Demo.Api.Tests.EndpointTests.UnitTests.V1.TestData;
22
using Microsoft.AspNetCore.Hosting;
33
using Microsoft.AspNetCore.Mvc.Testing;
44
using Microsoft.EntityFrameworkCore;
@@ -7,9 +7,9 @@
77
using System;
88
using System.Linq;
99
using System.Threading.Tasks;
10-
using Rest.Api.Datastore;
10+
using Xero.Demo.Api.Datastore;
1111

12-
namespace Rest.Api.Tests.Setup
12+
namespace Xero.Demo.Api.Tests.Setup
1313
{
1414
public class CustomWebApplicationFactory<TStartup> : WebApplicationFactory<TStartup> where TStartup : class
1515
{
@@ -22,7 +22,7 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
2222
services.Remove(descriptor);
2323

2424
services.AddDbContext<Database>(options => options.UseInMemoryDatabase("TestDB"));
25-
services.AddSingleton<IDatabase>(provider => provider.GetService<Database>());
25+
//services.AddSingleton<IDatabase>(provider => provider.GetService<Database>());
2626

2727
var sp = services.BuildServiceProvider();
2828

0 commit comments

Comments
 (0)