Exemplo n.º 1
0
        [Test] // behaviour
        public void Update_When_entity_is_updated_Then_it_makes_calls_to_repository_and_unit_of_work()
        {
            // 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>();

            A.CallTo(() => unitOfWorkFake.Set <Departure>()).Returns(departureRepositoryFake);
            var departureService = new DepartureService(unitOfWorkFake, AlwaysValidValidator);

            // Act
            var result = departureService.Update(departureDTOToUpdate);

            // Assert
            A.CallTo(() => departureRepositoryFake.Update(A <Departure> ._)).MustHaveHappenedOnceExactly();
            A.CallTo(() => unitOfWorkFake.Set <Departure>()).MustHaveHappenedOnceExactly();
            A.CallTo(() => unitOfWorkFake.SaveChanges()).MustHaveHappenedOnceExactly();
        }
        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);
        }
Exemplo n.º 3
0
        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 void Update_WhenDtoIsEmpty_ThenThrowValidExeption()
        {
            // Arrange
            var id  = default(Guid);
            var dto = new DepartureDto()
            {
            };

            var service = new DepartureService(unitOfWorkFake, mapper, validator);

            // Act

            // Assert
            Assert.Throws <ValidationException>(() => service.Update(id, dto));
        }
Exemplo n.º 5
0
        public async Task Update()
        {
            Departure DepartureUpdated = await DepartureService.Update(Departure, Departure.Id);

            Departure = new Departure();

            List <Departure> tempDepartures = await DepartureService.GetAll();

            Departures = new ObservableCollection <Departure>();
            foreach (var fl in tempDepartures)
            {
                Departures.Add(fl);
            }
            NotifyPropertyChanged(() => Departures);
        }
Exemplo n.º 6
0
        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");
        }
Exemplo n.º 7
0
        [Test] //behavior test
        public void Update_When_entity_is_invalid_Then_it_makes_no_calls_to_repository_and_unit_of_work()
        {
            // 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));

            A.CallTo(() => departureRepositoryFake.Update(A <Departure> ._)).MustNotHaveHappened();
            A.CallTo(() => unitOfWorkFake.DepartureRepository).MustNotHaveHappened();
            A.CallTo(() => unitOfWorkFake.Set <Departure>()).MustNotHaveHappened();
            A.CallTo(() => unitOfWorkFake.SaveChanges()).MustNotHaveHappened();
        }
Exemplo n.º 8
0
        public void Update_When_DepartureModel_is_not_valid_Then_throws_ValidatorException()
        {
            var departure1 = new DepartureDto()
            {
                ID      = -1,
                Date    = DateTime.Now,
                Number  = Guid.NewGuid(),
                CrewId  = 1,
                PlaneId = 1
            };
            var departure2 = new DepartureDto()
            {
                Date    = DateTime.Now,
                Number  = Guid.Empty,
                CrewId  = 1,
                PlaneId = 1
            };
            var departure3 = new DepartureDto()
            {
                Date    = DateTime.Now,
                Number  = Guid.NewGuid(),
                CrewId  = 0,
                PlaneId = 1
            };
            var departure4 = new DepartureDto()
            {
                Date    = DateTime.Now,
                Number  = Guid.NewGuid(),
                PlaneId = 1
            };
            var id = 1;

            Assert.Throws <FluentValidation.ValidationException>(() => service.Update(departure1, id));
            Assert.Throws <FluentValidation.ValidationException>(() => service.Update(departure2, id));
            Assert.Throws <FluentValidation.ValidationException>(() => service.Update(departure3, id));
            Assert.Throws <FluentValidation.ValidationException>(() => service.Update(departure4, id));
        }
 public void Put(int id, [FromBody] DepartureDTO value)
 {
     departureService.Update(id, value);
 }
Exemplo n.º 10
0
        async void Update()
        {
            await Departureservice.Update(Departure);

            await LoadEntity().ConfigureAwait(false);
        }
        async void Update()
        {
            await _departureService.Update(Departure);

            await LoadDepartures().ConfigureAwait(false);
        }
 public void Update_Should_CallRepositoryUpdate_When_Called()
 {
     _departureService.Update(_departureDTO);
     A.CallTo(() => _fakeUnitOfWork.DepartureRepository.Update(_departure, null)).MustHaveHappenedOnceExactly();
 }