Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
local.appsettings.config

# User-specific files
.idea/
*.suo
*.user
*.userosscache
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Please input your Name: Please input your Address: Please input your Due Date:
Please input the number of Red Square:
Please input the number of Blue Square:
Please input the number of Yellow Square:
Please input the number of Red Triangle:
Please input the number of Blue Triangle:
Please input the number of Yellow Triangle:
Please input the number of Red Circle:
Please input the number of Blue Circle:
Please input the number of Yellow Circle:
Your invoice report has been generated:

Name: David Wei Address: 26A Croydon Street, Sydenham, Christchurch 8024 Due Date: 29-09-2021 Order #: 0
-------------------------------------------------------------------------
| | Red | Blue | Yellow |
-------------------------------------------------------------------------
| Square | 1 | 2 | 3 |
| Triangle | 4 | 7 | 2 |
| Circle | 5 | 8 | 1 |
-------------------------------------------------------------------------

Squares 6 @ $1 ppi = $6
Triangles 13 @ $2 ppi = $26
Circles 14 @ $3 ppi = $42
Red Color Surcharge 10 @ $1 ppi = $10

Your cutting list has been generated:

Name: David Wei Address: 26A Croydon Street, Sydenham, Christchurch 8024 Due Date: 29-09-2021 Order #: 0
--------------------
| | Qty |
--------------------
| Square | 6 |
|Triangle | 13 |
| Circle | 14 |
--------------------

Your painting report has been generated:

Name: David Wei Address: 26A Croydon Street, Sydenham, Christchurch 8024 Due Date: 29-09-2021 Order #: 0
-------------------------------------------------------------------------
| | Red | Blue | Yellow |
-------------------------------------------------------------------------
| Square | 1 | 2 | 3 |
| Triangle | 4 | 7 | 2 |
| Circle | 5 | 8 | 1 |
-------------------------------------------------------------------------
12 changes: 12 additions & 0 deletions Order.Management.Test/Approvals/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
David Wei
26A Croydon Street, Sydenham, Christchurch 8024
29-09-2021
1
2
3
4
7
2
5
8
1
31 changes: 31 additions & 0 deletions Order.Management.Test/Order.Management.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ApprovalTests" Version="5.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<None Include="Approvals/input.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Order.Management\Order.Management.csproj" />
</ItemGroup>

</Project>
143 changes: 143 additions & 0 deletions Order.Management.Test/OrderTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
using System.Collections.Generic;
using System.Management;
using System.Runtime.InteropServices;
using Order.Management.Enums;
using Xunit;
using Order.Management.Models;

