Exemplo n.º 1
0
        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");
        }
Exemplo n.º 2
0
        [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();
        }
Exemplo n.º 3
0
        [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 Create_WhenDtoIsPassed_ThenReturnedTheSameWithCreatedId()
        {
            // Arrange
            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.Create(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 void Create_WhenDtoIsEmpty_ThenThrowValidExeption()
        {
            // Arrange
            var dto = new DepartureDto()
            {
            };

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

            // Act

            // Assert
            Assert.Throws <ValidationException>(() => service.Create(dto));
        }
Exemplo n.º 6
0
        public void Create_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
            };

            Assert.Throws <FluentValidation.ValidationException>(() => service.Create(departure1));
            Assert.Throws <FluentValidation.ValidationException>(() => service.Create(departure2));
            Assert.Throws <FluentValidation.ValidationException>(() => service.Create(departure3));
            Assert.Throws <FluentValidation.ValidationException>(() => service.Create(departure4));
        }
Exemplo n.º 7
0
        public async Task Create()
        {
            Departure Departure = await DepartureService.Create(this.Departure);

            Departure = new Departure();

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

            Departures = new ObservableCollection <Departure>();
            foreach (var item in tempDepartures)
            {
                Departures.Add(item);
            }
            NotifyPropertyChanged(() => Departures);
        }
Exemplo n.º 8
0
        public void Create_When_entity_is_created_Then_new_Departure_with_new_id_is_returned()
        {
            // Arrange
            var departureMock = new Departure()
            {
                Id       = 1,
                Date     = new DateTime(2018, 10, 1),
                FlightId = 1,
                PlaneId  = 1,
                CrewId   = 1
            };

            var departureDTOToCreate = new DepartureDTO()
            {
                Date     = new DateTime(2018, 10, 1),
                FlightId = 1,
                PlaneId  = 1,
                CrewId   = 1
            };

            var expectedDepartureDTO = new DepartureDTO()
            {
                Id       = 1,
                Date     = new DateTime(2018, 10, 1),
                FlightId = 1,
                PlaneId  = 1,
                CrewId   = 1
            };
            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, AlwaysValidValidator);

            // Act
            var result = departureService.Create(departureDTOToCreate);

            // Assert
            Assert.AreEqual(expectedDepartureDTO.Id, result.Id);
            Assert.AreEqual(expectedDepartureDTO.Date, result.Date);
            Assert.AreEqual(expectedDepartureDTO.FlightId, result.FlightId);
            Assert.AreEqual(expectedDepartureDTO.PlaneId, result.PlaneId);
            Assert.AreEqual(expectedDepartureDTO.CrewId, result.CrewId);
        }
 public void Post([FromBody] DepartureDTO value)
 {
     departureService.Create(value);
 }
Exemplo n.º 10
0
        async void Create()
        {
            await Departureservice.Create(Departure);

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

            await LoadDepartures().ConfigureAwait(false);
        }