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

TechTest #30

Open
wants to merge 15 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
89 changes: 71 additions & 18 deletions TechTest/AnyCompany.Tests/AnyCompany.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<?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="..\packages\NUnit3TestAdapter.3.17.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.17.0\build\net35\NUnit3TestAdapter.props')" />
<Import Project="..\packages\NUnit.3.12.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.12.0\build\NUnit.props')" />
<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>
<ProjectGuid>{CD5D577E-BDC9-4DFC-AC6A-B1DA474995F3}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AnyCompany.Tests</RootNamespace>
<AssemblyName>AnyCompany.Tests</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -30,24 +34,73 @@
<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"/>
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.4.4.0\lib\net45\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.14.0.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.14.5\lib\net45\Moq.dll</HintPath>
</Reference>
<Reference Include="NSubstitute, Version=4.2.0.0, Culture=neutral, PublicKeyToken=92dd2e9066daa5ca, processorArchitecture=MSIL">
<HintPath>..\packages\NSubstitute.4.2.2\lib\net46\NSubstitute.dll</HintPath>
</Reference>
<Reference Include="nunit.core, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.WithFramework.2.0.0\lib\nunit.core.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="nunit.core.interfaces, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.WithFramework.2.0.0\lib\nunit.core.interfaces.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.WithFramework.2.0.0\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="nunit.util, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.WithFramework.2.0.0\lib\nunit.util.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="NUnit.VisualStudio.TestAdapter, Version=2.0.0.0, Culture=neutral, PublicKeyToken=4cb40d35494691ac, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.WithFramework.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<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.Tests.cs" />
<Compile Include="OrderRepository.Tests.cs" />
<Compile Include="OrderService.Tests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UnitOfWork.Tests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</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>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NUnit.3.12.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.12.0\build\NUnit.props'))" />
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.17.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.17.0\build\net35\NUnit3TestAdapter.props'))" />
</Target>
</Project>
12 changes: 0 additions & 12 deletions TechTest/AnyCompany.Tests/Class1.cs

This file was deleted.

40 changes: 40 additions & 0 deletions TechTest/AnyCompany.Tests/CustomerRepository.Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AnyCompany.Models;
using AnyCompany.Repositories.CustomerRepository;
using NUnit.Framework;
using NSubstitute;
using NSubstitute.ExceptionExtensions;

namespace AnyCompany.Tests
{
[TestFixture]
public class CustomerRepositoryTest
{


[Test]
public static void Given_The_Correct_CustomerId_Is_Provided_Return_Correct_Customer_details ()
{
var customerRepo = Substitute.For<ICustomerRepository<Customer>>();

var results = CustomerRepository.Load(1);

Assert.IsNotNull(results);

}

[Test]
public static void Given_The_InCorrect_CustomerId_Is_Provided_Return_NoDetails()
{
var customerRepo = Substitute.For<ICustomerRepository<Customer>>();

var results = CustomerRepository.Load(1);

Assert.IsNull(results);
}
}
}
85 changes: 85 additions & 0 deletions TechTest/AnyCompany.Tests/OrderRepository.Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit;
using NUnit.Framework;
using Moq;
using AnyCompany.Models;
using AnyCompany.Repositories.CustomerRepository;
using NSubstitute;
using AnyCompany.Repositories.OrderRepository;
using NSubstitute.ExceptionExtensions;

namespace AnyCompany.Tests
{
[TestFixture]
public class OrderRepository
{

[Test]
public void Given_Correct_CustomerId_Check_If_GetCustOrders_returns_Results()
{
var orderRepo = Substitute.For<IOrderRepository<Order>>();
var custorders = orderRepo.GetCustomerOrders(1);

Assert.IsNotNull(custorders);
}

[Test]
public void Given_Correct_CustomerId_Check_If_GetAllOrders_returns_Results()
{
var orderRepo = Substitute.For<IOrderRepository<Order>>();
var custorders = orderRepo.GetAllOrders();

Assert.IsNotNull(custorders);
}

[Test]
public void Given_Not_Correct_CustomerId_Check_If_GetAllOrders_returns_No_Results()
{
var orderRepo = Substitute.For<IOrderRepository<Order>>();
var custorders = orderRepo.GetAllOrders();

Assert.IsNull(custorders);
}

[Test]
public void Given_Correct_OrderObject_Check_If_SaveOrder_Works()
{
var orderRepo = Substitute.For<IOrderRepository<Order>>();
var order = new Order {
Address = new Address{
HouseNumber = 23,
BuildingName = "Lister",
Country = "ZAR",
PostalCode = "2001",
CustomerId = 2,
Province = "Gauteng",
StreetName = "Jeppe",
Surburb = "MArshalltown"
},
Amount = 10,
CustomerAccountNumber = "1244",
CustomerId = 2,
OrderId = 3,
VAT = 0.2d
};

var response = orderRepo.Save(order);
Assert.IsTrue(response);
}

//[Test]
//public void Given_Incomplete_OrderObject_Check_If_SaveOrder_Returns_Null_Or_Throws_ArgumentException()
//{
// var orderRepo = Substitute.For<IUnitOfWork>();
// var order = new Order
// {
// };

// Assert.Throws<ArgumentException>(() => orderRepo.Save(order));
//}
}
}
144 changes: 144 additions & 0 deletions TechTest/AnyCompany.Tests/OrderService.Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using AnyCompany.Models;
using AnyCompany.Repositories.CustomerRepository;
using NSubstitute;

