public void CreateEntity_Should_Create_planeType_typeof_PlaneType() { // Arrange PlaneTypeDTO planeTypeDTO = new PlaneTypeDTO { Id = 1, Carrying = 240000, Model = "Passenger's", Seats = 200 }; PlaneType planeType = new PlaneType { Id = 1, Carrying = 240000, Model = "Passenger's", Seats = 200 }; var planeTypeRepository = new FakeRepository <PlaneType>(); var planeTypeService = new PlaneTypeService(planeTypeRepository); // Act planeTypeService.CreateEntity(planeTypeDTO); var result = planeTypeRepository.Get(1); // Assert Assert.AreEqual(planeType, 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); }
public void UpdateEntity_Should_Update_planeType_typeof_PlaneType() { // Arrange PlaneTypeDTO planeTypeDTO = new PlaneTypeDTO { Id = 1, Carrying = 240000, Model = "Passenger's", Seats = 200 }; PlaneType planeType = new PlaneType { Id = 1, Carrying = 240000, Model = "Passenger's", Seats = 200 }; var planeTypeRepository = A.Fake <IRepository <PlaneType> >(); A.CallTo(() => planeTypeRepository.Get(A <int> ._)).Returns(new PlaneType { Id = 1 }); var planeTypeService = new PlaneTypeService(planeTypeRepository); //Act planeTypeService.UpdateEntity(1, planeTypeDTO); var result = planeTypeRepository.Get(1); // Assert Assert.AreEqual(planeType, result); }
public PlaneTypeViewModel() { this.service = new PlaneTypeService(ApiService.GetInstance()); PlaneTypes = new ObservableCollection <PlaneType>(); FillPlaneTypesCollection(); }
[Test] // behaviour test public void Create_When_entity_is_created_Then_it_makes_calls_to_repository_and_unit_of_work() { // Arrange var planeTypeDTOToCreate = new PlaneTypeDTO() { Model = "AAABBBCCC", Seats = 500, Carrying = 400 }; var planeTypeRepositoryFake = A.Fake <IPlaneTypeRepository>(); var unitOfWorkFake = A.Fake <IUnitOfWork>(); A.CallTo(() => unitOfWorkFake.Set <PlaneType>()).Returns(planeTypeRepositoryFake); var planeTypeService = new PlaneTypeService(unitOfWorkFake, AlwaysValidValidator); // Act var result = planeTypeService.Create(planeTypeDTOToCreate); // Assert. Just behaviour A.CallTo(() => planeTypeRepositoryFake.Create(A <PlaneType> ._)).MustHaveHappenedOnceExactly(); A.CallTo(() => unitOfWorkFake.Set <PlaneType>()).MustHaveHappenedOnceExactly(); A.CallTo(() => unitOfWorkFake.SaveChanges()).MustHaveHappenedOnceExactly(); }
[Test] // behaviour test public void Create_When_entity_is_invalid_Then_it_makes_no_calls_to_repository_and_unit_of_work() { // Arrange var planeTypeDTOToCreate = new PlaneTypeDTO() { Model = "AAABBBCCC", Seats = 500, Carrying = 400 }; var planeTypeRepositoryFake = A.Fake <IPlaneTypeRepository>(); var unitOfWorkFake = A.Fake <IUnitOfWork>(); A.CallTo(() => unitOfWorkFake.Set <PlaneType>()).Returns(planeTypeRepositoryFake); var planeTypeService = new PlaneTypeService(unitOfWorkFake, AlwaysInValidValidator); // Act + Assert var exception = Assert.Throws <BadRequestException>(() => planeTypeService.Create(planeTypeDTOToCreate)); // Assert. Just behaviour A.CallTo(() => planeTypeRepositoryFake.Create(A <PlaneType> ._)).MustNotHaveHappened(); A.CallTo(() => unitOfWorkFake.PlaneTypeRepository).MustNotHaveHappened(); A.CallTo(() => unitOfWorkFake.Set <PlaneType>()).MustNotHaveHappened(); A.CallTo(() => unitOfWorkFake.SaveChanges()).MustNotHaveHappened(); }
public void Create_When_entity_is_invalid_Then_bad_request_exception_is_thrown() { // Arrange var planeTypeMock = new PlaneType() { Id = 2, Model = "AAABBBCCC", Seats = 500, Carrying = 400 }; var planeTypeDTOToCreate = new PlaneTypeDTO() { Model = "AAABBBCCC", Seats = 500, Carrying = 400 }; var planeTypeRepositoryFake = A.Fake <IPlaneTypeRepository>(); A.CallTo(() => planeTypeRepositoryFake.Create(A <PlaneType> ._)).Returns(planeTypeMock); var unitOfWorkFake = A.Fake <IUnitOfWork>(); A.CallTo(() => unitOfWorkFake.Set <PlaneType>()).Returns(planeTypeRepositoryFake); var planeTypeService = new PlaneTypeService(unitOfWorkFake, AlwaysInValidValidator); // Act + Assert var exception = Assert.Throws <BadRequestException>(() => planeTypeService.Create(planeTypeDTOToCreate), ""); Assert.AreEqual(exception.Message, "Is Invalid"); }
public PlaneType() { this.InitializeComponent(); pts = new PlaneTypeService(); list = pts.GetAll().Result; Add.Click += (sender, e) => Create(); }
public PlaneTypesViewModel(INavigationService navigationService) { _planeTypeService = new PlaneTypeService(); _navigationService = navigationService; NewPlaneType = new RelayCommand(New); AddPlaneType = new RelayCommand(Create); UpdatePlaneType = new RelayCommand(Update); DeletePlaneType = new RelayCommand(Delete); LoadPlaneTypes().ConfigureAwait(false); PlaneType = new PlaneType(); }
public PlaneTypesViewModel(INavigationService navigationService) { PlaneTypeservice = new PlaneTypeService(); navService = navigationService; RefreshEntity = new RelayCommand(Refresh); AddEntity = new RelayCommand(Create); UpdateEntity = new RelayCommand(Update); DeleteEntity = new RelayCommand(Delete); LoadEntity().ConfigureAwait(false); PlaneType = new PlaneType(); }
public void Update_When_entity_is_updated_Then_updated_entity_is_returned() { // Arrange var planeTypeMock = new PlaneType() { Id = 3, Model = "AAABBBCCC", Seats = 500, Carrying = 400 }; var planeTypeDTOToUpdate = new PlaneTypeDTO() { Id = 3, Model = "AAABBBCCC", Seats = 500, Carrying = 400 }; var expectedPlaneTypeDTO = new PlaneTypeDTO() { Id = 3, Model = "AAABBBCCC", Seats = 500, Carrying = 400 }; var planeTypeRepositoryFake = A.Fake <IPlaneTypeRepository>(); A.CallTo(() => planeTypeRepositoryFake.Update(A <PlaneType> ._)).Returns(planeTypeMock); var unitOfWorkFake = A.Fake <IUnitOfWork>(); A.CallTo(() => unitOfWorkFake.Set <PlaneType>()).Returns(planeTypeRepositoryFake); var planeTypeService = new PlaneTypeService(unitOfWorkFake, AlwaysValidValidator); // Act var result = planeTypeService.Update(planeTypeDTOToUpdate); // Assert Assert.AreEqual(expectedPlaneTypeDTO.Id, result.Id); Assert.AreEqual(expectedPlaneTypeDTO.Model, result.Model); Assert.AreEqual(expectedPlaneTypeDTO.Seats, result.Seats); Assert.AreEqual(expectedPlaneTypeDTO.Carrying, result.Carrying); }
public void PlaneTypeCreate() { PlaneTypeService planeTypeService = new PlaneTypeService(unitOfWork); PlaneTypeDTO planeTypeDTO = new PlaneTypeDTO() { Model = "test", CarryCapacity = 12, Places = 15 }; planeTypeService.CreatePlaneType(planeTypeDTO); PlaneType planeType = fakePlaneTypeRepository.Get(1); Assert.AreEqual(planeType.Model, planeTypeDTO.Model); Assert.AreEqual(planeType.CarryCapacity, planeTypeDTO.CarryCapacity); Assert.AreEqual(planeType.Places, planeTypeDTO.Places); }
public void UpdateEntity_When_planeType_doesnt_exist_Then_throw_exception() { // Arrange PlaneTypeDTO planeTypeDTO = new PlaneTypeDTO { Id = 1, Carrying = 240000, Model = "Passenger's", Seats = 200 }; var planeTypeRepository = A.Fake <IRepository <PlaneType> >(); A.CallTo(() => planeTypeRepository.Get(A <int> ._)).Returns(null); var planeTypeService = new PlaneTypeService(planeTypeRepository); //Act and Assert Assert.Throws <ValidationException>(() => planeTypeService.UpdateEntity(1, planeTypeDTO)); }
public PlaneTypeLogic() { PlaneTypeService = new PlaneTypeService(); this.InitializeComponent(); }
public PlaneTypeVM() { service = new PlaneTypeService(); Types = new ObservableCollection <PlaneType>(); ListInit(); }