Esempio n. 1
0
        public void GetAllAutomobiles_ShouldCallRepositoryGetAutomobiles()
        {
            var controller = new GasAutomobileController(_mockRepo.Object);

            controller.GetAllAutomobiles();

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

            var actionResult = controller.DeleteAutomobile(vin);

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

            controller.DeleteAutomobile(vin);

            _mockRepo.Verify(m => m.DeleteAutomobile(vin));
        }
Esempio n. 4
0
        public void GetAutomobile_ShouldCallRepository_GetAutomobileWithCorrectVIN()
        {
            var _mockRepo  = new Mock <IGasAutomobileRepository>();
            var controller = new GasAutomobileController(_mockRepo.Object);
            var VIN        = "123";

            controller.GetAutomobile(VIN);

            _mockRepo.Verify(m => m.GetAutomobile(VIN));
        }
Esempio n. 5
0
        public void DeleteAutomobile_ShouldReturnExceptionRequest_GivenRepositoryThrows()
        {
            var controller = new GasAutomobileController(_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));
        }
Esempio n. 6
0
        public void PostAutomobile_ShouldReturnBadRequest_GivenNull()
        {
            var controller = new GasAutomobileController(_mockRepo.Object);

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

            IHttpActionResult result = controller.PostAutomobile(null);

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

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

            var result = controller.GetAllAutomobiles();

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

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

            IHttpActionResult result = controller.GetAutomobile(vin);

            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }
Esempio n. 9
0
        public void PostAutomobile_ShouldCallRepository_InsertAutomobileWithCorrectVIN()
        {
            var _mockRepo  = new Mock <IGasAutomobileRepository>();
            var controller = new GasAutomobileController(_mockRepo.Object);
            var newAuto    = new GasAutomobile()
            {
                VIN = "123"
            };

            controller.PostAutomobile(newAuto);

            _mockRepo.Verify(m => m.InsertAutomobile(newAuto));
        }
Esempio n. 10
0
        public void PostAutomobile_ShouldReturnContentResult_GivenAutoSaved()
        {
            var expectedAuto = new GasAutomobile()
            {
                VIN = "1"
            };
            var controller = new GasAutomobileController(_mockRepo.Object);

            IHttpActionResult actionResult = controller.PostAutomobile(expectedAuto);
            var result = actionResult as NegotiatedContentResult <GasAutomobile>;

            Assert.IsNotNull(result);
            Assert.AreEqual(HttpStatusCode.Accepted, result.StatusCode);
            Assert.IsNotNull(result.Content);
            Assert.AreEqual(expectedAuto.VIN, result.Content.VIN);
        }
Esempio n. 11
0
        public void GetAutomobile_ShouldReturnAuto_GivenAutoReturnedFromRepo()
        {
            var vin  = "1";
            var auto = new GasAutomobile()
            {
                VIN = vin
            };
            var controller = new GasAutomobileController(_mockRepo.Object);

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

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

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Content);
            Assert.AreEqual(auto, result.Content);
        }
Esempio n. 12
0
        public void GetAllAutomobiles_ShouldReturnTask_GivenAutosReturnedFromRepo()
        {
            var vin  = "1";
            var auto = new GasAutomobile()
            {
                VIN = vin
            };
            var tasks = new List <GasAutomobile>();

            tasks.Add(auto);
            var controller = new GasAutomobileController(_mockRepo.Object);

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

            var result = controller.GetAllAutomobiles();

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