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

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

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

            var mockLocalizer = new MockStringLocalizer <DownloadTimesController>();

            IDownloadTimesApi theApi = new DownloadTimesApi(appSettings, mockRepo);
            var controller           = new DownloadTimesController(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);
        }
Example #2
0
        public async Task SuccessTest()
        {
            // Arrange
            IDownloadTimeRepository mockRepo = Substitute.For <IDownloadTimeRepository>();

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

            mockRepo
            .GetAllDownloadTimesAsync()
            .ReturnsForAnyArgs(Task.FromResult <IEnumerable <DownloadTimeModel> >(repositoryReturnValue));

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

            var mockLocalizer = new MockStringLocalizer <DownloadTimesController>();

            IDownloadTimesApi theApi = new DownloadTimesApi(appSettings, mockRepo);
            var controller           = new DownloadTimesController(mockCache, theApi, mockLocalizer);

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

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

            Assert.Equal(((List <DownloadTimeModel>)actualRecord).Count, repositoryReturnValue.Count);
        }