public async Task ExceptionTest() { // Arrange IProductTypeRepository mockRepo = Substitute.For <IProductTypeRepository>(); mockRepo .GetAllProductTypesAsync() .ThrowsForAnyArgs(new Exception("Test Exception")); IDistributedCache mockCache = Substitute.For <IDistributedCache>(); IOptions <Settings> appSettings = Substitute.For <IOptions <Settings> >(); var mockLocalizer = new MockStringLocalizer <ProductTypesController>(); IProductTypesApi theApi = new ProductTypesApi(appSettings, mockRepo); var controller = new ProductTypesController(mockCache, theApi, mockLocalizer); //// Act var actionResult = await controller.Get(); var objectResult = actionResult as Microsoft.AspNetCore.Mvc.ObjectResult; ////// Assert Assert.NotNull(objectResult); Assert.Equal(objectResult.StatusCode, (int)System.Net.HttpStatusCode.InternalServerError); }
//public async Task<ActionResult> Index() //{ //HttpResponseMessage responseMessage = await client.GetAsync(url + "/GetAll"); //if (responseMessage.IsSuccessStatusCode) //{ // var responseData = responseMessage.Content.ReadAsStringAsync().Result; // var settings = new JsonSerializerSettings // { // NullValueHandling = NullValueHandling.Ignore, // MissingMemberHandling = MissingMemberHandling.Ignore // }; // var product = JsonConvert.DeserializeObject<List<ProductDTO>>(responseData, settings); // // return View(product); // //var lst = new ProductBUS().ListNewProduct(); // ViewBag.NewProduct = product; // //var topdeal = new ProductBUS().TopDealProduct(); // ViewBag.TopDeal = product; // //ViewBag.SessionUser = Session["Customer"]; // return View(product); // } // return View(); //} //[Route("typeID={typeid?}")] public async Task <ActionResult> Index(string typeid) { HttpResponseMessage responseMessage = await client.GetAsync(url + "/products/ProductTypeID=" + typeid); if (responseMessage.IsSuccessStatusCode) { var responseData = responseMessage.Content.ReadAsStringAsync().Result; var settings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore }; var product = JsonConvert.DeserializeObject <List <ProductDTO> >(responseData, settings); // return View(product); //var lst = new ProductBUS().ListNewProduct(); ViewBag.ProductType = ctrl.Get(); ViewBag.NewProduct = product; //var topdeal = new ProductBUS().TopDealProduct(); ViewBag.TopDeal = product; //ViewBag.SessionUser = Session["Customer"]; return(View(product)); } return(View()); }
public void GetTest() { ProductTypes v = new ProductTypes(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.ParentId = AddProductTypes(); v.PTName = "m6X"; v.PTDes = "N4Ly2H"; context.Set <ProductTypes>().Add(v); context.SaveChanges(); } var rv = _controller.Get(v.ID.ToString()); Assert.IsNotNull(rv); }
public async Task GetProductTypeDetailsById_ValidRequest_SuccessResult() { var productTypeId = Guid.NewGuid(); var response = new ProductTypeDetailsResponseModel { ProductTypeID = productTypeId, ProductTypeKey = "ProductKey", ProductTypeName = "ProductTypeName" }; //Arrange BaseMediator.Setup(x => x.Send(It.IsAny <GetProductTypeDetailsQuery>(), new CancellationToken())). ReturnsAsync(response); var productTypesController = new ProductTypesController(BaseMediator.Object); //Action var result = await productTypesController.Get(productTypeId); //Assert Assert.IsType <ActionResult <ProductTypeDetailsResponseModel> >(result); }
public async Task GetProductTypes_ValidRequest_SuccessResult() { var response = new List <ProductTypeResponseModel>(); response.Add(new ProductTypeResponseModel { ProductTypeID = Guid.NewGuid(), ProductTypeKey = "ProductKey", ProductTypeName = "ProductTypeName" }); //Arrange BaseMediator.Setup(x => x.Send(It.IsAny <FetchProductTypeQuery>(), new CancellationToken())). ReturnsAsync(response); var productTypesController = new ProductTypesController(BaseMediator.Object); //Action var result = await productTypesController.Get(); //Assert Assert.IsType <List <ProductTypeResponseModel> >(result); }
public async Task SuccessTest() { // Arrange IProductTypeRepository mockRepo = Substitute.For <IProductTypeRepository>(); var repositoryReturnValue = new List <ProductTypeModel>() { new ProductTypeModel() { Description = "Description 1", ProductTypeId = 1 }, new ProductTypeModel() { Description = "Description 2", ProductTypeId = 2 } }; mockRepo .GetAllProductTypesAsync() .ReturnsForAnyArgs(Task.FromResult <IEnumerable <ProductTypeModel> >(repositoryReturnValue)); IDistributedCache mockCache = Substitute.For <IDistributedCache>(); IOptions <Settings> appSettings = Substitute.For <IOptions <Settings> >(); var mockLocalizer = new MockStringLocalizer <ProductTypesController>(); IProductTypesApi theApi = new ProductTypesApi(appSettings, mockRepo); var controller = new ProductTypesController(mockCache, theApi, mockLocalizer); //// Act var response = await controller.Get(); ////// Assert var actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)response).Value; Assert.Equal(((List <ProductTypeModel>)actualRecord).Count, repositoryReturnValue.Count); }
public ActionResult Create() { ViewBag.product_type_code = new SelectList(type.Get(), "Ref_Product_TypesDTO.product_type_code", "Ref_Product_TypesDTO.product_type_description"); return(View()); }