public void Get_WhenCorrectData_ShouldGetProperly() { // Arrange var person = new Person { Id = 1, Name = "Test", DateBirth = DateTime.Now.Date, Gender = GenderType.Male, Address = "TestAddress", Email = "*****@*****.**" }; Mapper.Reset(); Mapper.Initialize(cfg => cfg.CreateMap <Person, PassengerDto>()); var passenger = Mapper.Map <Person, PassengerDto>(person); var mockPersonRepository = new Mock <IRepository <Person> >(); var mockBookingRepository = new Mock <IRepository <Booking> >(); var mockFlightRepository = new Mock <IRepository <Flight> >(); mockPersonRepository.Setup(x => x.Get(It.Is <int>(m => m == person.Id))).Returns(person); var passengerService = new PassengerService(Mapper.Instance, mockPersonRepository.Object, mockBookingRepository.Object, mockFlightRepository.Object); // Act var expectedPassenger = passengerService.GetPassengerById(person.Id); // Assert Assert.AreEqual(expectedPassenger.Id, passenger.Id); Assert.AreEqual(expectedPassenger.Name, passenger.Name); Assert.AreEqual(expectedPassenger.Address, passenger.Address); Assert.AreEqual(expectedPassenger.DateBirth, passenger.DateBirth); Assert.AreEqual(expectedPassenger.Email, passenger.Email); Assert.AreEqual(expectedPassenger.Gender, passenger.Gender); }
public ActionResult Info(int?id) { if (!id.HasValue) { return(View()); } var passenger = _passengerService.GetPassengerById(id.Value); return(View(Mapper.Map <PassengerModel>(passenger))); }
public void Get_WhenIncorrectData_ShouldThrowAppropriateException() { // Arrange var person = new Person { Id = 1, Name = "Test", DateBirth = DateTime.Now.Date, Gender = GenderType.Male, Address = "TestAddress", Email = "*****@*****.**" }; 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.Get(It.Is <int>(m => m == person.Id))).Returns((Person)null); var passengerService = new PassengerService(Mapper.Instance, mockPersonRepository.Object, mockBookingRepository.Object, mockFlightRepository.Object); // Act & Assert var exception = Assert.Throws <WingsOnNotFoundException>(() => passengerService.GetPassengerById(person.Id)); Assert.AreEqual(exception.Message, "Passenger with specified ID is not found."); }