public void Create_When_entity_is_invalid_Then_bad_request_exception_is_thrown() { // Arrange var planeMock = new Plane() { Id = 2, Name = "Mock Plane 2", ReleaseDate = new DateTime(1950, 10, 10), PlaneTypeId = 1, ServiceLife = new TimeSpan(10_000 * 24, 0, 0) }; var planeDTOToCreate = new PlaneDTO() { Name = "Mock Plane 2", ReleaseDate = new DateTime(1950, 10, 10), PlaneTypeId = 1, ServiceLife = new TimeSpan(10_000 * 24, 0, 0) }; var planeRepositoryFake = A.Fake <IPlaneRepository>(); A.CallTo(() => planeRepositoryFake.Create(A <Plane> ._)).Returns(planeMock); var unitOfWorkFake = A.Fake <IUnitOfWork>(); A.CallTo(() => unitOfWorkFake.Set <Plane>()).Returns(planeRepositoryFake); var planeService = new PlaneService(unitOfWorkFake, AlwaysInValidValidator); // Act + Assert var exception = Assert.Throws <BadRequestException>(() => planeService.Create(planeDTOToCreate), ""); Assert.AreEqual(exception.Message, "Is Invalid"); }
public void CreateEntity_Should_Create_plane_typeof_Plane() { // Arrange PlaneDTO planeDTO = new PlaneDTO { Id = 1, ReleaseDate = new DateTime(2018, 07, 12), Name = "TY-143", PlaneTypeId = 1, Lifetime = new DateTime(2020, 07, 12) - new DateTime(2018, 07, 12) }; Plane plane = new Plane { Id = 1, ReleaseDate = new DateTime(2018, 07, 12), Name = "TY-143", PlaneTypeId = 1, Lifetime = new DateTime(2020, 07, 12) - new DateTime(2018, 07, 12) }; var planeRepository = new FakeRepository <Plane>(); var planeService = new PlaneService(planeRepository); // Act planeService.CreateEntity(planeDTO); var result = planeRepository.Get(1); // Assert Assert.AreEqual(plane, result); }
public void TestSetUp() { var connection = @"Server=DESKTOP-DMYTRO\SQLEXPRESS;Initial Catalog=Academy;Trusted_Connection=True;ConnectRetryCount=0"; DbContextOptionsBuilder <MyContext> t = new DbContextOptionsBuilder <MyContext>(); t.UseSqlServer(connection); mc = new MyContext(t.Options); CrewRepository crewRepository = new CrewRepository(mc); PilotRepository pilotRepository = new PilotRepository(mc); StewardessRepository stewardessRepository = new StewardessRepository(mc); FlightRepository flightRepository = new FlightRepository(mc); TicketRepository ticketRepository = new TicketRepository(mc); TakeOffRepository takeOffRepository = new TakeOffRepository(mc); PlaneRepository planeRepository = new PlaneRepository(mc); PlaneTypeRepository planeTypeRepository = new PlaneTypeRepository(mc); UnitOfWork unitOfWork = new UnitOfWork(crewRepository, flightRepository, pilotRepository, planeRepository, planeTypeRepository, stewardessRepository, takeOffRepository, ticketRepository, mc); CrewService crewService = new CrewService(unitOfWork); FlightService flightService = new FlightService(unitOfWork); StewardessService stewardessService = new StewardessService(unitOfWork); PilotService pilotService = new PilotService(unitOfWork); TicketService ticketService = new TicketService(unitOfWork); TakeOffService takeOffService = new TakeOffService(unitOfWork); PlaneService planeService = new PlaneService(unitOfWork); PlaneTypeService planeTypeService = new PlaneTypeService(unitOfWork); pilotController = new PilotController(pilotService); flightController = new FlightController(flightService); }
[Test] // behaviour test public void Create_When_entity_is_invalid_Then_it_makes_no_calls_to_repository_and_unit_of_work() { // Arrange var planeDTOToCreate = new PlaneDTO() { Name = "Mock Plane 2", ReleaseDate = new DateTime(1950, 10, 10), PlaneTypeId = 2, ServiceLife = new TimeSpan(10_000 * 24, 0, 0) }; var planeRepositoryFake = A.Fake <IPlaneRepository>(); var unitOfWorkFake = A.Fake <IUnitOfWork>(); A.CallTo(() => unitOfWorkFake.Set <Plane>()).Returns(planeRepositoryFake); var planeService = new PlaneService(unitOfWorkFake, AlwaysInValidValidator); // Act + Assert var exception = Assert.Throws <BadRequestException>(() => planeService.Create(planeDTOToCreate)); // Assert. Just behaviour A.CallTo(() => planeRepositoryFake.Create(A <Plane> ._)).MustNotHaveHappened(); A.CallTo(() => unitOfWorkFake.PlaneRepository).MustNotHaveHappened(); A.CallTo(() => unitOfWorkFake.Set <Plane>()).MustNotHaveHappened(); A.CallTo(() => unitOfWorkFake.SaveChanges()).MustNotHaveHappened(); }
public void Fly() { Uid = Thread.CurrentThread.GetHashCode(); Altitude = 0; FlightDistance = Rand.Next((int)MinDistance, (int)MaxDistance); TimeOfFligh = 0; Service = new PlaneService(new PlaneRepository(AppConfig.PlanesFolder + Uid + ".txt", true)); Distance = FlightDistance; Speed = 2; var distc = FlightDistance / 200; while (Distance > 0) { TimeOfFligh++; Distance -= Speed; Altitude = -Math.Pow(((FlightDistance - Distance) / distc) - 100, 2) + MaxAltitude; Thread.Sleep(200); if (TimeOfFligh % 10 == 0) { Service.Write(this); } } File.Delete(AppConfig.PlanesFolder + Uid + ".txt"); }
[Test] // behaviour test public void Create_When_entity_is_created_Then_it_makes_calls_to_repository_and_unit_of_work() { // Arrange var planeDTOToCreate = new PlaneDTO() { Name = "Mock Plane 1", ReleaseDate = new DateTime(1950, 10, 10), PlaneTypeId = 1, ServiceLife = new TimeSpan(10_000 * 24, 0, 0) }; var planeRepositoryFake = A.Fake <IPlaneRepository>(); var unitOfWorkFake = A.Fake <IUnitOfWork>(); A.CallTo(() => unitOfWorkFake.Set <Plane>()).Returns(planeRepositoryFake); var planeService = new PlaneService(unitOfWorkFake, AlwaysValidValidator); // Act var result = planeService.Create(planeDTOToCreate); // Assert. Just behaviour A.CallTo(() => planeRepositoryFake.Create(A <Plane> ._)).MustHaveHappenedOnceExactly(); A.CallTo(() => unitOfWorkFake.Set <Plane>()).MustHaveHappenedOnceExactly(); A.CallTo(() => unitOfWorkFake.SaveChanges()).MustHaveHappenedOnceExactly(); }
public void PlaneCreate() { PlaneService planeService = new PlaneService(unitOfWork); PlaneDTO planeDTO = new PlaneDTO() { Name = "test", Made = new DateTime(1, 2, 3), Exploitation = new TimeSpan(0, 1, 2), Type = new PlaneTypeDTO() { Model = "test", CarryCapacity = 12, Places = 15 } }; planeService.CreatePlane(planeDTO); Plane plane = fakePlaneRepository.Get(1); Assert.AreEqual(plane.Name, planeDTO.Name); Assert.AreEqual(plane.Made, planeDTO.Made); Assert.AreEqual(plane.Exploitation, planeDTO.Exploitation); Assert.AreEqual(plane.Type.Model, planeDTO.Type.Model); Assert.AreEqual(plane.Type.CarryCapacity, planeDTO.Type.CarryCapacity); Assert.AreEqual(plane.Type.Places, planeDTO.Type.Places); }
public void Delete_Plane_When_not_exists_Then_throws_ArgumentNullException() { var planeService = new PlaneService(unitOfWork, mapper, new PlaneValidator()); var id = 1123; Assert.Throws <ArgumentNullException>(() => planeService.Delete(id)); }
public void UpdateEntity_Should_Update_plane_typeof_Plane() { // Arrange PlaneDTO planeDTO = new PlaneDTO { Id = 1, ReleaseDate = new DateTime(2018, 07, 12), Name = "TY-143", PlaneTypeId = 1, Lifetime = new DateTime(2020, 07, 12) - new DateTime(2018, 07, 12) }; Plane plane = new Plane { Id = 1, ReleaseDate = new DateTime(2018, 07, 12), Name = "TY-143", PlaneTypeId = 1, Lifetime = new DateTime(2020, 07, 12) - new DateTime(2018, 07, 12) }; var planeRepository = A.Fake <IRepository <Plane> >(); A.CallTo(() => planeRepository.Get(A <int> ._)).Returns(new Plane { Id = 1 }); var planeService = new PlaneService(planeRepository); //Act planeService.UpdateEntity(1, planeDTO); var result = planeRepository.Get(1); // Assert Assert.AreEqual(plane, result); }
public Planes() { this.InitializeComponent(); ps = new PlaneService(); list = ps.GetAll().Result; Add.Click += (sender, e) => Create(); }
public void Deserialize_OpenSkyResponse_GetState_00() { string json = @"{'time':1526079430,'states':[['ab1644','','United States',1526079426,1526079429,-87.8424,42.0282,1013.46,false,118.95,36.03,9.75,null,944.88,'5373',false,0],['ac96b8','AAL2441 ','United States',1526079429,1526079429,-84.9193,35.5556,11277.6,false,224.61,292.63,0,null,11711.94,'1640',true,0]]}"; string expected = "ab1644"; var osr = PlaneService.Deserialize(json); Assert.Equal(osr.GetState(0, 0), expected); }
public void GetData_ReturnsNonEmptyString() { // Arrange // Act string actual = PlaneService.GetData(); // Assert Assert.False(String.IsNullOrWhiteSpace(actual)); }
public PlaneViewModel() { this.service = new PlaneService(ApiService.GetInstance()); TService = new PlaneTypeService(ApiService.GetInstance()); Planes = new ObservableCollection <Plane>(); Types = new ObservableCollection <PlaneType>(); FillPlanesCollection(); FillAdditionalCollections(); }
public void Update_Plane_When_update_expires_date_Then_results_are_in_db() { var planeService = new PlaneService(unitOfWork, mapper, new PlaneValidator()); var id = 2; var oldValue = planeService.Get(id).Expires; planeService.Update(new TimeSpan(900, 0, 0, 0), id); var newValue = planeService.Get(id).Expires; Assert.AreNotEqual(oldValue, newValue); }
public void Deserialize_ReturnsOpenSkyResponse_Time() { // Arrange string json = @"{'time':1526079430,'states':[['ab1644','','United States',1526079426,1526079429,-87.8424,42.0282,1013.46,false,118.95,36.03,9.75,null,944.88,'5373',false,0]]}"; int expected = 1526079430; // Act var actual = PlaneService.Deserialize(json); // Assert Assert.Equal(actual.Time, expected); }
public void Create_Plane_When_model_is_not_valid_Then_throws_ValidatorExceprion() { var planeService = new PlaneService(unitOfWork, mapper, new PlaneValidator()); var plane = new PlaneDto() { Name = "Bobo", Type = 1, Created = new DateTime(2013, 08, 03), Expires = new TimeSpan(29, 0, 0, 0) }; Assert.Throws <FluentValidation.ValidationException>(() => planeService.Create(plane)); }
public void Deserialize_OpenSkyResponse_Finds_First_ICAO() { // Arrange string json = @"{'time':1526079430,'states':[['ab1644','','United States',1526079426,1526079429,-87.8424,42.0282,1013.46,false,118.95,36.03,9.75,null,944.88,'5373',false,0],['ac96b8','AAL2441 ','United States',1526079429,1526079429,-84.9193,35.5556,11277.6,false,224.61,292.63,0,null,11711.94,'1640',true,0]]}"; string expected = "ab1644"; // Act var osr = PlaneService.Deserialize(json); string actual = osr.GetIcao24(0); // Assert Assert.Equal(expected, actual); }
public PlanesViewModel(INavigationService navigationService) { Planeservice = new PlaneService(); navService = navigationService; RefreshEntity = new RelayCommand(Refresh); AddEntity = new RelayCommand(Create); UpdateEntity = new RelayCommand(Update); DeleteEntity = new RelayCommand(Delete); LoadEntity().ConfigureAwait(false); Plane = new Plane(); }
public PlanesViewModel(INavigationService navigationService) { _planeService = new PlaneService(); _navigationService = navigationService; NewPlane = new RelayCommand(New); AddPlane = new RelayCommand(Create); UpdatePlane = new RelayCommand(Update); DeletePlane = new RelayCommand(Delete); LoadPlanes().ConfigureAwait(false); Plane = new Plane(); }
public void Update_Plane_When_id_is_not_in_db_Then_throws_NullReferenceException() { var planeService = new PlaneService(unitOfWork, mapper, new PlaneValidator()); var id = 1123; var plane = new PlaneDto() { Name = "Bobo", Type = 1, Created = new DateTime(2013, 08, 03), Expires = new TimeSpan(750, 0, 0, 0) }; Assert.Throws <NullReferenceException>(() => planeService.Update(plane, id)); }
public void Deserialize_OpenSkyResponse_Finds_First_Origin_Country() { // Arrange string json = @"{'time':1526079430,'states':[['ab1644','','United States',1526079426,1526079429,-87.8424,42.0282,1013.46,false,118.95,36.03,9.75,null,944.88,'5373',false,0]]}"; string expected = "United States"; // Act var osr = PlaneService.Deserialize(json); string actual = osr.GetOriginCountry(0); // Assert Assert.Equal(actual, expected); }
public void Update_When_entity_is_updated_Then_updated_entity_is_returned() { // Arrange var planeMock = new Plane() { Id = 3, Name = "Mock Plane 3", ReleaseDate = new DateTime(1950, 10, 10), PlaneTypeId = 3, ServiceLife = new TimeSpan(10_000 * 24, 0, 0) }; var planeDTOToUpdate = new PlaneDTO() { Id = 3, Name = "Mock Plane 3", ReleaseDate = new DateTime(1950, 10, 10), PlaneTypeId = 3, ServiceLife = new TimeSpan(10_000 * 24, 0, 0) }; var expectedPlaneDTO = new PlaneDTO() { Id = 3, Name = "Mock Plane 3", ReleaseDate = new DateTime(1950, 10, 10), PlaneTypeId = 3, ServiceLife = new TimeSpan(10_000 * 24, 0, 0) }; var planeRepositoryFake = A.Fake <IPlaneRepository>(); A.CallTo(() => planeRepositoryFake.Update(A <Plane> ._)).Returns(planeMock); var unitOfWorkFake = A.Fake <IUnitOfWork>(); A.CallTo(() => unitOfWorkFake.Set <Plane>()).Returns(planeRepositoryFake); var planeService = new PlaneService(unitOfWorkFake, AlwaysValidValidator); // Act var result = planeService.Update(planeDTOToUpdate); // Assert Assert.AreEqual(expectedPlaneDTO.Id, result.Id); Assert.AreEqual(expectedPlaneDTO.Name, result.Name); Assert.AreEqual(expectedPlaneDTO.ReleaseDate, result.ReleaseDate); Assert.AreEqual(expectedPlaneDTO.PlaneTypeId, result.PlaneTypeId); Assert.AreEqual(expectedPlaneDTO.ServiceLife, result.ServiceLife); }
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 Update_Plane_When_model_is_valid_Then_get_right_value_through_mapping() { var planeService = new PlaneService(unitOfWork, mapper, new PlaneValidator()); var id = 1; var plane = new PlaneDto() { Name = "Bobo", Type = 1, Created = new DateTime(2013, 08, 03), Expires = new TimeSpan(750, 0, 0, 0) }; planeService.Update(plane, id); var planeResult = planeService.Get(id); Assert.AreEqual(plane.Created, planeResult.Created); }
public async Task <bool> CreateService(PlaneService planeService) { try { await _context.PlaneService.AddAsync(new PlaneService() { Name = planeService.Name, Icon = planeService.Icon }); await _context.SaveChangesAsync(); return(true); }catch (Exception e) { return(false); } }
public void GetData_ReturnsJsonData() { // Act var actual = PlaneService.GetData(); char firstChar = ' '; foreach (char ch in actual) { if (!Char.IsWhiteSpace(ch)) { firstChar = ch; break; } } // Assert Assert.True(firstChar == '{' || firstChar == '['); }
public void UpdateEntity_When_plane_doesnt_exist_Then_throw_exception() { // Arrange PlaneDTO planeDTO = new PlaneDTO { Id = 1, ReleaseDate = new DateTime(2018, 07, 12), Name = "TY-143", PlaneTypeId = 1, Lifetime = new DateTime(2020, 07, 12) - new DateTime(2018, 07, 12) }; var planeRepository = A.Fake <IRepository <Plane> >(); A.CallTo(() => planeRepository.Get(A <int> ._)).Returns(null); var planeService = new PlaneService(planeRepository); //Act and Assert Assert.Throws <ValidationException>(() => planeService.UpdateEntity(1, planeDTO)); }
public PlaneVM() { service = new PlaneService(); Planes = new ObservableCollection <Plane>(); ListInit(); }
public PlaneLogic() { PlaneService = new PlaneService(); this.InitializeComponent(); }
public PlaneController(PlaneService planeService) { this.planeService = planeService; }