예제 #1
0
        public async Task Create(CrewDTO crewDto)
        {
            Pilot      pilot;
            Stewardess stewardess;

            try
            {
                pilot = await _pilotService.Get(crewDto.PilotId);

                stewardess = await _stewardessService.Get(crewDto.StewardessId);
            }
            catch (System.Exception)
            {
                return;
            }
            pilot.Id      = 0;
            stewardess.Id = 0;

            Crew crew = new Crew
            {
                Pilot        = pilot,
                Stewardesses = new List <Stewardess>
                {
                    stewardess
                }
            };

            await _service.Create(crew);

            await UpdateList();
        }
예제 #2
0
        [Test] // behaviour test
        public void Create_When_entity_is_invalid_Then_it_makes_no_calls_to_repository_and_unit_of_work()
        {
            // Arrange
            var crewDTOToCreate = new CrewDTO()
            {
                PilotId = 2
            };

            var crewRepositoryFake = A.Fake <ICrewRepository>();

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

            A.CallTo(() => unitOfWorkFake.Set <Crew>()).Returns(crewRepositoryFake);

            var crewService = new CrewService(unitOfWorkFake, AlwaysInValidValidator);

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

            // Assert. Just behaviour
            A.CallTo(() => crewRepositoryFake.Create(A <Crew> ._)).MustNotHaveHappened();
            A.CallTo(() => unitOfWorkFake.CrewRepository).MustNotHaveHappened();
            A.CallTo(() => unitOfWorkFake.Set <Crew>()).MustNotHaveHappened();
            A.CallTo(() => unitOfWorkFake.SaveChanges()).MustNotHaveHappened();
        }
예제 #3
0
        public void Create_When_entity_is_invalid_Then_bad_request_exception_is_thrown()
        {
            // Arrange
            var crewMock = new Crew()
            {
                Id      = 2,
                PilotId = 2
            };

            var crewDTOToCreate = new CrewDTO()
            {
                PilotId = 2
            };

            var crewRepositoryFake = A.Fake <ICrewRepository>();

            A.CallTo(() => crewRepositoryFake.Create(A <Crew> ._)).Returns(crewMock);

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

            A.CallTo(() => unitOfWorkFake.Set <Crew>()).Returns(crewRepositoryFake);

            var crewService = new CrewService(unitOfWorkFake, AlwaysInValidValidator);

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

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

            CrewDto CrewDto = null;

            CrewService service      = new CrewService(context);
            CrewDto     CrewDtoSaved = await service.Create(CrewDto);
        }
예제 #5
0
        public async Task SubmitCreate(int pilot, string st1, string st2)
        {
            InputCrew inputCrew = new InputCrew();

            inputCrew.PilotId = pilot;
            int[] stews = { Convert.ToInt32(st1), Convert.ToInt32(st2) };
            inputCrew.StewardessIds = stews;

            await cs.Create(inputCrew);

            this.Frame.Navigate(typeof(Crews));
        }
예제 #6
0
        public void Create_WhenDtoIsEmpty_ThenThrowValidExeption()
        {
            // Arrange
            var dto = new CrewDto()
            {
            };

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

            // Act

            // Assert
            Assert.Throws <ValidationException>(() => service.Create(dto));
        }
예제 #7
0
        public void Create_When_CrewModel_is_not_valid_Then_throws_ValidatorException()
        {
            var crew1 = new CrewDto()
            {
                Pilot      = 0,
                Stewadress = new List <int>()
                {
                    1
                }
            };
            var crew2 = new CrewDto()
            {
                Pilot      = 1,
                Stewadress = new List <int>()
                {
                    0
                }
            };
            var crew3 = new CrewDto()
            {
                Pilot = 1
            };
            var crew4 = new CrewDto()
            {
                ID         = -1,
                Pilot      = 1,
                Stewadress = new List <int>()
                {
                    1
                }
            };

            Assert.Throws <FluentValidation.ValidationException>(() => service.Create(crew1));
            Assert.Throws <FluentValidation.ValidationException>(() => service.Create(crew2));
            Assert.Throws <FluentValidation.ValidationException>(() => service.Create(crew3));
            Assert.Throws <FluentValidation.ValidationException>(() => service.Create(crew4));
        }
예제 #8
0
        public async Task Create()
        {
            Crew Crew = await CrewService.Create(this.Crew);

            Crew = new Crew();

            List <Crew> tempCrews = await CrewService.GetAll();

            Crews = new ObservableCollection <Crew>();
            foreach (var item in tempCrews)
            {
                Crews.Add(item);
            }
            NotifyPropertyChanged(() => Crews);
        }
