Skip to content

Commit e410c47

Browse files
committed
refactored
1 parent 9881557 commit e410c47

File tree

9 files changed

+50
-61
lines changed

9 files changed

+50
-61
lines changed

OA/OA.Infrastructure/Mapping/CustomerProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using AutoMapper;
22
using OA.Domain.Entities;
3-
using OA.Infrastructure.Model;
3+
using OA.Infrastructure.ViewModel;
44

55
namespace OA.Infrastructure.Mapping
66
{

OA/OA.Infrastructure/OA.Infrastructure.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
<ItemGroup>
88
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
9+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.5">
10+
<PrivateAssets>all</PrivateAssets>
11+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
12+
</PackageReference>
913
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
1014
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.1" />
1115
</ItemGroup>

OA/OA.Infrastructure/Model/CustomerModel.cs renamed to OA/OA.Infrastructure/ViewModel/CustomerModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace OA.Infrastructure.Model
1+
namespace OA.Infrastructure.ViewModel
22
{
33
public class CustomerModel
44
{

OA/OA.Service/Implementation/CustomerService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public void AddCustomer(Customer customer)
1717
_repo.Add(customer);
1818
}
1919

20-
public void DeleteCustomer(int id)
20+
public void DeleteCustomer(int customerId)
2121
{
22-
_repo.Delete(id);
22+
_repo.Delete(customerId);
2323
}
2424

2525
public bool SaveChangesAsync()

OA/OA.Test.Integration/ApiCustomerTest.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ public class ApiCustomerTest
1212
[TestCase("Get", "api/Customer/Amazon")]
1313
public async Task GetAllCustomerTestAsync(string method, string URL)
1414
{
15-
using (var client = new TestClientProvider().Client)
16-
{
17-
var request = new HttpRequestMessage(new HttpMethod(method), URL);
18-
var response = await client.SendAsync(request);
15+
using var client = new TestClientProvider().Client;
16+
var request = new HttpRequestMessage(new HttpMethod(method), URL);
17+
var response = await client.SendAsync(request);
1918

20-
response.EnsureSuccessStatusCode();
19+
response.EnsureSuccessStatusCode();
2120

22-
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
23-
}
21+
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
2422
}
2523
}
2624
}

OA/OA.Test.Unit/Controller/CustomerControllerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using NUnit.Framework;
55
using OA.Controllers;
66
using OA.Domain.Entities;
7-
using OA.Infrastructure.Model;
7+
using OA.Infrastructure.ViewModel;
88
using OA.Persistence.Contract;
99
using OA.Service.Contract;
1010
using System.Threading.Tasks;

OA/OA.Test.Unit/Data/CustomerContextTest.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ public class CustomerContextTest
1212
public void CanInsertCustomerIntoDatabasee()
1313
{
1414

15-
using (var context = new CustomerContext())
16-
{
17-
var customer = new Customer();
18-
context.Customers.Add(customer);
19-
Assert.AreEqual(EntityState.Added, context.Entry(customer).State);
20-
}
15+
using var context = new CustomerContext();
16+
var customer = new Customer();
17+
context.Customers.Add(customer);
18+
Assert.AreEqual(EntityState.Added, context.Entry(customer).State);
2119
}
2220
}
2321
}

OA/OA.Test.Unit/Persistence/GenericRepositoryTest.cs

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -30,74 +30,63 @@ public void Setup()
3030
[Test]
3131
public void CheckGenenricRepositoryAddCustomer()
3232
{
33-
using (var context = new CustomerContext(builder.Options))
34-
{
35-
var customerRepository = new GenericRepository<Customer>(context);
36-
customerRepository.Add(customer);
37-
var result = customerRepository.SaveChanges();
38-
Assert.IsTrue(result);
39-
}
33+
using var context = new CustomerContext(builder.Options);
34+
var customerRepository = new GenericRepository<Customer>(context);
35+
customerRepository.Add(customer);
36+
var result = customerRepository.SaveChanges();
37+
Assert.IsTrue(result);
4038
}
4139

