コード例 #1
0
        public void InsertAutomobile_ShouldThrowArgumentExcption_GivenAutoWithDuplicateVIN()
        {
            var expectedAuto = new DieselAutomobile()
            {
                VIN = "5555"
            };

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

            _repo.GetAutomobile(expectedAuto.VIN);
        }
コード例 #2
0
        public void PostAutomobile_ShouldCallRepository_InsertAutomobileWithCorrectVIN()
        {
            var _mockRepo  = new Mock <IDieselAutomobileRepository>();
            var controller = new DieselAutomobileController(_mockRepo.Object);
            var newAuto    = new DieselAutomobile()
            {
                VIN = "123"
            };

            controller.PostAutomobile(newAuto);

            _mockRepo.Verify(m => m.InsertAutomobile(newAuto));
        }
コード例 #3
0
        public void InsertAutomobile(DieselAutomobile 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);
        }
コード例 #4
0
        public void DeleteAutomobile_ShouldDeleteExistingAuto_GivenDifferentCaseOfVin()
        {
            var existingAuto = new DieselAutomobile()
            {
                VIN = "UPPER CASE VIN FOR DELETE"
            };

            _repo.InsertAutomobile(existingAuto);

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

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

            Assert.IsNull(actuaAuto);
        }
コード例 #5
0
        public void DeleteAutomobile_ShouldDeleteExistingAuto()
        {
            var existingAuto = new DieselAutomobile()
            {
                VIN = "vin for deletion"
            };

            _repo.InsertAutomobile(existingAuto);

            _repo.DeleteAutomobile(existingAuto.VIN);

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

            Assert.IsNull(actuaAuto);
        }
コード例 #6
0
        public void GetAutomobiles_ShouldReturn_InsertedAutomobile()
        {
            var expectedAuto = new DieselAutomobile()
            {
                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);
        }
コード例 #7
0
        public void PostAutomobile_ShouldSetLocationHeader()
        {
            var controller   = new DieselAutomobileController(_mockRepo.Object);
            var expectedAuto = new DieselAutomobile()
            {
                VIN = "1"
            };

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

            Assert.IsNotNull(createdResult);
            Assert.AreEqual("DefaultApi", createdResult.RouteName);
            Assert.AreEqual(expectedAuto.VIN, createdResult.RouteValues["id"]);
        }
コード例 #8
0
        public void AutomobileRepository_ShouldRetainListOfAutos_GivenMultipleInstances()
        {
            var expectedAuto = new DieselAutomobile()
            {
                VIN = "1111"
            };

            _repo.InsertAutomobile(expectedAuto);

            var repo2 = new DieselAutomobileRepository();

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

            Assert.IsNotNull(actualAuto);
            Assert.AreEqual(expectedAuto.VIN, actualAuto.VIN);
        }
コード例 #9
0
        public IHttpActionResult PostAutomobile(DieselAutomobile newAuto)
        {
            if (newAuto == null)
            {
                return(BadRequest());
            }
            try
            {
                _repository.InsertAutomobile(newAuto);
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }

            return(CreatedAtRoute("DefaultApi", new { id = newAuto.VIN }, newAuto));
        }
コード例 #10
0
        public void InsertAutomobile_ShouldStoreAutomobile()
        {
            var expectedAuto = new DieselAutomobile()
            {
                VIN = "1234", Odometer = 234, Make = "make it", Model = "model", Year = 1
            };

            _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);
        }
コード例 #11
0
        public void GetAutomobile_ShouldReturnAuto_GivenAutoReturnedFromRepo()
        {
            var vin  = "1";
            var auto = new DieselAutomobile()
            {
                VIN = vin
            };
            var controller = new DieselAutomobileController(_mockRepo.Object);

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

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

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Content);
            Assert.AreEqual(auto, result.Content);
        }
コード例 #12
0
        public void GetAllAutomobiles_ShouldReturnAuto_GivenAutosReturnedFromRepo()
        {
            var vin  = "1";
            var auto = new DieselAutomobile()
            {
                VIN = vin
            };
            var autos = new List <DieselAutomobile>();

            autos.Add(auto);
            var controller = new DieselAutomobileController(_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());
        }