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

Tumelo Mosia - TechTest #28

Open
wants to merge 7 commits 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
56 changes: 46 additions & 10 deletions TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.visualstudio.2.4.2\build\net452\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.4.2\build\net452\xunit.runner.visualstudio.props')" />
<Import Project="..\packages\xunit.core.2.4.1\build\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.4.1\build\xunit.core.props')" />
<Import Project="..\packages\Microsoft.NET.Test.Sdk.16.6.1\build\net40\Microsoft.NET.Test.Sdk.props" Condition="Exists('..\packages\Microsoft.NET.Test.Sdk.16.6.1\build\net40\Microsoft.NET.Test.Sdk.props')" />
<Import Project="..\packages\Microsoft.CodeCoverage.16.6.1\build\netstandard1.0\Microsoft.CodeCoverage.props" Condition="Exists('..\packages\Microsoft.CodeCoverage.16.6.1\build\netstandard1.0\Microsoft.CodeCoverage.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -30,24 +34,56 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System"/>
<Reference Include="System" />

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


<Reference Include="Microsoft.CSharp"/>
<Reference Include="Microsoft.CSharp" />

<Reference Include="System.Data"/>
<Reference Include="System.Data" />

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

<Reference Include="System.Xml"/>
<Reference Include="System.Xml" />
<Reference Include="Microsoft.VisualStudio.CodeCoverage.Shim">
<HintPath>..\packages\Microsoft.CodeCoverage.16.6.1\lib\net45\Microsoft.VisualStudio.CodeCoverage.Shim.dll</HintPath>
</Reference>
<Reference Include="xunit.abstractions">
<HintPath>..\packages\xunit.abstractions.2.0.3\lib\net35\xunit.abstractions.dll</HintPath>
</Reference>
<Reference Include="xunit.assert">
<HintPath>..\packages\xunit.assert.2.4.1\lib\netstandard1.1\xunit.assert.dll</HintPath>
</Reference>
<Reference Include="xunit.core">
<HintPath>..\packages\xunit.extensibility.core.2.4.1\lib\net452\xunit.core.dll</HintPath>
</Reference>
<Reference Include="xunit.execution.desktop">
<HintPath>..\packages\xunit.extensibility.execution.2.4.1\lib\net452\xunit.execution.desktop.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="CustomerUnitTests\GetCustomersUnitTests.cs" />
<Compile Include="OrderUnitTests\PlaceOrderTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AnyCompany\AnyCompany.csproj">
<Project>{C7E15594-7D8F-4C18-9DD7-14F3FBB1572D}</Project>
<Name>AnyCompany</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="CustomerUnitTests\" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\coverlet.collector.1.3.0\build\netstandard1.0\coverlet.collector.targets" Condition="Exists('..\packages\coverlet.collector.1.3.0\build\netstandard1.0\coverlet.collector.targets')" />
<Import Project="..\packages\Microsoft.CodeCoverage.16.6.1\build\netstandard1.0\Microsoft.CodeCoverage.targets" Condition="Exists('..\packages\Microsoft.CodeCoverage.16.6.1\build\netstandard1.0\Microsoft.CodeCoverage.targets')" />
<Import Project="..\packages\Microsoft.NET.Test.Sdk.16.6.1\build\net40\Microsoft.NET.Test.Sdk.targets" Condition="Exists('..\packages\Microsoft.NET.Test.Sdk.16.6.1\build\net40\Microsoft.NET.Test.Sdk.targets')" />
<Import Project="..\packages\xunit.core.2.4.1\build\xunit.core.targets" Condition="Exists('..\packages\xunit.core.2.4.1\build\xunit.core.targets')" />
</Project>
12 changes: 0 additions & 12 deletions TechTest/AnyCompany.Tests/Class1.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<Customer>;
Assert.True(result);
}
}
}
146 changes: 146 additions & 0 deletions TechTest/AnyCompany.Tests/OrderUnitTests/PlaceOrderTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
14 changes: 14 additions & 0 deletions TechTest/AnyCompany.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="coverlet.collector" version="1.3.0" targetFramework="net461" developmentDependency="true" />
<package id="Microsoft.CodeCoverage" version="16.6.1" targetFramework="net461" />
<package id="Microsoft.NET.Test.Sdk" version="16.6.1" targetFramework="net461" />
<package id="xunit" version="2.4.1" targetFramework="net461" />
<package id="xunit.abstractions" version="2.0.3" targetFramework="net461" />
<package id="xunit.analyzers" version="0.10.0" targetFramework="net461" />
<package id="xunit.assert" version="2.4.1" targetFramework="net461" />
<package id="xunit.core" version="2.4.1" targetFramework="net461" />
<package id="xunit.extensibility.core" version="2.4.1" targetFramework="net461" />
<package id="xunit.extensibility.execution" version="2.4.1" targetFramework="net461" />
<package id="xunit.runner.visualstudio" version="2.4.2" targetFramework="net461" developmentDependency="true" />
</packages>
15 changes: 9 additions & 6 deletions TechTest/AnyCompany/AnyCompany.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" 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>
Expand Down Expand Up @@ -40,12 +40,15 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Customer.cs" />
<Compile Include="CustomerRepository.cs" />
<Compile Include="Order.cs" />
<Compile Include="OrderRepository.cs" />
<Compile Include="OrderService.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Models\Order.cs" />
<Compile Include="Models\Customer.cs" />
<Compile Include="Repositories\CustomerRepository.cs" />
<Compile Include="Repositories\OrderRepository.cs" />
<Compile Include="Services\OrderService.cs" />
<Compile Include="Services\CustomerService.cs" />
<Compile Include="IServices\IOrdersService.cs" />
<Compile Include="IServices\ICustomerService.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
33 changes: 0 additions & 33 deletions TechTest/AnyCompany/CustomerRepository.cs

This file was deleted.

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

namespace AnyCompany.IServices
{
public interface ICustomerService
{
bool SaveCustomer(Customer customer);
List<Customer> GetCustomersWithOrders();
}
}
11 changes: 11 additions & 0 deletions TechTest/AnyCompany/IServices/IOrdersService.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +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<Order> Orders { get; set; }
}
}
10 changes: 10 additions & 0 deletions TechTest/AnyCompany/Models/Order.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
Loading