Skip to content

Commit

Permalink
Edwin_ThoughtWorks
Browse files Browse the repository at this point in the history
Assignment
  • Loading branch information
Edwin2109 committed Mar 24, 2013
0 parents commit 6e2d775
Show file tree
Hide file tree
Showing 85 changed files with 34,112 additions and 0 deletions.
6 changes: 6 additions & 0 deletions TaxCalculation.Console/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
40 changes: 40 additions & 0 deletions TaxCalculation.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TaxCalculation.Domain;
using TaxCalculation.Domain.Enums;
using TaxCalculation.Domain.Factories;
using TaxCalculation.Domain.Interfaces;
using TaxCalculation.Domain.Repositories;


namespace TaxCalculation.ConsoleApp
{
class Program
{
static void Main(string[] args)
{
IOrdersRepository repository = new OrdersRepository();
//
var orders = repository.ReadOrders("SalesData.txt");

foreach (var order in orders)
{
System.Console.WriteLine(order.OrderNumber);
foreach(var lineItem in order.LineItems)
{
System.Console.WriteLine(lineItem.GetQuantity() + " " + lineItem.Name + " " + decimal.Round(lineItem.GetTotal(),2));
}
Console.WriteLine("Sales Taxes: " + order.GetOrderLineTax());
Console.WriteLine("Total: " + order.GetOrderTotal());
Console.WriteLine(Environment.NewLine);
}
Console.ReadLine();
}


}
}
36 changes: 36 additions & 0 deletions TaxCalculation.Console/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("TaxCalculation.Console")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TaxCalculation.Console")]
[assembly: AssemblyCopyright("Copyright © 2013")]
[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("214b66b9-646e-45fb-913c-c28e725cfca9")]

// 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")]
64 changes: 64 additions & 0 deletions TaxCalculation.Console/TaxCalculation.ConsoleApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" 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>{5D8F40B3-BAF4-4522-8A7D-EA3D8D6E89F5}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TaxCalculation.Console</RootNamespace>
<AssemblyName>TaxCalculation.Console</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<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' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<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.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TaxCalculation.Domain\TaxCalculation.Domain.csproj">
<Project>{690771c4-1c1d-425c-8ddb-5cfad55c3418}</Project>
<Name>TaxCalculation.Domain</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
13 changes: 13 additions & 0 deletions TaxCalculation.Console/bin/Debug/SalesData.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#Quantity,Product,Price,ItemType
Order 1
1,book,12.49,Exempt
1,music CD,14.99,Basic
1,chocolate bar,0.85,Exempt
Order 2
1,imported box of chocolates,10.00,Import
1,imported bottle of perfume,47.50,BasicImport
Order 3
1,imported bottle of perfume,27.99,BasicImport
1,bottle of perfume,18.99,Basic
1,packet of headache pills,9.75,Exempt
1,imported box of chocolates,11.25,Import
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
C:\Edwin\ThoughtWorks\TaxCalculator\TaxCalculation.Console\obj\Debug\TaxCalculation.Console.csprojResolveAssemblyReference.cache
C:\Edwin\ThoughtWorks\TaxCalculator\TaxCalculation.Console\bin\Debug\TaxCalculation.Console.exe.config
C:\Edwin\ThoughtWorks\TaxCalculator\TaxCalculation.Console\bin\Debug\TaxCalculation.Console.exe
C:\Edwin\ThoughtWorks\TaxCalculator\TaxCalculation.Console\bin\Debug\TaxCalculation.Console.pdb
C:\Edwin\ThoughtWorks\TaxCalculator\TaxCalculation.Console\bin\Debug\TaxCalculation.Domain.dll
C:\Edwin\ThoughtWorks\TaxCalculator\TaxCalculation.Console\bin\Debug\TaxCalculation.Domain.pdb
C:\Edwin\ThoughtWorks\TaxCalculator\TaxCalculation.Console\obj\Debug\TaxCalculation.Console.exe
C:\Edwin\ThoughtWorks\TaxCalculator\TaxCalculation.Console\obj\Debug\TaxCalculation.Console.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
C:\Edwin\ThoughtWorks\TaxCalculator\TaxCalculation.Console\bin\Debug\TaxCalculation.Console.exe.config
C:\Edwin\ThoughtWorks\TaxCalculator\TaxCalculation.Console\bin\Debug\TaxCalculation.Console.exe
C:\Edwin\ThoughtWorks\TaxCalculator\TaxCalculation.Console\bin\Debug\TaxCalculation.Console.pdb
C:\Edwin\ThoughtWorks\TaxCalculator\TaxCalculation.Console\bin\Debug\TaxCalculation.Domain.dll
C:\Edwin\ThoughtWorks\TaxCalculator\TaxCalculation.Console\bin\Debug\TaxCalculation.Domain.pdb
C:\Edwin\ThoughtWorks\TaxCalculator\TaxCalculation.Console\obj\Debug\TaxCalculation.Console.exe
C:\Edwin\ThoughtWorks\TaxCalculator\TaxCalculation.Console\obj\Debug\TaxCalculation.Console.pdb
C:\Edwin\ThoughtWorks\TaxCalculator\TaxCalculation.Console\obj\Debug\TaxCalculation.ConsoleApp.csprojResolveAssemblyReference.cache
Binary file not shown.
Empty file.
Empty file.
Empty file.
15 changes: 15 additions & 0 deletions TaxCalculation.Domain/Enums/ItemType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TaxCalculation.Domain.Enums
{
[Flags]
public enum ItemType
{
Exempt = 0,
Basic = 1,
Import = 2
}
}
44 changes: 44 additions & 0 deletions TaxCalculation.Domain/Factories/LineItemFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TaxCalculation.Domain.Enums;
using TaxCalculation.Domain.Interfaces;

