示例#1
0
 public ActionResult Passengers()
 {
     return(View(new PassengersViewModel
     {
         Passengers = _passengerService.GetPassengers()
     }));
 }
示例#2
0
 private void BtnAdd_Click(object sender, RoutedEventArgs e)
 {
     if (TxtCustID.Text.Equals("") || TxtFlightID.Text.Equals(""))
     {
         MessageBox.Show("All Fields Required", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation);
     }
     else
     {
         try
         {
             Passenger ps = new Passenger(passengerService.GetPassengers().Count, int.Parse(TxtCustID.Text), int.Parse(TxtFlightID.Text));
             passengerService.Add(ps);
             RefreshList();
         } catch (Exception ex)
         {
             MessageBox.Show("Please enter an integer for ID", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
         }
     }
 }
示例#3
0
        public void GetAll_WhenGenderIsSet_ShouldReturnPassengersByGender()
        {
            // Arrange
            var getPassengersRequest = new GetPassengersRequest
            {
                Gender = Gender.Male
            };

            var passengersByGender = new List <Person>
            {
                new Person {
                    Id = 1, Name = "Test1", DateBirth = DateTime.Now.Date, Gender = GenderType.Male, Address = "TestAddress", Email = "*****@*****.**"
                },
                new Person {
                    Id = 2, Name = "Test2", DateBirth = DateTime.Now.Date, Gender = GenderType.Female, Address = "TestAddress", Email = "*****@*****.**"
                },
                new Person {
                    Id = 3, Name = "Test3", DateBirth = DateTime.Now.Date, Gender = GenderType.Male, Address = "TestAddress", Email = "*****@*****.**"
                }
            };

            Mapper.Reset();
            Mapper.Initialize(cfg => cfg.CreateMap <Person, PassengerDto>());

            var malePassengers = Mapper.Map <List <Person>, List <PassengerDto> >(passengersByGender.Where(pas => pas.Gender == GenderType.Male).ToList());

            var mockPersonRepository  = new Mock <IRepository <Person> >();
            var mockBookingRepository = new Mock <IRepository <Booking> >();
            var mockFlightRepository  = new Mock <IRepository <Flight> >();

            mockPersonRepository.Setup(x => x.GetAll()).Returns(passengersByGender);

            var passengerService = new PassengerService(Mapper.Instance, mockPersonRepository.Object, mockBookingRepository.Object, mockFlightRepository.Object);

            // Act
            var passengers = passengerService.GetPassengers(getPassengersRequest);

            // Assert
            Assert.AreEqual(malePassengers.Count, passengers.Count);
            Assert.AreEqual(malePassengers.Select(pas => pas.Id).ToList(), passengers.Select(pas => pas.Id).ToList());
        }
示例#4
0
        public void GetAll_WhenNoPassengers_ShouldThrowAppropriateException()
        {
            // Arrange
            var getPassengersRequest = new GetPassengersRequest();

            Mapper.Reset();
            Mapper.Initialize(cfg => cfg.CreateMap <Person, PassengerDto>());

            var mockPersonRepository  = new Mock <IRepository <Person> >();
            var mockBookingRepository = new Mock <IRepository <Booking> >();
            var mockFlightRepository  = new Mock <IRepository <Flight> >();

            mockPersonRepository.Setup(x => x.GetAll()).Returns((IEnumerable <Person>)null);

            var passengerService = new PassengerService(Mapper.Instance, mockPersonRepository.Object, mockBookingRepository.Object, mockFlightRepository.Object);

            // Act & Assert
            var exception = Assert.Throws <WingsOnNotFoundException>(() => passengerService.GetPassengers(getPassengersRequest));

            Assert.AreEqual(exception.Message, "Passengers are not found.");
        }