Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tech test solution #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>cd5d577e-bdc9-4dfc-ac6a-b1da474995f3</ProjectGuid>
<OutputType>Library</OutputType>
<ProjectGuid>{CD5D577E-BDC9-4DFC-AC6A-B1DA474995F3}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AnyCompany.Tests</RootNamespace>
<AssemblyName>AnyCompany.Tests</AssemblyName>
Expand All @@ -29,25 +29,28 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="System"/>

<Reference Include="System.Core"/>
<Reference Include="System.Xml.Linq"/>
<Reference Include="System.Data.DataSetExtensions"/>


<Reference Include="Microsoft.CSharp"/>

<Reference Include="System.Data"/>

<Reference Include="System.Net.Http"/>

<Reference Include="System.Xml"/>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AnyCompany\AnyCompany.csproj">
<Project>{c7e15594-7d8f-4c18-9dd7-14f3fbb1572d}</Project>
<Name>AnyCompany</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
12 changes: 0 additions & 12 deletions TechTest/AnyCompany.Tests/Class1.cs

This file was deleted.

27 changes: 27 additions & 0 deletions TechTest/AnyCompany.Tests/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using AnyCompany.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnyCompany.Tests
{
public class Program
{
static void Main(string[] args)
{
//Orderservice should be injected using a dependency injection container(e.g. Unity)
IOrderService orderService = new OrderService();

List<Customer> customers = orderService.LoadAllCustomersAndOrders();

Order order = new Order
{
Amount = 22d
};

orderService.PlaceOrder(order, 1);
}
}
}
14 changes: 10 additions & 4 deletions TechTest/AnyCompany/AnyCompany.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand All @@ -40,11 +41,16 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Customer.cs" />
<Compile Include="CustomerRepository.cs" />
<Compile Include="Order.cs" />
<Compile Include="OrderRepository.cs" />
<Compile Include="IOrderService.cs" />
<Compile Include="Model\Customer.cs" />
<Compile Include="Persistence\CustomerRepository.cs" />
<Compile Include="Model\Order.cs" />
<Compile Include="Persistence\DataAccessObjectFactory.cs" />
<Compile Include="Persistence\DataParameterHelper.cs" />
<Compile Include="Persistence\IDataAccessObject.cs" />
<Compile Include="Persistence\OrderRepository.cs" />
<Compile Include="OrderService.cs" />
<Compile Include="Persistence\SqlDataAccessObject.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
33 changes: 0 additions & 33 deletions TechTest/AnyCompany/CustomerRepository.cs

This file was deleted.

12 changes: 12 additions & 0 deletions TechTest/AnyCompany/IOrderService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using AnyCompany.Model;
using System.Collections.Generic;

namespace AnyCompany
{
public interface IOrderService
{
bool PlaceOrder(Order order, int customerId);

List<Customer> LoadAllCustomersAndOrders();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
using System;
using System.Collections.Generic;

namespace AnyCompany
namespace AnyCompany.Model
{
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<Order> Orders { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
namespace AnyCompany
namespace AnyCompany.Model
{
public class Order
{
public int OrderId { get; set; }

public double Amount { get; set; }

public double VAT { get; set; }
}
}
25 changes: 0 additions & 25 deletions TechTest/AnyCompany/OrderRepository.cs

This file was deleted.

58 changes: 47 additions & 11 deletions TechTest/AnyCompany/OrderService.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,60 @@
namespace AnyCompany
using AnyCompany.Model;
using System;
using System.Collections.Generic;

namespace AnyCompany
{
public class OrderService
public class OrderService : IOrderService
{
private readonly OrderRepository orderRepository = new OrderRepository();

public List<Customer> LoadAllCustomersAndOrders()
{
try
{
List<Customer> customers = CustomerRepository.LoadAllCustomers();

return customers;
}
catch (Exception ex)
{
throw new Exception("Failed to load customers.", ex);
}
}

public bool PlaceOrder(Order order, int customerId)
{
Customer customer = CustomerRepository.Load(customerId);
if (order == null)
throw new ArgumentNullException();

try
{
Customer customer = CustomerRepository.Load(customerId);

if (order.Amount == 0)
return false;

if (order.Amount == 0)
return false;
if (customer == null)
return false;

if (customer.Country == "UK")
order.VAT = 0.2d;
else
order.VAT = 0;
switch (customer.Country)
{
case "UK":
order.VAT = 0.2d;
break;
default:
order.VAT = 0;
break;
}

orderRepository.Save(order);
orderRepository.Save(order, customerId);

return true;
return true;
}
catch (Exception ex)
{
throw new Exception($"Failed to save order for customer with customer ID {customerId}", ex);
}
}
}
}
Loading