public void DisposeAlsoDisposesTheTemporaryFiles()
        {
            FilesContainer filesContainer = new FilesContainer(new Logger());

            filesContainer.LogAsFile("Content", null);
            filesContainer.LogAsFile("Content", null);

            List <TemporaryFile> temporaryFiles = filesContainer._temporaryFiles;

            filesContainer.Dispose();

            foreach (TemporaryFile item in temporaryFiles)
            {
                Assert.IsTrue(item._disposed);
            }
        }
        public void FileNameAlwaysHasValue(string fileName)
        {
            using (FilesContainer filesContainer = new FilesContainer(new Logger()))
            {
                LoggedFile loggedFile = filesContainer.LogAsFile("Content", fileName);

                Assert.IsNotNull(loggedFile.FileName);
            }
        }
        public void EmptyByteArrayIsIgnored()
        {
            using (FilesContainer filesContainer = new FilesContainer(new Logger()))
            {
                LoggedFile loggedFile = filesContainer.LogAsFile(new byte[] { }, "File.txt");

                Assert.IsNull(loggedFile);
            }
        }
        public void EmptyStringIsIgnored(string content)
        {
            using (FilesContainer filesContainer = new FilesContainer(new Logger()))
            {
                LoggedFile loggedFile = filesContainer.LogAsFile(content, "File.txt");

                Assert.IsNull(loggedFile);
            }
        }
        public void GetLoggedFilesIsNotReferenced()
        {
            using (FilesContainer filesContainer = new FilesContainer(new Logger()))
            {
                List <LoggedFile> loggedFiles = filesContainer.GetLoggedFiles();

                filesContainer.LogAsFile("Content", null);

                Assert.AreEqual(0, loggedFiles.Count);
            }
        }
        public void LogStringAsFileCreatesAPhysicalFile()
        {
            using (FilesContainer filesContainer = new FilesContainer(new Logger()))
            {
                string contents = "String file content";

                LoggedFile file = filesContainer.LogAsFile(contents, null);

                FileInfo fi = new FileInfo(file.FilePath);

                Assert.IsTrue(fi.Exists);
                Assert.IsNotNull(file.FileName);
                Assert.AreEqual(fi.Length, file.FileSize);
            }
        }
        public void LogByteArrayAsFileCreatesAPhysicalFile()
        {
            using (FilesContainer filesContainer = new FilesContainer(new Logger()))
            {
                byte[] contents = Encoding.UTF8.GetBytes("Byte[] file content");

                LoggedFile file = filesContainer.LogAsFile(contents, null);

                FileInfo fi = new FileInfo(file.FilePath);

                Assert.IsTrue(fi.Exists);
                Assert.IsNotNull(file.FileName);
                Assert.AreEqual(fi.Length, file.FileSize);
            }
        }
        public void LogStringAsFileLogsErrorMessageWhenFileSizeIsTooLarge()
        {
            int    maxFileSize = Convert.ToInt32(Constants.MaximumAllowedFileSizeInBytes);
            string contents    = string.Join(string.Empty, Enumerable.Range(0, maxFileSize + 1).Select(p => "0"));
            var    ex          = new FileSizeTooLargeException(contents.Length, Constants.MaximumAllowedFileSizeInBytes);

            Logger logger = new Logger();

            using (FilesContainer filesContainer = new FilesContainer(logger))
            {
                LoggedFile file = filesContainer.LogAsFile(contents, null);
            }

            LogMessage message = logger.DataContainer.LogMessages.FirstOrDefault();

            Assert.IsNotNull(message);
            Assert.AreEqual(LogLevel.Error, message.LogLevel);
            Assert.IsTrue(message.Message.Contains(ex.Message));
        }