public void SelectAllTypesFromPassesAssembliesToTypeFilterGetTypesToReceiveAllExportedTypes() { var assemblies = new[] { Assembly.GetExecutingAssembly(), Assembly.GetCallingAssembly() }; this.testee.SelectAllTypesFrom(assemblies); this.typeSelectorMock.Verify(tf => tf.GetExportedTypes(assemblies)); }
public void AllTypesReturnedByTypeFilterArePassedToTheGeneratorOnBindWith() { var types = new[] { typeof(int), typeof(object) }; var generatorMock = new Mock<IBindingGenerator>(); this.SetupTypeFilterGetTypes(types); this.testee.SelectAllTypesFrom(new Assembly[0]); this.testee.BindWith(generatorMock.Object); this.VerifyAllBindingsCreated(types, generatorMock); }
public void WhereFiltersNoneMatchingTypes() { var expectedTypes = new[] { typeof(int), typeof(object) }; var types = expectedTypes.Union(new[] { typeof(DefaultConvention) }); var generatorMock = new Mock<IBindingGenerator>(); this.SetupTypeFilterGetTypes(types); this.testee.SelectAllTypesFrom(new Assembly[0]); this.testee.Where(t => t.FullName.StartsWith("System.")); this.testee.BindWith(generatorMock.Object); this.VerifyAllBindingsCreated(expectedTypes, generatorMock); }
public void ConfigureScopesFromAttributesThrowsIfServiceHasMultipleScopes() { var types = new[] { typeof(ServiceWithMultipleScopes) }; var generatorMock = new Mock<IBindingGenerator>(); var bindingMocks = new[] { CreateBindingMock(), CreateBindingMock() }; this.SetupTypeFilterGetTypes(types); generatorMock.Setup(g => g.CreateBindings(typeof(ServiceWithMultipleScopes), this.bindingRoot)).Returns(bindingMocks.Select(b => b.Object)); this.testee.SelectAllTypesFrom(new Assembly[0]); this.testee.BindWith(generatorMock.Object); Assert.Throws<InvalidOperationException>(() => this.testee.ConfigureScopesFromAttributes()); }
public void ConfigureForWithService() { var types = new[] { typeof(int), typeof(object) }; var generatorMock = new Mock<IBindingGenerator>(); var intBindingMocks = new[] { CreateBindingMock(), CreateBindingMock() }; var objectBindingMocks = new[] { CreateBindingMock(), CreateBindingMock() }; this.SetupTypeFilterGetTypes(types); generatorMock.Setup(g => g.CreateBindings(typeof(int), this.bindingRoot)).Returns(intBindingMocks.Select(b => b.Object)); generatorMock.Setup(g => g.CreateBindings(typeof(object), this.bindingRoot)).Returns(objectBindingMocks.Select(b => b.Object)); this.testee.SelectAllTypesFrom(new Assembly[0]); this.testee.BindWith(generatorMock.Object); this.testee.ConfigureFor<int>((c, s) => c.InSingletonScope()); foreach (var bindingMock in intBindingMocks) { bindingMock.Verify(b => b.InSingletonScope()); } foreach (var bindingMock in objectBindingMocks) { bindingMock.Verify(b => b.InSingletonScope(), Times.Never()); } }
public void ConfigureScopesFromAttributes() { var types = new[] { typeof(SingletonScopedService), typeof(ThreadScopedService), typeof(TransientScopedService) }; var generatorMock = new Mock<IBindingGenerator>(); var singletonScopedBindingMocks = new[] { CreateBindingMock(), CreateBindingMock() }; var threadScopedBindingMocks = new[] { CreateBindingMock(), CreateBindingMock() }; var transientScopedBindingMocks = new[] { CreateBindingMock(), CreateBindingMock() }; this.SetupTypeFilterGetTypes(types); generatorMock.Setup(g => g.CreateBindings(typeof(SingletonScopedService), this.bindingRoot)).Returns(singletonScopedBindingMocks.Select(b => b.Object)); generatorMock.Setup(g => g.CreateBindings(typeof(ThreadScopedService), this.bindingRoot)).Returns(threadScopedBindingMocks.Select(b => b.Object)); generatorMock.Setup(g => g.CreateBindings(typeof(TransientScopedService), this.bindingRoot)).Returns(transientScopedBindingMocks.Select(b => b.Object)); this.testee.SelectAllTypesFrom(new Assembly[0]); this.testee.BindWith(generatorMock.Object); this.testee.ConfigureScopesFromAttributes(); foreach (var bindingMock in singletonScopedBindingMocks) { bindingMock.Verify(b => b.InSingletonScope()); } foreach (var bindingMock in threadScopedBindingMocks) { bindingMock.Verify(b => b.InThreadScope()); } foreach (var bindingMock in transientScopedBindingMocks) { bindingMock.Verify(b => b.InTransientScope()); } }
public void AdditionalTypesCanBeSelectedFromOtherAssembliesUsingFromSelectAgain() { var assemblies1 = new[] { Assembly.GetExecutingAssembly() }; var assemblies2 = new[] { Assembly.GetCallingAssembly() }; var types1 = new[] { typeof(object), typeof(float) }; var types2 = new[] { typeof(double), typeof(int) }; var generatorMock = new Mock<IBindingGenerator>(); this.SetupTypeFilterGetTypes(assemblies1, types1); this.SetupTypeFilterGetTypes(assemblies2, types2); this.testee.SelectAllTypesFrom(assemblies1); this.testee.SelectAllTypesFrom(assemblies2); this.testee.BindWith(generatorMock.Object); this.VerifyAllBindingsCreated(types1.Union(types2), generatorMock); }
public void MultipleIncludesAndExcludesCanBeDone() { var expectedTypes = new[] { typeof(int), typeof(object), typeof(double) }; var types = new[] { typeof(object), typeof(float) }; var generatorMock = new Mock<IBindingGenerator>(); this.SetupTypeFilterGetTypes(types); this.testee.SelectAllTypesFrom(new Assembly[0]); this.testee.Including(new[] { typeof(DefaultConvention) }); this.testee.Excluding(new[] { typeof(float) }); this.testee.Including(new[] { typeof(int), typeof(double) }); this.testee.Excluding(new[] { typeof(DefaultConvention), typeof(int) }); this.testee.Including(new[] { typeof(int) }); this.testee.BindWith(generatorMock.Object); this.VerifyAllBindingsCreated(expectedTypes, generatorMock); }
public void TypesArePassedDistinctToTheGenerator() { var expectedTypes = new[] { typeof(int), typeof(object) }; var types = expectedTypes.Union(expectedTypes); var generatorMock = new Mock<IBindingGenerator>(); this.SetupTypeFilterGetTypes(types); this.testee.SelectAllTypesFrom(new Assembly[0]); this.testee.BindWith(generatorMock.Object); this.VerifyAllBindingsCreated(expectedTypes, generatorMock); }
public void ExcludingRemovesTheGivenType() { var expectedTypes = new[] { typeof(int), typeof(object) }; var types = expectedTypes.Union(new[] { typeof(DefaultConvention) }); var generatorMock = new Mock<IBindingGenerator>(); this.SetupTypeFilterGetTypes(types); this.testee.SelectAllTypesFrom(new Assembly[0]); this.testee.Excluding(new[] { typeof(DefaultConvention) }); this.testee.BindWith(generatorMock.Object); this.VerifyAllBindingsCreated(expectedTypes, generatorMock); }