public async Task POST_Download_When_File_Is_Available_Returns_FileContentResult()
        {
            // Arrange
            var configurableDownloadableFileBusinessLogic = new Mock <IDownloadableFileBusinessLogic>();

            configurableDownloadableFileBusinessLogic
            .Setup(x => x.GetFileRemovingSensitiveInformationAsync(It.IsAny <string>()))
            .ReturnsAsync(new DownloadableFileModel("someName")
            {
                DataTable = new DataTable()
            });

            var webService          = IocContainer.Resolve <IWebService>();
            var sharedBusinessLogic = IocContainer.Resolve <ISharedBusinessLogic>();

            _TestDownloadableFileController = new DownloadableFileController(
                configurableDownloadableFileBusinessLogic.Object,
                null, webService,
                sharedBusinessLogic);

            // Act
            IActionResult actualResult = await _TestDownloadableFileController.DownloadFile("AFilePath");

            // Assert
            Assert.NotNull(actualResult);
            var expectedFileContentResult = actualResult as FileContentResult;

            Assert.NotNull(expectedFileContentResult, $"expected a expectedFileContentResult but was {actualResult.GetType()}");
            Assert.AreEqual("someName", expectedFileContentResult.FileDownloadName);
        }
        public async Task POST_IdentityLogs_Defaults_To_Base_Logs_Path_When_Not_Provided(string filePath, string expectedPath)
        {
            // Arrange
            string actualPath = string.Empty;
            var    configurableDownloadableFileBusinessLogic = new Mock <IDownloadableFileBusinessLogic>();

            configurableDownloadableFileBusinessLogic
            .Setup(x => x.GetListOfDownloadableItemsFromPathAsync(It.IsAny <string>()))
            .Callback((string fp) => { actualPath = fp; })
            .ReturnsAsync(new List <IDownloadableItem>());
            var sharedBusinessLogic = IocContainer.Resolve <ISharedBusinessLogic>();

            var webService = IocContainer.Resolve <IWebService>();

            _TestDownloadableFileController = new DownloadableFileController(
                configurableDownloadableFileBusinessLogic.Object,
                null, webService,
                sharedBusinessLogic);

            // Act
            await _TestDownloadableFileController.IdentityLogs(filePath);

            // Assert
            Assert.AreEqual(expectedPath, actualPath);
        }
        private void ConfigureDownloadableFileController()
        {
            var listOfDownloadableItems = new List <IDownloadableItem> {
                new DownloadableDirectory("Directory1"), new DownloadableDirectory("Directory2"), new DownloadableFile("file1")
            };

            var expectedLogsPath = "";

            var configurableDownloadableFileBusinessLogic = new Mock <IDownloadableFileBusinessLogic>();

            configurableDownloadableFileBusinessLogic
            .Setup(x => x.GetListOfDownloadableItemsFromPathAsync(It.IsAny <string>()))
            .ReturnsAsync(listOfDownloadableItems);

            var sharedBusinessLogic = IocContainer.Resolve <ISharedBusinessLogic>();

            var webService = IocContainer.Resolve <IWebService>();

            _TestDownloadableFileController = new DownloadableFileController(
                configurableDownloadableFileBusinessLogic.Object,
                null, webService,
                sharedBusinessLogic);
        }
        public async Task POST_Download_When_An_Argument_Is_Not_Provided_Returns_Bad_Request_ArgumentNull(string filePath,
                                                                                                          string argumentToBeLoggedAsMissing)
        {
            // Arrange
            string loggedExceptionMessage = string.Empty;
            var    configurableLogger     = new Mock <ILogger <DownloadableFileController> >();

            configurableLogger
            .Setup(
                x => x.Log(
                    It.IsAny <LogLevel>(),
                    It.IsAny <EventId>(),
                    It.IsAny <object>(),
                    It.IsAny <Exception>(),
                    It.IsAny <Func <object, Exception, string> >()))
            .Callback(
                (LogLevel logLevel,
                 EventId eventId,
                 object message,
                 Exception exception,
                 Func <object, Exception, string> formatter) => {
                // LogLevel myLogLevel = logLevel; // LogLevel.Error
                // EventId myEventId = eventId;
                // string myMessage= message.ToString(); // Value cannot be null.\nParameter name: filePath
                // Exception myException = exception; // System.ArgumentNullException
                loggedExceptionMessage = exception.Message;
                // Func<object, Exception, string> myFormatter = formatter;
            });

            var downloadableFileBusinessLogic = IocContainer.Resolve <IDownloadableFileBusinessLogic>();
            var sharedBusinessLogic           = IocContainer.Resolve <ISharedBusinessLogic>();

            var webService = IocContainer.Resolve <IWebService>();

            _TestDownloadableFileController = new DownloadableFileController(
                downloadableFileBusinessLogic,
                configurableLogger.Object,
                webService,
                sharedBusinessLogic);

            // Act
            IActionResult actualResult = await _TestDownloadableFileController.DownloadFile(filePath);

            Assert.NotNull(actualResult);
            var expectedBadRequestResult = actualResult as BadRequestResult;

            // Assert
            Assert.NotNull(expectedBadRequestResult, $"expected a BadRequestResult but was {actualResult.GetType()}");
            Assert.AreEqual((int)HttpStatusCode.BadRequest, expectedBadRequestResult.StatusCode);

            configurableLogger
            .Verify(
                x => x.Log(
                    LogLevel.Error     // Expected
                    ,
                    It.IsAny <EventId>(),
                    It.IsAny <object>(),
                    It.IsAny <ArgumentNullException>()    // Expected
                    ,
                    It.IsAny <Func <object, Exception, string> >()),
                Times.Once);

            Assert.AreEqual($"Value cannot be null.\r\nParameter name: {argumentToBeLoggedAsMissing}", loggedExceptionMessage);
        }
        public async Task POST_Download_When_File_Is_Not_Available_Returns_FileNotFoundException()
        {
            // Arrange
            string loggedExceptionMessage = string.Empty;
            var    configurableLogger     = new Mock <ILogger <DownloadableFileController> >();

            configurableLogger
            .Setup(
                x => x.Log(
                    It.IsAny <LogLevel>(),
                    It.IsAny <EventId>(),
                    It.IsAny <object>(),
                    It.IsAny <Exception>(),
                    It.IsAny <Func <object, Exception, string> >()))
            .Callback(
                (LogLevel logLevel,
                 EventId eventId,
                 object message,
                 Exception exception,
                 Func <object, Exception, string> formatter) => {
                // LogLevel myLogLevel = logLevel; // LogLevel.Error
                // EventId myEventId = eventId;
                // string myMessage= message.ToString(); // Value cannot be null.\nParameter name: filePath
                // Exception myException = exception; // System.ArgumentNullException
                loggedExceptionMessage = exception.Message;
                // Func<object, Exception, string> myFormatter = formatter;
            });

            var configurableDownloadableFileBusinessLogic = new Mock <IDownloadableFileBusinessLogic>();

            configurableDownloadableFileBusinessLogic
            .Setup(x => x.GetFileRemovingSensitiveInformationAsync(It.IsAny <string>()))
            .ThrowsAsync(new FileNotFoundException());

            var sharedBusinessLogic = IocContainer.Resolve <ISharedBusinessLogic>();

            var webService = IocContainer.Resolve <IWebService>();

            _TestDownloadableFileController = new DownloadableFileController(
                configurableDownloadableFileBusinessLogic.Object,
                configurableLogger.Object, webService,
                sharedBusinessLogic);

            // Act
            IActionResult actualResult = await _TestDownloadableFileController.DownloadFile("AFilePath");

            Assert.NotNull(actualResult);
            var expectedNotFoundResult = actualResult as NotFoundResult;

            // Assert
            Assert.NotNull(expectedNotFoundResult, $"expected a NotFoundResult but was {actualResult.GetType()}");
            Assert.AreEqual((int)HttpStatusCode.NotFound, expectedNotFoundResult.StatusCode);

            configurableLogger
            .Verify(
                x => x.Log(
                    LogLevel.Error     // Expected
                    ,
                    It.IsAny <EventId>(),
                    It.IsAny <object>(),
                    It.IsAny <Exception>()    // DirectoryNotFoundException or FileNotFoundException depending on the call being made to systemFileRepository or AzureFileRepository
                    ,
                    It.IsAny <Func <object, Exception, string> >()),
                Times.Once);

            Assert.IsTrue(
                loggedExceptionMessage.Contains("Unable to find"),
                $"The exception message was expected to contain 'Unable to find the specified file' but was '{loggedExceptionMessage}' ");
        }