コード例 #1
0
        public async Task PostPilot_WhenValid_ReturnsOkObjectResult()
        {
            MockService();
            controller = new PilotController(service.Object);
            var result = await controller.Create(pilots[0]) as OkObjectResult;

            Assert.IsInstanceOf <OkObjectResult>(result);
            Assert.IsTrue(result.StatusCode == 200);
        }
コード例 #2
0
        public async Task CreateShouldReturnCreatedID()
        {
            var newPilot = new Pilot {
                ID = 1
            };
            var newPilotCreate = new PilotCreate {
                ProducerID = 1
            };

            _aviMock.Setup(x => x.AddPilot(It.IsAny <Pilot>())).Returns(newPilot);
            var newAviqtorBL = new PilotController(_aviMock.Object);
            var result       = newAviqtorBL.Create(newPilotCreate);

            Assert.IsAssignableFrom <CreatedID>(result);
            Assert.Equal(result.ID, newPilotCreate.ProducerID);
            _aviMock.Verify(x => x.AddPilot(It.IsAny <Pilot>()));
        }
コード例 #3
0
        public async Task PostPilot_WhenInvalid_ReturnsBadRequestResult()
        {
            service = new Mock <IService <PilotDTO> >();
            service.Setup(x => x.Add(It.IsAny <PilotDTO>())).Throws <ArgumentNullException>();

            var invalidPilot = new PilotDTO
            {
                FirstName   = "No last name pilot",
                Experience  = 5,
                DateOfBirth = new DateTime(1960, 8, 30)
            };

            controller = new PilotController(service.Object);
            var result = await controller.Create(invalidPilot);

            Assert.IsInstanceOf <BadRequestResult>(result);
            Assert.IsTrue((result as BadRequestResult).StatusCode == 400);
        }