Ejemplo n.º 1
0
        public void LogFileLogsErrorMessageWhenFileSizeIsTooLarge()
        {
            int maxFileSize = Convert.ToInt32(Constants.MaximumAllowedFileSizeInBytes);

            byte[] contents = Enumerable.Range(0, maxFileSize + 1).Select(p => byte.MaxValue).ToArray();
            var    ex       = new FileSizeTooLargeException(contents.Length, Constants.MaximumAllowedFileSizeInBytes);

            Logger logger = new Logger();

            using (TemporaryFile sourceFile = new TemporaryFile())
            {
                File.WriteAllBytes(sourceFile.FileName, contents);

                using (FilesContainer filesContainer = new FilesContainer(logger))
                {
                    LoggedFile file = filesContainer.LogFile(sourceFile.FileName, null);
                }
            }

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

            Assert.IsNotNull(message);
            Assert.AreEqual(LogLevel.Error, message.LogLevel);
            Assert.IsTrue(message.Message.Contains(ex.Message));
        }
Ejemplo n.º 2
0
        public void LogFileCreatesAPhysicalCopyOfTheSourceFile()
        {
            using (TemporaryFile sourceFile = new TemporaryFile())
            {
                File.WriteAllText(sourceFile.FileName, "Source file content");

                string copiedFilePath   = null;
                bool   exists           = false;
                long   sourceFileLength = sourceFile.GetSize();

                using (FilesContainer filesContainer = new FilesContainer(new Logger()))
                {
                    LoggedFile file = filesContainer.LogFile(sourceFile.FileName, null);
                    copiedFilePath = file.FilePath;

                    exists = File.Exists(copiedFilePath);
                    Assert.IsTrue(exists);
                    Assert.AreEqual(sourceFileLength, file.FileSize);
                }

                exists = File.Exists(copiedFilePath);
                Assert.IsFalse(exists);

                exists = File.Exists(sourceFile.FileName);
                Assert.IsTrue(exists);
            }
        }
Ejemplo n.º 3
0
        public void LogFileCopiesTheContentsOfTheSourceFile()
        {
            using (TemporaryFile sourceFile = new TemporaryFile())
            {
                string sourceContent = "Source file content";

                File.WriteAllText(sourceFile.FileName, sourceContent);

                using (FilesContainer filesContainer = new FilesContainer(new Logger()))
                {
                    LoggedFile file = filesContainer.LogFile(sourceFile.FileName, null);

                    string content = File.ReadAllText(file.FilePath);

                    Assert.AreEqual(sourceContent, content);
                }
            }
        }
Ejemplo n.º 4
0
        public void LogFileLogsErrorMessageWhenFileWasNotFound()
        {
            string fileName = null;

            using (TemporaryFile tempFile = new TemporaryFile())
            {
                fileName = tempFile.FileName;
            }

            var ex = new LogFileException(fileName, new FileNotFoundException(null, fileName));

            Logger logger = new Logger();

            using (FilesContainer filesContainer = new FilesContainer(logger))
            {
                LoggedFile file = filesContainer.LogFile(fileName);
            }

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

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