Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added PurchaseTicketCommand and tests.
- Loading branch information
1 parent
3a1d929
commit 412d381
Showing
13 changed files
with
168 additions
and
10 deletions.
There are no files selected for viewing
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,6 +1,6 @@ | ||
ShowPlanner | ||
=========== | ||
|
||
A Demo Architecture Project | ||
## A Demo Architecture Project | ||
|
||
ShowPlanner.Api is the public facing Api (currently not implemented because no site-level contracts have been created). |
77 changes: 77 additions & 0 deletions
77
ShowPlanner.Commands.Unit.Tests/PurchaseTicketCommandTests.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,77 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using FizzWare.NBuilder; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
using ShowPlanner.Commands.Tickets; | ||
using ShowPlanner.Data; | ||
using ShowPlanner.Data.Models; | ||
|
||
namespace ShowPlanner.Commands.Unit.Tests | ||
{ | ||
[TestFixture] | ||
public class PurchaseTicketCommandTests | ||
{ | ||
[TestFixtureSetUp] | ||
public void BeforeAnyTestRuns() | ||
{ | ||
} | ||
|
||
[SetUp] | ||
public void BeforeEachTestRuns() | ||
{ | ||
this.Database = Substitute.For<IDatabase>(); | ||
this.Repository = Substitute.For<IRepository>(); | ||
this.Database.NewRepository().Returns(this.Repository); | ||
this.Command = new PurchaseTicketCommand(this.Database); | ||
} | ||
|
||
protected IRepository Repository { get; set; } | ||
|
||
protected PurchaseTicketCommand Command { get; set; } | ||
|
||
protected IDatabase Database { get; set; } | ||
|
||
[Test] | ||
public void Execute() | ||
{ | ||
// Arrange | ||
var customer = Builder<Customer> | ||
.CreateNew() | ||
.Build() | ||
; | ||
|
||
var ticket = Builder<Ticket> | ||
.CreateNew() | ||
.Do(row=> | ||
{ | ||
row.SoldTo = null; | ||
row.Sold = false; | ||
}) | ||
.Build() | ||
; | ||
|
||
this.Repository.Get<Customer>(customer.CustomerId.Value).Returns(customer); | ||
this.Repository.Get<Ticket>(ticket.TicketId.Value).Returns(ticket); | ||
|
||
var request = new PurchaseTicketRequest() | ||
{ | ||
CustomerId = customer.CustomerId.Value, | ||
TicketId = ticket.TicketId.Value | ||
}; | ||
|
||
// Act | ||
var response = this.Command.Execute(request); | ||
|
||
// Assert | ||
Assert.That(response.Success, Is.True); | ||
|
||
Assert.That(ticket.SoldTo, Is.SameAs(customer)); | ||
Assert.That(ticket.Sold, Is.True); | ||
|
||
this.Repository.Received().Commit(); | ||
} | ||
} | ||
} |
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 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 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,56 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using ShowPlanner.Data; | ||
using ShowPlanner.Data.Models; | ||
|
||
namespace ShowPlanner.Commands.Tickets | ||
{ | ||
|
||
public class PurchaseTicketRequest | ||
{ | ||
public int TicketId { get; set; } | ||
|
||
public int CustomerId { get; set; } | ||
} | ||
|
||
public class PurchaseTicketResponse | ||
{ | ||
public bool Success { get; set; } | ||
} | ||
|
||
public class PurchaseTicketCommand: ICommand<PurchaseTicketRequest, PurchaseTicketResponse> | ||
{ | ||
private readonly IDatabase _database; | ||
|
||
public PurchaseTicketCommand(IDatabase database) | ||
{ | ||
_database = database; | ||
} | ||
|
||
public PurchaseTicketResponse Execute(PurchaseTicketRequest request) | ||
{ | ||
using (var repository = _database.NewRepository()) | ||
{ | ||
var ticket = repository.Get<Ticket>(request.TicketId); | ||
var customer = repository.Get<Customer>(request.CustomerId); | ||
ticket.SoldTo = customer; | ||
ticket.Sold = true; | ||
repository.Commit(); | ||
|
||
return new PurchaseTicketResponse() | ||
{ | ||
Success = true, | ||
}; | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
} | ||
|
||
|
||
} |
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,13 +1,15 @@ | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace ShowPlanner.Data.Models | ||
{ | ||
public class Customer | ||
{ | ||
public int? CustomerId { get; set; } | ||
|
||
public string Name { get; set; } | ||
public IList<Ticket> Tickets { get; set; } | ||
|
||
public IList<Ticket> Tickets { get; set; } | ||
[Required] | ||
public string Name { get; set; } | ||
} | ||
} |
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 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,12 +1,16 @@ | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace ShowPlanner.Data.Models | ||
{ | ||
public class Performer | ||
{ | ||
public int? PerformerId { get; set; } | ||
public string Name { get; set; } | ||
|
||
public IList<Performance> Performances { get; set; } | ||
|
||
[Required] | ||
public string Name { get; set; } | ||
|
||
} | ||
} |
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,13 +1,15 @@ | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace ShowPlanner.Data.Models | ||
{ | ||
public class Show | ||
{ | ||
public int? ShowId { get; set; } | ||
|
||
public string Title { get; set; } | ||
|
||
public IList<Ticket> Tickets { get; set; } | ||
|
||
[Required] | ||
public string Title { get; set; } | ||
} | ||
} |
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 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,15 +1,19 @@ | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace ShowPlanner.Data.Models | ||
{ | ||
public class Stage | ||
{ | ||
public int? StageId { get; set; } | ||
public string Name { get; set; } | ||
|
||
public int? VenueId { get; set; } | ||
[Required] | ||
public Venue Venue { get; set; } | ||
|
||
public IList<Performance> Showings { get; set; } | ||
public IList<Performance> Showings { get; set; } | ||
|
||
[Required] | ||
public string Name { get; set; } | ||
} | ||
} |
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,18 +1,21 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace ShowPlanner.Data.Models | ||
{ | ||
public class Ticket | ||
{ | ||
public int? TicketId { get; set; } | ||
|
||
public int? ShowId { get; set; } | ||
[Required] | ||
public Show Show { get; set; } | ||
|
||
public int? CustomerId { get; set; } | ||
public Customer SoldTo { get; set; } | ||
|
||
public bool? Sold { get; set; } | ||
|
||
[Required] | ||
public decimal Price { get; set; } | ||
|
||
} | ||
} |
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