Beispiel #1
0
        public void PostPilotTestGoodResult_when_post_correct_then_HttpOK()
        {
            PilotDTO flight = new PilotDTO()
            {
                Name = "Name", Experience = 2, Surname = "Surname"
            };

            Assert.AreEqual(new HttpResponseMessage(HttpStatusCode.OK).StatusCode,
                            _controller.Post(flight).StatusCode);
        }
Beispiel #2
0
        public async Task PilotControllerPostReturnCreatedResult()
        {
            var pilot = new EditablePilotFields
            {
                SecondName = "Test",
                FirstName  = "Tester",
                BirthDate  = new DateTime(2001, 12, 12),
                Experience = 5
            };

            var createdPilot = await _pilotsController.Post(pilot) as CreatedResult;

            Assert.IsNotNull(createdPilot);
            Assert.AreEqual(201, createdPilot.StatusCode);
        }
        public void PUT_WhenPuttNewItem_ThenServiceReturnOkAndThisObject()
        {
            //Arrange
            var pilot = new PilotDto
            {
                Id         = Guid.NewGuid(),
                FirstName  = "FirstName",
                SecondName = "SecondName",
                Experience = 4,
                BirthDate  = new DateTime(1980, 1, 1)
            };

            var fakeService = A.Fake <IPilotService>();

            A.CallTo(() => fakeService.Update(pilot.Id, pilot)).Returns(pilot);

            var controller = new PilotsController(fakeService);

            //Act
            var response = controller.Post(pilot) as ObjectResult;

            //Assert
            Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode);
            Assert.IsInstanceOf(typeof(PilotDto), response.Value);
        }
        public void Post_When_dto_is_null_Then_return_status_code_400()
        {
            var service = A.Fake <IService <PilotDto> >();

            A.CallTo(() => service.Add(A <PilotDto> .That.IsNull())).Throws(new NullBodyException());
            var      controller = new PilotsController(service);
            PilotDto dto        = null;

            var result = controller.Post(dto) as StatusCodeResult;

            Assert.AreEqual(400, result.StatusCode);
        }
        public void Post_When_model_is_valid_Then_return_status_code_200()
        {
            var service = A.Fake <IPilotService>();
            var pilot   = new PilotDto()
            {
                Birthday   = DateTime.Now.AddYears(-30),
                Experience = 3,
                FirstName  = "Alex",
                LastName   = "Zams"
            };

            A.CallTo(() => service.Create(pilot)).Returns(1);
            var controller = new PilotsController(service);

            var result = controller.Post(pilot) as ObjectResult;

            Assert.AreEqual(200, result.StatusCode);
        }
        public void Post_When_model_is_not_valid_Then_return_status_code_404()
        {
            var service = A.Fake <IPilotService>();
            var pilot   = new PilotDto()
            {
                Birthday   = DateTime.Now,
                Experience = 3,
                FirstName  = "Alex",
                LastName   = "Zams"
            };

            A.CallTo(() => service.Create(pilot)).Throws(new FluentValidation.ValidationException(""));
            var controller = new PilotsController(service);

            var result = controller.Post(pilot) as ObjectResult;

            Assert.AreEqual(400, result.StatusCode);
        }
        public void Post_When_dto_is_not_valid_Then_return_status_code_400()
        {
            var service     = A.Fake <IService <PilotDto> >();
            var notValidDto = new PilotDto
            {
                FirstName  = "",
                LastName   = "Alexanrovich",
                Birthdate  = new DateTime(2020, 12, 19),
                Experience = -2
            };

            A.CallTo(() => service.Add(notValidDto)).Throws(new ValidationException(""));
            var controller = new PilotsController(service);
            var dto        = notValidDto;

            var result = controller.Post(dto) as StatusCodeResult;

            Assert.AreEqual(400, result.StatusCode);
        }
        public void Post_When_dto_is_valid_Then_return_status_code_201()
        {
            var service  = A.Fake <IService <PilotDto> >();
            var validDto = new PilotDto
            {
                FirstName  = "Sanya",
                LastName   = "Alexanrovich",
                Birthdate  = new DateTime(1989, 12, 19),
                Experience = 10
            };

            A.CallTo(() => service.Add(validDto)).Returns(1);
            var controller = new PilotsController(service);
            var dto        = validDto;

            var result = controller.Post(dto) as ObjectResult;

            Assert.AreEqual(201, result.StatusCode);
        }