diff --git a/ProjectB.Tests/Workflows/EmployeeFlows/AddGuestFlowTests.cs b/ProjectB.Tests/Workflows/EmployeeFlows/AddGuestFlowTests.cs new file mode 100644 index 0000000..d9bc8bd --- /dev/null +++ b/ProjectB.Tests/Workflows/EmployeeFlows/AddGuestFlowTests.cs @@ -0,0 +1,224 @@ +using Moq; +using ProjectB.Database; +using ProjectB.Models; +using ProjectB.Services; +using ProjectB.Workflows.EmployeeFlows; + +namespace ProjectBTest.Workflows.EmployeeFlows +{ + [TestClass] + public class AddGuestFlowTests + { + private Mock _contextMock; + private Mock _tourServiceMock; + private Mock _guestServiceMock; + private AddGuestFlow _addGuestFlow; + + [TestInitialize] + public void TestInitialize() + { + _contextMock = new Mock(); + _tourServiceMock = new Mock(); + _guestServiceMock = new Mock(); + + _addGuestFlow = new AddGuestFlow( + _contextMock.Object, + _tourServiceMock.Object, + _guestServiceMock.Object); + } + + [TestMethod] + public void HappyFlow() + { + // Arrange + string ticketNumber = "13548424"; + Guest guest = new Guest() { TicketNumber = ticketNumber }; + Tour newTour = new Tour(DateTime.Now.AddHours(2)) { Capacity = 13, Departed = false, Participants = new() }; + + _guestServiceMock.Setup(x => x.FindValidGuestById(ticketNumber)) + .Returns(guest); + + _tourServiceMock.Setup(x => x.GetTourForGuest(guest)) + .Returns((Tour?)null); + + _tourServiceMock.Setup(x => x.RegisterGuestForTour(guest, newTour)) + .Returns(true); + + // Act + var setGuestResult = _addGuestFlow.SetGuest(ticketNumber); + var setTourResult = _addGuestFlow.SetTour(newTour); + var commitResult = _addGuestFlow.Commit(); + + // Assert + Assert.IsTrue(setGuestResult.Success); + Assert.IsTrue(setTourResult.Success); + Assert.IsTrue(commitResult.Success); + } + + [TestMethod] + public void GuestIsNullOrWhiteSpace() + { + // Arrange + string ticketNumber = " "; + + // Act + var setGuestResult = _addGuestFlow.SetGuest(ticketNumber); + + // Assert + Assert.IsFalse(setGuestResult.Success); + Assert.AreEqual("guestIsNull", setGuestResult.MessageKey); + } + + [TestMethod] + public void InvalidTicket() + { + // Arrange + string ticketNumber = "13548424"; + + _guestServiceMock.Setup(x => x.FindValidGuestById(ticketNumber)) + .Returns((Guest?)null); + + // Act + var setGuestResult = _addGuestFlow.SetGuest(ticketNumber); + + // Assert + Assert.IsFalse(setGuestResult.Success); + Assert.AreEqual("invalidTicket", setGuestResult.MessageKey); + } + + [TestMethod] + public void GuestAlreadyHasReservation() + { + // Arrange + string ticketNumber = "13548424"; + Guest guest = new Guest() { TicketNumber = ticketNumber }; + Tour currentTour = new Tour(DateTime.Now.AddHours(1)) { Capacity = 13, Departed = false, Participants = new() { guest.TicketNumber } }; + + _guestServiceMock.Setup(x => x.FindValidGuestById(ticketNumber)) + .Returns(guest); + + _tourServiceMock.Setup(x => x.GetTourForGuest(guest)) + .Returns(currentTour); + + // Act + var setGuestResult = _addGuestFlow.SetGuest(ticketNumber); + + // Assert + Assert.IsFalse(setGuestResult.Success); + Assert.AreEqual("alreadyHasReservation", setGuestResult.MessageKey); + } + + [TestMethod] + public void SelectedTourIsFull() + { + // Arrange + string ticketNumber = "13548424"; + Guest guest = new Guest() { TicketNumber = ticketNumber }; + Tour newTour = new Tour(DateTime.Now.AddHours(2)) + { + Capacity = 13, + Departed = false, + Participants = new() { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" } + }; + + _guestServiceMock.Setup(x => x.FindValidGuestById(ticketNumber)) + .Returns(guest); + + _tourServiceMock.Setup(x => x.GetTourForGuest(guest)) + .Returns((Tour?)null); + + // Act + var setGuestResult = _addGuestFlow.SetGuest(ticketNumber); + var setTourResult = _addGuestFlow.SetTour(newTour); + + // Assert + Assert.IsTrue(setGuestResult.Success); + Assert.IsFalse(setTourResult.Success); + Assert.AreEqual("tourFull", setTourResult.MessageKey); + } + + [TestMethod] + public void SelectedTourIsInPast() + { + // Arrange + string ticketNumber = "13548424"; + Guest guest = new Guest() { TicketNumber = ticketNumber }; + Tour newTour = new Tour(DateTime.Now.AddHours(-1)) { Capacity = 13, Departed = false, Participants = new() }; + + _guestServiceMock.Setup(x => x.FindValidGuestById(ticketNumber)) + .Returns(guest); + + _tourServiceMock.Setup(x => x.GetTourForGuest(guest)) + .Returns((Tour?)null); + + // Act + var setGuestResult = _addGuestFlow.SetGuest(ticketNumber); + var setTourResult = _addGuestFlow.SetTour(newTour); + + // Assert + Assert.IsTrue(setGuestResult.Success); + Assert.IsFalse(setTourResult.Success); + Assert.AreEqual("tourInPast", setTourResult.MessageKey); + } + + [TestMethod] + public void SelectedTourHasDeparted() + { + // Arrange + string ticketNumber = "13548424"; + Guest guest = new Guest() { TicketNumber = ticketNumber }; + Tour newTour = new Tour(DateTime.Now.AddHours(2)) { Capacity = 13, Departed = true, Participants = new() }; + + _guestServiceMock.Setup(x => x.FindValidGuestById(ticketNumber)) + .Returns(guest); + + _tourServiceMock.Setup(x => x.GetTourForGuest(guest)) + .Returns((Tour?)null); + + // Act + var setGuestResult = _addGuestFlow.SetGuest(ticketNumber); + var setTourResult = _addGuestFlow.SetTour(newTour); + + // Assert + Assert.IsTrue(setGuestResult.Success); + Assert.IsFalse(setTourResult.Success); + Assert.AreEqual("tourDeparted", setTourResult.MessageKey); + } + + [TestMethod] + public void CommitWithoutSettingGuest() + { + // Arrange + Tour newTour = new Tour(DateTime.Now.AddHours(2)) { Capacity = 13, Departed = false, Participants = new() }; + + _addGuestFlow.SetTour(newTour); + + // Act + var commitResult = _addGuestFlow.Commit(); + + // Assert + Assert.IsFalse(commitResult.Success); + Assert.AreEqual("guestIsNull", commitResult.MessageKey); + } + + [TestMethod] + public void CommitWithoutSettingTour() + { + // Arrange + string ticketNumber = "13548424"; + Guest guest = new Guest() { TicketNumber = ticketNumber }; + + _guestServiceMock.Setup(x => x.FindValidGuestById(ticketNumber)) + .Returns(guest); + + _addGuestFlow.SetGuest(ticketNumber); + + // Act + var commitResult = _addGuestFlow.Commit(); + + // Assert + Assert.IsFalse(commitResult.Success); + Assert.AreEqual("tourIsNull", commitResult.MessageKey); + } + } +} diff --git a/ProjectB.Tests/Workflows/EmployeeFlows/RemoveGuestFlowTests.cs b/ProjectB.Tests/Workflows/EmployeeFlows/RemoveGuestFlowTests.cs new file mode 100644 index 0000000..5c35dcc --- /dev/null +++ b/ProjectB.Tests/Workflows/EmployeeFlows/RemoveGuestFlowTests.cs @@ -0,0 +1,188 @@ +using Moq; +using ProjectB.Database; +using ProjectB.Models; +using ProjectB.Services; +using ProjectB.Workflows.EmployeeFlows; + +namespace ProjectBTest.Workflows.EmployeeFlows +{ + [TestClass] + public class RemoveGuestFlowTests + { + private Mock _contextMock; + private Mock _tourServiceMock; + private Mock _guestServiceMock; + private RemoveGuestFlow _removeGuestFlow; + + [TestInitialize] + public void TestInitialize() + { + _contextMock = new Mock(); + _tourServiceMock = new Mock(); + _guestServiceMock = new Mock(); + + _removeGuestFlow = new RemoveGuestFlow( + _contextMock.Object, + _tourServiceMock.Object, + _guestServiceMock.Object); + } + + [TestMethod] + public void HappyFlow() + { + // Arrange + string ticketNumber = "13548424"; + Guest guest = new Guest() { TicketNumber = ticketNumber }; + Tour currentTour = new Tour(DateTime.Now.AddHours(1)) { Capacity = 13, Departed = false, Participants = new() { guest.TicketNumber } }; + + _guestServiceMock.Setup(x => x.FindValidGuestById(ticketNumber)) + .Returns(guest); + + _tourServiceMock.Setup(x => x.GetTourForGuest(guest)) + .Returns(currentTour); + + _tourServiceMock.Setup(x => x.DeleteReservationGuest(guest)) + .Returns(true); + + // Act + var setGuestResult = _removeGuestFlow.SetGuest(ticketNumber); + var setTourResult = _removeGuestFlow.SetTour(currentTour); + var commitResult = _removeGuestFlow.Commit(); + + // Assert + Assert.IsTrue(setGuestResult.Success); + Assert.IsTrue(setTourResult.Success); + Assert.IsTrue(commitResult.Success); + } + + [TestMethod] + public void GuestIsNullOrWhiteSpace() + { + // Arrange + string ticketNumber = " "; + + // Act + var setGuestResult = _removeGuestFlow.SetGuest(ticketNumber); + + // Assert + Assert.IsFalse(setGuestResult.Success); + Assert.AreEqual("guestIsNull", setGuestResult.MessageKey); + } + + [TestMethod] + public void InvalidGuestTicket() + { + // Arrange + string ticketNumber = "13548424"; + + _guestServiceMock.Setup(x => x.FindValidGuestById(ticketNumber)) + .Returns((Guest?)null); + + // Act + var setGuestResult = _removeGuestFlow.SetGuest(ticketNumber); + + // Assert + Assert.IsFalse(setGuestResult.Success); + Assert.AreEqual("guestIsNull", setGuestResult.MessageKey); + } + + [TestMethod] + public void NoReservationFound() + { + // Arrange + string ticketNumber = "13548424"; + Guest guest = new Guest() { TicketNumber = ticketNumber }; + + _guestServiceMock.Setup(x => x.FindValidGuestById(ticketNumber)) + .Returns(guest); + + _tourServiceMock.Setup(x => x.GetTourForGuest(guest)) + .Returns((Tour?)null); + + // Act + var setGuestResult = _removeGuestFlow.SetGuest(ticketNumber); + + // Assert + Assert.IsFalse(setGuestResult.Success); + Assert.AreEqual("noReservationFound", setGuestResult.MessageKey); + } + + [TestMethod] + public void SelectedTourIsEmpty() + { + // Arrange + Tour tour = new Tour(DateTime.Now.AddHours(2)) { Capacity = 13, Departed = false, Participants = new() }; + + // Act + var setTourResult = _removeGuestFlow.SetTour(tour); + + // Assert + Assert.IsFalse(setTourResult.Success); + Assert.AreEqual("tourEmpty", setTourResult.MessageKey); + } + + [TestMethod] + public void SelectedTourIsInPast() + { + // Arrange + Tour tour = new Tour(DateTime.Now.AddHours(-1)) { Capacity = 13, Departed = false, Participants = new() { "13548424" } }; + + // Act + var setTourResult = _removeGuestFlow.SetTour(tour); + + // Assert + Assert.IsFalse(setTourResult.Success); + Assert.AreEqual("tourInPast", setTourResult.MessageKey); + } + + [TestMethod] + public void SelectedTourHasDeparted() + { + // Arrange + Tour tour = new Tour(DateTime.Now.AddHours(2)) { Capacity = 13, Departed = true, Participants = new() { "13548424" } }; + + // Act + var setTourResult = _removeGuestFlow.SetTour(tour); + + // Assert + Assert.IsFalse(setTourResult.Success); + Assert.AreEqual("tourDeparted", setTourResult.MessageKey); + } + + [TestMethod] + public void CommitWithoutSettingGuest() + { + // Arrange + Tour tour = new Tour(DateTime.Now.AddHours(2)) { Capacity = 13, Departed = false, Participants = new() { "13548424" } }; + + _removeGuestFlow.SetTour(tour); + + // Act + var commitResult = _removeGuestFlow.Commit(); + + // Assert + Assert.IsFalse(commitResult.Success); + Assert.AreEqual("guestIsNull", commitResult.MessageKey); + } + + [TestMethod] + public void CommitWithoutSettingTour() + { + // Arrange + string ticketNumber = "13548424"; + Guest guest = new Guest() { TicketNumber = ticketNumber }; + + _guestServiceMock.Setup(x => x.FindValidGuestById(ticketNumber)) + .Returns(guest); + + _removeGuestFlow.SetGuest(ticketNumber); + + // Act + var commitResult = _removeGuestFlow.Commit(); + + // Assert + Assert.IsFalse(commitResult.Success); + Assert.AreEqual("tourIsNull", commitResult.MessageKey); + } + } +} diff --git a/ProjectB.Tests/Workflows/EmployeeFlows/StartTourFlowTests.cs b/ProjectB.Tests/Workflows/EmployeeFlows/StartTourFlowTests.cs new file mode 100644 index 0000000..d0cdccd --- /dev/null +++ b/ProjectB.Tests/Workflows/EmployeeFlows/StartTourFlowTests.cs @@ -0,0 +1,287 @@ +using Moq; +using ProjectB.Database; +using ProjectB.Models; +using ProjectB.Services; +using ProjectB.Workflows.EmployeeFlows; + +namespace ProjectBTest.Workflows.EmployeeFlows +{ + [TestClass] + public class StartTourFlowTests + { + private Mock _contextMock; + private Mock _tourServiceMock; + private Mock _guestServiceMock; + private Mock _employeeServiceMock; + private StartTourFlow _startTourFlow; + + [TestInitialize] + public void TestInitialize() + { + _contextMock = new Mock(); + _tourServiceMock = new Mock(); + _guestServiceMock = new Mock(); + _employeeServiceMock = new Mock(); + + _startTourFlow = new StartTourFlow( + _contextMock.Object, + _tourServiceMock.Object, + _guestServiceMock.Object, + _employeeServiceMock.Object); + } + + [TestMethod] + public void HappyFlow() + { + // Arrange + string ticketNumber = "13548424"; + Guest guest = new Guest() { TicketNumber = ticketNumber }; + Tour tour = new Tour(DateTime.Now.AddHours(1)) { Capacity = 13, Departed = false, Participants = new List { guest.TicketNumber } }; + string employeeNumber = "001"; + + _guestServiceMock.Setup(x => x.FindValidGuestById(ticketNumber)).Returns(guest); + _employeeServiceMock.Setup(x => x.ValidateEmployeeNumber(employeeNumber)).Returns(true); + + // Act + var setTourResult = _startTourFlow.SetTour(tour); + var setEmployeeNumberResult = _startTourFlow.SetEmployeeNumber(employeeNumber); + var addGuestResult = _startTourFlow.AddGuest(ticketNumber); + var commitResult = _startTourFlow.Commit(); + + // Assert + Assert.IsTrue(setTourResult.Success); + Assert.IsTrue(setEmployeeNumberResult.Success); + Assert.IsTrue(addGuestResult.Success); + Assert.IsTrue(commitResult.Success); + } + + [TestMethod] + public void AddGuest_GuestIsNullOrWhiteSpace() + { + // Act + var addGuestResult = _startTourFlow.AddGuest(" "); + + // Assert + Assert.IsFalse(addGuestResult.Success); + Assert.AreEqual("guestIsNull", addGuestResult.MessageKey); + } + + [TestMethod] + public void AddGuest_InvalidTicket() + { + // Arrange + string ticketNumber = "13548424"; + + _guestServiceMock.Setup(x => x.FindValidGuestById(ticketNumber)).Returns((Guest?)null); + + // Act + var addGuestResult = _startTourFlow.AddGuest(ticketNumber); + + // Assert + Assert.IsFalse(addGuestResult.Success); + Assert.AreEqual("invalidTicket", addGuestResult.MessageKey); + } + + [TestMethod] + public void AddGuest_TicketAlreadyScanned() + { + // Arrange + string ticketNumber = "13548424"; + Guest guest = new Guest() { TicketNumber = ticketNumber }; + + _guestServiceMock.Setup(x => x.FindValidGuestById(ticketNumber)).Returns(guest); + + // Act + _startTourFlow.ScannedTickets.Add(ticketNumber); + var addGuestResult = _startTourFlow.AddGuest(ticketNumber); + + // Assert + Assert.IsFalse(addGuestResult.Success); + Assert.AreEqual("ticketAlreadyScanned", addGuestResult.MessageKey); + } + + [TestMethod] + public void AddGuest_TourIsNull() + { + // Arrange + string ticketNumber = "13548424"; + Guest guest = new Guest() { TicketNumber = ticketNumber }; + + _guestServiceMock.Setup(x => x.FindValidGuestById(ticketNumber)).Returns(guest); + + // Act + var addGuestResult = _startTourFlow.AddGuest(ticketNumber); + + // Assert + Assert.IsFalse(addGuestResult.Success); + Assert.AreEqual("tourIsNull", addGuestResult.MessageKey); + } + + [TestMethod] + public void AddGuest_TicketNotInTour() + { + // Arrange + string ticketNumber = "13548424"; + Guest guest = new Guest() { TicketNumber = ticketNumber }; + Tour tour = new Tour(DateTime.Now.AddHours(1)) { Capacity = 13, Departed = false, Participants = new List() }; + + _guestServiceMock.Setup(x => x.FindValidGuestById(ticketNumber)).Returns(guest); + _startTourFlow.SetTour(tour); + + // Act + var addGuestResult = _startTourFlow.AddGuest(ticketNumber); + + // Assert + Assert.IsFalse(addGuestResult.Success); + Assert.AreEqual("ticketNotInTour", addGuestResult.MessageKey); + } + + [TestMethod] + public void SetTour_TourIsNull() + { + // Act + var setTourResult = _startTourFlow.SetTour(null); + + // Assert + Assert.IsFalse(setTourResult.Success); + Assert.AreEqual("tourIsNull", setTourResult.MessageKey); + } + + [TestMethod] + public void SetTour_TourIsFull() + { + // Arrange + Tour tour = new Tour(DateTime.Now.AddHours(1)) { Capacity = 13, Departed = false, Participants = Enumerable.Range(1, 13).Select(x => x.ToString()).ToList() }; + + // Act + var setTourResult = _startTourFlow.SetTour(tour); + + // Assert + Assert.IsFalse(setTourResult.Success); + Assert.AreEqual("tourFull", setTourResult.MessageKey); + } + + [TestMethod] + public void SetTour_TourIsInPast() + { + // Arrange + Tour tour = new Tour(DateTime.Now.AddHours(-1)) { Capacity = 13, Departed = false, Participants = new List() }; + + // Act + var setTourResult = _startTourFlow.SetTour(tour); + + // Assert + Assert.IsFalse(setTourResult.Success); + Assert.AreEqual("tourInPast", setTourResult.MessageKey); + } + + [TestMethod] + public void SetTour_TourHasDeparted() + { + // Arrange + Tour tour = new Tour(DateTime.Now.AddHours(1)) { Capacity = 13, Departed = true, Participants = new List() }; + + // Act + var setTourResult = _startTourFlow.SetTour(tour); + + // Assert + Assert.IsFalse(setTourResult.Success); + Assert.AreEqual("tourDeparted", setTourResult.MessageKey); + } + + [TestMethod] + public void SetEmployeeNumber_EmployeeNumberIsNullOrWhiteSpace() + { + // Act + var setEmployeeNumberResult = _startTourFlow.SetEmployeeNumber(" "); + + // Assert + Assert.IsFalse(setEmployeeNumberResult.Success); + Assert.AreEqual("employeeNumberIsNull", setEmployeeNumberResult.MessageKey); + } + + [TestMethod] + public void SetEmployeeNumber_InvalidEmployeeNumber() + { + // Arrange + string employeeNumber = "001"; + + _employeeServiceMock.Setup(x => x.ValidateEmployeeNumber(employeeNumber)).Returns(false); + + // Act + var setEmployeeNumberResult = _startTourFlow.SetEmployeeNumber(employeeNumber); + + // Assert + Assert.IsFalse(setEmployeeNumberResult.Success); + Assert.AreEqual("employeeNumberInvalid", setEmployeeNumberResult.MessageKey); + } + + [TestMethod] + public void Commit_NoScannedTickets() + { + // Arrange + string ticketNumber = "13548424"; + Guest guest = new Guest() { TicketNumber = ticketNumber }; + Tour tour = new Tour(DateTime.Now.AddHours(1)) { Capacity = 13, Departed = false, Participants = new List { guest.TicketNumber } }; + string employeeNumber = "001"; + + _guestServiceMock.Setup(x => x.FindValidGuestById(ticketNumber)).Returns(guest); + _employeeServiceMock.Setup(x => x.ValidateEmployeeNumber(employeeNumber)).Returns(true); + + _startTourFlow.SetTour(tour); + _startTourFlow.SetEmployeeNumber(employeeNumber); + + // Act + var commitResult = _startTourFlow.Commit(); + + // Assert + Assert.IsFalse(commitResult.Success); + Assert.AreEqual("noScannedTickets", commitResult.MessageKey); + } + + [TestMethod] + public void Commit_TourIsNull() + { + // Arrange + string ticketNumber = "13548424"; + Guest guest = new Guest() { TicketNumber = ticketNumber }; + string employeeNumber = "001"; + + _guestServiceMock.Setup(x => x.FindValidGuestById(ticketNumber)).Returns(guest); + _employeeServiceMock.Setup(x => x.ValidateEmployeeNumber(employeeNumber)).Returns(true); + + _startTourFlow.SetEmployeeNumber(employeeNumber); + _startTourFlow.AddGuest(ticketNumber); + + // Act + var commitResult = _startTourFlow.Commit(); + + // Assert + Assert.IsFalse(commitResult.Success); + Assert.AreEqual("tourIsNull", commitResult.MessageKey); + } + + [TestMethod] + public void Commit_HappyFlow() + { + // Arrange + string ticketNumber = "13548424"; + Guest guest = new Guest() { TicketNumber = ticketNumber }; + Tour tour = new Tour(DateTime.Now.AddHours(1)) { Capacity = 13, Departed = false, Participants = new List { guest.TicketNumber } }; + string employeeNumber = "001"; + + _guestServiceMock.Setup(x => x.FindValidGuestById(ticketNumber)).Returns(guest); + _employeeServiceMock.Setup(x => x.ValidateEmployeeNumber(employeeNumber)).Returns(true); + + _startTourFlow.SetTour(tour); + _startTourFlow.SetEmployeeNumber(employeeNumber); + _startTourFlow.AddGuest(ticketNumber); + + // Act + var commitResult = _startTourFlow.Commit(); + + // Assert + Assert.IsTrue(commitResult.Success); + } + } +}