public async Task UpdateSelected(Pilot pilot) { await _service.Update(SelectedItem.Id, pilot); SelectedItem = null; await UpdateList(); }
[Test] // behaviour public void Update_When_entity_is_updated_Then_it_makes_calls_to_repository_and_unit_of_work() { // Arrange var pilotDTOToUpdate = new PilotDTO() { Id = 3, FirstName = "Pilot3", LastName = "Pilot3", BirthDate = new DateTime(1970, 10, 1), Experience = 15 }; var pilotRepositoryFake = A.Fake <IPilotRepository>(); var unitOfWorkFake = A.Fake <IUnitOfWork>(); A.CallTo(() => unitOfWorkFake.Set <Pilot>()).Returns(pilotRepositoryFake); var pilotService = new PilotService(unitOfWorkFake, AlwaysValidValidator); // Act var result = pilotService.Update(pilotDTOToUpdate); // Assert A.CallTo(() => pilotRepositoryFake.Update(A <Pilot> ._)).MustHaveHappenedOnceExactly(); A.CallTo(() => unitOfWorkFake.Set <Pilot>()).MustHaveHappenedOnceExactly(); A.CallTo(() => unitOfWorkFake.SaveChanges()).MustHaveHappenedOnceExactly(); }
public void Update_WhenDtoIsPassed_ThenReturnedTheSameWithPassedId() { // Arrange var id = Guid.NewGuid(); var dto = new PilotDto() { FirstName = "FirstName", SecondName = "SecondName", BirthDate = new DateTime(1980, 1, 1), Experience = 5 }; var service = new PilotService(unitOfWorkFake, mapper, alwaysValidValidator); // Act var returnedDto = service.Update(id, dto); // Assert Assert.True(returnedDto.Id == id); Assert.AreEqual(dto.FirstName, returnedDto.FirstName); Assert.AreEqual(dto.SecondName, returnedDto.SecondName); Assert.AreEqual(dto.BirthDate, returnedDto.BirthDate); Assert.AreEqual(dto.Experience, returnedDto.Experience); }
public async Task UpdateReturnsTrue() { var pilotService = new PilotService(_unitOfWork, _mapper); var result = await pilotService.Update(1, new EditablePilotFields()); Assert.IsTrue(result); }
public async Task UpdateUnExistingEntityReturnsFalse() { var pilotService = new PilotService(_unitOfWork, _mapper); var result = await pilotService.Update(NotExistingPilotId, new EditablePilotFields()); Assert.IsFalse(result); }
public async Task Update_WhenPilotNull_ThenReturnExeption() { var Pilots = new IFakeRepository <Pilot>(); var context = new IFakeUnitOfFactory(); PilotDto PilotDto = null; PilotService service = new PilotService(context); PilotDto PilotDtoSaved = await service.Update(PilotDto); }
public async Task SubmitEdit(int id, string name, string surname, DateTime birth, TimeSpan exp) { Pilot p = new Pilot(); p.Name = name; p.Surname = surname; p.Birth = birth; p.Experience = exp; await ps.Update(id, p); this.Frame.Navigate(typeof(Pilots)); }
public void Update_When_entity_is_updated_Then_updated_entity_is_returned() { // Arrange var pilotMock = new Pilot() { Id = 3, FirstName = "Pilot3", LastName = "Pilot3", BirthDate = new DateTime(1970, 10, 1), Experience = 15 }; var pilotDTOToUpdate = new PilotDTO() { Id = 3, FirstName = "Pilot3", LastName = "Pilot3", BirthDate = new DateTime(1970, 10, 1), Experience = 15 }; var expectedPilotDTO = new PilotDTO() { Id = 3, FirstName = "Pilot3", LastName = "Pilot3", BirthDate = new DateTime(1970, 10, 1), Experience = 15 }; var pilotRepositoryFake = A.Fake <IPilotRepository>(); A.CallTo(() => pilotRepositoryFake.Update(A <Pilot> ._)).Returns(pilotMock); var unitOfWorkFake = A.Fake <IUnitOfWork>(); A.CallTo(() => unitOfWorkFake.Set <Pilot>()).Returns(pilotRepositoryFake); var pilotService = new PilotService(unitOfWorkFake, AlwaysValidValidator); // Act var result = pilotService.Update(pilotDTOToUpdate); // Assert Assert.AreEqual(expectedPilotDTO.Id, result.Id, "Id"); Assert.AreEqual(expectedPilotDTO.FirstName, result.FirstName); Assert.AreEqual(expectedPilotDTO.LastName, result.LastName); Assert.AreEqual(expectedPilotDTO.BirthDate, result.BirthDate); Assert.AreEqual(expectedPilotDTO.Experience, result.Experience); }
public void Update_WhenDtoIsEmpty_ThenThrowValidExeption() { // Arrange var id = default(Guid); var dto = new PilotDto() { }; var service = new PilotService(unitOfWorkFake, mapper, validator); // Act // Assert Assert.Throws <ValidationException>(() => service.Update(id, dto)); }
public async Task Update() { Pilot PilotUpdated = await PilotService.Update(Pilot, Pilot.Id); Pilot = new Pilot(); List <Pilot> tempPilots = await PilotService.GetAll(); Pilots = new ObservableCollection <Pilot>(); foreach (var fl in tempPilots) { Pilots.Add(fl); } NotifyPropertyChanged(() => Pilots); }
public void UpdatePilot_WhenInvalid_ThrowsArgumentNullException() { var pilot = new PilotDTO { Id = 1, LastName = "Ivanov", DateOfBirth = new DateTime(1960, 8, 30), Experience = 9 }; var service = new PilotService(fakeUnitOfWork, mapper); Assert.ThrowsAsync <ArgumentNullException>( () => service.Update(pilot)); }
public void UpdatePilot_WhenNotExistingInBase_ThrowsArgumentNullException() { var pilot = new PilotDTO { Id = 10, LastName = "test_pilot_lastname", DateOfBirth = new DateTime(1990, 8, 30), Experience = 5 }; var service = new PilotService(fakeUnitOfWork, mapper); Assert.ThrowsAsync <ArgumentNullException>( () => service.Update(pilot)); }
public async Task Update_WhenValidPilot_ThenReturnPilot() { var Pilots = new IFakeRepository <Pilot>(); var context = new IFakeUnitOfFactory(); PilotDto PilotDto = new PilotDto() { Id = 154, Name = "Nataly" }; PilotService service = new PilotService(context); PilotDto PilotDtoSaved = await service.Update(PilotDto); Assert.AreEqual(PilotDto.Name, PilotDtoSaved.Name); Assert.AreEqual(PilotDto.Id, PilotDtoSaved.Id); }
public async Task UpdatePilot_WhenValid_UpdatesPilot() { var pilot = new PilotDTO { Id = 1, FirstName = "UpdatedIvan", LastName = "Ivanov", DateOfBirth = new DateTime(1960, 8, 30), Experience = 9 }; var service = new PilotService(fakeUnitOfWork, mapper); await service.Update(pilot); var result = fakeUnitOfWork.PilotRepository.GetAll().Result.FirstOrDefault( x => x.FirstName == "UpdatedIvan"); Assert.IsNotNull(result); }
public void Update_When_entity_is_invalid_Then_bad_request_exception_is_thrown() { // Arrange var pilotDTOToUpdate = new PilotDTO() { Id = 3, FirstName = "Pilot3", LastName = "Pilot3", BirthDate = new DateTime(1970, 10, 1), Experience = 15 }; var pilotRepositoryFake = A.Fake <IPilotRepository>(); var unitOfWorkFake = A.Fake <IUnitOfWork>(); var pilotService = new PilotService(unitOfWorkFake, AlwaysInValidValidator); // Act + Assert var exception = Assert.Throws <BadRequestException>(() => pilotService.Update(pilotDTOToUpdate), ""); Assert.AreEqual(exception.Message, "Is Invalid"); }
private async void Update(object sender, RoutedEventArgs e) { if (ValidatePilot() == false) { MessageDialog showDialog = new MessageDialog("Please check your inputs"); await showDialog.ShowAsync(); } else { var p = new Pilot { Id = PilotData.Id, FirstName = FirstName.Text, LastName = LastName.Text, Experience = Convert.ToInt32(Experience.Text), DateOfBirth = Convert.ToDateTime(DateOfBirth.Text) }; await _pilotService.Update(p); this.Frame.Navigate(typeof(PilotsPage)); } }
[Test] //behavior test public void Update_When_entity_is_invalid_Then_it_makes_no_calls_to_repository_and_unit_of_work() { // Arrange var pilotDTOToUpdate = new PilotDTO() { Id = 3, FirstName = "Pilot3", LastName = "Pilot3", BirthDate = new DateTime(1970, 10, 1), Experience = 15 }; var pilotRepositoryFake = A.Fake <IPilotRepository>(); var unitOfWorkFake = A.Fake <IUnitOfWork>(); var pilotService = new PilotService(unitOfWorkFake, AlwaysInValidValidator); // Act + Assert var exception = Assert.Throws <BadRequestException>(() => pilotService.Update(pilotDTOToUpdate)); A.CallTo(() => pilotRepositoryFake.Update(A <Pilot> ._)).MustNotHaveHappened(); A.CallTo(() => unitOfWorkFake.PilotRepository).MustNotHaveHappened(); A.CallTo(() => unitOfWorkFake.Set <Pilot>()).MustNotHaveHappened(); A.CallTo(() => unitOfWorkFake.SaveChanges()).MustNotHaveHappened(); }
public void Update_When_PilotModel_is_not_valid_Then_throws_ValidatorException() { var pilot1 = new PilotDto() { ID = -1, Birthday = DateTime.Now.AddYears(-30), FirstName = "Alex", LastName = "Zamekula", Experience = 3 }; var pilot2 = new PilotDto() { Birthday = DateTime.Now, FirstName = "Alex", LastName = "Zamekula", Experience = 3 }; var pilot3 = new PilotDto() { Birthday = DateTime.Now.AddYears(-30), FirstName = "Alex", LastName = "Zamekula", Experience = 1 }; var pilot4 = new PilotDto() { Birthday = DateTime.Now.AddYears(-30), LastName = "Zamekula", Experience = 4 }; Assert.Throws <FluentValidation.ValidationException>(() => service.Update(pilot1, 1)); Assert.Throws <FluentValidation.ValidationException>(() => service.Update(pilot2, 1)); Assert.Throws <FluentValidation.ValidationException>(() => service.Update(pilot3, 1)); Assert.Throws <FluentValidation.ValidationException>(() => service.Update(pilot4, 1)); }
public void Update_Should_CallRepositoryUpdate_When_Called() { _pilotService.Update(_pilotDTO); A.CallTo(() => _fakeUnitOfWork.Set <Pilot>().Update(A <Pilot> .That.IsInstanceOf(typeof(Pilot)), null)).MustHaveHappenedOnceExactly(); }
async void Update() { await _pilotService.Update(Pilot); await LoadPilots().ConfigureAwait(false); }
async void Update() { await Pilotservice.Update(Pilot); await LoadEntity().ConfigureAwait(false); }