Ejemplo n.º 1
0
        public async Task When_NotFindCar_Then_ReturnBadRequest()
        {
            var carService = new Mock <ICarService>(MockBehavior.Strict);

            carService.Setup(p => p.GetCar(0)).Returns(Task.FromResult <Car>(null));

            WC.CarController carController = new WC.CarController(carService.Object);
            var result = await carController.GetCar(0);

            Assert.That(result, Is.TypeOf <BadRequestResult>());

            carService.VerifyAll();
        }
Ejemplo n.º 2
0
        public async Task When_FindAllCard_Then_ReturnAllExistingCars()
        {
            var carService = new Mock <ICarService>(MockBehavior.Strict);

            carService.Setup(p => p.GetCars()).Returns(Task.FromResult <IList <Car> >(new List <Car>()));

            WC.CarController carController = new WC.CarController(carService.Object);
            var result = await carController.GetCars();

            Assert.That(result, Is.TypeOf <OkObjectResult>());
            Assert.AreEqual((((result as OkObjectResult)?.Value as IList <Car>).Count), 0);
            carService.VerifyAll();
        }
Ejemplo n.º 3
0
        public async Task When_ModelStateIsNotValid_Then_ReturnBadRequest()
        {
            var carService = new Mock <ICarService>(MockBehavior.Strict);
            var carExample = new Car()
            {
                PlateNumber = "123"
            };

            WC.CarController carController = new WC.CarController(carService.Object);
            carController.ModelState.AddModelError("car", "Car not valid");

            var result = await carController.AddCar(carExample);

            Assert.That(result, Is.TypeOf <BadRequestResult>());
            carService.VerifyAll();
        }
Ejemplo n.º 4
0
        public async Task When_FindCar_Then_ReturnOkWithObiect()
        {
            var retCar = new Car()
            {
                Id = 1,
            };

            var carService = new Mock <ICarService>(MockBehavior.Strict);

            carService.Setup(p => p.GetCar(1)).Returns(Task.FromResult <Car>(retCar));

            WC.CarController carController = new WC.CarController(carService.Object);
            var result = await carController.GetCar(1);

            Assert.That(result, Is.TypeOf <OkObjectResult>());
            Assert.AreEqual((((result as OkObjectResult)?.Value as Car)?.Id ?? 0), 1);
            carService.VerifyAll();
        }
Ejemplo n.º 5
0
        public async Task When_ModelStateIsValid_Then_ReturnCreatedObject()
        {
            var carService = new Mock <ICarService>(MockBehavior.Strict);
            var carExample = new Car()
            {
                PlateNumber = "123"
            };

            carService.Setup(p => p.AddCar(carExample)).Returns(Task.FromResult <Car>(carExample));

            WC.CarController carController = new WC.CarController(carService.Object);

            var result = await carController.AddCar(carExample);

            Assert.That(result, Is.TypeOf <OkObjectResult>());
            Assert.AreEqual((((result as OkObjectResult)?.Value as Car)?.PlateNumber ?? "123"), carExample.PlateNumber);
            carService.VerifyAll();
        }
Ejemplo n.º 6
0
        public void When_RunWithoutService_Then_GetNullReferenceException()
        {
            var controller = new WC.CarController(null);

            Assert.That(async() => await controller.GetCar(0), Throws.TypeOf <NullReferenceException>());
        }