mirror of
https://github.com/ysoftdevs/Theatrical-Players-Refactoring-Kata.git
synced 2026-04-22 16:59:00 +02:00
add csharp version to the exercice
This commit is contained in:
5
csharp/.gitignore
vendored
Normal file
5
csharp/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
.DS_Store
|
||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
.vs/
|
||||||
|
.vscode/
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using ApprovalTests;
|
||||||
|
using ApprovalTests.Reporters;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace TheatricalPlayersRefactoringKata.Tests
|
||||||
|
{
|
||||||
|
public class StatementPrinterTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
[UseReporter(typeof(DiffReporter))]
|
||||||
|
public void test_statement_exemple()
|
||||||
|
{
|
||||||
|
var plays = new Dictionary<string, Play>();
|
||||||
|
plays.Add("hamlet", new Play("Hamlet", "tragedy"));
|
||||||
|
plays.Add("as-like", new Play("As You Like It", "comedy"));
|
||||||
|
plays.Add("othello", new Play("Othello", "tragedy"));
|
||||||
|
|
||||||
|
Invoice invoice = new Invoice("BigCo", new List<Performance>{new Performance("hamlet", 55),
|
||||||
|
new Performance("as-like", 35),
|
||||||
|
new Performance("othello", 40)});
|
||||||
|
|
||||||
|
StatementPrinter statementPrinter = new StatementPrinter();
|
||||||
|
var result = statementPrinter.Print(invoice, plays);
|
||||||
|
|
||||||
|
Approvals.Verify(result);
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void test_statement_with_new_play_types()
|
||||||
|
{
|
||||||
|
var plays = new Dictionary<string, Play>();
|
||||||
|
plays.Add("henry-v", new Play("Henry V", "history"));
|
||||||
|
plays.Add("as-like", new Play("As You Like It", "pastoral"));
|
||||||
|
|
||||||
|
Invoice invoice = new Invoice("BigCoII", new List<Performance>{new Performance("henry-v", 53),
|
||||||
|
new Performance("as-like", 55)});
|
||||||
|
|
||||||
|
StatementPrinter statementPrinter = new StatementPrinter();
|
||||||
|
|
||||||
|
Assert.Throws<Exception>(() => statementPrinter.Print(invoice, plays));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
Statement for BigCo
|
||||||
|
Hamlet: $650.00 (55 seats)
|
||||||
|
As You Like It: $580.00 (35 seats)
|
||||||
|
Othello: $500.00 (40 seats)
|
||||||
|
Amount owed is $1,730.00
|
||||||
|
You earned 47 credits
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="ApprovalTests" Version="4.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
|
||||||
|
<PackageReference Include="xunit" Version="2.4.0" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TheatricalPlayersRefactoringKata\TheatricalPlayersRefactoringKata.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
48
csharp/TheatricalPlayersRefactoringKata.sln
Normal file
48
csharp/TheatricalPlayersRefactoringKata.sln
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 15
|
||||||
|
VisualStudioVersion = 15.0.26124.0
|
||||||
|
MinimumVisualStudioVersion = 15.0.26124.0
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TheatricalPlayersRefactoringKata", "TheatricalPlayersRefactoringKata\TheatricalPlayersRefactoringKata.csproj", "{B380BB58-50A5-435D-9B52-5045A2F93761}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TheatricalPlayersRefactoringKata.Tests", "TheatricalPlayersRefactoringKata.Tests\TheatricalPlayersRefactoringKata.Tests.csproj", "{47FAD5CE-0FB3-4C9F-A430-68E58A1B094F}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{B380BB58-50A5-435D-9B52-5045A2F93761}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B380BB58-50A5-435D-9B52-5045A2F93761}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B380BB58-50A5-435D-9B52-5045A2F93761}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{B380BB58-50A5-435D-9B52-5045A2F93761}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{B380BB58-50A5-435D-9B52-5045A2F93761}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{B380BB58-50A5-435D-9B52-5045A2F93761}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{B380BB58-50A5-435D-9B52-5045A2F93761}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B380BB58-50A5-435D-9B52-5045A2F93761}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{B380BB58-50A5-435D-9B52-5045A2F93761}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{B380BB58-50A5-435D-9B52-5045A2F93761}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{B380BB58-50A5-435D-9B52-5045A2F93761}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{B380BB58-50A5-435D-9B52-5045A2F93761}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{47FAD5CE-0FB3-4C9F-A430-68E58A1B094F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{47FAD5CE-0FB3-4C9F-A430-68E58A1B094F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{47FAD5CE-0FB3-4C9F-A430-68E58A1B094F}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{47FAD5CE-0FB3-4C9F-A430-68E58A1B094F}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{47FAD5CE-0FB3-4C9F-A430-68E58A1B094F}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{47FAD5CE-0FB3-4C9F-A430-68E58A1B094F}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{47FAD5CE-0FB3-4C9F-A430-68E58A1B094F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{47FAD5CE-0FB3-4C9F-A430-68E58A1B094F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{47FAD5CE-0FB3-4C9F-A430-68E58A1B094F}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{47FAD5CE-0FB3-4C9F-A430-68E58A1B094F}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{47FAD5CE-0FB3-4C9F-A430-68E58A1B094F}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{47FAD5CE-0FB3-4C9F-A430-68E58A1B094F}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
20
csharp/TheatricalPlayersRefactoringKata/Invoice.cs
Normal file
20
csharp/TheatricalPlayersRefactoringKata/Invoice.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace TheatricalPlayersRefactoringKata
|
||||||
|
{
|
||||||
|
public class Invoice
|
||||||
|
{
|
||||||
|
private string _customer;
|
||||||
|
private List<Performance> _performances;
|
||||||
|
|
||||||
|
public string Customer { get => _customer; set => _customer = value; }
|
||||||
|
public List<Performance> Performances { get => _performances; set => _performances = value; }
|
||||||
|
|
||||||
|
public Invoice(string customer, List<Performance> performance)
|
||||||
|
{
|
||||||
|
this._customer = customer;
|
||||||
|
this._performances = performance;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
18
csharp/TheatricalPlayersRefactoringKata/Performance.cs
Normal file
18
csharp/TheatricalPlayersRefactoringKata/Performance.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace TheatricalPlayersRefactoringKata
|
||||||
|
{
|
||||||
|
public class Performance
|
||||||
|
{
|
||||||
|
private string _playID;
|
||||||
|
private int _audience;
|
||||||
|
|
||||||
|
public string PlayID { get => _playID; set => _playID = value; }
|
||||||
|
public int Audience { get => _audience; set => _audience = value; }
|
||||||
|
|
||||||
|
public Performance(string playID, int audience)
|
||||||
|
{
|
||||||
|
this._playID = playID;
|
||||||
|
this._audience = audience;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
16
csharp/TheatricalPlayersRefactoringKata/Play.cs
Normal file
16
csharp/TheatricalPlayersRefactoringKata/Play.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
namespace TheatricalPlayersRefactoringKata
|
||||||
|
{
|
||||||
|
public class Play
|
||||||
|
{
|
||||||
|
private string _name;
|
||||||
|
private string _type;
|
||||||
|
|
||||||
|
public string Name { get => _name; set => _name = value; }
|
||||||
|
public string Type { get => _type; set => _type = value; }
|
||||||
|
|
||||||
|
public Play(string name, string type) {
|
||||||
|
this._name = name;
|
||||||
|
this._type = type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
52
csharp/TheatricalPlayersRefactoringKata/StatementPrinter.cs
Normal file
52
csharp/TheatricalPlayersRefactoringKata/StatementPrinter.cs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace TheatricalPlayersRefactoringKata
|
||||||
|
{
|
||||||
|
public class StatementPrinter
|
||||||
|
{
|
||||||
|
public string Print(Invoice invoice, Dictionary<string, Play> plays)
|
||||||
|
{
|
||||||
|
var totalAmount = 0;
|
||||||
|
var volumeCredits = 0;
|
||||||
|
var result = string.Format("Statement for {0}\n", invoice.Customer);
|
||||||
|
CultureInfo cultureInfo = new CultureInfo("en-US");
|
||||||
|
|
||||||
|
foreach(var perf in invoice.Performances)
|
||||||
|
{
|
||||||
|
var play = plays[perf.PlayID];
|
||||||
|
var thisAmount = 0;
|
||||||
|
switch (play.Type)
|
||||||
|
{
|
||||||
|
case "tragedy":
|
||||||
|
thisAmount = 40000;
|
||||||
|
if (perf.Audience > 30) {
|
||||||
|
thisAmount += 1000 * (perf.Audience - 30);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "comedy":
|
||||||
|
thisAmount = 30000;
|
||||||
|
if (perf.Audience > 20) {
|
||||||
|
thisAmount += 10000 + 500 * (perf.Audience - 20);
|
||||||
|
}
|
||||||
|
thisAmount += 300 * perf.Audience;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Exception("unknown type: " + play.Type);
|
||||||
|
}
|
||||||
|
// add volume credits
|
||||||
|
volumeCredits += Math.Max(perf.Audience - 30, 0);
|
||||||
|
// add extra credit for every ten comedy attendees
|
||||||
|
if ("comedy" == play.Type) volumeCredits += (int)Math.Floor((decimal)perf.Audience / 5);
|
||||||
|
|
||||||
|
// print line for this order
|
||||||
|
result += String.Format(cultureInfo, " {0}: {1:C} ({2} seats)\n", play.Name, Convert.ToDecimal(thisAmount / 100), perf.Audience);
|
||||||
|
totalAmount += thisAmount;
|
||||||
|
}
|
||||||
|
result += String.Format(cultureInfo, "Amount owed is {0:C}\n", Convert.ToDecimal(totalAmount / 100));
|
||||||
|
result += String.Format("You earned {0} credits\n", volumeCredits);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
Reference in New Issue
Block a user