Ejemplo n.º 1
0
        public void CreatesInstance_WhenIncomeingParametersAreCorrect(string journeyID, string administrativeCost)
        {
            //arrange
            List <string> testParameters = new List <string>()
            {
                journeyID, administrativeCost
            };

            Mock <IDatabase>         databaseMock         = new Mock <IDatabase>();
            Mock <ITravellerFactory> travellerFactoryMock = new Mock <ITravellerFactory>();

            databaseMock.Setup(x => x.Journeys)
            .Returns(new List <IJourney>()
            {
                It.IsAny <IJourney>(), It.IsAny <IJourney>(), It.IsAny <IJourney>(),
            });

            databaseMock.Setup(x => x.Tickets)
            .Returns(new List <ITicket>());

            ICommand createTicketCommand = new Traveller.Commands.Creating.CreateTicketCommand(databaseMock.Object, travellerFactoryMock.Object);

            //act
            createTicketCommand.Execute(testParameters);

            //assert
            Assert.AreEqual(1, databaseMock.Object.Tickets.Count);
        }
Ejemplo n.º 2
0
        public void ThrowException_WhenTheListWithTheParametersIsNullOrEmpty()
        {
            //arrange
            Mock <IDatabase>         databaseMock         = new Mock <IDatabase>();
            Mock <ITravellerFactory> travellerFactoryMock = new Mock <ITravellerFactory>();

            ICommand createTicketCommand = new Traveller.Commands.Creating.CreateTicketCommand(databaseMock.Object, travellerFactoryMock.Object);

            List <string> testParameters = null;

            //act and assert
            Assert.ThrowsException <ArgumentNullException>(() => createTicketCommand.Execute(testParameters));
        }
Ejemplo n.º 3
0
        public void ReturnTicketCreationSuccessMessage_WhenParametersAreCorrect()
        {
            //arrange
            List <string> testParameters = new List <string>()
            {
                "0", "20.99"
            };
            Mock <IDatabase>         databaseMock         = new Mock <IDatabase>();
            Mock <ITravellerFactory> travellerFactoryMock = new Mock <ITravellerFactory>();

            ICommand createTicketCommand = new Traveller.Commands.Creating.CreateTicketCommand(databaseMock.Object, travellerFactoryMock.Object);

            Mock <IJourney> journeyMock = new Mock <IJourney>();

            List <IJourney> listOfJourneys = new List <IJourney>()
            {
                journeyMock.Object
            };

            databaseMock.Setup(x => x.Journeys)
            .Returns(listOfJourneys);

            databaseMock.Setup(x => x.Tickets)
            .Returns(new List <ITicket>());

            ITicket expectedTicket = new Ticket(journeyMock.Object, decimal.Parse(testParameters[1]));

            travellerFactoryMock.Setup(x => x.CreateTicket(It.IsAny <IJourney>(), It.IsAny <decimal>()))
            .Returns(expectedTicket);

            //act
            string testOutput     = createTicketCommand.Execute(testParameters);
            string expectedOutput = $"Ticket with ID {databaseMock.Object.Tickets.Count - 1} was created.";

            //Expected output must be initialized after the command execution.

            //assert
            Assert.AreEqual(expectedOutput, testOutput);
        }
Ejemplo n.º 4
0
        public void ThrowException_WhenIncomeingParametersAreNotCorrect(string journeyID, string administrativeCost)
        {
            //arrange
            List <string> testParameters = new List <string>()
            {
                journeyID, administrativeCost
            };

            Mock <IDatabase>         databaseMock         = new Mock <IDatabase>();
            Mock <ITravellerFactory> travellerFactoryMock = new Mock <ITravellerFactory>();

            databaseMock.Setup(x => x.Journeys)
            .Returns(new List <IJourney>()
            {
                It.IsAny <IJourney>(), It.IsAny <IJourney>(), It.IsAny <IJourney>(),
            });

            ICommand createTicketCommand = new Traveller.Commands.Creating.CreateTicketCommand(databaseMock.Object, travellerFactoryMock.Object);

            //act and assert
            Assert.ThrowsException <ArgumentException>(() => createTicketCommand.Execute(testParameters));
        }
Ejemplo n.º 5
0
        public void CreateTicketAndAddItIntoTheDatabase_WhenParametersAreCorrect()
        {
            //arrange
            List <string> testParameters = new List <string>()
            {
                "0", "20.99"
            };
            Mock <IDatabase>         databaseMock         = new Mock <IDatabase>();
            Mock <ITravellerFactory> travellerFactoryMock = new Mock <ITravellerFactory>();

            ICommand createTicketCommand = new Traveller.Commands.Creating.CreateTicketCommand(databaseMock.Object, travellerFactoryMock.Object);

            Mock <IJourney> journeyMock = new Mock <IJourney>();

            List <IJourney> listOfJourneys = new List <IJourney>()
            {
                journeyMock.Object
            };

            databaseMock.Setup(x => x.Journeys)
            .Returns(listOfJourneys);

            databaseMock.Setup(x => x.Tickets)
            .Returns(new List <ITicket>());

            ITicket expectedTicket = new Ticket(journeyMock.Object, decimal.Parse(testParameters[1]));

            travellerFactoryMock.Setup(x => x.CreateTicket(It.IsAny <IJourney>(), It.IsAny <decimal>()))
            .Returns(expectedTicket);

            //act
            createTicketCommand.Execute(testParameters);

            //assert
            Assert.AreEqual(1, databaseMock.Object.Tickets.Count);
            Assert.AreEqual(databaseMock.Object.Tickets[0], expectedTicket);
        }