Add project files.

This commit is contained in:
2019-11-18 16:59:38 +01:00
parent 5ec0c4fa3e
commit eef116b5f6
22 changed files with 841 additions and 0 deletions

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.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>{07F455FF-CE11-40F2-A66E-95FA497522FB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BrokerageLib</RootNamespace>
<AssemblyName>BrokerageLib</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</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="CommissionConstants.cs" />
<Compile Include="CommissionCalculator.cs" />
<Compile Include="PaymentDate.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Content Include="Scenarios\CommisionCalcScenario.txt" />
<Content Include="Scenarios\PaymentDateScenario.txt" />
</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>

View File

@ -0,0 +1,35 @@
using System;
namespace BrokerageLib {
public class CommissionCalculator {
public decimal DetermineVariableRate(int unitsSold, decimal unitPrice) {
// Sales representative gets top commission rate
// if they sell over the sales threshold amount
// or if they sell more than the max unit threshold
if (unitsSold < 0)
{
throw new ArgumentOutOfRangeException("UnitsSold cannot be less than zero.");
}
if (unitPrice < 0)
{
throw new ArgumentOutOfRangeException("unitPrice cannot be less than zero.");
}
decimal grossSale = unitsSold * unitPrice;
if (grossSale > Constants.CommissionThreshold.SalesAmount || unitsSold > Constants.CommissionThreshold.UnitAmount)
{
return grossSale * Constants.CommissionRate.Top;
}
else
{
return grossSale * Constants.CommissionRate.Standard;
}
}
}
}

View File

@ -0,0 +1,21 @@
namespace BrokerageLib {
public class Constants {
public class CommissionRate {
public const decimal Standard = 0.08m;
public const decimal Earner = 0.11m;
public const decimal Top = 0.14m;
}
public class Discount {
public const decimal PreferredCustomer = 0.2m;
public const decimal BulkOrder = 0.5m;
}
public class CommissionThreshold {
public const decimal SalesAmount = 12000m;
public const decimal UnitAmount = 400m;
}
}
}

View File

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BrokerageLib.PaymentSystem {
public class PaymentDate {
/// <summary>
/// Calculates a payment date 30 days in the future
/// from the provided date.
/// If the payment date is on a weekend,
/// then move it to the first work day after the
/// proposed date
/// </summary>
/// <param name="startingDate">the date to use as starting date.</param>
/// <returns></returns>
public DateTime CalculateFuturePaymentDate(DateTime startingDate) {
var tempDate = startingDate.AddDays(30);
switch (tempDate.DayOfWeek)
{
case DayOfWeek.Saturday:
tempDate = tempDate.AddDays(2);
break;
case DayOfWeek.Sunday:
tempDate = tempDate.AddDays(1); // Error in our code here!
break;
}
return tempDate;
}
}
}

View File

@ -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("BrokerageLib")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BrokerageLib")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[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("07f455ff-ce11-40f2-a66e-95fa497522fb")]
// 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")]

View File

@ -0,0 +1 @@


View File

@ -0,0 +1,10 @@
[ The Given-When-Then pattern ]
To calculate the next payment date for our customer bills
Given a valid start date
When the future calculated payment date falls on a weekday
Then use the calculated date
Given a valid start date
When the future calculated payment date falls on a weekend
Then use the first Monday after calculated date