Пример #1
0
        public void Test(string baseDirectoryPath)
        {
            var localhost = new IPEndPoint(IPAddress.Loopback, 0);

            using (var logger = new FileMessagePackStreamLogger(baseDirectoryPath))
            {
                var now = DateTimeOffset.Now;
                logger.Write(now, localhost, new byte[] { 1, 2, 3 });

                var file = FileMessagePackStreamLoggerTest.AssertFilePath(logger.DirectoryPath, now, localhost.Address.ToString());
                Assert.That(File.ReadAllBytes(file), Is.EqualTo(new byte[] { 1, 2, 3 }));
            }
        }
Пример #2
0
        public void TestWrite_DirectoryDoesNotExist_WrittenToFile()
        {
            using (var tempDirectory = TempDirectory.Create())
                using (var logger = new FileMessagePackStreamLogger(tempDirectory.Path))
                {
                    var now = DateTimeOffset.Now;
                    Assert.That(Directory.Exists(logger.DirectoryPath), Is.False);
                    logger.Write(now, _localhost, new byte[] { 1, 2, 3 });

                    var file = AssertFilePath(logger.DirectoryPath, now, _localhost.Address.ToString());
                    Assert.That(File.ReadAllBytes(file), Is.EqualTo(new byte[] { 1, 2, 3 }));
                }
        }
Пример #3
0
        public void TestWrite_NullStream_EmptyFile()
        {
            using (var tempDirectory = TempDirectory.Create())
                using (var logger = new FileMessagePackStreamLogger(tempDirectory.Path))
                {
                    var now = DateTimeOffset.Now;
                    Directory.CreateDirectory(logger.DirectoryPath);
                    logger.Write(now, _localhost, null);

                    var file = AssertFilePath(logger.DirectoryPath, now, _localhost.Address.ToString());
                    Assert.That(File.ReadAllBytes(file), Is.Empty);
                }
        }
Пример #4
0
        public void TestWrite_EndPointIsNull_HostNameIsUsed()
        {
            using (var tempDirectory = TempDirectory.Create())
                using (var logger = new FileMessagePackStreamLogger(tempDirectory.Path))
                {
                    var now = DateTimeOffset.Now;
                    Directory.CreateDirectory(logger.DirectoryPath);
                    logger.Write(now, null, new byte[] { 1, 2, 3 });

                    var file = AssertFilePath(logger.DirectoryPath, now, null);
                    Assert.That(File.ReadAllBytes(file), Is.EqualTo(new byte[] { 1, 2, 3 }));
                }
        }
Пример #5
0
        public void TestWrite_Twise_DifferenceAppended()
        {
            using (var tempDirectory = TempDirectory.Create())
                using (var logger = new FileMessagePackStreamLogger(tempDirectory.Path))
                {
                    var now = DateTimeOffset.Now;
                    Directory.CreateDirectory(logger.DirectoryPath);
                    logger.Write(now, _localhost, new byte[] { 1, 2, 3 });
                    logger.Write(now, _localhost, new byte[] { 1, 2, 3, 4, 5 });

                    var file = AssertFilePath(logger.DirectoryPath, now, _localhost.Address.ToString());
                    Assert.That(File.ReadAllBytes(file), Is.EqualTo(new byte[] { 1, 2, 3, 4, 5 }));
                }
        }