public void DeleteWithInvalidId() { var mockRepositorycar = new Mock <IAdvertiseCarDetailsService>(); // Arrange AdvertisedCarController controller = new AdvertisedCarController(mockRepositorycar.Object, _ownerValidationService, _logger); controller.Request = new HttpRequestMessage(); controller.Configuration = new HttpConfiguration(); var response = controller.Delete(0); HttpError succesful; Assert.IsTrue(response.TryGetContentValue <HttpError>(out succesful)); Assert.AreEqual(System.Net.HttpStatusCode.BadRequest, response.StatusCode); }
public void Post() { int carID = 1; // bool yes = true; var mockRepositorycar = new Mock <IAdvertiseCarDetailsService>(); var carDetailObject = new AdvertisedCarDetailsDTO { CarDetails = new AdvertisedCarDTO { ID = 1, Year = "2017", Make = "sample string 3", Model = "sample string 4", AdvertisedPriceType = "eCg", ECGAmount = 6.0m, DAPAmount = 7.0m, AdvertisedAmount = 8.0m, }, OwnerDetails = new OwnerDTO { Id = 1, Name = "", PhoneNumber = "", Email = "", DealerABN = "fgds", OwnerType = "D", Comments = "sample string 7", } }; mockRepositorycar.Setup(x => x.CreateAdvertiseCarDetailsEntry(carDetailObject)).Returns(carID); // Arrange AdvertisedCarController controller = new AdvertisedCarController(mockRepositorycar.Object, _ownerValidationService, _logger); controller.Request = new HttpRequestMessage(); controller.Configuration = new HttpConfiguration(); var response = controller.Post(carDetailObject); string succesful; Assert.IsTrue(response.TryGetContentValue <string>(out succesful)); Assert.AreEqual(System.Net.HttpStatusCode.OK, response.StatusCode); Assert.AreEqual(succesful, "1 Inserted successfully"); }
public void Get() { var mockRepository = new Mock <IAdvertiseCarDetailsService>(); mockRepository.Setup(x => x.GetListOfAdvertisedCars("2017", "1", "1")) .Returns(new List <AdvertisedCarDTO> { new AdvertisedCarDTO { ID = 1 } }); // Arrange AdvertisedCarController controller = new AdvertisedCarController(mockRepository.Object, _ownerValidationService, _logger); var results = controller.Get("2017", "1", "1"); Assert.IsNotNull(results); Assert.AreEqual(1, results.Count); Assert.AreEqual(1, results.FirstOrDefault().ID); }
public void PutWithIncomleteValuesForOwnerType() { int carID = 1; var mockRepositorycar = new Mock <IAdvertiseCarDetailsService>(); var carDetailObject = new AdvertisedCarDetailsDTO { CarDetails = new AdvertisedCarDTO { ID = 1, Year = "as", Make = "sample string 3", Model = "sample string 4", AdvertisedPriceType = "eCg", ECGAmount = 6.0m, DAPAmount = 7.0m, AdvertisedAmount = 8.0m, }, OwnerDetails = new OwnerDTO { Id = 1, Name = "", PhoneNumber = "asd", Email = "", DealerABN = "", OwnerType = "D", Comments = "sample string 7", } }; // Arrange AdvertisedCarController controller = new AdvertisedCarController(mockRepositorycar.Object, _ownerValidationService, _logger); controller.Request = new HttpRequestMessage(); controller.Configuration = new HttpConfiguration(); var response = controller.Put(carID, carDetailObject); HttpError succesful; Assert.IsTrue(response.TryGetContentValue <HttpError>(out succesful)); Assert.AreEqual(System.Net.HttpStatusCode.BadRequest, response.StatusCode); }
public void Delete() { int carID = 1; var mockRepositorycar = new Mock <IAdvertiseCarDetailsService>(); mockRepositorycar.Setup(x => x.DeleteAdvertiseCarDetailsEntry(carID)).Returns(true); // Arrange AdvertisedCarController controller = new AdvertisedCarController(mockRepositorycar.Object, _ownerValidationService, _logger); controller.Request = new HttpRequestMessage(); controller.Configuration = new HttpConfiguration(); var response = controller.Delete(carID); string succesful; Assert.IsTrue(response.TryGetContentValue <string>(out succesful)); Assert.AreEqual(System.Net.HttpStatusCode.OK, response.StatusCode); Assert.AreEqual(succesful, "Deleted succesfully"); }