namespace AnyCompany.Tests
{
[TestFixture]
public class OrderServiceTests
{
[Test]
public void CheckIf_GetCustomerWithOrders_Returns_None_Empty_results()
{
var iunitRepo = Substitute.For<IUnitOfWork>();
var unitRep = new OrderService(iunitRepo);
var custorders = unitRep.GetCustomersWithOrders();

Assert.NotNull(custorders);
}

[Test]
public void Given_Non_Empty_Correct_CustomerId_PlaceOrder_Return_Results()
{
var iunitRepo = Substitute.For<IUnitOfWork>();
var unitRep = new OrderService(iunitRepo);
var order = new Order
{
Amount = 50,
CustomerId = 1,
OrderId = 1,
CustomerAccountNumber = "7KK23",
VAT = 0,
Address = new Address
{
HouseNumber = 23,
PostalCode = "2001",
StreetName = "Ramaphosa Street",
Surburb = "Saxonworld",
Province = "Gauteng",
Country = "South Africa",
CustomerId = 1
}
};
var placeorderTest = unitRep.PlaceOrder(order, 1);

Assert.IsNotNull(placeorderTest);
Assert.IsTrue(placeorderTest);
}

[Test]
public void Given_Invalid_CustomerId_PlaceOrder_Return_False_Results()
{
var iunitRepo = Substitute.For<IUnitOfWork>();
var unitRep = new OrderService(iunitRepo);
var order = new Order
{
Amount = 50,
CustomerId = 1,
OrderId = 1,
CustomerAccountNumber = "7KK23",
VAT = 0,
Address = new Address
{
HouseNumber = 23,
PostalCode = "2001",
StreetName = "Ramaphosa Street",
Surburb = "Saxonworld",
Province = "Gauteng",
Country = "South Africa",
CustomerId = 0
}
};
var placeorderTest = unitRep.PlaceOrder(order, 0);

Assert.IsNotNull(placeorderTest);
Assert.IsFalse(placeorderTest);
}

[Test]
public void Given_Invalid_CustomerId_PlaceOrder_Return_No_Results()
{

var iunitRepo = Substitute.For<IUnitOfWork>();
var unitRep = new OrderService(iunitRepo);
var order = new Order
{
Amount = 50,
OrderId = 1,
CustomerAccountNumber = "7KK23",
VAT = 0,
Address = new Address
{
HouseNumber = 23,
PostalCode = "2001",
StreetName = "Ramaphosa Street",
Surburb = "Saxonworld",
Province = "Gauteng",
Country = "South Africa"
}
};
var placeorderTest = unitRep.PlaceOrder(order, 0);

Assert.IsFalse(placeorderTest);
}

[Test]
public void Given_Empty_Order_Object_PlaceOrder_Return_False_Results()
{
var iunitRepo = Substitute.For<IUnitOfWork>();
var unitRep = new OrderService(iunitRepo);

var placeorderTest = unitRep.PlaceOrder(new Order { },1);

Assert.IsFalse(placeorderTest);
}

[Test]
public void Check_If_GetOrders_Returns_Results()
{
var iunitRepo = Substitute.For<IUnitOfWork>();
var unitRep = new OrderService(iunitRepo);

var getorders = unitRep.GetOrders();

Assert.IsNotNull(getorders);
}

[Test]
public void Check_If_GetCustomers_Returns_Results()
{
var iunitRepo = Substitute.For<IUnitOfWork>();
var unitRep = new OrderService(iunitRepo);

var getcustomers = unitRep.GetCustomers();

Assert.IsNotNull(getcustomers);
}
}
}
Loading