-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reorganização e refatoração do código, inclusão de peças históricas e…
… correção nos testes
- Loading branch information
Showing
18 changed files
with
445 additions
and
146 deletions.
There are no files selected for viewing
183 changes: 131 additions & 52 deletions
183
TheatricalPlayersRefactoringKata.Tests/StatementPrinterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,145 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using ApprovalTests; | ||
using ApprovalTests.Reporters; | ||
using Moq; | ||
using Xunit; | ||
using TheatricalPlayersRefactoringKata.Services; | ||
using TheatricalPlayersRefactoringKata.Models; | ||
using TheatricalPlayersRefactoringKata.Services.Formatters; | ||
using TheatricalPlayersRefactoringKata.Services.PlayType; | ||
|
||
namespace TheatricalPlayersRefactoringKata.Tests; | ||
|
||
public class StatementPrinterTests | ||
namespace TheatricalPlayersRefactoringKata.Tests | ||
{ | ||
[Fact] | ||
[UseReporter(typeof(DiffReporter))] | ||
public void TestStatementExampleLegacy() | ||
public class StatementPrinterTests | ||
{ | ||
var plays = new Dictionary<string, Play>(); | ||
plays.Add("hamlet", new Play("Hamlet", 4024, "tragedy")); | ||
plays.Add("as-like", new Play("As You Like It", 2670, "comedy")); | ||
plays.Add("othello", new Play("Othello", 3560, "tragedy")); | ||
|
||
Invoice invoice = new Invoice( | ||
"BigCo", | ||
new List<Performance> | ||
[Fact] | ||
[UseReporter(typeof(DiffReporter))] | ||
public void TestStatementExampleLegacy() | ||
{ | ||
var plays = new Dictionary<string, Play> | ||
{ | ||
new Performance("hamlet", 55), | ||
new Performance("as-like", 35), | ||
new Performance("othello", 40), | ||
} | ||
); | ||
{ "hamlet", new Play("Hamlet", 4024, "tragedy") }, | ||
{ "as-like", new Play("As You Like It", 2670, "comedy") }, | ||
{ "othello", new Play("Othello", 3560, "tragedy") } | ||
}; | ||
|
||
StatementPrinter statementPrinter = new StatementPrinter(); | ||
var result = statementPrinter.Print(invoice, plays); | ||
Invoice invoice = new Invoice( | ||
"BigCo", | ||
new List<Performance> | ||
{ | ||
new Performance("hamlet", 55), | ||
new Performance("as-like", 35), | ||
new Performance("othello", 40) | ||
} | ||
); | ||
|
||
Approvals.Verify(result); | ||
} | ||
StatementPrinter statementPrinter = new StatementPrinter(); | ||
var result = statementPrinter.Print(invoice, plays); | ||
|
||
[Fact] | ||
[UseReporter(typeof(DiffReporter))] | ||
public void TestTextStatementExample() | ||
{ | ||
var plays = new Dictionary<string, Play>(); | ||
plays.Add("hamlet", new Play("Hamlet", 4024, "tragedy")); | ||
plays.Add("as-like", new Play("As You Like It", 2670, "comedy")); | ||
plays.Add("othello", new Play("Othello", 3560, "tragedy")); | ||
plays.Add("henry-v", new Play("Henry V", 3227, "history")); | ||
plays.Add("john", new Play("King John", 2648, "history")); | ||
plays.Add("richard-iii", new Play("Richard III", 3718, "history")); | ||
|
||
Invoice invoice = new Invoice( | ||
"BigCo", | ||
new List<Performance> | ||
Approvals.Verify(result); | ||
} | ||
|
||
[Fact] | ||
[UseReporter(typeof(DiffReporter))] | ||
public void TestTextStatementExample() | ||
{ | ||
var plays = new Dictionary<string, Play> | ||
{ | ||
{ "hamlet", new Play("Hamlet", 4024, "tragedy") }, | ||
{ "as-like", new Play("As You Like It", 2670, "comedy") }, | ||
{ "othello", new Play("Othello", 3560, "tragedy") }, | ||
{ "henry-v", new Play("Henry V", 3227, "history") }, | ||
{ "john", new Play("King John", 2648, "history") }, | ||
{ "richard-iii", new Play("Richard III", 3718, "history") } | ||
}; | ||
|
||
Invoice invoice = new Invoice( | ||
"BigCo", | ||
new List<Performance> | ||
{ | ||
new Performance("hamlet", 55), | ||
new Performance("as-like", 35), | ||
new Performance("othello", 40), | ||
new Performance("henry-v", 20), | ||
new Performance("john", 39), | ||
new Performance("henry-v", 20), | ||
} | ||
); | ||
|
||
StatementPrinter statementPrinter = new StatementPrinter(); | ||
var result = statementPrinter.Print(invoice, plays); | ||
|
||
Approvals.Verify(result); | ||
} | ||
|
||
[Fact] | ||
[UseReporter(typeof(DiffReporter))] | ||
public void TestXmlStatementExample() | ||
{ | ||
var plays = new Dictionary<string, Play> | ||
{ | ||
{ "hamlet", new Play("Hamlet", 4024, "tragedy") }, | ||
{ "as-like", new Play("As You Like It", 2670, "comedy") }, | ||
{ "othello", new Play("Othello", 3560, "tragedy") }, | ||
{ "henry-v", new Play("Henry V", 3227, "history") }, | ||
{ "john", new Play("King John", 2648, "history") }, | ||
{ "richard-iii", new Play("Richard III", 3718, "history") } | ||
}; | ||
|
||
Invoice invoice = new Invoice( | ||
"BigCo", | ||
new List<Performance> | ||
{ | ||
new Performance("hamlet", 55), | ||
new Performance("as-like", 35), | ||
new Performance("othello", 40), | ||
new Performance("henry-v", 20), | ||
new Performance("john", 39), | ||
new Performance("henry-v", 20), | ||
} | ||
); | ||
|
||
StatementPrinter statementPrinter = new StatementPrinter(); | ||
var result = statementPrinter.PrintXml(invoice, plays); | ||
|
||
Approvals.Verify(result); | ||
} | ||
|
||
[Fact] | ||
public void TestGenerateStatement() | ||
{ | ||
var plays = new Dictionary<string, Play> | ||
{ | ||
new Performance("hamlet", 55), | ||
new Performance("as-like", 35), | ||
new Performance("othello", 40), | ||
new Performance("henry-v", 20), | ||
new Performance("john", 39), | ||
new Performance("henry-v", 20) | ||
} | ||
); | ||
|
||
StatementPrinter statementPrinter = new StatementPrinter(); | ||
var result = statementPrinter.Print(invoice, plays); | ||
|
||
Approvals.Verify(result); | ||
{ "hamlet", new Play("Hamlet", 4024, "tragedy") } | ||
}; | ||
|
||
var invoice = new Invoice( | ||
"BigCo", | ||
new List<Performance> | ||
{ | ||
new Performance("hamlet", 30) | ||
} | ||
); | ||
|
||
var statementPrinter = new StatementPrinter(); | ||
var statement = statementPrinter.GenerateStatement(invoice, plays); | ||
|
||
Assert.NotNull(statement); | ||
Assert.Single(statement.Items); | ||
Assert.Equal(30, statement.Items[0].Seats); | ||
Assert.Equal("Hamlet", statement.Items[0].PlayName); | ||
} | ||
|
||
[Fact] | ||
public void TestFormatterLogic() | ||
{ | ||
var formatterMock = new Mock<IStatementFormatter>(); | ||
formatterMock.Setup(x => x.Format(It.IsAny<Statement>())).Returns("Mock result"); | ||
|
||
var statement = new Statement { Customer = "BigCo" }; | ||
var result = formatterMock.Object.Format(statement); | ||
|
||
Assert.Equal("Mock result", result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace TheatricalPlayersRefactoringKata; | ||
|
||
public class Invoice | ||
{ | ||
public string Customer { get; set; } | ||
public List<Performance> Performances { get; set; } | ||
|
||
public Invoice(string customer, List<Performance> performances) | ||
{ | ||
Customer = customer; | ||
Performances = performances; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace TheatricalPlayersRefactoringKata; | ||
|
||
public class Performance | ||
{ | ||
public string PlayId { get; set; } | ||
public int Audience { get; set; } | ||
|
||
public Performance(string playId, int audience) | ||
{ | ||
PlayId = playId; | ||
Audience = audience; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace TheatricalPlayersRefactoringKata; | ||
|
||
public class Play | ||
{ | ||
public string Name { get; set; } | ||
public int Lines { get; set; } | ||
public string Type { get; set; } | ||
|
||
public Play(string name, int lines, string type) | ||
{ | ||
Name = name; | ||
Lines = lines; | ||
Type = type; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace TheatricalPlayersRefactoringKata.Models; | ||
|
||
public class Statement | ||
{ | ||
public string Customer { get; set; } | ||
public List<StatementItem> Items { get; set; } = new(); | ||
public decimal TotalAmount { get; set; } | ||
public int TotalCredits { get; set; } | ||
} | ||
|
||
public class StatementItem | ||
{ | ||
public string PlayName { get; set; } | ||
public decimal AmountOwed { get; set; } | ||
public int EarnedCredits { get; set; } | ||
public int Seats { get; set; } | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
TheatricalPlayersRefactoringKata/Services/Formatters/IStatementFormatter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using TheatricalPlayersRefactoringKata.Models; | ||
|
||
namespace TheatricalPlayersRefactoringKata.Services.Formatters; | ||
|
||
public interface IStatementFormatter | ||
{ | ||
string Format(Statement statement); | ||
} |
23 changes: 23 additions & 0 deletions
23
TheatricalPlayersRefactoringKata/Services/Formatters/TextStatementFormatter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Globalization; | ||
using TheatricalPlayersRefactoringKata.Models; | ||
|
||
namespace TheatricalPlayersRefactoringKata.Services.Formatters; | ||
|
||
public class TextStatementFormatter : IStatementFormatter | ||
{ | ||
public string Format(Statement statement) | ||
{ | ||
var cultureInfo = new CultureInfo("en-US"); | ||
var result = $"Statement for {statement.Customer}\n"; | ||
|
||
foreach (var item in statement.Items) | ||
{ | ||
result += $" {item.PlayName}: {item.AmountOwed.ToString("C", cultureInfo)} ({item.Seats} seats)\n"; | ||
} | ||
|
||
result += $"Amount owed is {statement.TotalAmount.ToString("C", cultureInfo)}\n"; | ||
result += $"You earned {statement.TotalCredits} credits\n"; | ||
|
||
return result; | ||
} | ||
} |
Oops, something went wrong.