From a715828feae7d95fd2c30ddf67ce0805d380ad8d Mon Sep 17 00:00:00 2001 From: iamcalvinn Date: Thu, 9 Jul 2020 22:15:01 +0200 Subject: [PATCH 1/7] changes. --- TechTest/AnyCompany/AnyCompany.csproj | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/TechTest/AnyCompany/AnyCompany.csproj b/TechTest/AnyCompany/AnyCompany.csproj index 5b0498d..c8930b2 100644 --- a/TechTest/AnyCompany/AnyCompany.csproj +++ b/TechTest/AnyCompany/AnyCompany.csproj @@ -1,5 +1,5 @@  - + Debug @@ -40,12 +40,18 @@ - - - - - + + + + + + + + + + + \ No newline at end of file From 665e74e3ae679906d09224a1788414fc38e8b089 Mon Sep 17 00:00:00 2001 From: iamcalvinn Date: Thu, 9 Jul 2020 22:27:47 +0200 Subject: [PATCH 2/7] changes. --- .../AnyCompany.Tests/AnyCompany.Tests.csproj | 18 +++--- TechTest/AnyCompany.Tests/Class1.cs | 1 + TechTest/AnyCompany/AnyCompany.csproj | 9 +-- TechTest/AnyCompany/Models/Customer.cs | 18 ++++++ TechTest/AnyCompany/Models/Order.cs | 10 ++++ .../Repositories/CustomerRepository.cs | 59 +++++++++++++++++++ .../Repositories/OrderRepository.cs | 47 +++++++++++++++ .../AnyCompany/Services/CustomerService.cs | 35 +++++++++++ TechTest/AnyCompany/Services/OrderService.cs | 40 +++++++++++++ 9 files changed, 221 insertions(+), 16 deletions(-) create mode 100644 TechTest/AnyCompany/Models/Customer.cs create mode 100644 TechTest/AnyCompany/Models/Order.cs create mode 100644 TechTest/AnyCompany/Repositories/CustomerRepository.cs create mode 100644 TechTest/AnyCompany/Repositories/OrderRepository.cs create mode 100644 TechTest/AnyCompany/Services/CustomerService.cs create mode 100644 TechTest/AnyCompany/Services/OrderService.cs diff --git a/TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj b/TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj index b537fc2..fa0ccc4 100644 --- a/TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj +++ b/TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj @@ -1,5 +1,5 @@ - + Debug @@ -30,20 +30,20 @@ 4 - + - - - + + + - + - + - + - + diff --git a/TechTest/AnyCompany.Tests/Class1.cs b/TechTest/AnyCompany.Tests/Class1.cs index 5957505..a59be8b 100644 --- a/TechTest/AnyCompany.Tests/Class1.cs +++ b/TechTest/AnyCompany.Tests/Class1.cs @@ -8,5 +8,6 @@ namespace AnyCompany.Tests { public class Class1 { + } } diff --git a/TechTest/AnyCompany/AnyCompany.csproj b/TechTest/AnyCompany/AnyCompany.csproj index c8930b2..f76d3d0 100644 --- a/TechTest/AnyCompany/AnyCompany.csproj +++ b/TechTest/AnyCompany/AnyCompany.csproj @@ -41,17 +41,12 @@ - - + + - - - - - \ No newline at end of file diff --git a/TechTest/AnyCompany/Models/Customer.cs b/TechTest/AnyCompany/Models/Customer.cs new file mode 100644 index 0000000..9ed3e74 --- /dev/null +++ b/TechTest/AnyCompany/Models/Customer.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; + +namespace AnyCompany +{ + public class Customer + { + public int CustomerId { get; set; } + + public string Country { get; set; } + + public DateTime DateOfBirth { get; set; } + + public string Name { get; set; } + + public List Orders { get; set; } + } +} diff --git a/TechTest/AnyCompany/Models/Order.cs b/TechTest/AnyCompany/Models/Order.cs new file mode 100644 index 0000000..899fb6c --- /dev/null +++ b/TechTest/AnyCompany/Models/Order.cs @@ -0,0 +1,10 @@ +namespace AnyCompany +{ + public class Order + { + public int OrderId { get; set; } + public int CustomerId { get; set; } + public decimal Amount { get; set; } //changed double to decimal. When handling money, decimal type gives a high level of accuracy / easy to avoid rounding errors. + public decimal VAT { get; set; } + } +} diff --git a/TechTest/AnyCompany/Repositories/CustomerRepository.cs b/TechTest/AnyCompany/Repositories/CustomerRepository.cs new file mode 100644 index 0000000..0dbd47a --- /dev/null +++ b/TechTest/AnyCompany/Repositories/CustomerRepository.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Data.SqlClient; + +namespace AnyCompany +{ + public static class CustomerRepository + { + private static string ConnectionString = @"Data Source=(local);Database=Customers;User Id=admin;Password=password;"; + + public static Customer Load(int customerId) + { + Customer customer = new Customer(); + + SqlConnection connection = new SqlConnection(ConnectionString); + connection.Open(); + + SqlCommand command = new SqlCommand("SELECT * FROM Customer WHERE CustomerId = " + customerId, + connection); + var reader = command.ExecuteReader(); + + while (reader.Read()) + { + customer.Name = reader["Name"].ToString(); + customer.DateOfBirth = DateTime.Parse(reader["DateOfBirth"].ToString()); + customer.Country = reader["Country"].ToString(); + } + + connection.Close(); + + return customer; + } + + public static List GetCustomers() { + SqlConnection connection = new SqlConnection(ConnectionString); + connection.Open(); + + SqlCommand command = new SqlCommand("SELECT * FROM Customer", + connection); + var reader = command.ExecuteReader(); + + List customers = new List(); + while (reader.Read()) + { + Customer customer = new Customer(); + + customer.CustomerId = Convert.ToInt32(reader["CustomerId"]); + customer.Name = reader["Name"].ToString(); + customer.DateOfBirth = DateTime.Parse(reader["DateOfBirth"].ToString()); + customer.Country = reader["Country"].ToString(); + + customers.Add(customer); + } + + connection.Close(); + return customers; + } + } +} diff --git a/TechTest/AnyCompany/Repositories/OrderRepository.cs b/TechTest/AnyCompany/Repositories/OrderRepository.cs new file mode 100644 index 0000000..8383f71 --- /dev/null +++ b/TechTest/AnyCompany/Repositories/OrderRepository.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Data.SqlClient; + +namespace AnyCompany +{ + internal static class OrderRepository + { + private static string ConnectionString = @"Data Source=(local);Database=Orders;User Id=admin;Password=password;"; + + public static void Save(Order order) + { + SqlConnection connection = new SqlConnection(ConnectionString); + connection.Open(); + + SqlCommand command = new SqlCommand("INSERT INTO Orders VALUES (@OrderId, @CustomerId, @Amount, @VAT)", connection); + + command.Parameters.AddWithValue("@OrderId", order.OrderId); + command.Parameters.AddWithValue("@CustomerId", order.CustomerId); + command.Parameters.AddWithValue("@Amount", order.Amount); + command.Parameters.AddWithValue("@VAT", order.VAT); + + command.ExecuteNonQuery(); + + connection.Close(); + } + + public static List GetOrders(int customerId) + { + SqlConnection connection = new SqlConnection(ConnectionString); + connection.Open(); + SqlCommand command = new SqlCommand("SELECT * FROM Order Where CustomerId = " + customerId, connection); + var reader = command.ExecuteReader(); + + List orders = new List(); + while (reader.Read()) + { + Order order = new Order(); + order.Amount = Convert.ToDecimal(reader["Amount"]); + order.VAT = Convert.ToDecimal(reader["VAT"]); + orders.Add(order); + } + connection.Close(); + return orders; + } + } +} diff --git a/TechTest/AnyCompany/Services/CustomerService.cs b/TechTest/AnyCompany/Services/CustomerService.cs new file mode 100644 index 0000000..26a9c84 --- /dev/null +++ b/TechTest/AnyCompany/Services/CustomerService.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Data.SqlClient; + +namespace AnyCompany +{ + public class CustomerService + { + public List GetCustomersWithOrders() { + var customers = new List(); + try + { + customers = CustomerRepository.GetCustomers(); + foreach (var customer in customers) + { + customer.Orders = OrderRepository.GetOrders(customer.CustomerId); + } + } + catch (SqlException ex) + { + //{code to log error} + + return customers; + } + catch (Exception ex) + { + //{code to log error} + + return customers; + } + + return customers; + } + } +} diff --git a/TechTest/AnyCompany/Services/OrderService.cs b/TechTest/AnyCompany/Services/OrderService.cs new file mode 100644 index 0000000..9d8f9c7 --- /dev/null +++ b/TechTest/AnyCompany/Services/OrderService.cs @@ -0,0 +1,40 @@ +using System; +using System.Data.SqlClient; + +namespace AnyCompany +{ + public class OrderService + { + public bool PlaceOrder(Order order, int customerId) + { + try + { + Customer customer = CustomerRepository.Load(customerId); + + if (order.Amount == 0) + return false; + + if (customer.Country == "UK") + order.VAT = 0.2m; + else + order.VAT = 0; + + OrderRepository.Save(order); + } + catch (SqlException ex) + { + //{code to log error} + + return false; + } + catch (Exception ex) + { + //{code to log error} + + return false; + } + + return true; + } + } +} From b17e647479011f34734f1cf891997c4fdf7bbea1 Mon Sep 17 00:00:00 2001 From: iamcalvinn Date: Thu, 9 Jul 2020 22:41:26 +0200 Subject: [PATCH 3/7] Deleted files. --- TechTest/AnyCompany/Customer.cs | 13 --------- TechTest/AnyCompany/CustomerRepository.cs | 33 ----------------------- TechTest/AnyCompany/Order.cs | 9 ------- TechTest/AnyCompany/OrderRepository.cs | 25 ----------------- TechTest/AnyCompany/OrderService.cs | 24 ----------------- 5 files changed, 104 deletions(-) delete mode 100644 TechTest/AnyCompany/Customer.cs delete mode 100644 TechTest/AnyCompany/CustomerRepository.cs delete mode 100644 TechTest/AnyCompany/Order.cs delete mode 100644 TechTest/AnyCompany/OrderRepository.cs delete mode 100644 TechTest/AnyCompany/OrderService.cs diff --git a/TechTest/AnyCompany/Customer.cs b/TechTest/AnyCompany/Customer.cs deleted file mode 100644 index aa994b6..0000000 --- a/TechTest/AnyCompany/Customer.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace AnyCompany -{ - public class Customer - { - public string Country { get; set; } - - public DateTime DateOfBirth { get; set; } - - public string Name { get; set; } - } -} diff --git a/TechTest/AnyCompany/CustomerRepository.cs b/TechTest/AnyCompany/CustomerRepository.cs deleted file mode 100644 index e3de9b7..0000000 --- a/TechTest/AnyCompany/CustomerRepository.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Data.SqlClient; - -namespace AnyCompany -{ - public static class CustomerRepository - { - private static string ConnectionString = @"Data Source=(local);Database=Customers;User Id=admin;Password=password;"; - - public static Customer Load(int customerId) - { - Customer customer = new Customer(); - - SqlConnection connection = new SqlConnection(ConnectionString); - connection.Open(); - - SqlCommand command = new SqlCommand("SELECT * FROM Customer WHERE CustomerId = " + customerId, - connection); - var reader = command.ExecuteReader(); - - while (reader.Read()) - { - customer.Name = reader["Name"].ToString(); - customer.DateOfBirth = DateTime.Parse(reader["DateOfBirth"].ToString()); - customer.Country = reader["Country"].ToString(); - } - - connection.Close(); - - return customer; - } - } -} diff --git a/TechTest/AnyCompany/Order.cs b/TechTest/AnyCompany/Order.cs deleted file mode 100644 index fec8e7b..0000000 --- a/TechTest/AnyCompany/Order.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace AnyCompany -{ - public class Order - { - public int OrderId { get; set; } - public double Amount { get; set; } - public double VAT { get; set; } - } -} diff --git a/TechTest/AnyCompany/OrderRepository.cs b/TechTest/AnyCompany/OrderRepository.cs deleted file mode 100644 index 3229885..0000000 --- a/TechTest/AnyCompany/OrderRepository.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Data.SqlClient; - -namespace AnyCompany -{ - internal class OrderRepository - { - private static string ConnectionString = @"Data Source=(local);Database=Orders;User Id=admin;Password=password;"; - - public void Save(Order order) - { - SqlConnection connection = new SqlConnection(ConnectionString); - connection.Open(); - - SqlCommand command = new SqlCommand("INSERT INTO Orders VALUES (@OrderId, @Amount, @VAT)", connection); - - command.Parameters.AddWithValue("@OrderId", order.OrderId); - command.Parameters.AddWithValue("@Amount", order.Amount); - command.Parameters.AddWithValue("@VAT", order.VAT); - - command.ExecuteNonQuery(); - - connection.Close(); - } - } -} diff --git a/TechTest/AnyCompany/OrderService.cs b/TechTest/AnyCompany/OrderService.cs deleted file mode 100644 index ebfb103..0000000 --- a/TechTest/AnyCompany/OrderService.cs +++ /dev/null @@ -1,24 +0,0 @@ -namespace AnyCompany -{ - public class OrderService - { - private readonly OrderRepository orderRepository = new OrderRepository(); - - public bool PlaceOrder(Order order, int customerId) - { - Customer customer = CustomerRepository.Load(customerId); - - if (order.Amount == 0) - return false; - - if (customer.Country == "UK") - order.VAT = 0.2d; - else - order.VAT = 0; - - orderRepository.Save(order); - - return true; - } - } -} From 9a1010154f5db48726eb05e37e480fb04c2d9fa6 Mon Sep 17 00:00:00 2001 From: iamcalvinn Date: Fri, 10 Jul 2020 12:45:32 +0200 Subject: [PATCH 4/7] Improvements and unit tests. --- .../AnyCompany.Tests/AnyCompany.Tests.csproj | 39 ++++++++++++++++++- .../GetCustomersUnitTests.cs | 28 +++++++++++++ TechTest/AnyCompany.Tests/packages.config | 14 +++++++ TechTest/AnyCompany/AnyCompany.csproj | 5 +++ .../Repositories/CustomerRepository.cs | 18 +++++++++ .../Repositories/OrderRepository.cs | 30 ++++++++++++-- .../AnyCompany/Services/CustomerService.cs | 22 ++++++++++- TechTest/AnyCompany/Services/OrderService.cs | 29 ++++++++++++-- 8 files changed, 177 insertions(+), 8 deletions(-) create mode 100644 TechTest/AnyCompany.Tests/CustomerUnitTests/GetCustomersUnitTests.cs create mode 100644 TechTest/AnyCompany.Tests/packages.config diff --git a/TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj b/TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj index fa0ccc4..84ffc8f 100644 --- a/TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj +++ b/TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj @@ -1,5 +1,9 @@ + + + + Debug @@ -44,10 +48,43 @@ + + ..\packages\Microsoft.CodeCoverage.16.6.1\lib\net45\Microsoft.VisualStudio.CodeCoverage.Shim.dll + + + ..\packages\xunit.abstractions.2.0.3\lib\net35\xunit.abstractions.dll + + + ..\packages\xunit.assert.2.4.1\lib\netstandard1.1\xunit.assert.dll + + + ..\packages\xunit.extensibility.core.2.4.1\lib\net452\xunit.core.dll + + + ..\packages\xunit.extensibility.execution.2.4.1\lib\net452\xunit.execution.desktop.dll + - + + + + + + {C7E15594-7D8F-4C18-9DD7-14F3FBB1572D} + AnyCompany + + + + + + + + + + + + diff --git a/TechTest/AnyCompany.Tests/CustomerUnitTests/GetCustomersUnitTests.cs b/TechTest/AnyCompany.Tests/CustomerUnitTests/GetCustomersUnitTests.cs new file mode 100644 index 0000000..6638306 --- /dev/null +++ b/TechTest/AnyCompany.Tests/CustomerUnitTests/GetCustomersUnitTests.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AnyCompany.IServices; +using Xunit; + +namespace AnyCompany.Tests +{ + public class GetCustomersUnitTests + { + private ICustomerService customerService; + + public GetCustomersUnitTests(ICustomerService _customerService) + { + this.customerService = _customerService; + } + + [Fact] + public void GetCustomer_CheckReturnType_ReturnTrue() + { + var customers = customerService.GetCustomersWithOrders(); + var result = customers is List; + Assert.True(result); + } + } +} diff --git a/TechTest/AnyCompany.Tests/packages.config b/TechTest/AnyCompany.Tests/packages.config new file mode 100644 index 0000000..90178b9 --- /dev/null +++ b/TechTest/AnyCompany.Tests/packages.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TechTest/AnyCompany/AnyCompany.csproj b/TechTest/AnyCompany/AnyCompany.csproj index f76d3d0..26ce830 100644 --- a/TechTest/AnyCompany/AnyCompany.csproj +++ b/TechTest/AnyCompany/AnyCompany.csproj @@ -47,6 +47,11 @@ + + + + + \ No newline at end of file diff --git a/TechTest/AnyCompany/Repositories/CustomerRepository.cs b/TechTest/AnyCompany/Repositories/CustomerRepository.cs index 0dbd47a..0ebb876 100644 --- a/TechTest/AnyCompany/Repositories/CustomerRepository.cs +++ b/TechTest/AnyCompany/Repositories/CustomerRepository.cs @@ -31,6 +31,24 @@ public static Customer Load(int customerId) return customer; } + public static int Save(Customer customer) + { + SqlConnection connection = new SqlConnection(ConnectionString); + connection.Open(); + + SqlCommand command = new SqlCommand("INSERT INTO Customer VALUES (@CutomerId, @Name, @DateOfBirth, @Country)", connection); + + command.Parameters.AddWithValue("@CutomerId", customer.CustomerId); + command.Parameters.AddWithValue("@Name", customer.Name); + command.Parameters.AddWithValue("@DateOfBirth", customer.DateOfBirth); + command.Parameters.AddWithValue("@Country", customer.Country); + + var result = command.ExecuteNonQuery(); + + connection.Close(); + return result; + } + public static List GetCustomers() { SqlConnection connection = new SqlConnection(ConnectionString); connection.Open(); diff --git a/TechTest/AnyCompany/Repositories/OrderRepository.cs b/TechTest/AnyCompany/Repositories/OrderRepository.cs index 8383f71..4d05e54 100644 --- a/TechTest/AnyCompany/Repositories/OrderRepository.cs +++ b/TechTest/AnyCompany/Repositories/OrderRepository.cs @@ -8,7 +8,7 @@ internal static class OrderRepository { private static string ConnectionString = @"Data Source=(local);Database=Orders;User Id=admin;Password=password;"; - public static void Save(Order order) + public static int Save(Order order) { SqlConnection connection = new SqlConnection(ConnectionString); connection.Open(); @@ -20,16 +20,40 @@ public static void Save(Order order) command.Parameters.AddWithValue("@Amount", order.Amount); command.Parameters.AddWithValue("@VAT", order.VAT); - command.ExecuteNonQuery(); + var result = command.ExecuteNonQuery(); connection.Close(); + return result; + } + + public static Order GetOrder(int orderId) { + Order order = new Order(); + + SqlConnection connection = new SqlConnection(ConnectionString); + connection.Open(); + + SqlCommand command = new SqlCommand("SELECT * FROM Orders WHERE OrderId = " + orderId, + connection); + var reader = command.ExecuteReader(); + + while (reader.Read()) + { + order.OrderId = Convert.ToInt32(reader["OrderId"]); + order.CustomerId = Convert.ToInt32(reader["CustomerId"]); + order.Amount = Convert.ToInt32(reader["Amount"].ToString()); + order.VAT = Convert.ToInt32(reader["VAT"].ToString()); + } + + connection.Close(); + + return order; } public static List GetOrders(int customerId) { SqlConnection connection = new SqlConnection(ConnectionString); connection.Open(); - SqlCommand command = new SqlCommand("SELECT * FROM Order Where CustomerId = " + customerId, connection); + SqlCommand command = new SqlCommand("SELECT * FROM Orders Where CustomerId = " + customerId, connection); var reader = command.ExecuteReader(); List orders = new List(); diff --git a/TechTest/AnyCompany/Services/CustomerService.cs b/TechTest/AnyCompany/Services/CustomerService.cs index 26a9c84..88d811c 100644 --- a/TechTest/AnyCompany/Services/CustomerService.cs +++ b/TechTest/AnyCompany/Services/CustomerService.cs @@ -1,11 +1,31 @@ using System; using System.Collections.Generic; using System.Data.SqlClient; +using AnyCompany.IServices; namespace AnyCompany { - public class CustomerService + public class CustomerService : ICustomerService { + public bool SaveCustomer(Customer customer) + { + int result = 0; + try + { + result = CustomerRepository.Save(customer); + } + catch (SqlException ex) + { + //{code to log error} + } + catch (Exception ex) + { + //{code to log error} + } + if (result == 0) { return false; } + return true; + } + public List GetCustomersWithOrders() { var customers = new List(); try diff --git a/TechTest/AnyCompany/Services/OrderService.cs b/TechTest/AnyCompany/Services/OrderService.cs index 9d8f9c7..3d3ee42 100644 --- a/TechTest/AnyCompany/Services/OrderService.cs +++ b/TechTest/AnyCompany/Services/OrderService.cs @@ -1,17 +1,38 @@ using System; +using System.Collections.Generic; using System.Data.SqlClient; +using AnyCompany.IServices; namespace AnyCompany { - public class OrderService + public class OrderService : IOrdersService { + public Order GetOrder(int orderId) + { + var order = new Order(); + try + { + order = OrderRepository.GetOrder(orderId); + } + catch (SqlException ex) + { + //{code to log error} + } + catch (Exception ex) + { + //{code to log error} + } + return order; + } + public bool PlaceOrder(Order order, int customerId) { + int result = 0; try { Customer customer = CustomerRepository.Load(customerId); - if (order.Amount == 0) + if (order.Amount <= 0) return false; if (customer.Country == "UK") @@ -19,7 +40,7 @@ public bool PlaceOrder(Order order, int customerId) else order.VAT = 0; - OrderRepository.Save(order); + result = OrderRepository.Save(order); } catch (SqlException ex) { @@ -34,6 +55,8 @@ public bool PlaceOrder(Order order, int customerId) return false; } + if (result == 0) { return false; } + return true; } } From 4d4df25321f9ea66cd01d6da0c43ac269d30661f Mon Sep 17 00:00:00 2001 From: iamcalvinn Date: Fri, 10 Jul 2020 12:55:00 +0200 Subject: [PATCH 5/7] commit second try... --- TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj | 3 +-- TechTest/AnyCompany.Tests/Class1.cs | 13 ------------- TechTest/AnyCompany/AnyCompany.csproj | 5 +---- 3 files changed, 2 insertions(+), 19 deletions(-) delete mode 100644 TechTest/AnyCompany.Tests/Class1.cs diff --git a/TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj b/TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj index 84ffc8f..3636e25 100644 --- a/TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj +++ b/TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj @@ -66,8 +66,8 @@ - + @@ -76,7 +76,6 @@ - diff --git a/TechTest/AnyCompany.Tests/Class1.cs b/TechTest/AnyCompany.Tests/Class1.cs deleted file mode 100644 index a59be8b..0000000 --- a/TechTest/AnyCompany.Tests/Class1.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AnyCompany.Tests -{ - public class Class1 - { - - } -} diff --git a/TechTest/AnyCompany/AnyCompany.csproj b/TechTest/AnyCompany/AnyCompany.csproj index 26ce830..d920fbb 100644 --- a/TechTest/AnyCompany/AnyCompany.csproj +++ b/TechTest/AnyCompany/AnyCompany.csproj @@ -47,11 +47,8 @@ - - - - + \ No newline at end of file From 61b0bf00cd50bf86dc86f0d42d2c99f563465fb1 Mon Sep 17 00:00:00 2001 From: iamcalvinn Date: Fri, 10 Jul 2020 13:00:13 +0200 Subject: [PATCH 6/7] missing files --- .../OrderUnitTests/PlaceOrderTests.cs | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 TechTest/AnyCompany.Tests/OrderUnitTests/PlaceOrderTests.cs diff --git a/TechTest/AnyCompany.Tests/OrderUnitTests/PlaceOrderTests.cs b/TechTest/AnyCompany.Tests/OrderUnitTests/PlaceOrderTests.cs new file mode 100644 index 0000000..3a6a73c --- /dev/null +++ b/TechTest/AnyCompany.Tests/OrderUnitTests/PlaceOrderTests.cs @@ -0,0 +1,146 @@ +using System; +using AnyCompany.IServices; +using Xunit; + +namespace AnyCompany.Tests +{ + public class PlaceOrderTests + { + private readonly IOrdersService orderService; + private readonly ICustomerService customerService; + + public PlaceOrderTests(IOrdersService _orderService, ICustomerService _customerService) + { + this.orderService = _orderService; + this.customerService = _customerService; + } + + //Amount check + [Fact] + public void PlaceOrder_AmountGreaterThanZero_ReturnTrue() + { + Order order = new Order + { + OrderId = 1, + CustomerId = 1, + Amount = 10 + }; + + var result = orderService.PlaceOrder(order, order.CustomerId); + Assert.True(result); + } + + [Fact] + public void PlaceOrder_AmountZero_ReturnFalse() { + Order order = new Order { + OrderId = 1, + CustomerId = 1, + Amount = 0 + }; + + var result = orderService.PlaceOrder(order, order.CustomerId); + Assert.False(result, "Amount should be greater than zero"); + } + + [Fact] + public void PlaceOrder_AmountNegative_ReturnFalse() + { + Order order = new Order + { + OrderId = 1, + CustomerId = 1, + Amount = -10 + }; + + var result = orderService.PlaceOrder(order, order.CustomerId); + Assert.False(result, "Amount should be greater than zero"); + } + + + //Vat check + [Fact] + public void PlaceOrder_CountryNotUk_ReturnTrue() { + decimal VAT = 0.0m; + Customer customer = new Customer { + Name = "XAEA-12", + CustomerId = 1, + Country = "South Africa", + DateOfBirth = DateTime.Now.AddYears(-25), + }; + + customerService.SaveCustomer(customer); + + Order order = new Order + { + OrderId = 1, + CustomerId = 1, + Amount = 10 + }; + + orderService.PlaceOrder(order, order.CustomerId); + var _order = orderService.GetOrder(order.OrderId); + + var result = _order.VAT == VAT; + + Assert.True(result); + } + + [Fact] + public void PlaceOrder_CountryNotUk_ReturnFalse() + { + decimal VAT = 0.0m; + Customer customer = new Customer + { + Name = "XAEA-12", + CustomerId = 1, + Country = "South Africa", + DateOfBirth = DateTime.Now.AddYears(-25), + }; + + customerService.SaveCustomer(customer); + + Order order = new Order + { + OrderId = 1, + CustomerId = 1, + Amount = 10 + }; + + orderService.PlaceOrder(order, order.CustomerId); + var _order = orderService.GetOrder(order.OrderId); + + var result = _order.VAT != VAT; + + Assert.False(result, "If country is not UK, VAT must be set to 0"); + } + + [Fact] + public void PlaceOrder_CountryUk_ReturnTrue() + { + decimal VAT = 0.2m; + Customer customer = new Customer + { + Name = "XAEA-12", + CustomerId = 1, + Country = "UK", + DateOfBirth = DateTime.Now.AddYears(-25), + }; + + customerService.SaveCustomer(customer); + + Order order = new Order + { + OrderId = 1, + CustomerId = 1, + Amount = 10 + }; + + orderService.PlaceOrder(order, order.CustomerId); + var _order = orderService.GetOrder(order.OrderId); + + var result = _order.VAT == VAT; + + Assert.True(result); + } + } +} From 659fc787c9dbb07679c88f2d32b04b6a7e0210e4 Mon Sep 17 00:00:00 2001 From: iamcalvinn Date: Fri, 10 Jul 2020 13:01:16 +0200 Subject: [PATCH 7/7] missing files --- TechTest/AnyCompany/IServices/ICustomerService.cs | 11 +++++++++++ TechTest/AnyCompany/IServices/IOrdersService.cs | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 TechTest/AnyCompany/IServices/ICustomerService.cs create mode 100644 TechTest/AnyCompany/IServices/IOrdersService.cs diff --git a/TechTest/AnyCompany/IServices/ICustomerService.cs b/TechTest/AnyCompany/IServices/ICustomerService.cs new file mode 100644 index 0000000..5940248 --- /dev/null +++ b/TechTest/AnyCompany/IServices/ICustomerService.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace AnyCompany.IServices +{ + public interface ICustomerService + { + bool SaveCustomer(Customer customer); + List GetCustomersWithOrders(); + } +} diff --git a/TechTest/AnyCompany/IServices/IOrdersService.cs b/TechTest/AnyCompany/IServices/IOrdersService.cs new file mode 100644 index 0000000..d921d71 --- /dev/null +++ b/TechTest/AnyCompany/IServices/IOrdersService.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace AnyCompany.IServices +{ + public interface IOrdersService + { + bool PlaceOrder(Order order, int customerId); + Order GetOrder(int orderId); + } +}