public void Update_WhenDtoIsPassed_ThenReturnedTheSameWithPassedId() { // Arrange var id = Guid.NewGuid(); var crewId = Guid.NewGuid(); var airplaneId = Guid.NewGuid(); var dto = new DepartureDto() { Time = new DateTime(2018, 7, 17, 13, 0, 0), CrewId = crewId, AirplaneId = airplaneId }; A.CallTo(() => unitOfWorkFake.CrewRepositiry.Get(crewId)).Returns(new Crew { Id = crewId }); A.CallTo(() => unitOfWorkFake.AeroplaneRepository.Get(airplaneId)).Returns(new Aeroplane { Id = airplaneId }); var service = new DepartureService(unitOfWorkFake, mapper, alwaysValidValidator); // Act var returnedDto = service.Update(id, dto); // Assert Assert.True(returnedDto.Id != default(Guid)); Assert.AreEqual(dto.CrewId, returnedDto.CrewId); Assert.AreEqual(dto.AirplaneId, returnedDto.AirplaneId); Assert.AreEqual(dto.Time, returnedDto.Time); }
public DepartureVM() { service = new DepartureService(); Departures = new ObservableCollection <Departure>(); SelectedDeparture = new Departure(); ListInit(); }
public void RegisterDeparture_WithoutRateConfiguration_ShouldReturnAnException() { // Arrange (preparación) var response = "No existe una tarifa configurada para el tipo de vehículo"; var idVehicle = "AAA111"; DtoDeparture departureDTOBuilder = new DepartureDTOBuilder() .WithIdVehicle(idVehicle) .Build(); var EntryEntity = new List <EntryEntity>(); EntryEntity.Add(new EntryEntity() { IdVehicle = departureDTOBuilder.IdVehicle }); _entryRepository.Setup(repo => repo.List(er => er.IdVehicle == idVehicle)).Returns(EntryEntity); var entryService = new DepartureService(_departureRepository.Object, _entryRepository.Object, _rateService.Object, _cellService.Object); // Act try { var result = entryService.RegistryDeparture(departureDTOBuilder); } catch (Exception e) { // Assert Assert.AreEqual(e.Message, response); throw; } }
public void RegisterDeparture_WithBadCCEntry_ShouldReturnAnException() { // Arrange (preparación) var response = "No fue posible determinar el cilindraje del vehículo"; var IdVehicleType = VehicleTypeEnum.motorcycle; var idVehicle = "AAABBB"; DtoDeparture departure = new DepartureDTOBuilder() .WithIdVehicle(idVehicle) .Build(); var EntryEntity = new List <EntryEntity>(); EntryEntity.Add(new EntryEntity() { IdVehicle = departure.IdVehicle, IdVehicleType = IdVehicleType }); _entryRepository.Setup(repo => repo.List(er => er.IdVehicle == idVehicle)).Returns(EntryEntity); _rateService.Setup(rs => rs.GetRateByVehicleType(IdVehicleType)).Returns(new RateEntity()); var entryService = new DepartureService(_departureRepository.Object, _entryRepository.Object, _rateService.Object, _cellService.Object); // Act try { var result = entryService.RegistryDeparture(departure); } catch (Exception e) { // Assert Assert.AreEqual(e.Message, response); throw; } }
public void Create_When_entity_is_invalid_Then_bad_request_exception_is_thrown() { // Arrange var departureMock = new Departure() { Id = 2, Date = new DateTime(2018, 10, 1), FlightId = 2, PlaneId = 2, CrewId = 2 }; var departureDTOToCreate = new DepartureDTO() { Date = new DateTime(2018, 10, 1), FlightId = 2, PlaneId = 2, CrewId = 2 }; var departureRepositoryFake = A.Fake <IDepartureRepository>(); A.CallTo(() => departureRepositoryFake.Create(A <Departure> ._)).Returns(departureMock); var unitOfWorkFake = A.Fake <IUnitOfWork>(); A.CallTo(() => unitOfWorkFake.Set <Departure>()).Returns(departureRepositoryFake); var departureService = new DepartureService(unitOfWorkFake, AlwaysInValidValidator); // Act + Assert var exception = Assert.Throws <BadRequestException>(() => departureService.Create(departureDTOToCreate), ""); Assert.AreEqual(exception.Message, "Is Invalid"); }
[Test] // behaviour test public void Create_When_entity_is_invalid_Then_it_makes_no_calls_to_repository_and_unit_of_work() { // Arrange var departureDTOToCreate = new DepartureDTO() { Date = new DateTime(2018, 10, 1), FlightId = 2, PlaneId = 2, CrewId = 2 }; var departureRepositoryFake = A.Fake <IDepartureRepository>(); var unitOfWorkFake = A.Fake <IUnitOfWork>(); A.CallTo(() => unitOfWorkFake.Set <Departure>()).Returns(departureRepositoryFake); var departureService = new DepartureService(unitOfWorkFake, AlwaysInValidValidator); // Act + Assert var exception = Assert.Throws <BadRequestException>(() => departureService.Create(departureDTOToCreate)); // Assert. Just behaviour A.CallTo(() => departureRepositoryFake.Create(A <Departure> ._)).MustNotHaveHappened(); A.CallTo(() => unitOfWorkFake.DepartureRepository).MustNotHaveHappened(); A.CallTo(() => unitOfWorkFake.Set <Departure>()).MustNotHaveHappened(); A.CallTo(() => unitOfWorkFake.SaveChanges()).MustNotHaveHappened(); }
public void CreateEntity_Should_Create_departure_typeof_Departure() { // Arrange DepartureDTO departureDTO = new DepartureDTO { Id = 1, CrewId = 1, FlightId = 1, FlightNumber = 1111, PlaneId = 1, Time = new DateTime(2018, 07, 12) }; Departure departure = new Departure { Id = 1, CrewId = 1, FlightId = 1, FlightNumber = 1111, PlaneId = 1, Time = new DateTime(2018, 07, 12) }; var departureRepository = new FakeRepository <Departure>(); var departureService = new DepartureService(departureRepository); // Act departureService.CreateEntity(departureDTO); var result = departureRepository.Get(1); // Assert Assert.AreEqual(departure, result); }
[Test] // behaviour test public void Create_When_entity_is_created_Then_it_makes_calls_to_repository_and_unit_of_work() { // Arrange var departureDTOToCreate = new DepartureDTO() { Date = new DateTime(2018, 10, 1), FlightId = 1, PlaneId = 1, CrewId = 1 }; var departureRepositoryFake = A.Fake <IDepartureRepository>(); var unitOfWorkFake = A.Fake <IUnitOfWork>(); A.CallTo(() => unitOfWorkFake.Set <Departure>()).Returns(departureRepositoryFake); var departureService = new DepartureService(unitOfWorkFake, AlwaysValidValidator); // Act var result = departureService.Create(departureDTOToCreate); // Assert. Just behaviour A.CallTo(() => departureRepositoryFake.Create(A <Departure> ._)).MustHaveHappenedOnceExactly(); A.CallTo(() => unitOfWorkFake.Set <Departure>()).MustHaveHappenedOnceExactly(); A.CallTo(() => unitOfWorkFake.SaveChanges()).MustHaveHappenedOnceExactly(); }
public DepartureViewModel() { Title = "Departure"; DepartureService = new DepartureService(); SearchFilter = ""; Departures = new ObservableCollection <Departure>(); Departure = new Departure(); Search(); }
public DepartureView() { this.InitializeComponent(); _departureService = new DepartureService(); DepartureDtos = new ObservableCollection <DepartureDto>(); AirplaneTypesList.ItemsSource = DepartureDtos; }
public DepartureViewModel(IDialogService dialogService) { _dialogService = dialogService; _service = new DepartureService(); AddCommand = new RelayCommand(AddDeparture); UpdateCommand = new RelayCommand(UpdateDeparture); DeleteCommand = new RelayCommand(DeleteDeparture); DownloadData(); }
public void RegisterDeparture_WithoutEntry_ShouldReturnAnException() { // Arrange (preparación) DtoDeparture departureDTOBuilder = new DepartureDTOBuilder() .WithIdVehicle("AAA111") .Build(); var entryService = new DepartureService(_departureRepository.Object, _entryRepository.Object, _rateService.Object, _cellService.Object); // Act entryService.RegistryDeparture(departureDTOBuilder); }
public DeparturesViewModel(INavigationService navigationService) { _departureService = new DepartureService(); _navigationService = navigationService; NewDeparture = new RelayCommand(New); AddDeparture = new RelayCommand(Create); UpdateDeparture = new RelayCommand(Update); DeleteDeparture = new RelayCommand(Delete); LoadDepartures().ConfigureAwait(false); Departure = new Departure(); }
public void GetDepartures_WithoutData_ShouldReturnEmptyList() { // Arrange _departureRepository.Setup(r => r.List()).Returns(new List <DepartureEntity>()); var entryService = new DepartureService(_departureRepository.Object, _entryRepository.Object, _rateService.Object, _cellService.Object); // Act var result = entryService.GetDepartures(); // Assert Assert.IsTrue(result.Count() <= 0); }
public DeparturesViewModel(INavigationService navigationService) { Departureservice = new DepartureService(); navService = navigationService; RefreshEntity = new RelayCommand(Refresh); AddEntity = new RelayCommand(Create); UpdateEntity = new RelayCommand(Update); DeleteEntity = new RelayCommand(Delete); LoadEntity().ConfigureAwait(false); Departure = new Departure(); }
public void Create_WhenDtoIsEmpty_ThenThrowValidExeption() { // Arrange var dto = new DepartureDto() { }; var service = new DepartureService(unitOfWorkFake, mapper, validator); // Act // Assert Assert.Throws <ValidationException>(() => service.Create(dto)); }
public void Update_When_entity_is_updated_Then_updated_entity_is_returned() { // Arrange var departureMock = new Departure() { Id = 3, Date = new DateTime(2018, 10, 1), FlightId = 3, PlaneId = 3, CrewId = 3 }; var departureDTOToUpdate = new DepartureDTO() { Id = 3, Date = new DateTime(2018, 10, 1), FlightId = 3, PlaneId = 3, CrewId = 3 }; var expectedDepartureDTO = new DepartureDTO() { Id = 3, Date = new DateTime(2018, 10, 1), FlightId = 3, PlaneId = 3, CrewId = 3 }; var departureRepositoryFake = A.Fake <IDepartureRepository>(); A.CallTo(() => departureRepositoryFake.Update(A <Departure> ._)).Returns(departureMock); var unitOfWorkFake = A.Fake <IUnitOfWork>(); A.CallTo(() => unitOfWorkFake.Set <Departure>()).Returns(departureRepositoryFake); var departureService = new DepartureService(unitOfWorkFake, AlwaysValidValidator); // Act var result = departureService.Update(departureDTOToUpdate); // Assert Assert.AreEqual(expectedDepartureDTO.Id, result.Id, "Id"); Assert.AreEqual(expectedDepartureDTO.PlaneId, result.PlaneId); Assert.AreEqual(expectedDepartureDTO.FlightId, result.FlightId); Assert.AreEqual(expectedDepartureDTO.Date, result.Date); Assert.AreEqual(expectedDepartureDTO.CrewId, result.CrewId); }
public DepartureViewModel() { this.service = new DepartureService(ApiService.GetInstance()); FService = new FlightService(ApiService.GetInstance()); CService = new CrewService(ApiService.GetInstance()); PService = new PlaneService(ApiService.GetInstance()); Departures = new ObservableCollection <Departure>(); Flights = new ObservableCollection <Flight>(); Crews = new ObservableCollection <Crew>(); Planes = new ObservableCollection <Plane>(); FillDeparturesCollection(); FillAdditionalCollections(); }
public void GetEntryByBadId_ShouldReturn_DtoEmpty() { // Arrange var newId = Guid.NewGuid().ToString(); _departureRepository.Setup(r => r.GetById(newId)); var entryService = new DepartureService(_departureRepository.Object, _entryRepository.Object, _rateService.Object, _cellService.Object); // Act DtoDeparture result = entryService.GetEntryById(id: newId); // Assert Assert.IsNull(result.Id); }
public void GetEntryById_ShouldReturn_DtoDepartureEntity() { // Arrange DepartureEntity departureEntity = new DepartureEntityBuilder() .WithId(Guid.NewGuid().ToString()) .Build(); _departureRepository.Setup(r => r.GetById(departureEntity.Id)).Returns(departureEntity); var entryService = new DepartureService(_departureRepository.Object, _entryRepository.Object, _rateService.Object, _cellService.Object); // Act DtoDeparture result = entryService.GetEntryById(id: departureEntity.Id); // Assert Assert.IsNotNull(result); }
public void GetDepartures_WithData_ShouldReturnListWithValues() { // Arrange _departureRepository.Setup(r => r.List()).Returns(new List <DepartureEntity> { new DepartureEntity { DepartureTime = DateTime.Now, Id = Guid.NewGuid().ToString() } }); var entryService = new DepartureService(_departureRepository.Object, _entryRepository.Object, _rateService.Object, _cellService.Object); // Act var result = entryService.GetDepartures(); // Assert Assert.IsTrue(result.Count() > 0); }
public void GetEntryByBadId_ShouldReturn_Null() { // Arrange DepartureEntity departureEntity = new DepartureEntityBuilder() .WithId(Guid.NewGuid().ToString()) .Build(); var id = Guid.NewGuid().ToString(); _departureRepository.Setup(r => r.List(dr => dr.IdEntry == id)).Returns(new List <DepartureEntity>()); var entryService = new DepartureService(_departureRepository.Object, _entryRepository.Object, _rateService.Object, _cellService.Object); // Act DepartureEntity result = entryService.GetDepartureByEntryId(id); // Assert Assert.IsNull(result); }
public void Setup() { var optionsBuilder = new DbContextOptionsBuilder <ParkingDbContext>().UseInMemoryDatabase("integrationTestDB"); contexto = new ParkingDbContext(optionsBuilder.Options); entryRepository = new Repository <EntryEntity>(contexto); cellRepository = new Repository <CellEntity>(contexto); departureRepository = new Repository <DepartureEntity>(contexto); rateRepository = new Repository <RateEntity>(contexto); placaRepository = new Repository <PlacaEntity>(contexto); picoPlacarepository = new Repository <PicoPlacaDigits>(contexto); cellService = new CellService(cellRepository); rateService = new RateService(rateRepository); placaService = new PlacaService(placaRepository, picoPlacarepository); departureService = new DepartureService(departureRepository, entryRepository, rateService, cellService); contexto.Database.EnsureCreated(); }
public void GetDepartureByVehicleId_ShouldReturn_Null() { // Arrange DepartureEntity departureEntity = new DepartureEntityBuilder() .WithId(Guid.NewGuid().ToString()) .WithIdVehicle("ASD123") .Build(); var vehicleId = "AAA111"; _departureRepository.Setup(r => r.List(dr => dr.IdVehicle == vehicleId)).Returns(new List <DepartureEntity>()); var entryService = new DepartureService(_departureRepository.Object, _entryRepository.Object, _rateService.Object, _cellService.Object); // Act DepartureEntity result = entryService.GetDepartureByVehicleId(vehicleId); // Assert Assert.IsNull(result); }
public void UpdateEntity_When_departure_doesnt_exist_Then_throw_exception() { // Arrange DepartureDTO departureDTO = new DepartureDTO { Id = 1, CrewId = 1, FlightId = 1, FlightNumber = 1111, PlaneId = 1, Time = new DateTime(2018, 07, 12) }; var departureRepository = A.Fake <IRepository <Departure> >(); A.CallTo(() => departureRepository.Get(A <int> ._)).Returns(null); var departureService = new DepartureService(departureRepository); //Act and Assert Assert.Throws <ValidationException>(() => departureService.UpdateEntity(1, departureDTO)); }
public void Update_When_entity_is_invalid_Then_bad_request_exception_is_thrown() { // Arrange var departureDTOToUpdate = new DepartureDTO() { Id = 3, Date = new DateTime(2018, 10, 1), FlightId = 3, PlaneId = 3, CrewId = 3 }; var departureRepositoryFake = A.Fake <IDepartureRepository>(); var unitOfWorkFake = A.Fake <IUnitOfWork>(); var departureService = new DepartureService(unitOfWorkFake, AlwaysInValidValidator); // Act + Assert var exception = Assert.Throws <BadRequestException>(() => departureService.Update(departureDTOToUpdate), ""); Assert.AreEqual(exception.Message, "Is Invalid"); }
public void UpdateEntity_Should_Update_departure_typeof_Departure() { // Arrange DepartureDTO departureDTO = new DepartureDTO { Id = 1, CrewId = 1, FlightId = 1, FlightNumber = 1111, PlaneId = 1, Time = new DateTime(2018, 07, 12) }; Departure departure = new Departure { Id = 1, CrewId = 1, FlightId = 1, FlightNumber = 1111, PlaneId = 1, Time = new DateTime(2018, 07, 12) }; var departureRepository = A.Fake <IRepository <Departure> >(); A.CallTo(() => departureRepository.Get(A <int> ._)).Returns(new Departure { Id = 1 }); var departureService = new DepartureService(departureRepository); //Act departureService.UpdateEntity(1, departureDTO); var result = departureRepository.Get(1); // Assert Assert.AreEqual(departure, result); }
public void SetUp() { unitOfWork = new FakeUnitOfWork(); mapper = new Mapping(unitOfWork); service = new DepartureService(unitOfWork, mapper, new DepartureValidator()); }
public DepartureController(DepartureService departureService) { this.departureService = departureService; }
public DepartureViewModel() { _departureService = new DepartureService(); }