diff --git a/TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj b/TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj
index b537fc2..c980440 100644
--- a/TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj
+++ b/TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj
@@ -1,10 +1,10 @@
-
+
Debug
AnyCPU
- cd5d577e-bdc9-4dfc-ac6a-b1da474995f3
+ {CD5D577E-BDC9-4DFC-AC6A-B1DA474995F3}
Library
Properties
AnyCompany.Tests
@@ -30,24 +30,24 @@
4
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+ {c7e15594-7d8f-4c18-9dd7-14f3fbb1572d}
+ AnyCompany
+
+
-
+
\ No newline at end of file
diff --git a/TechTest/AnyCompany.Tests/Class1.cs b/TechTest/AnyCompany.Tests/Class1.cs
index 5957505..59617fc 100644
--- a/TechTest/AnyCompany.Tests/Class1.cs
+++ b/TechTest/AnyCompany.Tests/Class1.cs
@@ -3,10 +3,26 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using AnyCompany.Interface;
namespace AnyCompany.Tests
{
public class Class1
{
+ private string customerId = "c26f9aca-97e5-405a-b75b-bb1126850244";
+
+ public void LoadCustomerTest()
+ {
+ Guid.TryParse(customerId, out var custid);
+ CustomerRepository.Load(custid);
+ }
+
+ public void PlaceOrderTest()
+ {
+ Guid.TryParse(customerId, out var custid);
+ var orderService = new OrderService();
+ var orderVerify = orderService.PlaceOrder(new Order() { Amount = 123.34 }, custid);
+ Console.WriteLine(orderVerify ? "Order successful" : "Order unsuccessful");
+ }
}
}
diff --git a/TechTest/AnyCompany.UnitTest/AnyCompany.UnitTest.csproj b/TechTest/AnyCompany.UnitTest/AnyCompany.UnitTest.csproj
new file mode 100644
index 0000000..d1fbeab
--- /dev/null
+++ b/TechTest/AnyCompany.UnitTest/AnyCompany.UnitTest.csproj
@@ -0,0 +1,74 @@
+
+
+
+
+
+ Debug
+ AnyCPU
+ {F7622560-215C-4700-AA76-81F1C532069A}
+ Library
+ Properties
+ AnyCompany.UnitTest
+ AnyCompany.UnitTest
+ v4.7.2
+ 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
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ ..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll
+
+
+ ..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {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.UnitTest/AnyCompanyUnitTest.cs b/TechTest/AnyCompany.UnitTest/AnyCompanyUnitTest.cs
new file mode 100644
index 0000000..4121178
--- /dev/null
+++ b/TechTest/AnyCompany.UnitTest/AnyCompanyUnitTest.cs
@@ -0,0 +1,31 @@
+using System;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace AnyCompany.UnitTest
+{
+ [TestClass]
+ public class AnyCompanyUnitTest
+ {
+ private readonly string testId = "c26f9aca-97e5-405a-b75b-bb1126850244";
+
+ [TestMethod]
+ public void LoadCustomer_Test()
+ {
+ Guid.TryParse(testId, out var custid);
+ var cust = CustomerRepository.Load(custid);
+ Assert.IsNotNull(cust);
+ }
+
+
+ [TestMethod]
+ public void PlaceOrderTest()
+ {
+ var orderService = new OrderService();
+ Guid.TryParse(testId, out var custid);
+ var order = new Order() { Amount = 124.4 };
+
+ var orderVerfify = orderService.PlaceOrder(order, custid);
+ Assert.IsTrue(orderVerfify);
+ }
+ }
+}
diff --git a/TechTest/AnyCompany.UnitTest/Properties/AssemblyInfo.cs b/TechTest/AnyCompany.UnitTest/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..f057994
--- /dev/null
+++ b/TechTest/AnyCompany.UnitTest/Properties/AssemblyInfo.cs
@@ -0,0 +1,20 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+[assembly: AssemblyTitle("AnyCompany.UnitTest")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("AnyCompany.UnitTest")]
+[assembly: AssemblyCopyright("Copyright © 2020")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+[assembly: ComVisible(false)]
+
+[assembly: Guid("f7622560-215c-4700-aa76-81f1c532069a")]
+
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/TechTest/AnyCompany.UnitTest/packages.config b/TechTest/AnyCompany.UnitTest/packages.config
new file mode 100644
index 0000000..2f7c5a1
--- /dev/null
+++ b/TechTest/AnyCompany.UnitTest/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..00cf6c0 100644
--- a/TechTest/AnyCompany/AnyCompany.csproj
+++ b/TechTest/AnyCompany/AnyCompany.csproj
@@ -32,6 +32,8 @@
+
+
@@ -40,12 +42,27 @@
-
-
-
-
+
+
+
+
+
+ True
+ True
+ Settings.settings
+
+
+
+
+
+
+ SettingsSingleFileGenerator
+ Settings.Designer.cs
+
+
+
\ No newline at end of file
diff --git a/TechTest/AnyCompany/Interface/IOrder.cs b/TechTest/AnyCompany/Interface/IOrder.cs
new file mode 100644
index 0000000..10dd789
--- /dev/null
+++ b/TechTest/AnyCompany/Interface/IOrder.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AnyCompany.Interface
+{
+ public interface IOrder
+ {
+ int OrderId { get; set; }
+ double Amount { get; set; }
+ double VAT { get; set; }
+ Guid CustomerId { get; set; }
+ }
+}
diff --git a/TechTest/AnyCompany/Interface/IOrderRepository.cs b/TechTest/AnyCompany/Interface/IOrderRepository.cs
new file mode 100644
index 0000000..4fb7574
--- /dev/null
+++ b/TechTest/AnyCompany/Interface/IOrderRepository.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AnyCompany.Interface
+{
+ public interface IOrderRepository
+ {
+ void Save(IOrder order);
+ }
+}
diff --git a/TechTest/AnyCompany/Model/Customer.cs b/TechTest/AnyCompany/Model/Customer.cs
new file mode 100644
index 0000000..a97223d
--- /dev/null
+++ b/TechTest/AnyCompany/Model/Customer.cs
@@ -0,0 +1,16 @@
+using System;
+using AnyCompany.Interface;
+
+namespace AnyCompany
+{
+ public class Customer
+ {
+ public Guid CustomerId { get; set; }
+
+ public string Country { get; set; }
+
+ public DateTime DateOfBirth { get; set; }
+
+ public string Name { get; set; }
+ }
+}
diff --git a/TechTest/AnyCompany/Model/Order.cs b/TechTest/AnyCompany/Model/Order.cs
new file mode 100644
index 0000000..d3d0bed
--- /dev/null
+++ b/TechTest/AnyCompany/Model/Order.cs
@@ -0,0 +1,13 @@
+using System;
+using AnyCompany.Interface;
+
+namespace AnyCompany
+{
+ public class Order : IOrder
+ {
+ public int OrderId { get; set; }
+ public double Amount { get; set; }
+ public double VAT { get; set; }
+ public Guid CustomerId { get; set; }
+ }
+}
diff --git a/TechTest/AnyCompany/OrderService.cs b/TechTest/AnyCompany/OrderService.cs
index ebfb103..a0b1bdb 100644
--- a/TechTest/AnyCompany/OrderService.cs
+++ b/TechTest/AnyCompany/OrderService.cs
@@ -1,21 +1,22 @@
-namespace AnyCompany
+using System;
+using AnyCompany.Interface;
+
+namespace AnyCompany
{
public class OrderService
{
private readonly OrderRepository orderRepository = new OrderRepository();
- public bool PlaceOrder(Order order, int customerId)
+ public bool PlaceOrder(IOrder order, Guid customerId)
{
- Customer customer = CustomerRepository.Load(customerId);
+ var customer = CustomerRepository.Load(customerId);
- if (order.Amount == 0)
+ if (order.Amount < 0.0)
return false;
- if (customer.Country == "UK")
- order.VAT = 0.2d;
- else
- order.VAT = 0;
+ order.VAT = customer.Country == "UK" ? Properties.Settings.Default.ukVat : Properties.Settings.Default.otherVat;
+ order.CustomerId = customerId;
orderRepository.Save(order);
return true;
diff --git a/TechTest/AnyCompany/Properties/Settings.Designer.cs b/TechTest/AnyCompany/Properties/Settings.Designer.cs
new file mode 100644
index 0000000..2a350e8
--- /dev/null
+++ b/TechTest/AnyCompany/Properties/Settings.Designer.cs
@@ -0,0 +1,65 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace AnyCompany.Properties {
+
+
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.0.0.0")]
+ internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+
+ private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+
+ public static Settings Default {
+ get {
+ return defaultInstance;
+ }
+ }
+
+ [global::System.Configuration.ApplicationScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("Data Source=(local);Database=Customers;User Id=admin;Password=password;")]
+ public string connCustomers {
+ get {
+ return ((string)(this["connCustomers"]));
+ }
+ }
+
+ [global::System.Configuration.ApplicationScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("0.2")]
+ public double ukVat {
+ get {
+ return ((double)(this["ukVat"]));
+ }
+ }
+
+ [global::System.Configuration.ApplicationScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("0")]
+ public double otherVat {
+ get {
+ return ((double)(this["otherVat"]));
+ }
+ }
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("Data Source=(local);Database=Orders;User Id=admin;Password=password")]
+ public string connOrders {
+ get {
+ return ((string)(this["connOrders"]));
+ }
+ set {
+ this["connOrders"] = value;
+ }
+ }
+ }
+}
diff --git a/TechTest/AnyCompany/Properties/Settings.settings b/TechTest/AnyCompany/Properties/Settings.settings
new file mode 100644
index 0000000..e253964
--- /dev/null
+++ b/TechTest/AnyCompany/Properties/Settings.settings
@@ -0,0 +1,18 @@
+
+
+
+
+
+ Data Source=(local);Database=Customers;User Id=admin;Password=password;
+
+
+ 0.2
+
+
+ 0
+
+
+ Data Source=(local);Database=Orders;User Id=admin;Password=password
+
+
+
\ No newline at end of file
diff --git a/TechTest/AnyCompany/Repository/CustomerRepository.cs b/TechTest/AnyCompany/Repository/CustomerRepository.cs
new file mode 100644
index 0000000..e5c7a12
--- /dev/null
+++ b/TechTest/AnyCompany/Repository/CustomerRepository.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Data.SqlClient;
+using AnyCompany.Interface;
+
+namespace AnyCompany
+{
+ public static class CustomerRepository
+ {
+ public static Customer Load(Guid customerId)
+ {
+ var customer = new Customer();
+
+ try
+ {
+ var query = "SELECT " +
+ "c.Country, " +
+ "c.DateOfBirth, " +
+ "c.Name," +
+ "OrderId," +
+ "Amount," +
+ "VAT" +
+ "FROM " +
+ "Customer AS c" +
+ "INNER JOIN" +
+ "Orders.dbo.Orders AS o" +
+ "ON" +
+ "c.CustomerId = o.CustomerId" +
+ "WHERE " +
+ " c.CustomerId = " + customerId;
+
+ using (var conn = new SqlConnection(Properties.Settings.Default.connCustomers))
+ {
+ conn.Open();
+ using (var cmd = new SqlCommand(query, conn))
+ {
+ var reader = cmd.ExecuteReader();
+ while (reader.Read())
+ {
+ customer.Name = reader["Name"].ToString();
+ customer.DateOfBirth = DateTime.Parse(reader["DateOfBirth"].ToString());
+ customer.Country = reader["Country"].ToString();
+ }
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+
+ return customer;
+ }
+ }
+}
diff --git a/TechTest/AnyCompany/Repository/OrderRepository.cs b/TechTest/AnyCompany/Repository/OrderRepository.cs
new file mode 100644
index 0000000..3886498
--- /dev/null
+++ b/TechTest/AnyCompany/Repository/OrderRepository.cs
@@ -0,0 +1,35 @@
+using System;
+using System.Data.SqlClient;
+using AnyCompany.Interface;
+
+namespace AnyCompany
+{
+ internal class OrderRepository : IOrderRepository
+ {
+ public void Save(IOrder order)
+ {
+ const string query = "INSERT INTO Orders VALUES (@OrderId, @Amount, @VAT)";
+
+ try
+ {
+ using (var conn = new SqlConnection(Properties.Settings.Default.connOrders))
+ {
+ conn.Open();
+ using (var cmd = new SqlCommand(query, conn))
+ {
+ cmd.Parameters.AddWithValue("@OrderId", order.OrderId);
+ cmd.Parameters.AddWithValue("@Amount", order.Amount);
+ cmd.Parameters.AddWithValue("@VAT", order.VAT);
+ cmd.Parameters.AddWithValue("@CustomerId", order.CustomerId);
+ cmd.ExecuteNonQuery();
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e);
+ throw;
+ }
+ }
+ }
+}
diff --git a/TechTest/AnyCompany/app.config b/TechTest/AnyCompany/app.config
new file mode 100644
index 0000000..4bbc895
--- /dev/null
+++ b/TechTest/AnyCompany/app.config
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Data Source=(local);Database=Customers;User Id=admin;Password=password;
+
+
+ 0.2
+
+
+ 0
+
+
+
+
+
+
+ Data Source=(local);Database=Orders;User Id=admin;Password=password
+
+
+
+
\ No newline at end of file
diff --git a/TechTest/TechTest.sln b/TechTest/TechTest.sln
index 1c1c57a..24ea1a6 100644
--- a/TechTest/TechTest.sln
+++ b/TechTest/TechTest.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.27004.2005
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.28803.540
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnyCompany", "AnyCompany\AnyCompany.csproj", "{C7E15594-7D8F-4C18-9DD7-14F3FBB1572D}"
EndProject
@@ -12,6 +12,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Instructions.txt = Instructions.txt
EndProjectSection
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnyCompany.UnitTest", "..\..\vuvu\tech-test\TechTest\AnyCompany.UnitTest\AnyCompany.UnitTest.csproj", "{F7622560-215C-4700-AA76-81F1C532069A}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -26,6 +28,10 @@ Global
{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
+ {F7622560-215C-4700-AA76-81F1C532069A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F7622560-215C-4700-AA76-81F1C532069A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F7622560-215C-4700-AA76-81F1C532069A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F7622560-215C-4700-AA76-81F1C532069A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE