Ejemplo n.º 1
0
        public void GetAllAutomobiles_ShouldCallRepositoryGetAutomobiles()
        {
            var controller = new ElectricAutomobileController(_mockRepo.Object);

            controller.GetAllAutomobiles();

            _mockRepo.Verify(m => m.GetAutomobiles());
        }
Ejemplo n.º 2
0
        public void DeleteAutomobile_ShouldReturnCorrectResult_GivenDeleteDoesNotThrow()
        {
            var controller = new ElectricAutomobileController(_mockRepo.Object);
            var vin        = "1";

            var actionResult = controller.DeleteAutomobile(vin);

            Assert.IsInstanceOfType(actionResult, typeof(OkResult));
        }
Ejemplo n.º 3
0
        public void DeleteAutomobile_ShouldCallRepository_GivenAutoWithCorrectVIN()
        {
            var controller = new ElectricAutomobileController(_mockRepo.Object);
            var vin        = "1";

            controller.DeleteAutomobile(vin);

            _mockRepo.Verify(m => m.DeleteAutomobile(vin));
        }
Ejemplo n.º 4
0
        public void GetAutomobile_ShouldCallRepository_GetAutomobileWithCorrectVin()
        {
            var _mockRepo  = new Mock <IElectricAutomobileRepository>();
            var controller = new ElectricAutomobileController(_mockRepo.Object);
            var vin        = "1";

            controller.GetAutomobile(vin);

            _mockRepo.Verify(m => m.GetAutomobile(vin));
        }
Ejemplo n.º 5
0
        public void DeleteAutomobile_ShouldReturnExceptionRequest_GivenRepositoryThrows()
        {
            var controller = new ElectricAutomobileController(_mockRepo.Object);

            _mockRepo.Setup(a => a.DeleteAutomobile(It.IsAny <string>())).Throws(new Exception("boom"));

            IHttpActionResult result = controller.DeleteAutomobile("bad news");

            Assert.IsInstanceOfType(result, typeof(ExceptionResult));
        }
Ejemplo n.º 6
0
        public void PostAutomobile_ShouldReturnBadRequest_GivenNull()
        {
            var controller = new ElectricAutomobileController(_mockRepo.Object);

            _mockRepo.Setup(a => a.InsertAutomobile(It.IsAny <ElectricAutomobile>())).Throws(new Exception("should not be called"));

            IHttpActionResult result = controller.PostAutomobile(null);

            Assert.IsInstanceOfType(result, typeof(BadRequestResult));
        }
Ejemplo n.º 7
0
        public void GetAllAutomobiles_ShouldReturnEmptyList_GivenNoAutosReturnedFromRepo()
        {
            var controller = new ElectricAutomobileController(_mockRepo.Object);

            _mockRepo.Setup(m => m.GetAutomobiles()).Returns((List <ElectricAutomobile>)null);

            var result = controller.GetAllAutomobiles();

            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Count());
        }
Ejemplo n.º 8
0
        public void GetAutomobile_ShouldReturnNotFound_GivenNoAutoReturnedFromRepo()
        {
            var controller = new ElectricAutomobileController(_mockRepo.Object);
            var vin        = "1";

            _mockRepo.Setup(m => m.GetAutomobile(vin)).Returns((ElectricAutomobile)null);

            IHttpActionResult result = controller.GetAutomobile(vin);

            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }
Ejemplo n.º 9
0
        public void PostAutomobile_ShouldCallRepository_InsertAutomobileWithCorrectVIN()
        {
            var _mockRepo  = new Mock <IElectricAutomobileRepository>();
            var controller = new ElectricAutomobileController(_mockRepo.Object);
            var newAuto    = new ElectricAutomobile()
            {
                VIN = "123"
            };

            controller.PostAutomobile(newAuto);

            _mockRepo.Verify(m => m.InsertAutomobile(newAuto));
        }
Ejemplo n.º 10
0
        public void PostAutomobile_ShouldSetLocationHeader()
        {
            var controller   = new ElectricAutomobileController(_mockRepo.Object);
            var expectedAuto = new ElectricAutomobile()
            {
                VIN = "1"
            };

            IHttpActionResult actionResult = controller.PostAutomobile(expectedAuto);
            var createdResult = actionResult as CreatedAtRouteNegotiatedContentResult <ElectricAutomobile>;

            Assert.IsNotNull(createdResult);
            Assert.AreEqual("DefaultApi", createdResult.RouteName);
            Assert.AreEqual(expectedAuto.VIN, createdResult.RouteValues["id"]);
        }
Ejemplo n.º 11
0
        public void GetAutomobile_ShouldReturnAuto_GivenAutoReturnedFromRepo()
        {
            var vin  = "1";
            var auto = new ElectricAutomobile()
            {
                VIN = vin
            };
            var controller = new ElectricAutomobileController(_mockRepo.Object);

            _mockRepo.Setup(m => m.GetAutomobile(vin)).Returns(auto);

            IHttpActionResult actionResult = controller.GetAutomobile(vin);
            var result = actionResult as OkNegotiatedContentResult <ElectricAutomobile>;

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Content);
            Assert.AreEqual(auto, result.Content);
        }
Ejemplo n.º 12
0
        public void GetAllAutomobiles_ShouldReturnAuto_GivenAutosReturnedFromRepo()
        {
            var vin  = "1";
            var auto = new ElectricAutomobile()
            {
                VIN = vin
            };
            var autos = new List <ElectricAutomobile>();

            autos.Add(auto);
            var controller = new ElectricAutomobileController(_mockRepo.Object);

            _mockRepo.Setup(m => m.GetAutomobiles()).Returns(autos);

            var result = controller.GetAllAutomobiles();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(auto, result.First());
        }