Skip to content

Commit

Permalink
Missing Lifestyle.Scoped tests added.
Browse files Browse the repository at this point in the history
  • Loading branch information
dot_net_junkie committed Oct 9, 2015
1 parent 0da13c7 commit 3b1e14d
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion SimpleInjector.NET.Tests.Unit/LifestyleScopedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,72 @@ public void DefaultScopedLifestyle_SetWithLifestyleScoped_ThrowsException()
"later on when Lifestyle.Scoped is supplied to one of the Register methods.");
}

[TestMethod]
public void ScopedProxyLifestyleDependencyLength_Always_ReturnsLengthOfDefaultScopedLifestyle()
{
// Arrange
int expectedLength = 502; // Anything different than the default length for scoped (500).

var container = new Container();

container.Options.DefaultScopedLifestyle = new CustomScopedLifestyle(length: expectedLength);

// Act
int actualLength = Lifestyle.Scoped.DependencyLength(container);

// Assert
Assert.AreEqual(expectedLength, actualLength);
}

[TestMethod]
public void ScopedProxyLifestyleCreateCurrentScopeProvider_Always_ReturnsScopeOfDefaultScopedLifestyle()
{
// Arrange
Scope expectedScope = new Scope();

var container = new Container();

container.Options.DefaultScopedLifestyle = new CustomScopedLifestyle(scope: expectedScope);

// Act
Scope actualScope = Lifestyle.Scoped.CreateCurrentScopeProvider(container)();

// Assert
Assert.AreSame(expectedScope, actualScope);
}

[TestMethod]
public void ScopedProxyLifestyleCreateRegistration_Always_WrapsTheScopeOfDefaultScopedLifestyle()
{
// Arrange
var expectedLifestyle = new LifetimeScopeLifestyle();

var container = new Container();

container.Options.DefaultScopedLifestyle = expectedLifestyle;

// Act
var registration = Lifestyle.Scoped.CreateRegistration(typeof(NullLogger), container);

var actualLifestyle = registration.Lifestyle;

// Assert
Assert.AreSame(expectedLifestyle, actualLifestyle);
}

private sealed class CustomScopedLifestyle : ScopedLifestyle
{
private readonly Scope scope;
private readonly int length;

public CustomScopedLifestyle(Scope scope = null) : base("Custom Scope")
public CustomScopedLifestyle(Scope scope = null, int? length = null) : base("Custom Scope")
{
this.scope = scope;
this.length = length ?? base.Length;
}

protected override int Length => this.length;

protected internal override Func<Scope> CreateCurrentScopeProvider(Container container)
{
return () => this.scope;
Expand Down

0 comments on commit 3b1e14d

Please sign in to comment.