Skip to content

Commit

Permalink
Better decorator test
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Zanoni committed Nov 22, 2021
1 parent 5def7df commit 69c2c47
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Tests/DecoratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,19 @@ public void ShouldReturnInstance_ResultsShouldBeWrappedAndDifferent()
string result1;
string result2;

using (_provider.CreateScope())
using (var scope = _provider.CreateScope())
{
IScopedDecorator decorator = _provider.GetRequiredService<IScopedDecorator>();
IScopedDecorator decorator = scope.ServiceProvider.GetRequiredService<IScopedDecorator>();
result1 = decorator.DecoratedResult;
string result1Again = decorator.DecoratedResult;

Assert.Equal(result1, result1Again);
}

using (_provider.CreateScope())
using (var scope = _provider.CreateScope())
{
IScopedDecorator decorator = _provider.GetRequiredService<IScopedDecorator>();
IScopedDecorator decorator = scope.ServiceProvider.GetRequiredService<IScopedDecorator>();
result2 = decorator.DecoratedResult;

}

Assert.NotEqual(result1, result2);
Expand Down Expand Up @@ -97,13 +99,14 @@ public interface IScopedDecorator
public class ScopedDecorator : IScopedDecorator
{
private readonly IScopedDecorator _decoratedInstance;
private readonly Guid _key = Guid.NewGuid();

public ScopedDecorator(IScopedDecorator decoratedInstance)
{
_decoratedInstance = decoratedInstance;
}

public string DecoratedResult => $"{Guid.NewGuid()} " + _decoratedInstance.DecoratedResult;
public string DecoratedResult => $"{_key} " + _decoratedInstance.DecoratedResult;
}

public class ScopeDecoratedClass : IScopedDecorator
Expand Down

0 comments on commit 69c2c47

Please sign in to comment.