예제 #1
0
        [Test] // behaviour test
        public void Create_When_entity_is_invalid_Then_it_makes_no_calls_to_repository_and_unit_of_work()
        {
            // Arrange
            var pilotDTOToCreate = new PilotDTO()
            {
                FirstName  = "Pilot2",
                LastName   = "Pilot2",
                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, AlwaysInValidValidator);

            // Act + Assert
            var exception = Assert.Throws <BadRequestException>(() => pilotService.Create(pilotDTOToCreate));

            // Assert. Just behaviour
            A.CallTo(() => pilotRepositoryFake.Create(A <Pilot> ._)).MustNotHaveHappened();
            A.CallTo(() => unitOfWorkFake.PilotRepository).MustNotHaveHappened();
            A.CallTo(() => unitOfWorkFake.Set <Pilot>()).MustNotHaveHappened();
            A.CallTo(() => unitOfWorkFake.SaveChanges()).MustNotHaveHappened();
        }
예제 #2
0
        [Test] // behaviour test
        public void Create_When_entity_is_created_Then_it_makes_calls_to_repository_and_unit_of_work()
        {
            // Arrange
            var pilotDTOToCreate = new PilotDTO()
            {
                FirstName  = "Pilot1",
                LastName   = "Pilot1",
                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.Create(pilotDTOToCreate);

            // Assert. Just behaviour
            A.CallTo(() => pilotRepositoryFake.Create(A <Pilot> ._)).MustHaveHappenedOnceExactly();
            A.CallTo(() => unitOfWorkFake.Set <Pilot>()).MustHaveHappenedOnceExactly();
            A.CallTo(() => unitOfWorkFake.SaveChanges()).MustHaveHappenedOnceExactly();
        }
예제 #3
0
        public void Create_When_entity_is_invalid_Then_bad_request_exception_is_thrown()
        {
            // Arrange
            var pilotMock = new Pilot()
            {
                Id         = 2,
                FirstName  = "Pilot2",
                LastName   = "Pilot2",
                BirthDate  = new DateTime(1970, 10, 1),
                Experience = 15
            };

            var pilotDTOToCreate = new PilotDTO()
            {
                FirstName  = "Pilot2",
                LastName   = "Pilot2",
                BirthDate  = new DateTime(1970, 10, 1),
                Experience = 15
            };

            var pilotRepositoryFake = A.Fake <IPilotRepository>();

            A.CallTo(() => pilotRepositoryFake.Create(A <Pilot> ._)).Returns(pilotMock);

            var unitOfWorkFake = A.Fake <IUnitOfWork>();

            A.CallTo(() => unitOfWorkFake.Set <Pilot>()).Returns(pilotRepositoryFake);

            var pilotService = new PilotService(unitOfWorkFake, AlwaysInValidValidator);

            // Act + Assert
            var exception = Assert.Throws <BadRequestException>(() => pilotService.Create(pilotDTOToCreate), "");

            Assert.AreEqual(exception.Message, "Is Invalid");
        }
예제 #4
0
        public async Task Create_WhenPilotNull_ThenReturnExeption()
        {
            var Pilots  = new IFakeRepository <Pilot>();
            var context = new IFakeUnitOfFactory();

            PilotDto PilotDto = null;

            PilotService service       = new PilotService(context);
            PilotDto     PilotDtoSaved = await service.Create(PilotDto);
        }
        public async Task SubmitCreate(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.Create(p);

            this.Frame.Navigate(typeof(Pilots));
        }
예제 #6
0
        public void Create_Pilot_When_get_Then_find()
        {
            var pilotService = new PilotService(unitOfWork, mapper, new PilotValidator());
            var id           = pilotService.Create(new BSA2018_Hometask4.Shared.DTO.PilotDto
            {
                Birthday   = DateTime.Now.AddYears(-30),
                Experience = 3,
                FirstName  = "Oleksii",
                LastName   = "Bogdanovych"
            });

            Assert.AreEqual(id, pilotService.Get(id).ID);
            pilotService.Delete(id);
        }
        public void Create_WhenDtoIsEmpty_ThenThrowValidExeption()
        {
            // Arrange
            var dto = new PilotDto()
            {
            };

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

            // Act

            // Assert
            Assert.Throws <ValidationException>(() => service.Create(dto));
        }
        public void Create_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.Create(pilot1));
            Assert.Throws <FluentValidation.ValidationException>(() => service.Create(pilot2));
            Assert.Throws <FluentValidation.ValidationException>(() => service.Create(pilot3));
            Assert.Throws <FluentValidation.ValidationException>(() => service.Create(pilot4));
        }
예제 #9
0
        public async Task Create()
        {
            Pilot Pilot = await PilotService.Create(this.Pilot);

            Pilot = new Pilot();

            List <Pilot> tempPilots = await PilotService.GetAll();

            Pilots = new ObservableCollection <Pilot>();
            foreach (var item in tempPilots)
            {
                Pilots.Add(item);
            }
            NotifyPropertyChanged(() => Pilots);
        }
예제 #10
0
        public void Create_When_entity_is_created_Then_new_pilot_with_new_id_is_returned()
        {
            // Arrange
            var pilotMock = new Pilot()
            {
                Id         = 1,
                FirstName  = "Pilot1",
                LastName   = "Pilot1",
                BirthDate  = new DateTime(1970, 10, 1),
                Experience = 15
            };

            var pilotDTOToCreate = new PilotDTO()
            {
                FirstName  = "Pilot1",
                LastName   = "Pilot1",
                BirthDate  = new DateTime(1970, 10, 1),
                Experience = 15
            };

            var expectedPilotDTO = new PilotDTO()
            {
                Id         = 1,
                FirstName  = "Pilot1",
                LastName   = "Pilot1",
                BirthDate  = new DateTime(1970, 10, 1),
                Experience = 15
            };
            var pilotRepositoryFake = A.Fake <IPilotRepository>();

            A.CallTo(() => pilotRepositoryFake.Create(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.Create(pilotDTOToCreate);

            // Assert
            Assert.AreEqual(expectedPilotDTO.Id, result.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);
        }
예제 #11
0
        public async Task Create_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.Create(pilotDto);

            Assert.AreEqual(pilotDto.Name, PilotDtoSaved.Name);
            Assert.AreEqual(pilotDto.Id, PilotDtoSaved.Id);
        }
        public void Create_WhenDtoIsPassed_ThenReturnedTheSameWithCreatedId()
        {
            // Arrange
            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.Create(dto);

            // Assert
            Assert.True(returnedDto.Id != default(Guid));
            Assert.AreEqual(dto.FirstName, returnedDto.FirstName);
            Assert.AreEqual(dto.SecondName, returnedDto.SecondName);
            Assert.AreEqual(dto.BirthDate, returnedDto.BirthDate);
            Assert.AreEqual(dto.Experience, returnedDto.Experience);
        }
예제 #13
0
        public async Task Create(Pilot pilot)
        {
            await _service.Create(pilot);

            await UpdateList();
        }
예제 #14
0
        async void Create()
        {
            await Pilotservice.Create(Pilot);

            await LoadEntity().ConfigureAwait(false);
        }
예제 #15
0
        async void Create()
        {
            await _pilotService.Create(Pilot);

            await LoadPilots().ConfigureAwait(false);
        }