public void Get_ExisingId_OkRespose(int idOfVehicle, bool isThere) { _repository.Setup(r => r.Get(5)).Returns(new Vehicle("x", "x", "x")); var result = _unitUnderTest.Get(5); Assert.AreEqual(isThere, typeof(OkObjectResult).IsInstanceOfType(result)); }
public void Get_Nothing_EmptyCollection() { _repoMock.Setup(r => r.GetAll()).Returns((IEnumerable <Car>)null); var items = _unitUnderTest.Get(); CollectionAssert.IsEmpty(items); }
//[Fact] public void GetAllVehicles() { //Arrange var result = valuesController.Get(); //Act string json = JsonConvert.SerializeObject(result); Response response = JsonConvert.DeserializeObject <Response>(json); //Assert Assert.Equal(200, response.StatusCode); }
public async Task GET_All_RETURNS_OK() { // Arrange _mockDataManager.Setup(manager => manager.GetAllAsync()) .ReturnsAsync(GetFakeVehicleLists()); // Act var result = await _controller.Get(); // Assert var vehicles = Assert.IsType <List <VehicleQueryResponse> >(result); Assert.Equal(2, vehicles.Count); }
public void Get_IdIsZero_ReturnNotFound() { var result = vehiclesController.Get(0); // Conrete type Assert.That(result, Is.TypeOf <NotFoundResult>()); // Derrived Assert.That(result, Is.InstanceOf <ActionResult>()); // Concrete type result.Should().BeOfType <NotFoundResult>(); // Derrived }
public async void Get_WithBadId() { // arrange var targetId = Guid.Empty; var errorCodeConverter = new ErrorCodeConverter(); var vehicleServiceMoq = new Mock <IVehicleService>(); vehicleServiceMoq.Setup(x => x.Get(It.IsAny <Guid>())) .ReturnsAsync(() => new Result <Vehicle>(ResultCode.Success, TestVehicle())); var dataStructureConverterMoq = new Mock <IDataStructureConverter>(); var sut = new VehiclesController(vehicleServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.Get(targetId); var badRequestResult = result as BadRequestObjectResult; // assert Assert.NotNull(badRequestResult); }
public async void Get_WhenNotFound() { // arrange var targetId = Guid.NewGuid(); var errorCodeConverter = new ErrorCodeConverter(); var vehicleServiceMoq = new Mock <IVehicleService>(); vehicleServiceMoq.Setup(x => x.Get(It.IsAny <Guid>())) .ReturnsAsync(() => new Result <Vehicle>(ResultCode.NotFound)); var dataStructureConverterMoq = new Mock <IDataStructureConverter>(); var sut = new VehiclesController(vehicleServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.Get(targetId); var notFoundResult = result as NotFoundResult; // assert Assert.Equal(404, notFoundResult.StatusCode); }
public void Should_Get_By_Id_Fail() { var controller = new VehiclesController(vehicleStorage.Object, logger.Object); var result = controller.Get(new Guid()); Assert.False(result != null, "Get By Id Test failed for fail case"); }
public void Should_Get_By_Id() { var controller = new VehiclesController(vehicleStorage.Object, logger.Object); var result = controller.Get(new Guid(id)); Assert.True(result != null, "Get By Id Test failed"); }
public async void Get_ReturnsData() { // arrange var targetId = IdentifierHelper.VehicleId;; var errorCodeConverter = new ErrorCodeConverter(); var vehicleServiceMoq = new Mock <IVehicleService>(); vehicleServiceMoq.Setup(x => x.Get(It.IsAny <Guid>())) .ReturnsAsync(() => new Result <Vehicle>(ResultCode.Success, TestVehicle())); var dataStructureConverterMoq = new Mock <IDataStructureConverter>(); dataStructureConverterMoq.Setup(x => x.ConvertAndMap <VehicleModel, Vehicle>(It.IsAny <string>(), It.IsAny <Vehicle>())) .Returns(new Dictionary <string, object> { { "vehicle", VehicleHelper.Get() } }); var sut = new VehiclesController(vehicleServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.Get(targetId); var okResult = result as OkObjectResult; var response = okResult.Value as Dictionary <string, object>; // assert Assert.NotNull(response.Values); }
public void Get_Test() { quotesProviderMock.Setup(q => q.GetQuoteSubset(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(new List <QuoteSubsetModel>()); var controller = new VehiclesController(quotesProviderMock.Object); var result = controller.Get(); Assert.IsNotNull(result); }
public void Should_Get_All() { var controller = new VehiclesController(vehicleStorage.Object, logger.Object); var result = controller.Get(); Assert.True(result.Count() == 1, "Get All Test failed"); Assert.True(result.FirstOrDefault().Id == new Guid(id), "Get test failed for the items returned"); }
public void TestGetVehicleByClaimAndVin() { string newClaimNumber = TestDataGenerator.GenerateUniqueClaimNumber(); MitchellClaim expectedClaim = TestDataGenerator.GetTestClaim(newClaimNumber); // Create a new claim HttpResponseMessage response = _claimsController.Post(expectedClaim); Assert.AreEqual(HttpStatusCode.Created, response.StatusCode, "A POST of a new claim should succeed."); VehicleDetails vehicleDetails0 = _vehiclesController.Get(newClaimNumber, expectedClaim.Vehicles[0].Vin); Assert.AreEqual(expectedClaim.Vehicles[0], vehicleDetails0, "GET of vehicle[0] of a claim should succeed."); VehicleDetails vehicleDetails1 = _vehiclesController.Get(newClaimNumber, expectedClaim.Vehicles[1].Vin); Assert.AreEqual(expectedClaim.Vehicles[1], vehicleDetails1, "GET of vehicle[1] of a claim should succeed."); }
// TODO: other invalid types if necessary public void GetVehicleWithMalformedVehicleIdResultsInBadRequest(string id) { var mock = new Mock <IVehicleRepositorical>(); var controller = new VehiclesController(mock.Object); var result = controller.Get(id); var actionResult = Assert.IsType <ActionResult <VehicleInfo> >(result); var badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(actionResult.Result); // TODO: Error object }
public void GetVehiclesResultsInOk() { var mock = new Mock <IVehicleRepositorical>(); mock.SetupGet(m => m.Vehicles).Returns(new[] { new Vehicle() }); var controller = new VehiclesController(mock.Object); var result = controller.Get(); var actionResult = Assert.IsType <ActionResult <IEnumerable <VehicleInfo> > >(result); var okResult = Assert.IsType <OkObjectResult>(actionResult.Result); }
public void Get_ShouldReturnNotReturnAnythingVehicles() { VehiclesController vc = new VehiclesController(_vehicle, _cache); var vcs = vc.Get(new VehicleSearchCriteria() { Year = 2017 }).GetAwaiter().GetResult(); Assert.InRange(vcs.Count(), 1, 10); }
public void GetVehicleWithInvalidVehicleIdResultsInNotFound() { var mock = new Mock <IVehicleRepositorical>(); mock.Setup(m => m.FindById(It.IsAny <string>())) .Returns(default(Vehicle)); var controller = new VehiclesController(mock.Object); var result = controller.Get("1"); var actionResult = Assert.IsType <ActionResult <VehicleInfo> >(result); var notFoundResult = Assert.IsType <NotFoundResult>(actionResult.Result); }
public void GetVehiclesResultsInCorrectVehicleCount() { var mock = new Mock <IVehicleRepositorical>(); mock.SetupGet(m => m.Vehicles).Returns(new[] { new Vehicle() }); var controller = new VehiclesController(mock.Object); var result = controller.Get(); var actionResult = Assert.IsType <ActionResult <IEnumerable <VehicleInfo> > >(result); var okResult = Assert.IsType <OkObjectResult>(actionResult.Result); var sequence = Assert.IsAssignableFrom <IEnumerable <VehicleInfo> >(okResult.Value); Assert.Single(sequence); }
public void Post() { // Arrange VehiclesController controller = new VehiclesController(); var vehicle = new Vehicle(1, "bats", "batmobile", 2016); // Act controller.Post(vehicle); var result = controller.Get(vehicle.Id); // Assert Assert.AreEqual(vehicle.Year, result.Year); }
public void GetById() { // Arrange VehiclesController controller = new VehiclesController() { Repository = () => new VehicleFactory().GetRepository(_version) }; // Act var result = controller.Get(10000); // Assert // Assert.AreEqual("value", result); }
public void Get() { // Arrange VehiclesController controller = new VehiclesController() { Repository = () => new VehicleFactory().GetRepository(_version) }; // Act IEnumerable <Vehicle> result = controller.Get(); // Could perform model validation etc . // However most of the testing is done in UTVehicleRespositoryV1 , UTNoSql }
public void GetByYear() { // Arrange VehiclesController controller = new VehiclesController(); var vehicle = new Vehicle(1, "bats", "batmobile", 2016); InMemoryVehicleRepository.Instance.Add(vehicle); // Act var result = controller.Get(year: vehicle.Year); // Assert Assert.AreEqual(vehicle.Id, result.ToList()[0].Id); }
public void Delete() { // Arrange VehiclesController controller = new VehiclesController(); var vehicle = new Vehicle(1, "bats", "batmobile", 2016); InMemoryVehicleRepository.Instance.Add(vehicle); // Act controller.Delete(vehicle.Id); var result = controller.Get(vehicle.Id); //Assert Assert.IsNull(result); }
public void Version10CausesNoException() { var mock = new Mock <IVehicleRepositorical>(); var httpContext = new DefaultHttpContext(); httpContext.Request.Headers["Accept"] = "application/json;v=1.0"; var controller = new VehiclesController(mock.Object) { ControllerContext = new ControllerContext { HttpContext = httpContext } }; var result = controller.Get(); var actionResult = Assert.IsType <ActionResult <IEnumerable <VehicleInfo> > >(result); }
public void Get_NoId_ReturnsVehicles() { mockVehicleRepo.Setup(x => x.GetAllVehicles()).Returns(new List <Vehicle>() { GenerateTestVehicle(1), GenerateTestVehicle(2) }); //mockVehicleRepo.Stub(x => x.GetAllVehicles()).Return(new List<Vehicle>() { GenerateTestCar() }); controller = new VehiclesController(mockVehicleRepo.Object); var result = controller.Get(); Assert.Equal(2, result.Count()); var indexable = result.ToList(); Assert.True(indexable[0].Equals(GenerateTestVehicle(1))); Assert.True(indexable[1].Equals(GenerateTestVehicle(2))); }
public void Put() { // Arrange VehiclesController controller = new VehiclesController(); var vehicle = new Vehicle(1, "bats", "batmobile", 2016); InMemoryVehicleRepository.Instance.Add(vehicle); // Act var updatedVehicle = vehicle.CloneWith(vehicle.Id, year: 2010); controller.Put(updatedVehicle); var result = controller.Get(vehicle.Id); // Assert Assert.AreEqual(updatedVehicle.Year, result.Year); }
public void GetVehicleWithValidVehicleIdResultsInOk() { var mock = new Mock <IVehicleRepositorical>(); mock.Setup(m => m.FindById(It.Is <string>(s => s == "1"))) .Returns(new Vehicle { VehicleIdentifier = "10", ModelIdentifier = "TestName" }); var controller = new VehiclesController(mock.Object); var result = controller.Get("1"); var actionResult = Assert.IsType <ActionResult <VehicleInfo> >(result); var okResult = Assert.IsType <OkObjectResult>(actionResult.Result); var vehicle = Assert.IsType <VehicleInfo>(okResult.Value); Assert.Equal("TestName", vehicle.ModelIdentifier); Assert.Equal("10", vehicle.VehicleIdentifier); }
public void Get() { // Arrange var controller = new VehiclesController(); var vehicle1 = new Vehicle(1, "bats", "batmobile", 2005); var vehicle2 = new Vehicle(2, "Chrysler", "The Green Hornet", 1966); InMemoryVehicleRepository.Instance.Add(vehicle1); InMemoryVehicleRepository.Instance.Add(vehicle2); // Act IEnumerable <Vehicle> result = controller.Get(); // Assert Assert.IsNotNull(result); Assert.AreEqual(2, result.Count()); Assert.AreEqual(vehicle1.Id, result.ElementAt(0).Id); Assert.AreEqual(vehicle2.Id, result.ElementAt(1).Id); }
public void ShouldGet() { var service = new Mock <IVehicleService>(); var controller = new VehiclesController(service.Object); var payload = new VehicleViewModel[] { new VehicleViewModel { Name = "Test Vehicle", EngineId = 1, WheelId = 1 } }; service.Setup(x => x.GetVehicles()).Returns(payload); var result = controller.Get(); Assert.IsType <OkObjectResult>(result); Assert.Equal(((OkObjectResult)result).Value, payload); }