Skip to content

Commit a4c7739

Browse files
authored
Merge pull request #1 from AJEETX/Dev
Dev
2 parents 53ba28c + a205d5c commit a4c7739

File tree

14 files changed

+124
-63
lines changed

14 files changed

+124
-63
lines changed

src/Api.Test/EndpointsTests/UnitTests/V1/Products/CreateTest.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ namespace Xero.Demo.Api.Tests.EndpointTests.UnitTests.V1.Products
1616
[Trait("Category", "Unit")]
1717
public class CreateTest : IDisposable
1818
{
19-
private Mock<ILogger<ProductsController>> moqLogger;
2019
private DbContextOptions<Database> options;
2120

2221
public CreateTest()
2322
{
24-
moqLogger = new Mock<ILogger<ProductsController>>();
2523
options = new DbContextOptionsBuilder<Database>().UseInMemoryDatabase(databaseName: SampleDataV1.Database).Options;
2624
}
2725

@@ -30,7 +28,7 @@ public async Task PostAsync_Adds_Product_Successfully_With_Valid_Product_Details
3028
{
3129
//Given
3230
using var moqDatabase = new Database(options);
33-
var sut = new ProductsController(moqLogger.Object, moqDatabase)
31+
var sut = new ProductsController(moqDatabase)
3432
{
3533
ControllerContext = new ControllerContext()
3634
};
@@ -52,7 +50,6 @@ public async Task PostAsync_Adds_Product_Successfully_With_Valid_Product_Details
5250

5351
public void Dispose()
5452
{
55-
moqLogger = null;
5653
options = null;
5754
}
5855
}

src/Api.Test/EndpointsTests/UnitTests/V1/Products/DeleteTest.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ namespace Xero.Demo.Api.Tests.EndpointTests.UnitTests.V1.Products
1717
public class DeleteTest : IDisposable
1818
{
1919
private Database moqDatabase;
20-
private Mock<ILogger<ProductsController>> moqLogger;
2120

2221
public DeleteTest()
2322
{
24-
moqLogger = new Mock<ILogger<ProductsController>>();
2523
var options = new DbContextOptionsBuilder<Database>().UseInMemoryDatabase(databaseName: SampleDataV1.Database).Options;
2624
moqDatabase = new Database(options);
2725
}
@@ -30,7 +28,7 @@ public DeleteTest()
3028
public async Task DeleteAsync_Deletes_Product_Successfully_With_Valid_Product_Id()
3129
{
3230
//Given
33-
var sut = new ProductsController(moqLogger.Object, moqDatabase)
31+
var sut = new ProductsController(moqDatabase)
3432
{
3533
ControllerContext = new ControllerContext()
3634
};
@@ -53,7 +51,6 @@ public async Task DeleteAsync_Deletes_Product_Successfully_With_Valid_Product_Id
5351
public void Dispose()
5452
{
5553
moqDatabase = null;
56-
moqLogger = null;
5754
}
5855
}
5956
}

src/Api.Test/EndpointsTests/UnitTests/V1/Products/ReadTest.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@ namespace Xero.Demo.Api.Tests.EndpointTests.UnitTests.V1.Products
1818
public class ReadTest : IDisposable
1919
{
2020
private Database moqDatabase;
21-
private Mock<ILogger<ProductsController>> moqLogger;
2221
private ProductsController sut;
2322

2423
public ReadTest()
2524
{
26-
moqLogger = new Mock<ILogger<ProductsController>>();
2725
var options = new DbContextOptionsBuilder<Database>().UseInMemoryDatabase(databaseName: SampleDataV1.Database).Options;
2826
moqDatabase = new Database(options);
29-
sut = new ProductsController(moqLogger.Object, moqDatabase)
27+
sut = new ProductsController(moqDatabase)
3028
{
3129
ControllerContext = new ControllerContext()
3230
};
@@ -39,7 +37,6 @@ public ReadTest()
3937
public void Dispose()
4038
{
4139
moqDatabase = null;
42-
moqLogger = null;
4340
sut = null;
4441
}
4542

src/Api.Test/EndpointsTests/UnitTests/V1/Products/UpdateTest.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ namespace Xero.Demo.Api.Tests.EndpointTests.UnitTests.V1.Products
1717
public class UpdateTest : IDisposable
1818
{
1919
private Database moqDatabase;
20-
private Mock<ILogger<ProductsController>> moqLogger;
2120

2221
public UpdateTest()
2322
{
24-
moqLogger = new Mock<ILogger<ProductsController>>();
2523
var options = new DbContextOptionsBuilder<Database>().UseInMemoryDatabase(databaseName: SampleDataV1.Database).Options;
2624
moqDatabase = new Database(options);
2725
}
@@ -30,7 +28,7 @@ public UpdateTest()
3028
public async Task PutAsync_Updates_Product_Successfully_With_Valid_Product_Id_and_Details()
3129
{
3230
//Given
33-
var sut = new ProductsController(moqLogger.Object, moqDatabase)
31+
var sut = new ProductsController(moqDatabase)
3432
{
3533
ControllerContext = new ControllerContext()
3634
};
@@ -39,7 +37,7 @@ public async Task PutAsync_Updates_Product_Successfully_With_Valid_Product_Id_an
3937
TraceIdentifier = SampleDataV1.TraceIdentifier
4038
};
4139

42-
var product = await moqDatabase.Products.AddAsync(SampleDataV1.Product); //adding the product to be database
40+
var product = await moqDatabase.Products.AddAsync(SampleDataV1.Product); //adding the product to be database
4341
await moqDatabase.SaveChangesAsync(); //saving the product to be updated
4442
product.Entity.Description = SampleDataV1.NewDescription;
4543

@@ -54,7 +52,6 @@ public async Task PutAsync_Updates_Product_Successfully_With_Valid_Product_Id_an
5452
public void Dispose()
5553
{
5654
moqDatabase = null;
57-
moqLogger = null;
5855
}
5956
}
6057
}

src/Api/Endpoints/V1/Products/Create.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ namespace Xero.Demo.Api.Endpoints.V1.Products
1616
public partial class ProductsController : BaseApiController
1717
{
1818
public readonly Database _db;
19-
public readonly ILogger<ProductsController> _logger;
2019

21-
public ProductsController(ILogger<ProductsController> logger, Database db)
20+
public ProductsController(Database db)
2221
{
23-
_logger = logger;
2422
_db = db;
2523
}
2624

@@ -41,13 +39,9 @@ public async Task<IActionResult> PostAsync(Product product, string culture = "en
4139
{
4240
if (!ModelState.IsValid) return BadRequest(ModelState.GetErrorMessages());
4341

44-
var traceIdentifier = HttpContext.TraceIdentifier;
45-
_logger.LogInformation(string.Format(LogMessage.PreRequestLog, nameof(PostAsync), product.Id, traceIdentifier));
46-
4742
var entity = await _db.Products.AddAsync(product);
4843
var count = await _db.SaveChangesAsync();
4944

50-
_logger.LogInformation(string.Format(LogMessage.PostRequestLog, nameof(PostAsync), entity.Entity.Id, traceIdentifier));
5145
var responseProduct = new ProductDTO
5246
{
5347
DeliveryPrice = entity.Entity.DeliveryPrice,

src/Api/Endpoints/V1/Products/Delete.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,13 @@ public async Task<IActionResult> DeleteAsync(Guid id, string culture = "en-US")
2828
{
2929
if (!ModelState.IsValid || id == Guid.Empty) return BadRequest(ModelState.GetErrorMessages());
3030

31-
var traceIdentifier = HttpContext.TraceIdentifier;
32-
_logger.LogInformation(string.Format(LogMessage.PreRequestLog, nameof(DeleteAsync), id, traceIdentifier));
33-
3431
var product = await _db.Products.FindAsync(id);
3532

3633
if (product == default) return NotFound(string.Format(CustomException.NotFoundException, id));
3734

3835
var productRemoved = _db.Products.Remove(product);
3936
rowCountDeleted = await _db.SaveChangesAsync();
4037

41-
_logger.LogInformation(string.Format(LogMessage.PostRequestLog, nameof(DeleteAsync), id, traceIdentifier));
42-
4338
return deleted ? NoContent() : StatusCode(StatusCodes.Status500InternalServerError);
4439
}
4540
}

src/Api/Endpoints/V1/Products/Read.cs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using Microsoft.AspNetCore.Http;
44
using Microsoft.AspNetCore.Mvc;
55
using Microsoft.EntityFrameworkCore;
6-
using Microsoft.Extensions.Logging;
76
using System;
87
using System.Collections.Generic;
98
using System.Linq;
@@ -27,19 +26,15 @@ public async Task<IActionResult> GetAsync(string culture = "en-US")
2726
//var language = AddLocalizationExtension._e[WELCOME];
2827
//_logger.LogInformation(string.Format(AddLocalizationExtension._e[WELCOME].Value));
2928

30-
var traceIdentifier = HttpContext.TraceIdentifier;
31-
_logger.LogInformation(string.Format(LogMessage.PreRequestLog, nameof(GetAsync), string.Empty, traceIdentifier));
32-
3329
var products = await _db.Products.AsQueryable().ToListAsync();
3430

35-
_logger.LogInformation(string.Format(LogMessage.PostRequestLog, nameof(GetAsync), string.Empty, traceIdentifier));
36-
var res = products.Select(p => new ProductDTO
37-
{
38-
Id=p.Id,
39-
Name=p.Name,
40-
Description=p.Description,
41-
Price=p.Price,
42-
DeliveryPrice=p.DeliveryPrice
31+
var res = products.Select(p => new ProductDTO
32+
{
33+
Id = p.Id,
34+
Name = p.Name,
35+
Description = p.Description,
36+
Price = p.Price,
37+
DeliveryPrice = p.DeliveryPrice
4338
}).ToList();
4439
return Ok(res);
4540
}
@@ -58,20 +53,16 @@ public async Task<IActionResult> GetByIdAsync(Guid id)
5853
{
5954
if (!ModelState.IsValid || id == Guid.Empty) return BadRequest(ModelState.GetErrorMessages());
6055

61-
var traceIdentifier = HttpContext.TraceIdentifier;
62-
_logger.LogInformation(string.Format(LogMessage.PostRequestLog, nameof(GetByIdAsync), id, traceIdentifier));
63-
6456
var product = await _db.Products.FindAsync(id);
6557
if (product == default) return NotFound(string.Format(CustomException.NotFoundException, id));
6658

67-
_logger.LogInformation(string.Format(LogMessage.PostRequestLog, nameof(GetByIdAsync), id, traceIdentifier));
68-
69-
var responseProduct = new ProductDTO {
70-
Id=product.Id,
71-
Name=product.Name,
72-
Description=product.Description,
73-
DeliveryPrice=product.DeliveryPrice,
74-
Price=product.DeliveryPrice
59+
var responseProduct = new ProductDTO
60+
{
61+
Id = product.Id,
62+
Name = product.Name,
63+
Description = product.Description,
64+
DeliveryPrice = product.DeliveryPrice,
65+
Price = product.DeliveryPrice
7566
};
7667

7768
return Ok(responseProduct);

src/Api/Endpoints/V1/Products/Update.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,13 @@ public async Task<IActionResult> PutAsync(Guid id, Product product, string cultu
2727
{
2828
if (!ModelState.IsValid) return BadRequest(ModelState.GetErrorMessages());
2929

30-
var traceIdentifier = HttpContext.TraceIdentifier;
31-
_logger.LogInformation(string.Format(LogMessage.PostRequestLog, nameof(DeleteAsync), id, traceIdentifier));
32-
3330
var savedProduct = await _db.Products.FindAsync(id);
3431

3532
if (savedProduct == default) return NotFound(string.Format(CustomException.NotFoundException, id));
3633

3734
_db.Products.Update(product);
3835
var count = await _db.SaveChangesAsync();
3936

40-
_logger.LogInformation(string.Format(LogMessage.PostRequestLog, nameof(DeleteAsync), id, traceIdentifier));
41-
4237
return count == 1 ? NoContent() : StatusCode(StatusCodes.Status500InternalServerError);
4338
}
4439
}

src/Api/Xero.Demo.Api.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2828
</PackageReference>
2929
<PackageReference Include="Microsoft.FeatureManagement.AspNetCore" Version="2.2.0" />
30+
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="1.4.0" />
3031
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
3132
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
3233
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
File renamed without changes.

0 commit comments

Comments
 (0)