Created
March 16, 2011 17:54
-
-
Save Talljoe/872945 to your computer and use it in GitHub Desktop.
IEnumerable tests.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Ninject.Tests.Integration | |
{ | |
using System.Collections.Generic; | |
using Ninject.Tests.Fakes; | |
using Ninject.Tests.Integration.StandardKernelTests; | |
using Ninject.Tests.MSTestAttributes; | |
using Xunit; | |
using Xunit.Should; | |
[TestClass] | |
public class WhenAnExplicitIEnumerableIsRegistered : StandardKernelContext | |
{ | |
public WhenAnExplicitIEnumerableIsRegistered() | |
{ | |
this.kernel.Bind<IEnumerable<IWeapon>>().ToMethod(c => new[] { new Shuriken(), }); | |
} | |
[Fact] | |
public void GetShouldReturnExplicitEnumerable() | |
{ | |
var service = this.kernel.Get<IEnumerable<IWeapon>>(); | |
service.ShouldNotBeNull(); | |
service.ShouldNotBeEmpty(); | |
} | |
[Fact] | |
public void GetAllShouldReturnEmpty() | |
{ | |
var service = this.kernel.GetAll<IWeapon>(); | |
service.ShouldNotBeNull(); | |
service.ShouldBeEmpty(); | |
} | |
[Fact] | |
public void InjectionShouldInjectExplicitEnumerable() | |
{ | |
var service = this.kernel.Get<Armory>(); | |
service.Weapons.ShouldNotBeNull(); | |
service.Weapons.ShouldNotBeEmpty(); | |
} | |
} | |
[TestClass] | |
public class WhenNoEnumerableIsRegistered : StandardKernelContext | |
{ | |
public WhenNoEnumerableIsRegistered() | |
{ | |
this.kernel.Bind<IWeapon>().ToConstant(new Shuriken()); | |
} | |
[Fact] | |
public void GetShouldReturnImplicitEnumerable() | |
{ | |
var service = this.kernel.Get<IEnumerable<IWeapon>>(); | |
service.ShouldNotBeNull(); | |
service.ShouldNotBeEmpty(); | |
} | |
[Fact] | |
public void GetAllShouldReturnImplicitEnumerable() | |
{ | |
var service = this.kernel.GetAll<IWeapon>(); | |
service.ShouldNotBeNull(); | |
service.ShouldNotBeEmpty(); | |
} | |
[Fact] | |
public void InjectionShouldInjectImplicitEnumerable() | |
{ | |
var service = this.kernel.Get<Armory>(); | |
service.Weapons.ShouldNotBeNull(); | |
service.Weapons.ShouldNotBeEmpty(); | |
} | |
} | |
public class Armory | |
{ | |
public IEnumerable<IWeapon> Weapons { get; private set; } | |
public Armory(IEnumerable<IWeapon> weapons) | |
{ | |
this.Weapons = weapons; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment