Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5400c81
Testing commit and sync
nkauza Aug 18, 2020
1a44849
Add class library project for Models, remove models from AnyCompany p…
nkauza Aug 18, 2020
6f3189f
Created Repository Class Library and added an inteface with Save and…
nkauza Aug 18, 2020
5449b01
Moved the Order repository to the Repository class library and Implem…
nkauza Aug 18, 2020
1079072
Implement IDisposable interface and added a constructor to open the D…
nkauza Aug 18, 2020
46f95a4
Replace the hardcorded sql script with a stored procedure. Remove Ord…
nkauza Aug 18, 2020
319eefd
Created Folder inside the Repository project to backup the stored pro…
nkauza Aug 18, 2020
3055fa3
Created GetOrders Stored Procedure and Impleted the GetOrders method …
nkauza Aug 18, 2020
551fc0d
Moved the customer repository class the the Repository class library …
nkauza Aug 18, 2020
b913bb4
Remove duplicate Customer Repository and Order Reposity from AnyCompany
nkauza Aug 18, 2020
27ee570
Added the IOrderService interface and defined the PlaceOrder, GetCust…
nkauza Aug 18, 2020
945a6b1
Implement the IOrderService interface and add reference to the Reposi…
nkauza Aug 18, 2020
ff9b256
Wrap the code inside PlaceOrder method with a using statement to allo…
nkauza Aug 18, 2020
eb87072
Call the Load method from Customer Repository inside the Order Servic…
nkauza Aug 18, 2020
581a5da
Update the Place Order method to call the local Get customer method i…
nkauza Aug 18, 2020
6a45987
Implement excetion handling and return false if an exception has occu…
nkauza Aug 18, 2020
a10eb2b
Implement the GetOrders method return orders from the Order repository
nkauza Aug 18, 2020
672c41e
Move the DB connection string to an App config file, and update the c…
nkauza Aug 18, 2020
849d89a
Update the order repository to read the connection string from the Ap…
nkauza Aug 18, 2020
88f46e5
Change the AnyCompany.Tests class library to a Unit Test Project
nkauza Aug 18, 2020
47b0e5c
Refererence the AnyCompany class library and Models class library
nkauza Aug 18, 2020
9fee580
Update the IOrderService interface to be public so that it can be acc…
nkauza Aug 18, 2020
e0a43e3
Implement Unit Test methods to test Place order and Get orders custom…
nkauza Aug 18, 2020
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
49 changes: 49 additions & 0 deletions TechTest/AnyCompany.Models/AnyCompany.Models.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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>{1586B2DA-3864-426F-BE39-81DC89C4F667}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AnyCompany.Models</RootNamespace>
<AssemblyName>AnyCompany.Models</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</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" />
</ItemGroup>
<ItemGroup>
<Compile Include="Customer.cs" />
<Compile Include="Order.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -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; }
}
}
17 changes: 17 additions & 0 deletions TechTest/AnyCompany.Models/Order.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
36 changes: 36 additions & 0 deletions TechTest/AnyCompany.Models/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
66 changes: 66 additions & 0 deletions TechTest/AnyCompany.Repository/AnyCompany.Repository.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?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>{C90C052C-DF98-45B5-B1F3-62BF20658B5A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AnyCompany.Repository</RootNamespace>
<AssemblyName>AnyCompany.Repository</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<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="CustomerRepository.cs" />
<Compile Include="Interfaces\IOrderRepository.cs" />
<Compile Include="OrderRepository.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AnyCompany.Models\AnyCompany.Models.csproj">
<Project>{1586b2da-3864-426f-be39-81dc89c4f667}</Project>
<Name>AnyCompany.Models</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="DBStoredProcs\spGetCustomer.sql" />
<Content Include="DBStoredProcs\spGetOrders.sql" />
<Content Include="DBStoredProcs\spPlaceOrder.sql" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
6 changes: 6 additions & 0 deletions TechTest/AnyCompany.Repository/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="DBConnectionString" providerName="System.Data.SqlClient" connectionString="Data Source=(local);Database=Customers;User Id=admin;Password=password;"/>
</connectionStrings>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;

namespace AnyCompany.Tests
namespace AnyCompany.Repository
{
public class Class1
{
Expand Down
55 changes: 55 additions & 0 deletions TechTest/AnyCompany.Repository/CustomerRepository.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
14 changes: 14 additions & 0 deletions TechTest/AnyCompany.Repository/DBStoredProcs/spGetCustomer.sql
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions TechTest/AnyCompany.Repository/DBStoredProcs/spGetOrders.sql
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions TechTest/AnyCompany.Repository/DBStoredProcs/spPlaceOrder.sql
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions TechTest/AnyCompany.Repository/Interfaces/IOrderRepository.cs
Original file line number Diff line number Diff line change
@@ -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<Order> GetOrders();
}
}
Loading