From d96f28a37fb8c0c84ae574f9359a0f378b3198c0 Mon Sep 17 00:00:00 2001 From: Charanpreet Date: Tue, 15 Sep 2020 23:25:54 +0530 Subject: [PATCH] #4 Fixed Naming Conventions Issue --- CustomerService/Classes/ResultsWithEvents.cs | 18 +++++----- .../Controllers/CustomerController.cs | 2 +- CustomerService/Models/Customer.cs | 19 ++++++----- .../Service/CustomerDataService.cs | 6 ++-- .../CustomersAndOrdersEndToEndTest.cs | 2 +- ServiceCommon/Classes/CustomerCreatedEvent.cs | 20 +++++------ ServiceCommon/Classes/Money.cs | 33 +++++++------------ .../WebAPI/CreateCustomerResponse.cs | 6 ++-- 8 files changed, 49 insertions(+), 57 deletions(-) diff --git a/CustomerService/Classes/ResultsWithEvents.cs b/CustomerService/Classes/ResultsWithEvents.cs index ff818ec..4267eba 100644 --- a/CustomerService/Classes/ResultsWithEvents.cs +++ b/CustomerService/Classes/ResultsWithEvents.cs @@ -9,25 +9,25 @@ namespace CustomerService.Classes { public class ResultsWithEvents { - public Customer customer; - public List events; + public Customer Customer { get; set; } + public List Events { get; set; } public ResultsWithEvents() { } - public ResultsWithEvents(Customer _customer, List _events) + public ResultsWithEvents(Customer customer, List events) { - customer = _customer; - events = _events; + Customer = customer; + Events = events; } - public ResultsWithEvents(Customer _customer, IDomainEvent _event) + public ResultsWithEvents(Customer customer, IDomainEvent domainEvent) { - customer = _customer; + Customer = customer; List eventList = new List(); - eventList.Add(_event); - events = eventList; + eventList.Add(domainEvent); + Events = eventList; } } } diff --git a/CustomerService/Controllers/CustomerController.cs b/CustomerService/Controllers/CustomerController.cs index ee6fa75..bca39a6 100644 --- a/CustomerService/Controllers/CustomerController.cs +++ b/CustomerService/Controllers/CustomerController.cs @@ -29,7 +29,7 @@ public IActionResult CreateCustomer([FromBody] CreateCustomerRequest request) { CustomerDataService customerService = new CustomerDataService(customerRepository, domainEventPublisher); Customer customer = customerService.CreateCustomer(request.Name, request.CreditLimit); - CreateCustomerResponse createCustomerResponse = new CreateCustomerResponse(customer.id); + CreateCustomerResponse createCustomerResponse = new CreateCustomerResponse(customer.Id); return Ok(createCustomerResponse); } } diff --git a/CustomerService/Models/Customer.cs b/CustomerService/Models/Customer.cs index b614f59..ac5934c 100644 --- a/CustomerService/Models/Customer.cs +++ b/CustomerService/Models/Customer.cs @@ -12,19 +12,22 @@ namespace CustomerService.Models [Table("Customer")] public class Customer { - public long id { get; set; } - public string name { get; set; } + [Column("id")] + public long Id { get; set; } + [Column("name")] + public string Name { get; set; } [NotMapped] - public Money creditlimit { get; set; } - public DateTime creationtime { get; set; } + public Money CreditLimit { get; set; } + [Column("creationtime")] + public DateTime CreationTime { get; set; } public Customer() { } - public Customer(String _name, Money _creditLimit) + public Customer(string name, Money creditLimit) { - name = _name; - creditlimit = _creditLimit; - creationtime = System.DateTime.Now; + Name = name; + CreditLimit = creditLimit; + CreationTime = System.DateTime.Now; } } diff --git a/CustomerService/Service/CustomerDataService.cs b/CustomerService/Service/CustomerDataService.cs index cb986cc..583da29 100644 --- a/CustomerService/Service/CustomerDataService.cs +++ b/CustomerService/Service/CustomerDataService.cs @@ -27,8 +27,8 @@ public Customer CreateCustomer(String name, Money creditLimit) using (var scope = new TransactionScope()) { ResultsWithEvents customerWithEvents = Create(name, creditLimit); - customer = customerRepository.InsertCustomer(customerWithEvents.customer); - domainEventPublisher.Publish(customer.id.ToString(), customer.id, customerWithEvents.events); + customer = customerRepository.InsertCustomer(customerWithEvents.Customer); + domainEventPublisher.Publish(customer.Id.ToString(), customer.Id, customerWithEvents.Events); scope.Complete(); return customer; } @@ -36,7 +36,7 @@ public Customer CreateCustomer(String name, Money creditLimit) public static ResultsWithEvents Create(String name, Money creditLimit) { Customer customer = new Customer(name, creditLimit); - var customerCreatedEvent = new CustomerCreatedEvent(customer.name, customer.creditlimit); + var customerCreatedEvent = new CustomerCreatedEvent(customer.Name, customer.CreditLimit); List eventList = new List(); eventList.Add(customerCreatedEvent); return new ResultsWithEvents(customer, eventList); diff --git a/EndToEndTests/CustomersAndOrdersEndToEndTest.cs b/EndToEndTests/CustomersAndOrdersEndToEndTest.cs index 2eee89f..d82f724 100644 --- a/EndToEndTests/CustomersAndOrdersEndToEndTest.cs +++ b/EndToEndTests/CustomersAndOrdersEndToEndTest.cs @@ -34,7 +34,7 @@ public async Task CustomerShouldbeCreated() Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); string jsonString = await response.Content.ReadAsStringAsync(); var customerResponse = JsonSerializer.Deserialize(jsonString); - Assert.IsNotNull(customerResponse.customerId); + Assert.IsNotNull(customerResponse.CustomerId); } } } diff --git a/ServiceCommon/Classes/CustomerCreatedEvent.cs b/ServiceCommon/Classes/CustomerCreatedEvent.cs index d107b98..8602b96 100644 --- a/ServiceCommon/Classes/CustomerCreatedEvent.cs +++ b/ServiceCommon/Classes/CustomerCreatedEvent.cs @@ -7,36 +7,36 @@ namespace ServiceCommon.Classes { public class CustomerCreatedEvent : ICustomerEvent { - public String name { get; set; } - private Money creditLimit { get; set; } + public String Name { get; set; } + private Money CreditLimit { get; set; } public CustomerCreatedEvent() { } - public CustomerCreatedEvent(String _name, Money _creditLimit) + public CustomerCreatedEvent(String name, Money creditLimit) { - name = name; - creditLimit = creditLimit; + Name = name; + CreditLimit = creditLimit; } public String GetName() { - return name; + return Name; } public void SetName(String name) { - this.name = name; + Name = name; } public Money GetCreditLimit() { - return creditLimit; + return CreditLimit; } - public void SetCreditLimit(Money _creditLimit) + public void SetCreditLimit(Money creditLimit) { - creditLimit = _creditLimit; + CreditLimit = creditLimit; } } } \ No newline at end of file diff --git a/ServiceCommon/Classes/Money.cs b/ServiceCommon/Classes/Money.cs index fc2fceb..56d8874 100644 --- a/ServiceCommon/Classes/Money.cs +++ b/ServiceCommon/Classes/Money.cs @@ -8,7 +8,7 @@ namespace ServiceCommon.Classes public class Money { public static Money ZERO = new Money(0); - public decimal amount { get; set; } + public decimal Amount { get; set; } public Money() { @@ -16,40 +16,29 @@ public Money() public Money(int i) { - amount = Convert.ToDecimal(i); + Amount = Convert.ToDecimal(i); } public Money(String s) { - amount = Convert.ToDecimal(s); + Amount = Convert.ToDecimal(s); } - public Money(decimal _amount) + public Money(decimal amount) { - amount = _amount; + Amount = amount; } - - public decimal getAmount() - { - return amount; - } - - public void setAmount(decimal _amount) - { - this.amount = _amount; - } - - public bool isGreaterThanOrEqual(Money other) + public bool IsGreaterThanOrEqual(Money other) { - return amount >= other.amount; + return Amount >= other.Amount; } - public Money add(Money other) + public Money Add(Money other) { - return new Money(amount + (other.amount)); + return new Money(Amount + (other.Amount)); } - public Money subtract(Money other) + public Money Subtract(Money other) { - return new Money(amount - (other.amount)); + return new Money(Amount - (other.Amount)); } } } \ No newline at end of file diff --git a/ServiceCommon/WebAPI/CreateCustomerResponse.cs b/ServiceCommon/WebAPI/CreateCustomerResponse.cs index 20c82fe..8302f8c 100644 --- a/ServiceCommon/WebAPI/CreateCustomerResponse.cs +++ b/ServiceCommon/WebAPI/CreateCustomerResponse.cs @@ -7,15 +7,15 @@ namespace ServiceCommon.Common { public class CreateCustomerResponse { - public long customerId { get; set; } + public long CustomerId { get; set; } public CreateCustomerResponse() { } - public CreateCustomerResponse(long _customerId) + public CreateCustomerResponse(long customerId) { - customerId = _customerId; + CustomerId = customerId; } } }