namespace TaxCalculation.Domain.Factories
{
public static class LineItemFactory
{
private static readonly Rounding ROUNDING = new Rounding(0.05M);
private static readonly ITax BASICTAX = new Tax(0.1M, ROUNDING);
private static readonly ITax IMPORTTAX = new Tax(0.05M, ROUNDING);
private static readonly ITax EXEMPTTAX = new Tax(0.0M, ROUNDING);

private static readonly Dictionary<ItemType, ITax> itemTaxLookup = new Dictionary<ItemType, ITax>()
{
{ ItemType.Basic, BASICTAX },
{ ItemType.Import, IMPORTTAX },
{ ItemType.Exempt, EXEMPTTAX }
};

public static ILineItem GetLineItem(string name, decimal price, int quantity, ItemType itemType)
{
ILineItem item = new LineItem(name, price, quantity);

foreach (int flag in Enum.GetValues(typeof(ItemType)))
{
if ((flag & (int)itemType) == flag)
{
item = (ILineItem)Activator.CreateInstance(typeof(LineItemTaxDecorator), new object[] { item, itemTaxLookup[(ItemType)flag] });
}
}

return item;
}

public static ILineItem GetLineItem(string name, decimal price, int quantity)
{
return new LineItem(name, price, quantity);
}
}
}
16 changes: 16 additions & 0 deletions TaxCalculation.Domain/Interfaces/ILineItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TaxCalculation.Domain.Interfaces
{
public interface ILineItem
{
string Name { get; }
decimal GetPrice();
int GetQuantity();
decimal GetLineTax();
decimal GetTotal();
}
}
12 changes: 12 additions & 0 deletions TaxCalculation.Domain/Interfaces/IOrdersRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TaxCalculation.Domain.Interfaces
{
public interface IOrdersRepository
{
List<Order> ReadOrders(string textFilePath);
}
}
8 changes: 8 additions & 0 deletions TaxCalculation.Domain/Interfaces/IRounding.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;
namespace TaxCalculation.Domain.Interfaces
{
public interface IRounding
{
decimal Round(decimal valToRound);
}
}
14 changes: 14 additions & 0 deletions TaxCalculation.Domain/Interfaces/ITax.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TaxCalculation.Domain.Interfaces
{
public interface ITax
{
IRounding Rounding { get; }
decimal Rate { get; }
decimal CalculateTax(decimal itemPrice);
}
}
59 changes: 59 additions & 0 deletions TaxCalculation.Domain/LineItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TaxCalculation.Domain.Interfaces;

namespace TaxCalculation.Domain
{
public class LineItem : ILineItem
{
private string _name;
private decimal _price;
private int _quantity;

public LineItem(string name, decimal price, int quantity)
{
#region Parameter Checking
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException("name");
if(price < 0)
throw new ArgumentException("price");
#endregion

this._name = name;
this._price = price;
this._quantity = quantity;

}

#region ILineItem Members

public string Name
{
get { return this._name; }
}

public decimal GetPrice()
{
return this._price;
}

public int GetQuantity()
{
return this._quantity;
}

public decimal GetLineTax()
{
return 0.0M;
}

public decimal GetTotal()
{
return this.GetPrice() + this.GetLineTax();
}

#endregion
}
}
Loading

0 comments on commit 6e2d775

Please sign in to comment.