-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from marcus-talbot42/fixes/functionality-and-s…
…hizzles Fixes/functionality and shizzles
- Loading branch information
Showing
9 changed files
with
559 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageReference Include="Moq" Version="4.20.70" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ProjectB\ProjectB.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" /> | ||
</ItemGroup> | ||
|
||
</Project> |
172 changes: 172 additions & 0 deletions
172
ProjectB.Tests/Workflows/GuestFlows/CreateReservationFlowTests.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,172 @@ | ||
using Moq; | ||
using ProjectB.Database; | ||
using ProjectB.Models; | ||
using ProjectB.Services; | ||
using ProjectB.Workflows.GuestFlows; | ||
|
||
namespace ProjectBTest.Workflows.GuestFlows | ||
{ | ||
[TestClass] | ||
public class CreateReservationFlowTests | ||
{ | ||
private Mock<IDatabaseContext> _contextMock; | ||
private Mock<ITourService> _tourServiceMock; | ||
private CreateReservationFlow _createReservationFlow; | ||
|
||
[TestInitialize] | ||
public void TestInitialize() | ||
{ | ||
_contextMock = new Mock<IDatabaseContext>(); | ||
_tourServiceMock = new Mock<ITourService>(); | ||
|
||
_createReservationFlow = new CreateReservationFlow( | ||
_contextMock.Object, | ||
_tourServiceMock.Object); | ||
} | ||
|
||
[TestMethod] | ||
public void HappyFlow() | ||
{ | ||
// Arrange | ||
Guest guest = new Guest() { TicketNumber = "13548424" }; | ||
Tour tour = new Tour(DateTime.Now.AddHours(1)) { Capacity = 13, Departed = false, Participants = new() }; | ||
|
||
// Set up mocks for dependencies | ||
_tourServiceMock.Setup(x => x.GetTourForGuest(guest)) | ||
.Returns((Tour?)null); | ||
|
||
_tourServiceMock.Setup(x => x.RegisterGuestForTour(guest, tour)) | ||
.Returns(true); | ||
|
||
// Act | ||
var setGuestResult = _createReservationFlow.SetGuest(guest); | ||
var setTourResult = _createReservationFlow.SetTour(tour); | ||
var commitResult = _createReservationFlow.Commit(); | ||
|
||
// Assert | ||
Assert.IsTrue(setGuestResult.Success); | ||
Assert.IsTrue(setTourResult.Success); | ||
Assert.IsTrue(commitResult.Success); | ||
} | ||
|
||
[TestMethod] | ||
public void SetGuest_GuestIsNull() | ||
{ | ||
// Act | ||
var setGuestResult = _createReservationFlow.SetGuest(null); | ||
|
||
// Assert | ||
Assert.IsFalse(setGuestResult.Success); | ||
Assert.AreEqual("guestIsNull", setGuestResult.MessageKey); | ||
} | ||
|
||
[TestMethod] | ||
public void SetGuest_AlreadyHasReservation() | ||
{ | ||
// Arrange | ||
Guest guest = new Guest() { TicketNumber = "13548424" }; | ||
Tour tour = new Tour(DateTime.Now.AddHours(1)) { Capacity = 13, Departed = false, Participants = new() { "13548424" } }; | ||
|
||
// Set up mocks for dependencies | ||
_tourServiceMock.Setup(x => x.GetTourForGuest(guest)) | ||
.Returns(tour); | ||
|
||
// Act | ||
var setGuestResult = _createReservationFlow.SetGuest(guest); | ||
|
||
// Assert | ||
Assert.IsFalse(setGuestResult.Success); | ||
Assert.AreEqual("alreadyHasReservation", setGuestResult.MessageKey); | ||
} | ||
|
||
[TestMethod] | ||
public void SetTour_TourIsNull() | ||
{ | ||
// Act | ||
var setTourResult = _createReservationFlow.SetTour(null); | ||
|
||
// Assert | ||
Assert.IsFalse(setTourResult.Success); | ||
Assert.AreEqual("tourIsNull", setTourResult.MessageKey); | ||
} | ||
|
||
[TestMethod] | ||
public void SetTour_TourFull() | ||
{ | ||
// Arrange | ||
Tour tour = new Tour(DateTime.Now.AddHours(1)) | ||
{ | ||
Capacity = 13, | ||
Departed = false, | ||
Participants = new() { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" } | ||
}; | ||
|
||
// Act | ||
var setTourResult = _createReservationFlow.SetTour(tour); | ||
|
||
// Assert | ||
Assert.IsFalse(setTourResult.Success); | ||
Assert.AreEqual("tourFull", setTourResult.MessageKey); | ||
} | ||
|
||
[TestMethod] | ||
public void SetTour_TourInPast() | ||
{ | ||
// Arrange | ||
Tour tour = new Tour(DateTime.Now.AddHours(-1)) { Capacity = 13, Departed = false, Participants = new() }; | ||
|
||
// Act | ||
var setTourResult = _createReservationFlow.SetTour(tour); | ||
|
||
// Assert | ||
Assert.IsFalse(setTourResult.Success); | ||
Assert.AreEqual("tourInPast", setTourResult.MessageKey); | ||
} | ||
|
||
[TestMethod] | ||
public void SetTour_TourDeparted() | ||
{ | ||
// Arrange | ||
Tour tour = new Tour(DateTime.Now.AddHours(1)) { Capacity = 13, Departed = true, Participants = new() }; | ||
|
||
// Act | ||
var setTourResult = _createReservationFlow.SetTour(tour); | ||
|
||
// Assert | ||
Assert.IsFalse(setTourResult.Success); | ||
Assert.AreEqual("tourDeparted", setTourResult.MessageKey); | ||
} | ||
|
||
[TestMethod] | ||
public void Commit_GuestIsNull() | ||
{ | ||
// Arrange | ||
Tour tour = new Tour(DateTime.Now.AddHours(1)) { Capacity = 13, Departed = false, Participants = new() }; | ||
|
||
// Act | ||
var setTourResult = _createReservationFlow.SetTour(tour); | ||
var commitResult = _createReservationFlow.Commit(); | ||
|
||
// Assert | ||
Assert.IsTrue(setTourResult.Success); | ||
Assert.IsFalse(commitResult.Success); | ||
Assert.AreEqual("guestIsNull", commitResult.MessageKey); | ||
} | ||
|
||
[TestMethod] | ||
public void Commit_TourIsNull() | ||
{ | ||
// Arrange | ||
Guest guest = new Guest() { TicketNumber = "13548424" }; | ||
|
||
// Act | ||
var setGuestResult = _createReservationFlow.SetGuest(guest); | ||
var commitResult = _createReservationFlow.Commit(); | ||
|
||
// Assert | ||
Assert.IsTrue(setGuestResult.Success); | ||
Assert.IsFalse(commitResult.Success); | ||
Assert.AreEqual("tourIsNull", commitResult.MessageKey); | ||
} | ||
} | ||
} |
131 changes: 131 additions & 0 deletions
131
ProjectB.Tests/Workflows/GuestFlows/DeleteReservationFlowTests.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,131 @@ | ||
using Moq; | ||
using ProjectB.Database; | ||
using ProjectB.Models; | ||
using ProjectB.Services; | ||
using ProjectB.Workflows.GuestFlows; | ||
|
||
namespace ProjectBTest.Workflows | ||
{ | ||
[TestClass] | ||
public class DeleteReservationFlowTests | ||
{ | ||
private Mock<IDatabaseContext> _contextMock; | ||
private Mock<ITourService> _tourServiceMock; | ||
private DeleteReservationFlow _deleteReservationFlow; | ||
|
||
[TestInitialize] | ||
public void TestInitialize() | ||
{ | ||
_contextMock = new Mock<IDatabaseContext>(); | ||
_tourServiceMock = new Mock<ITourService>(); | ||
|
||
_deleteReservationFlow = new DeleteReservationFlow( | ||
_contextMock.Object, | ||
_tourServiceMock.Object); | ||
} | ||
|
||
[TestMethod] | ||
public void HappyFlow() | ||
{ | ||
// Arrange | ||
Guest guest = new Guest() { TicketNumber = "13548424" }; | ||
Tour tour = new Tour(DateTime.Now.AddHours(1)) { Capacity = 13, Departed = false, Participants = new() { guest.TicketNumber } }; | ||
|
||
// Set up mocks for dependencies | ||
_tourServiceMock.Setup(x => x.DeleteReservationGuest(guest)) | ||
.Returns(true); | ||
|
||
_tourServiceMock.Setup(x => x.GetTourForGuest(guest)) | ||
.Returns(tour); | ||
|
||
// Act | ||
var setGuest = _deleteReservationFlow.SetGuest(guest); | ||
var commit = _deleteReservationFlow.Commit(); | ||
|
||
// Assert | ||
Assert.IsTrue(setGuest.Success); | ||
Assert.IsTrue(commit.Success); | ||
} | ||
|
||
[TestMethod] | ||
public void SetGuest_GuestIsNull() | ||
{ | ||
// Arrange | ||
Guest? guest = null; | ||
|
||
// Act | ||
var setGuest = _deleteReservationFlow.SetGuest(guest); | ||
|
||
// Assert | ||
Assert.IsFalse(setGuest.Success); | ||
Assert.AreEqual("guestIsNull", setGuest.MessageKey); | ||
} | ||
|
||
[TestMethod] | ||
public void SetGuest_NoReservationFound() | ||
{ | ||
// Arrange | ||
Guest guest = new Guest() { TicketNumber = "13548424" }; | ||
|
||
// Set up mocks for dependencies | ||
_tourServiceMock.Setup(x => x.GetTourForGuest(guest)) | ||
.Returns((Tour?)null); | ||
|
||
// Act | ||
var setGuest = _deleteReservationFlow.SetGuest(guest); | ||
|
||
// Assert | ||
Assert.IsFalse(setGuest.Success); | ||
Assert.AreEqual("noReservationFound", setGuest.MessageKey); | ||
} | ||
|
||
[TestMethod] | ||
public void SetGuest_TourDeparted() | ||
{ | ||
// Arrange | ||
Guest guest = new Guest() { TicketNumber = "13548424" }; | ||
Tour tour = new Tour(DateTime.Now.AddHours(1)) { Capacity = 13, Departed = true, Participants = new() { guest.TicketNumber } }; | ||
|
||
// Set up mocks for dependencies | ||
_tourServiceMock.Setup(x => x.GetTourForGuest(guest)) | ||
.Returns(tour); | ||
|
||
// Act | ||
var setGuest = _deleteReservationFlow.SetGuest(guest); | ||
|
||
// Assert | ||
Assert.IsFalse(setGuest.Success); | ||
Assert.AreEqual("tourDeparted", setGuest.MessageKey); | ||
} | ||
|
||
[TestMethod] | ||
public void Commit_GuestIsNull() | ||
{ | ||
// Act | ||
var commit = _deleteReservationFlow.Commit(); | ||
|
||
// Assert | ||
Assert.IsFalse(commit.Success); | ||
Assert.AreEqual("guestIsNull", commit.MessageKey); | ||
} | ||
|
||
[TestMethod] | ||
public void Commit_TourIsNull() | ||
{ | ||
// Arrange | ||
Guest guest = new Guest() { TicketNumber = "13548424" }; | ||
|
||
// Set up mocks for dependencies | ||
_tourServiceMock.Setup(x => x.GetTourForGuest(guest)) | ||
.Returns((Tour?)null); | ||
|
||
// Act | ||
_deleteReservationFlow.SetGuest(guest); | ||
var commit = _deleteReservationFlow.Commit(); | ||
|
||
// Assert | ||
Assert.IsFalse(commit.Success); | ||
Assert.AreEqual("guestIsNull", commit.MessageKey); | ||
} | ||
} | ||
} |
Oops, something went wrong.