예제 #9
0
        public void Delete_Crew_When_search_by_id_Then_throws_NullReferenceException()
        {
            var crewService = new CrewService(unitOfWork, mapper, new CrewValidator());

            var id = crewService.Create(new CrewDto()
            {
                Pilot      = 1,
                Stewadress = new List <int>()
                {
                    1
                }
            });

            crewService.Delete(id);
            Assert.Throws <NullReferenceException>(() => crewService.Get(id));
        }
예제 #10
0
        public async Task Create_WhenValidCrew_ThenReturnCrew()
        {
            var Crews   = new IFakeRepository <Crew>();
            var context = new IFakeUnitOfFactory();

            CrewDto CrewDto = new CrewDto()
            {
                Id      = 154,
                PilotId = 5
            };

            CrewService service      = new CrewService(context);
            CrewDto     CrewDtoSaved = await service.Create(CrewDto);

            Assert.AreEqual(CrewDto.PilotId, CrewDtoSaved.PilotId);
            Assert.AreEqual(CrewDto.Id, CrewDtoSaved.Id);
        }
예제 #11
0
        public void Create_WhenDtoIsPassed_ThenReturnedTheSameWithCreatedId()
        {
            // Arrange
            var pilotId        = Guid.NewGuid();
            var stewardessesId = new List <Guid> {
                Guid.NewGuid()
            };

            var dto = new CrewDto()
            {
                PilotId        = pilotId,
                StewardessesId = stewardessesId
            };

            A.CallTo(() => unitOfWorkFake.PilotRepositiry.Get(pilotId)).Returns(new Pilot {
                Id = pilotId
            });

            A.CallTo(() => unitOfWorkFake.StewardessRepositiry.GetAll())
            .Returns(new List <Stewardess> {
                new Stewardess {
                    Id = stewardessesId[0]
                }
            });

            var service = new CrewService(unitOfWorkFake, mapper, alwaysValidValidator);

            // Act
            var returnedDto = service.Create(dto);

            // Assert
            Assert.True(returnedDto.Id != default(Guid));
            Assert.AreEqual(dto.PilotId, returnedDto.PilotId);
            Assert.AreEqual(dto.StewardessesId.Count, returnedDto.StewardessesId.Count);

            foreach (var item in dto.StewardessesId)
            {
                Assert.Contains(item, returnedDto.StewardessesId);
            }
        }
예제 #12
0
        [Test] // behaviour test
        public void Create_When_entity_is_created_Then_it_makes_calls_to_repository_and_unit_of_work()
        {
            // Arrange
            var crewDTOToCreate = new CrewDTO()
            {
                PilotId = 1
            };

            var crewRepositoryFake = A.Fake <ICrewRepository>();

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

            A.CallTo(() => unitOfWorkFake.Set <Crew>()).Returns(crewRepositoryFake);

            var crewService = new CrewService(unitOfWorkFake, AlwaysValidValidator);

            // Act
            var result = crewService.Create(crewDTOToCreate);

            // Assert. Just behaviour
            A.CallTo(() => crewRepositoryFake.Create(A <Crew> ._)).MustHaveHappenedOnceExactly();
            A.CallTo(() => unitOfWorkFake.Set <Crew>()).MustHaveHappenedOnceExactly();
            A.CallTo(() => unitOfWorkFake.SaveChanges()).MustHaveHappenedOnceExactly();
        }
예제 #13
0
        public void Create_When_entity_is_created_Then_new_Crew_with_new_id_is_returned()
        {
            // Arrange
            var crewMock = new Crew()
            {
                Id      = 1,
                PilotId = 1
            };

            var crewDTOToCreate = new CrewDTO()
            {
                PilotId = 1
            };

            var expectedCrewDTO = new CrewDTO()
            {
                Id      = 1,
                PilotId = 1
            };
            var crewRepositoryFake = A.Fake <ICrewRepository>();

            A.CallTo(() => crewRepositoryFake.Create(A <Crew> ._)).Returns(crewMock);

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

            A.CallTo(() => unitOfWorkFake.Set <Crew>()).Returns(crewRepositoryFake);

            var crewService = new CrewService(unitOfWorkFake, AlwaysValidValidator);

            // Act
            var result = crewService.Create(crewDTOToCreate);

            // Assert
            Assert.AreEqual(expectedCrewDTO.Id, result.Id);
            Assert.AreEqual(expectedCrewDTO.PilotId, result.PilotId);
        }
예제 #14
0
        async void Create()
        {
            await Crewservice.Create(Crew);

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

            await LoadCrews().ConfigureAwait(false);
        }