Skip to content

Migrate LoggerMessageAttributeTests.cs to AwesomeAssertions #95

@Meir017

Description

@Meir017

Part of #94 - Migrate tests to AwesomeAssertions

File Details

  • Path: test/LoggerUsage.Tests/LoggerMessageAttributeTests.cs
  • Lines: 3,548
  • Assertions: ~450
  • Test Methods: 56 (51 Facts, 5 Theories)
  • Complexity: ⭐⭐⭐⭐⭐ Very High

Scope

This is the largest and most complex test file in the project. It contains extensive tests for LoggerMessage attribute analysis including:

  • Event ID and event name scenarios
  • Log level variations
  • Message template parsing
  • Parameter extraction
  • Complex nested assertions with Assert.IsType<T>

Migration Checklist

  • Add using AwesomeAssertions; at the top
  • Replace Assert.NotNull().Should().NotBeNull()
  • Replace Assert.Single().Should().ContainSingle()
  • Replace Assert.Equal().Should().Be()
  • Replace Assert.IsType<T>().Should().BeOfType<T>().Which
  • Replace Assert.Empty().Should().BeEmpty()
  • Replace Assert.Contains().Should().Contain()
  • Replace Assert.True() / Assert.False().Should().BeTrue() / .Should().BeFalse()
  • Run tests and verify all pass

Example Transformations

Before:

Assert.NotNull(loggerUsages);
Assert.Single(loggerUsages.Results);
var details = Assert.IsType<EventIdDetails>(loggerUsages.Results[0].EventId);
Assert.Equal(6, details.Id.Value);

After:

loggerUsages.Should().NotBeNull();
loggerUsages.Results.Should().ContainSingle()
    .Which.EventId.Should().BeOfType<EventIdDetails>()
    .Which.Id.Value.Should().Be(6);

Tips

  • Use .Which for chaining assertions on collection elements
  • Consider using AssertionScope for multiple related assertions
  • Test complex scenarios first to ensure patterns work correctly

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions