Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for large cell logging in Azure Sink #163

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -571,4 +571,75 @@ public async Task WhenALoggerUsesASASSinkItIsRetrievableFromTheTableWithProperti

await table.DeleteAsync();
}



[Fact (Skip = "Does not work with Storage Emulator as it does not feature the 64K cell limit (or 32K string)")]
public async Task WhenALoggerWritesToTheSinkAndACellExceeds32KAnExceptionIsRaised()
{
var storageAccount = new TableServiceClient(DevelopmentStorageAccountConnectionString);
var table = storageAccount.GetTableClient($"LogUnitTest{DateTime.Now.Ticks}");

var logger = new LoggerConfiguration()
.WriteTo.AzureTableStorage(
storageAccount: storageAccount,
storageTableName: table.Name)
.CreateLogger();

var exception = new ArgumentException("Some exception");

const string messageTemplate = "{tooBig}";

var tooBig = new string('a', 33000);

Assert.Throws<Exception>(() => logger.Information(exception, messageTemplate, tooBig));

logger.Dispose();

await table.DeleteAsync();
}

[Fact (Skip = "Does not work with Storage Emulator as it does not feature the 64K cell limit (or 32K string)")]
public async Task WhenALoggerWritesToTheSinkAndACellExceeds32KAnExceptionIsRaisedButSubsequentCallsContinueToWorkAsExpected()
{
var storageAccount = new TableServiceClient(DevelopmentStorageAccountConnectionString);
var table = storageAccount.GetTableClient($"LogUnitTest{DateTime.Now.Ticks}");

var logger = new LoggerConfiguration()
.WriteTo.AzureTableStorage(
storageAccount: storageAccount,
storageTableName: table.Name)
.CreateLogger();

var exception = new ArgumentException("Some exception");

const string messageTemplate = "{tooBig}";

var tooBig = new string('a', 33000);
var notTooBig = new string('b', 1000);

Assert.Throws<Exception>(() => logger.Information(exception, messageTemplate, tooBig));

// After the expected exception, the logger should continue to work on subsequent calls
const string messageTemplate2 = "{Properties} should go in their {Numbered} {Space}";

logger.Information(exception, messageTemplate2, "Properties", 1234, ' ');
logger.Dispose();

var result = (await TableQueryTakeDynamicAsync(table, takeCount: 1)).First();

// Check the presence of same properties as in previous version
Assert.Equal(messageTemplate2, result["MessageTemplate"]);
Assert.Equal("Information", result["Level"]);
Assert.Equal("System.ArgumentException: Some exception", result["Exception"]);
Assert.Equal("\"Properties\" should go in their 1234 ", result["RenderedMessage"]);

// Check the presence of the new properties.
Assert.Equal("Properties", result["Properties"]);
Assert.Equal(1234, result["Numbered"]);
Assert.Equal(" ", result["Space"]);

await table.DeleteAsync();
}

}