public void InsertAutomobile_ShouldThrowArgumentExcption_GivenAutoWithDuplicateVIN()
        {
            var expectedAuto = new GasAutomobile()
            {
                VIN = "5555"
            };

            _repo.InsertAutomobile(expectedAuto);
            _repo.InsertAutomobile(expectedAuto);

            _repo.GetAutomobile(expectedAuto.VIN);
        }
Пример #2
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));
        }
Пример #3
0
        public void InsertAutomobile(GasAutomobile auto)
        {
            if (auto == null || string.IsNullOrWhiteSpace(auto.VIN))
            {
                throw new ArgumentException("Invalid auto, either auto is null or invalid VIN");
            }
            var existingAuto = GetAutomobile(auto.VIN);

            if (existingAuto != null)
            {
                throw new ArgumentException("Duplicate VIN is not allowed");
            }
            _storedAutos.Add(auto);
        }
        public void DeleteAutomobile_ShouldDeleteExistingAuto_GivenDifferentCaseOfVin()
        {
            var existingAuto = new GasAutomobile()
            {
                VIN = "UPPER CASE VIN FOR DELETE"
            };

            _repo.InsertAutomobile(existingAuto);

            _repo.DeleteAutomobile(existingAuto.VIN.ToLower());

            var actuaAuto = _repo.GetAutomobile(existingAuto.VIN);

            Assert.IsNull(actuaAuto);
        }
        public void DeleteAutomobile_ShouldDeleteExistingAuto()
        {
            var existingAuto = new GasAutomobile()
            {
                VIN = "vin for deletion"
            };

            _repo.InsertAutomobile(existingAuto);

            _repo.DeleteAutomobile(existingAuto.VIN);

            var actuaAuto = _repo.GetAutomobile(existingAuto.VIN);

            Assert.IsNull(actuaAuto);
        }
        public void GetAutomobiles_ShouldReturn_InsertedAutomobile()
        {
            var expectedAuto = new GasAutomobile()
            {
                VIN = "9911"
            };

            _repo.InsertAutomobile(expectedAuto);

            var autos      = _repo.GetAutomobiles();
            var actualAuto = autos.FirstOrDefault(a => a.VIN == expectedAuto.VIN);

            Assert.IsNotNull(actualAuto);
            Assert.AreEqual(expectedAuto.VIN, actualAuto.VIN);
        }
 public IHttpActionResult PostAutomobile(GasAutomobile newAuto)
 {
     if (newAuto == null)
     {
         return(BadRequest());
     }
     try
     {
         _repository.InsertAutomobile(newAuto);
     }
     catch (Exception e)
     {
         return(InternalServerError(e));
     }
     return(Content(HttpStatusCode.Accepted, newAuto));
 }
        public void GasAutomobileRepository_ShouldRetainListOfAutos_GivenMultipleInstances()
        {
            var expectedAuto = new GasAutomobile()
            {
                VIN = "1111"
            };

            _repo.InsertAutomobile(expectedAuto);

            var repo2 = new GasAutomobileRepository();

            var actualAuto = repo2.GetAutomobile(expectedAuto.VIN);

            Assert.IsNotNull(actualAuto);
            Assert.AreEqual(expectedAuto.VIN, actualAuto.VIN);
        }
Пример #9
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);
        }
Пример #10
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);
        }
        public void InsertAutomobile_ShouldStoreAutomobile()
        {
            var expectedAuto = new GasAutomobile()
            {
                VIN = "1234", Odometer = 234, Make = "make it", Model = "model", Year = 1, NumberOfSparkPlugs = 8
            };

            _repo.InsertAutomobile(expectedAuto);

            var actualAuto = _repo.GetAutomobile(expectedAuto.VIN);

            Assert.IsNotNull(actualAuto);
            Assert.AreEqual(expectedAuto.VIN, actualAuto.VIN);
            Assert.AreEqual(expectedAuto.Odometer, actualAuto.Odometer);
            Assert.AreEqual(expectedAuto.Make, actualAuto.Make);
            Assert.AreEqual(expectedAuto.Model, actualAuto.Model);
            Assert.AreEqual(expectedAuto.Year, actualAuto.Year);
            Assert.AreEqual(expectedAuto.NumberOfSparkPlugs, actualAuto.NumberOfSparkPlugs);
        }
Пример #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());
        }