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 override async Task LoadAsync(int productId) { Id = productId; Products.Clear(); var products = await _productRepository.GetAllProductsAsync(); foreach (var product in products) { Products.Add(product); } var prodTypes = await _productTypeRepository.GetAllProductTypesAsync(); foreach (var prodType in prodTypes) { ProductTypes.Add(prodType); } SelectedProductType = ProductTypes.First(); Product = Products.First(s => s.ProductTypeId == SelectedProductType.Id); SelectedProductMeasure = Product.ProductMeasure; foreach (var product in Products) { if (product.ProductTypeId == SelectedProductType.Id) { SeriesCollection.Add(new ColumnSeries { Title = product.Name, Values = new ChartValues <int> { product.StockBalance } }); Labels.Add(product.ProductType.Type); } } }
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); }