Exemple #1
0
        public async Task ReturnsContentOfFileWhenNoRange()
        {
            var    file     = Path.GetTempFileName();
            string contents = new string('A', 1000);
            await File.WriteAllTextAsync(file, contents).ConfigureAwait(false);

            var mockLogger = new Mock <ILogger <LogfileProvider> >();
            var config     = new SpringBootConfig
            {
                LogFilePath = file,
            };

            var mockMonitor = new Mock <IOptionsMonitor <SpringBootConfig> >();

            mockMonitor.Setup(x => x.CurrentValue).Returns(config);

            var sut = new LogfileProvider(mockLogger.Object, mockMonitor.Object);

            var result = sut.GetLog();

            using var sr = new StreamReader(result);
            var resultStr = await sr.ReadToEndAsync().ConfigureAwait(false);

            resultStr.Should().HaveLength(1000);
        }
Exemple #2
0
        public void ReturnsErrorWhenFileDoesNotExist()
        {
            var mockLogger = new Mock <ILogger <LogfileProvider> >();
            var config     = new SpringBootConfig
            {
                LogFilePath = "does/not/exist.log",
            };

            var mockMonitor = new Mock <IOptionsMonitor <SpringBootConfig> >();

            mockMonitor.Setup(x => x.CurrentValue).Returns(config);

            var sut = new LogfileProvider(mockLogger.Object, mockMonitor.Object);

            sut.Invoking(x => sut.GetLog().ConfigureAwait(false)).Should().Throw <FileNotFoundException>();
        }