namespace Order.Management.Test
{
public class OrderTest
{
public static IEnumerable<object[]> OrderWithColorTotalData =>
GetSampleOrderList(QuantitySample, QuantityTotalByColorSample);

public static IEnumerable<object[]> OrderWithShapeTotalData =>
GetSampleOrderList(QuantitySample, QuantityTotalByShapeSample);


[Theory]
[MemberData(nameof(OrderWithColorTotalData))]
void OrderColorTotalTestTheory(Models.Order order, int[] expectTotalByColor)
{
int red = expectTotalByColor[0];
int blue = expectTotalByColor[1];
int yellow = expectTotalByColor[2];
Assert.Equal(order.GetNumbersOfColour(ShapeColours.Red), red);
Assert.Equal(order.GetNumbersOfColour(ShapeColours.Blue), blue);
Assert.Equal(order.GetNumbersOfColour(ShapeColours.Yellow), yellow);
}

[Theory]
[MemberData(nameof(OrderWithShapeTotalData))]
void OrderShapeTotalTestTheory(Models.Order order, int[] expectTotalByShape)
{
int squareTotal = expectTotalByShape[0];
int triangleTotal = expectTotalByShape[1];
int circleTotal = expectTotalByShape[2];
Assert.Equal(order.GetNumbersOfShape(Shapes.Square), squareTotal);
Assert.Equal(order.GetNumbersOfShape(Shapes.Triangle), triangleTotal);
Assert.Equal(order.GetNumbersOfShape(Shapes.Circle), circleTotal);
}

private static int[][] QuantitySample { get; } =
{
new[]
{
//Red, Blue, Yellow
1, 2, 3, //square
4, 7, 2, //triangle
5, 8, 1, //circle
},
new[]
{
//Red, Blue, Yellow
1, 2, 3,
2, 5, 6,
3, 8, 1,
},
new[]
{
//Red, Blue, Yellow
0, 3, 4,
1, 5, 8,
9, 2, 3,
},
};

private static int[][] QuantityTotalByColorSample { get; } =
{
new[]
{
//Red, Blue, Yellow
10, 17, 6,
},
new[]
{
//Red, Blue, Yellow
6, 15, 10,
},
new[]
{
//Red, Blue, Yellow
10, 10, 15,
},
};

private static int[][] QuantityTotalByShapeSample { get; } =
{
new[]
{
//Square, Triangle, Circle
6, 13, 14,
},
new[]
{
//Square, Triangle, Circle
6, 13, 12,
},
new[]
{
//Square, Triangle, Circle
7, 14, 14,
},
};

private static IEnumerable<object[]> GetSampleOrderList(int[][] quantitySample, int[][] quantityTotalSample)
{
var index = 0;
foreach (var quantityList in quantitySample)
{
var order = new Models.Order
{
CustomerName = "David Wei",
Address = "21 Stanbury Avenue, Somerfield, Christchurch 8024",
DueDate = "28-09-2021",
OrderNumber = 1000,
OrderedBlocks = GetSampleOrderItemList(quantityList)
};
yield return new object[] {order, quantityTotalSample[index]};
index++;
}
}

private static List<OrderItem> GetSampleOrderItemList(int[] quantityList)
{
var orderItemList = new List<OrderItem>();
var quantityIndex = 0;
foreach (var shape in Constants.CurrentShapes)
foreach (ShapeColours colour in Constants.CurrentColours)
{
var quantity = quantityList[quantityIndex];
orderItemList.Add(new OrderItem()
{
Shape = new Shape(shape, colour),
Quantity = quantity,
});
quantityIndex++;
}

return orderItemList;
}
}
}
30 changes: 30 additions & 0 deletions Order.Management.Test/ProgramTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.IO;
using System.Reflection;
using ApprovalTests;
using ApprovalTests.Namers;
using ApprovalTests.Reporters;
using Xunit;

namespace Order.Management.Test
{
[UseReporter(typeof(DiffReporter))]
[UseApprovalSubdirectory("Approvals")]
public class ProgramTest
{
[Fact]
public void TestMainOutputs()
{
using var fakeStdout = new StringWriter();
Console.SetOut(fakeStdout);

var currentDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
using var inputNames = new StreamReader($@"{currentDir}/Approvals/input.txt");
// Tell console to get its input from the file, not from the keyboard
Console.SetIn(inputNames);

Program.Main(new string[] { });
Approvals.Verify(fakeStdout.ToString());
}
}
}
6 changes: 6 additions & 0 deletions Order.Management.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.29519.87
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Order.Management", "Order.Management\Order.Management.csproj", "{1DAC7794-3F0E-4083-95A9-2E6FF9512C0C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Order.Management.Test", "Order.Management.Test\Order.Management.Test.csproj", "{AEA22CA0-3BCB-4793-994C-F81440CD8C99}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{1DAC7794-3F0E-4083-95A9-2E6FF9512C0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1DAC7794-3F0E-4083-95A9-2E6FF9512C0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1DAC7794-3F0E-4083-95A9-2E6FF9512C0C}.Release|Any CPU.Build.0 = Release|Any CPU
{AEA22CA0-3BCB-4793-994C-F81440CD8C99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AEA22CA0-3BCB-4793-994C-F81440CD8C99}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AEA22CA0-3BCB-4793-994C-F81440CD8C99}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AEA22CA0-3BCB-4793-994C-F81440CD8C99}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
37 changes: 0 additions & 37 deletions Order.Management/Circle.cs

This file was deleted.

33 changes: 33 additions & 0 deletions Order.Management/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Microsoft.VisualBasic.CompilerServices;
using Order.Management.Enums;
using Order.Management.Exceptions;

namespace Order.Management
{
public static class Constants
{
// Constants for Reports
public const int TableWidth = 73;
public const int CuttingReportTableWidth = 20;

// Constants for Orders
public const decimal CirclePrice = 3m;
public const decimal SquarePrice = 1m;
public const decimal TrianglePrice = 2m;
public const decimal AdditionalCharge = 1m;

public static Shapes[] CurrentShapes = new[]
{
Shapes.Square,
Shapes.Triangle,
Shapes.Circle,
};

public static ShapeColours[] CurrentColours = new[]
{
ShapeColours.Red,
ShapeColours.Blue,
ShapeColours.Yellow,
};
}
}
Loading