diff --git a/TechTest/AnyCompany.Models/AnyCompany.Models.csproj b/TechTest/AnyCompany.Models/AnyCompany.Models.csproj
new file mode 100644
index 0000000..a7a90b9
--- /dev/null
+++ b/TechTest/AnyCompany.Models/AnyCompany.Models.csproj
@@ -0,0 +1,49 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {1586B2DA-3864-426F-BE39-81DC89C4F667}
+ Library
+ Properties
+ AnyCompany.Models
+ AnyCompany.Models
+ v4.6.1
+ 512
+ true
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/TechTest/AnyCompany/Customer.cs b/TechTest/AnyCompany.Models/Customer.cs
similarity index 52%
rename from TechTest/AnyCompany/Customer.cs
rename to TechTest/AnyCompany.Models/Customer.cs
index aa994b6..03f5511 100644
--- a/TechTest/AnyCompany/Customer.cs
+++ b/TechTest/AnyCompany.Models/Customer.cs
@@ -1,13 +1,16 @@
using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
-namespace AnyCompany
+namespace AnyCompany.Models
{
public class Customer
{
+ public int CustomerId { get; set; }
public string Country { get; set; }
-
public DateTime DateOfBirth { get; set; }
-
public string Name { get; set; }
}
}
diff --git a/TechTest/AnyCompany.Models/Order.cs b/TechTest/AnyCompany.Models/Order.cs
new file mode 100644
index 0000000..d496638
--- /dev/null
+++ b/TechTest/AnyCompany.Models/Order.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AnyCompany.Models
+{
+ public class Order
+ {
+ public int OrderId { get; set; }
+ public double Amount { get; set; }
+ public double VAT { get; set; }
+ public int CustomerId { get; set; }
+ public Customer Customer { get; set; }
+ }
+}
diff --git a/TechTest/AnyCompany.Models/Properties/AssemblyInfo.cs b/TechTest/AnyCompany.Models/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..0e725f9
--- /dev/null
+++ b/TechTest/AnyCompany.Models/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("AnyCompany.Models")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("AnyCompany.Models")]
+[assembly: AssemblyCopyright("Copyright © 2020")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("1586b2da-3864-426f-be39-81dc89c4f667")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/TechTest/AnyCompany.Repository/AnyCompany.Repository.csproj b/TechTest/AnyCompany.Repository/AnyCompany.Repository.csproj
new file mode 100644
index 0000000..c16108d
--- /dev/null
+++ b/TechTest/AnyCompany.Repository/AnyCompany.Repository.csproj
@@ -0,0 +1,66 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {C90C052C-DF98-45B5-B1F3-62BF20658B5A}
+ Library
+ Properties
+ AnyCompany.Repository
+ AnyCompany.Repository
+ v4.6.1
+ 512
+ true
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {1586b2da-3864-426f-be39-81dc89c4f667}
+ AnyCompany.Models
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/TechTest/AnyCompany.Repository/App.config b/TechTest/AnyCompany.Repository/App.config
new file mode 100644
index 0000000..c1af150
--- /dev/null
+++ b/TechTest/AnyCompany.Repository/App.config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/TechTest/AnyCompany.Tests/Class1.cs b/TechTest/AnyCompany.Repository/Class1.cs
similarity index 83%
rename from TechTest/AnyCompany.Tests/Class1.cs
rename to TechTest/AnyCompany.Repository/Class1.cs
index 5957505..4772651 100644
--- a/TechTest/AnyCompany.Tests/Class1.cs
+++ b/TechTest/AnyCompany.Repository/Class1.cs
@@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;
-namespace AnyCompany.Tests
+namespace AnyCompany.Repository
{
public class Class1
{
diff --git a/TechTest/AnyCompany.Repository/CustomerRepository.cs b/TechTest/AnyCompany.Repository/CustomerRepository.cs
new file mode 100644
index 0000000..28fcedb
--- /dev/null
+++ b/TechTest/AnyCompany.Repository/CustomerRepository.cs
@@ -0,0 +1,55 @@
+using AnyCompany.Models;
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Data;
+using System.Data.SqlClient;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AnyCompany.Repository
+{
+ public static class CustomerRepository
+ {
+ private static string ConnectionString = ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;
+
+ public static Customer Load(int customerId)
+ {
+ Customer customer = new Customer();
+
+ SqlConnection connection = new SqlConnection(ConnectionString);
+
+ try
+ {
+ connection.Open();
+
+ SqlCommand command = new SqlCommand("spGetCustomer",
+ connection);
+
+ command.CommandType = CommandType.StoredProcedure;
+
+ command.Parameters.AddWithValue("@customerId", customerId);
+
+ var reader = command.ExecuteReader();
+
+ while (reader.Read())
+ {
+ customer.Name = reader["Name"].ToString();
+ customer.DateOfBirth = DateTime.Parse(reader["DateOfBirth"].ToString());
+ customer.Country = reader["Country"].ToString();
+ }
+ }
+ catch (Exception e)
+ {
+ throw e;
+ }
+ finally
+ {
+ connection.Close();
+ }
+
+ return customer;
+ }
+ }
+}
diff --git a/TechTest/AnyCompany.Repository/DBStoredProcs/spGetCustomer.sql b/TechTest/AnyCompany.Repository/DBStoredProcs/spGetCustomer.sql
new file mode 100644
index 0000000..1852cbd
--- /dev/null
+++ b/TechTest/AnyCompany.Repository/DBStoredProcs/spGetCustomer.sql
@@ -0,0 +1,14 @@
+-- Author: Kgaugelo
+-- Create date: 2020-08-15
+-- Description: Get Customer Details
+-- =============================================
+CREATE PROCEDURE spGetCustomer
+ @CustomerId INT
+AS
+BEGIN
+
+ SET NOCOUNT ON;
+
+ SELECT * FROM [Customer]
+ WHERE CustomerId = @CustomerId
+END
diff --git a/TechTest/AnyCompany.Repository/DBStoredProcs/spGetOrders.sql b/TechTest/AnyCompany.Repository/DBStoredProcs/spGetOrders.sql
new file mode 100644
index 0000000..d993047
--- /dev/null
+++ b/TechTest/AnyCompany.Repository/DBStoredProcs/spGetOrders.sql
@@ -0,0 +1,14 @@
+-- Author: Kgaugelo
+-- Create date: 2020-08-15
+-- Description: Get List of Customer and their orders
+-- =============================================
+CREATE PROCEDURE spGetOrders
+AS
+BEGIN
+
+ SET NOCOUNT ON;
+
+ SELECT * FROM [Orders] O
+ INNER JOIN [Customers] C
+ ON C.CustomerId = O.CustomerId
+END
diff --git a/TechTest/AnyCompany.Repository/DBStoredProcs/spPlaceOrder.sql b/TechTest/AnyCompany.Repository/DBStoredProcs/spPlaceOrder.sql
new file mode 100644
index 0000000..2c568a8
--- /dev/null
+++ b/TechTest/AnyCompany.Repository/DBStoredProcs/spPlaceOrder.sql
@@ -0,0 +1,17 @@
+-- Author: Kgaugelo
+-- Create date: 2020-08-15
+-- Description: Plece New Customer Order
+-- =============================================
+CREATE PROCEDURE spPlaceOrder
+ @OrderId INT,
+ @Amount DECIMAL(18,2),
+ @VAT DECIMAL(18,2),
+ @CustomerId INT
+AS
+BEGIN
+ SET NOCOUNT ON;
+
+ INSERT INTO Orders
+ VALUES (@Amount, @VAT, @CustomerId)
+END
+GO
diff --git a/TechTest/AnyCompany.Repository/Interfaces/IOrderRepository.cs b/TechTest/AnyCompany.Repository/Interfaces/IOrderRepository.cs
new file mode 100644
index 0000000..01eca57
--- /dev/null
+++ b/TechTest/AnyCompany.Repository/Interfaces/IOrderRepository.cs
@@ -0,0 +1,15 @@
+using AnyCompany.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AnyCompany.Repository.Interfaces
+{
+ interface IOrderRepository
+ {
+ void Save(Order order);
+ List GetOrders();
+ }
+}
diff --git a/TechTest/AnyCompany.Repository/OrderRepository.cs b/TechTest/AnyCompany.Repository/OrderRepository.cs
new file mode 100644
index 0000000..b7ebd9b
--- /dev/null
+++ b/TechTest/AnyCompany.Repository/OrderRepository.cs
@@ -0,0 +1,85 @@
+using AnyCompany.Models;
+using AnyCompany.Repository.Interfaces;
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Data;
+using System.Data.SqlClient;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AnyCompany.Repository
+{
+ public class OrderRepository : IOrderRepository, IDisposable
+ {
+ private static string ConnectionString = ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;
+
+ private readonly SqlConnection connection = null;
+
+ public OrderRepository()
+ {
+ try
+ {
+ connection = new SqlConnection(ConnectionString);
+ connection.Open();
+ }
+ catch (SqlException e)
+ {
+ throw e;
+ }
+ }
+
+ public void Dispose()
+ {
+ if (connection != null)
+ connection.Close();
+ }
+
+ public List GetOrders()
+ {
+ List Orders = new List();
+
+ SqlCommand command = new SqlCommand("spGetOrders",
+ connection);
+
+ command.CommandType = CommandType.StoredProcedure;
+
+ var reader = command.ExecuteReader();
+
+ while (reader.Read())
+ {
+ Order order = new Order();
+ order.Customer = new Customer();
+
+ order.OrderId = (int)reader["OrderId"];
+ order.Amount = (double)reader["Amount"];
+ order.VAT = (double)reader["Country"];
+ order.CustomerId = (int)reader["CustomerId"];
+ order.Customer.CustomerId = (int)reader["CustomerId"];
+ order.Customer.Name = reader["Name"].ToString();
+ order.Customer.DateOfBirth = DateTime.Parse(reader["DateOfBirth"].ToString());
+ order.Customer.Country = reader["Country"].ToString();
+
+ Orders.Add(order);
+ }
+
+ return Orders;
+ }
+
+ public void Save(Order order)
+ {
+ SqlCommand command = new SqlCommand("spPlaceOrder", connection);
+
+ command.CommandType = CommandType.StoredProcedure;
+
+ command.Parameters.AddWithValue("@Amount", order.Amount);
+ command.Parameters.AddWithValue("@VAT", order.VAT);
+ command.Parameters.AddWithValue("@CustomerId", order.CustomerId);
+
+ command.ExecuteNonQuery();
+
+ connection.Close();
+ }
+ }
+}
diff --git a/TechTest/AnyCompany.Repository/Properties/AssemblyInfo.cs b/TechTest/AnyCompany.Repository/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..182c1f4
--- /dev/null
+++ b/TechTest/AnyCompany.Repository/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("AnyCompany.Repository")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("AnyCompany.Repository")]
+[assembly: AssemblyCopyright("Copyright © 2020")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("c90c052c-df98-45b5-b1f3-62bf20658b5a")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj b/TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj
index b537fc2..7fad1f4 100644
--- a/TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj
+++ b/TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj
@@ -1,16 +1,25 @@
-
-
+
+
+
Debug
AnyCPU
- cd5d577e-bdc9-4dfc-ac6a-b1da474995f3
+ {B5D8C02D-7528-47CE-AC78-F3460AAA87CF}
Library
Properties
AnyCompany.Tests
AnyCompany.Tests
v4.6.1
512
+ {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
+ 15.0
+ $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
+ $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages
+ False
+ UnitTest
+
+
true
@@ -30,24 +39,40 @@
4
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+ ..\packages\MSTest.TestFramework.2.1.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll
+
+
+ ..\packages\MSTest.TestFramework.2.1.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll
+
+
+
-
+
+
+
+
+
+
+ {1586b2da-3864-426f-be39-81dc89c4f667}
+ AnyCompany.Models
+
+
+ {c7e15594-7d8f-4c18-9dd7-14f3fbb1572d}
+ AnyCompany
+
+
+
-
+
+
+ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
+
+
+
+
+
+
\ No newline at end of file
diff --git a/TechTest/AnyCompany.Tests/Properties/AssemblyInfo.cs b/TechTest/AnyCompany.Tests/Properties/AssemblyInfo.cs
index 726eefa..652591c 100644
--- a/TechTest/AnyCompany.Tests/Properties/AssemblyInfo.cs
+++ b/TechTest/AnyCompany.Tests/Properties/AssemblyInfo.cs
@@ -1,36 +1,20 @@
-using System.Reflection;
+using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
[assembly: AssemblyTitle("AnyCompany.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Investec Bank")]
+[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AnyCompany.Tests")]
-[assembly: AssemblyCopyright("Copyright © Investec Bank 2018")]
+[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("cd5d577e-bdc9-4dfc-ac6a-b1da474995f3")]
+[assembly: Guid("b5d8c02d-7528-47ce-ac78-f3460aaa87cf")]
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/TechTest/AnyCompany.Tests/UnitTest1.cs b/TechTest/AnyCompany.Tests/UnitTest1.cs
new file mode 100644
index 0000000..a70fdd7
--- /dev/null
+++ b/TechTest/AnyCompany.Tests/UnitTest1.cs
@@ -0,0 +1,112 @@
+using System;
+using System.Collections.Generic;
+using AnyCompany.Models;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace AnyCompany.Tests
+{
+ [TestClass]
+ public class UnitTest1
+ {
+ private AnyCompany.Interfaces.IOrderService _OrderService;
+
+ [TestInitialize]
+ public void TestSetup()
+ {
+ _OrderService = new OrderService();
+ }
+
+ [TestMethod]
+ public void TestPlaceOrderForASingleCustomerSuccess()
+ {
+ var order = Getorder();
+ var customer = Getcustomer();
+
+ var IsSuccess = _OrderService.PlaceOrder(order, customer.CustomerId);
+
+ Assert.IsTrue(IsSuccess);
+ }
+
+ [TestMethod]
+ [ExpectedException(typeof(ArgumentException), "An error has occured placing the order.")]
+ public void TestPlaceOrderForASingleCustomerFail()
+ {
+ var order = Getorder();
+ order.Amount = 0;
+
+ var customer = Getcustomer();
+
+ var IsSuccess = _OrderService.PlaceOrder(order, customer.CustomerId);
+
+ Assert.IsTrue(IsSuccess);
+ }
+
+ [TestMethod]
+ public void TestGetAllCustomersAndTheirOrdersSuccess()
+ {
+ var cOrders = _OrderService.GetOrders();
+
+ Assert.AreNotEqual(0, cOrders.Count);
+
+ foreach (var custOrder in cOrders)
+ {
+ Console.WriteLine($"Name: {custOrder.Customer.Name} -Country: {custOrder.Customer.Country} - Amount: ${custOrder.Amount} VAT: {custOrder.VAT} ");
+ }
+ }
+
+ public List Customers()
+ {
+ List ListOfCustomers = new List()
+ {
+ new Customer()
+ {
+ CustomerId = 1, Name = "Kgaugelo", Country = "UK", DateOfBirth = new DateTime(1989, 07, 18)
+ }, new Customer()
+ {
+ CustomerId = 2, Name = "Maidi", Country = "SA", DateOfBirth = new DateTime(1993, 02, 23)
+ }
+ };
+
+ return ListOfCustomers;
+ }
+
+ public Customer Getcustomer()
+ {
+ Customer steve = new Customer { CustomerId = 1, Name = "Steve", Country = "UK", DateOfBirth = new DateTime(2001, 2, 13) };
+
+ return steve;
+ }
+
+ public List OrderList()
+ {
+ Customer customer = new Customer();
+ customer = Getcustomer();
+
+ Order den = Getorder();
+ var ordersList = new List()
+ {
+ new Order { OrderId = 1, Amount = 1229.76, CustomerId = 1, VAT = 0, Customer = Customers()[0] },
+ new Order { OrderId = 2, Amount = 432.21, CustomerId = 1, VAT = 0, Customer = Customers()[1] },
+ new Order { OrderId = 3, Amount = 139.50, CustomerId = 2, VAT = 0, Customer = customer }, den
+ };
+
+ return ordersList;
+ }
+
+ public Order Getorder()
+ {
+ Order den = new Order();
+ Customer customer = new Customer();
+ den.Amount = 139.50;
+ den.CustomerId = 2;
+ den.VAT = 0;
+ customer.CustomerId = 2;
+ customer.Name = "Den";
+ customer.Country = "SA";
+ customer.DateOfBirth = new DateTime(2001, 2, 13);
+ den.Customer = customer;
+
+ return den;
+ }
+ }
+}
diff --git a/TechTest/AnyCompany.Tests/packages.config b/TechTest/AnyCompany.Tests/packages.config
new file mode 100644
index 0000000..6eebc36
--- /dev/null
+++ b/TechTest/AnyCompany.Tests/packages.config
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/TechTest/AnyCompany/AnyCompany.csproj b/TechTest/AnyCompany/AnyCompany.csproj
index 5b0498d..9b0162e 100644
--- a/TechTest/AnyCompany/AnyCompany.csproj
+++ b/TechTest/AnyCompany/AnyCompany.csproj
@@ -40,12 +40,19 @@
-
-
-
-
+
+
+
+ {1586b2da-3864-426f-be39-81dc89c4f667}
+ AnyCompany.Models
+
+
+ {c90c052c-df98-45b5-b1f3-62bf20658b5a}
+ AnyCompany.Repository
+
+
\ No newline at end of file
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/Interfaces/IOrderService.cs b/TechTest/AnyCompany/Interfaces/IOrderService.cs
new file mode 100644
index 0000000..8b942ce
--- /dev/null
+++ b/TechTest/AnyCompany/Interfaces/IOrderService.cs
@@ -0,0 +1,16 @@
+using AnyCompany.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AnyCompany.Interfaces
+{
+ public interface IOrderService
+ {
+ bool PlaceOrder(Order order, int customerId);
+ Customer GetCustomer(int customerId);
+ List GetOrders();
+ }
+}
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
index ebfb103..77e21a5 100644
--- a/TechTest/AnyCompany/OrderService.cs
+++ b/TechTest/AnyCompany/OrderService.cs
@@ -1,24 +1,51 @@
-namespace AnyCompany
+using AnyCompany.Interfaces;
+using AnyCompany.Models;
+using AnyCompany.Repository;
+using System;
+using System.Collections.Generic;
+
+namespace AnyCompany
{
- public class OrderService
+ public class OrderService: IOrderService
{
- private readonly OrderRepository orderRepository = new OrderRepository();
+ public Customer GetCustomer(int customerId)
+ {
+ return CustomerRepository.Load(customerId);
+ }
+
+ public List GetOrders()
+ {
+ using (OrderRepository orderRepository = new OrderRepository())
+ {
+ return orderRepository.GetOrders();
+ }
+ }
public bool PlaceOrder(Order order, int customerId)
{
- Customer customer = CustomerRepository.Load(customerId);
+ try
+ {
+ using (OrderRepository orderRepository = new OrderRepository())
+ {
+ Customer customer = GetCustomer(customerId);
- if (order.Amount == 0)
- return false;
+ if (order.Amount == 0)
+ return false;
- if (customer.Country == "UK")
- order.VAT = 0.2d;
- else
- order.VAT = 0;
+ if (customer.Country == "UK")
+ order.VAT = 0.2d;
+ else
+ order.VAT = 0;
- orderRepository.Save(order);
+ orderRepository.Save(order);
- return true;
+ return true;
+ }
+ }
+ catch (Exception Ex)
+ {
+ throw Ex;
+ }
}
}
}
diff --git a/TechTest/TechTest.sln b/TechTest/TechTest.sln
index 1c1c57a..dada917 100644
--- a/TechTest/TechTest.sln
+++ b/TechTest/TechTest.sln
@@ -1,17 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.27004.2005
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.30225.117
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnyCompany", "AnyCompany\AnyCompany.csproj", "{C7E15594-7D8F-4C18-9DD7-14F3FBB1572D}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnyCompany.Tests", "AnyCompany.Tests\AnyCompany.Tests.csproj", "{CD5D577E-BDC9-4DFC-AC6A-B1DA474995F3}"
-EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B6D3C1BB-2A37-4E17-9EE3-DEF28286E782}"
ProjectSection(SolutionItems) = preProject
Instructions.txt = Instructions.txt
EndProjectSection
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnyCompany.Models", "AnyCompany.Models\AnyCompany.Models.csproj", "{1586B2DA-3864-426F-BE39-81DC89C4F667}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnyCompany.Repository", "AnyCompany.Repository\AnyCompany.Repository.csproj", "{C90C052C-DF98-45B5-B1F3-62BF20658B5A}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnyCompany.Tests", "AnyCompany.Tests\AnyCompany.Tests.csproj", "{B5D8C02D-7528-47CE-AC78-F3460AAA87CF}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -22,10 +26,18 @@ Global
{C7E15594-7D8F-4C18-9DD7-14F3FBB1572D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7E15594-7D8F-4C18-9DD7-14F3FBB1572D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7E15594-7D8F-4C18-9DD7-14F3FBB1572D}.Release|Any CPU.Build.0 = Release|Any CPU
- {CD5D577E-BDC9-4DFC-AC6A-B1DA474995F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {CD5D577E-BDC9-4DFC-AC6A-B1DA474995F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {CD5D577E-BDC9-4DFC-AC6A-B1DA474995F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {CD5D577E-BDC9-4DFC-AC6A-B1DA474995F3}.Release|Any CPU.Build.0 = Release|Any CPU
+ {1586B2DA-3864-426F-BE39-81DC89C4F667}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {1586B2DA-3864-426F-BE39-81DC89C4F667}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {1586B2DA-3864-426F-BE39-81DC89C4F667}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {1586B2DA-3864-426F-BE39-81DC89C4F667}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C90C052C-DF98-45B5-B1F3-62BF20658B5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C90C052C-DF98-45B5-B1F3-62BF20658B5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C90C052C-DF98-45B5-B1F3-62BF20658B5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C90C052C-DF98-45B5-B1F3-62BF20658B5A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B5D8C02D-7528-47CE-AC78-F3460AAA87CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B5D8C02D-7528-47CE-AC78-F3460AAA87CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B5D8C02D-7528-47CE-AC78-F3460AAA87CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B5D8C02D-7528-47CE-AC78-F3460AAA87CF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE