Beispiel #1
0
        public void CallBuyTicketOnUserServiceWithEpectedParameters(string currentUserId)
        {
            // Arrange
            var userService      = new Mock <IUserService>();
            var mappingService   = new Mock <IMappingService>();
            var ticketController = new TicketController(userService.Object, mappingService.Object);

            var userId = "userId";

            ticketController.GetLoggedUserId = () => userId;

            var flights = new List <DetailsFlightViewModel>()
            {
                new DetailsFlightViewModel()
                {
                    Id = 1
                },
                new DetailsFlightViewModel()
                {
                    Id = 2
                },
                new DetailsFlightViewModel()
                {
                    Id = 3
                },
            };

            ticketController.TempData["Ticket"] = flights;

            var mappingPresentationFlightResult = new PresentationFlight(It.IsAny <int>(),
                                                                         It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <decimal>(), It.IsAny <string>(), It.IsAny <int>());

            mappingService.Setup(m => m.Map <PresentationFlight>(It.IsAny <DetailsFlightViewModel>())).Returns(mappingPresentationFlightResult);

            // Act
            ticketController.Buy();

            // Assert
            userService.Verify(u => u.BuyTicket(userId, It.Is <IEnumerable <PresentationFlight> >(p => p.Count() == flights.Count)), Times.Once);
        }
Beispiel #2
0
        public void CallMappingServiceOnExpectedFlightCollection()
        {
            // Arrange
            var userService      = new Mock <IUserService>();
            var mappingService   = new Mock <IMappingService>();
            var ticketController = new TicketController(userService.Object, mappingService.Object);

            var userId = "userId";

            ticketController.GetLoggedUserId = () => userId;

            var flights = new List <DetailsFlightViewModel>()
            {
                new DetailsFlightViewModel()
                {
                    Id = 1
                },
                new DetailsFlightViewModel()
                {
                    Id = 2
                },
                new DetailsFlightViewModel()
                {
                    Id = 3
                },
            };

            ticketController.TempData["Ticket"] = flights;

            // Act
            ticketController.Buy();

            // Assert
            foreach (var flight in flights)
            {
                mappingService.Verify(m => m.Map <PresentationFlight>(flight), Times.Once);
            }
        }