Beispiel #1
0
        public async Task ExceptionTest()
        {
            // Arrange
            IBrandRepository mockRepo = Substitute.For <IBrandRepository>();

            mockRepo
            .GetProductBrandsAsync()
            .ThrowsForAnyArgs(new Exception("Test Exception"));

            IDistributedCache   mockCache   = Substitute.For <IDistributedCache>();
            IOptions <Settings> appSettings = Substitute.For <IOptions <Settings> >();

            var mockLocalizer = new MockStringLocalizer <BrandController>();

            IBrandApi theApi     = new BrandApi(appSettings, mockRepo);
            var       controller = new BrandController(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);
        }
Beispiel #2
0
        public async Task SuccessTest()
        {
            // Arrange
            IBrandRepository mockRepo = Substitute.For <IBrandRepository>();

            var repositoryReturnValue = new List <ProductBrandModel>()
            {
                new ProductBrandModel()
                {
                    Description = "Description 1",
                    ID          = 1
                },
                new ProductBrandModel()
                {
                    Description = "Description 2",
                    ID          = 2
                }
            };

            mockRepo
            .GetProductBrandsAsync()
            .ReturnsForAnyArgs(Task.FromResult <IEnumerable <ProductBrandModel> >(repositoryReturnValue));

            IDistributedCache   mockCache   = Substitute.For <IDistributedCache>();
            IOptions <Settings> appSettings = Substitute.For <IOptions <Settings> >();

            IStringLocalizer <BrandController> mockLocalizer = Substitute.For <IStringLocalizer <BrandController> >();

            mockLocalizer = new MockStringLocalizer <BrandController>();

            IBrandApi       theApi     = new BrandApi(appSettings, mockRepo);
            BrandController controller = new BrandController(mockCache, theApi, mockLocalizer);

            //// Act
            var response = await controller.Get();

            ////// Assert
            var actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)response).Value;

            Assert.Equal(((List <ProductBrandModel>)actualRecord).Count, repositoryReturnValue.Count);
        }
Beispiel #3
0
 public BrandApiTests()
 {
     instance = new BrandApi();
 }