4240
[Test]
4341
public void CheckGenenricRepositoryUpdateCustomer()
4442
{
45-
using (var context = new CustomerContext(builder.Options))
46-
{
47-
var customerRepository = new GenericRepository<Customer>(context);
48-
customerRepository.Update(customer);
49-
var result = customerRepository.SaveChanges();
50-
Assert.IsTrue(result);
51-
}
43+
using var context = new CustomerContext(builder.Options);
44+
var customerRepository = new GenericRepository<Customer>(context);
45+
customerRepository.Update(customer);
46+
var result = customerRepository.SaveChanges();
47+
Assert.IsTrue(result);
5248
}
5349

5450
[Test]
5551
public void CheckGenenricRepositoryDeleteCustomer()
5652
{
57-
using (var context = new CustomerContext(builder.Options))
58-
{
59-
var customerRepository = new GenericRepository<Customer>(context);
53+
using var context = new CustomerContext(builder.Options);
54+
var customerRepository = new GenericRepository<Customer>(context);
6055

61-
customerRepository.Add(customer);
62-
customerRepository.SaveChanges();
56+
customerRepository.Add(customer);
57+
customerRepository.SaveChanges();
6358

64-
customerRepository.Delete(customer.Id);
65-
var result = customerRepository.SaveChanges();
66-
Assert.IsTrue(result);
67-
}
59+
customerRepository.Delete(customer.Id);
60+
var result = customerRepository.SaveChanges();
61+
Assert.IsTrue(result);
6862
}
6963

7064
[Test]
7165
public void CheckGenenricRepositoryGetCustomer()
7266
{
73-
using (var context = new CustomerContext(builder.Options))
74-
{
75-
76-
var customerRepository = new GenericRepository<Customer>(context);
77-
customerRepository.Add(new Customer { CustomerName = "Shweta Naik", Address = "Bangalore" });
78-
customerRepository.Add(new Customer { CustomerName = "Amit Naik", Address = "Bangalore" });
79-
customerRepository.SaveChanges();
67+
using var context = new CustomerContext(builder.Options);
68+
var customerRepository = new GenericRepository<Customer>(context);
69+
customerRepository.Add(new Customer { CustomerName = "Shweta Naik", Address = "Bangalore" });
70+
customerRepository.Add(new Customer { CustomerName = "Amit Naik", Address = "Bangalore" });
71+
customerRepository.SaveChanges();
8072

81-
var cust = customerRepository.GetAll();
73+
var cust = customerRepository.GetAll();
8274

83-
Assert.LessOrEqual(2, cust.Count());
84-
}
75+
Assert.LessOrEqual(2, cust.Count());
8576
}
8677

8778
[Test]
8879
public void CheckGenenricRepositoryGetByIdCustomer()
8980
{
90-
using (var context = new CustomerContext(builder.Options))
91-
{
92-
var customerRepository = new GenericRepository<Customer>(context);
93-
customerRepository.Add(new Customer { CustomerName = "Shweta Naik", Address = "Bangalore" });
94-
customerRepository.Add(new Customer { CustomerName = "Amit Naik", Address = "Bangalore" });
95-
customerRepository.SaveChanges();
81+
using var context = new CustomerContext(builder.Options);
82+
var customerRepository = new GenericRepository<Customer>(context);
83+
customerRepository.Add(new Customer { CustomerName = "Shweta Naik", Address = "Bangalore" });
84+
customerRepository.Add(new Customer { CustomerName = "Amit Naik", Address = "Bangalore" });
85+
customerRepository.SaveChanges();
9686

97-
var cust = customerRepository.GetById(1);
87+
var cust = customerRepository.GetById(1);
9888

99-
Assert.AreEqual(1, cust.Id);
100-
}
89+
Assert.AreEqual(1, cust.Id);
10190
}
10291

10392
}

OA/OA/Controllers/CustomerController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using Microsoft.AspNetCore.Http;
33
using Microsoft.AspNetCore.Mvc;
44
using OA.Domain.Entities;
5-
using OA.Infrastructure.Model;
5+
using OA.Infrastructure.ViewModel;
66
using OA.Persistence.Contract;
77
using OA.Service.Contract;
88
using System;

0 commit comments

Comments
 (0)