public void Install(IWindsorContainer container, IConfigurationStore store) { ///equivalent to SimpleInjector's RegisterManyForOpenGeneric: ///container.RegisterManyForOpenGeneric( /// typeof(IHandler<>), /// AppDomain.CurrentDomain.GetAssemblies()); /// ref: http://simpleinjector.codeplex.com/wikipage?title=Castle%20Windsor container.Register(AllTypes.From( AppDomain.CurrentDomain.GetAssemblies() .Where(a => !a.IsDynamic) //dynamic assemblys don't export types... .SelectMany(a => a.GetExportedTypes())) .BasedOn(typeof(IHandleEvent <>)) .Unless(t => t.IsGenericTypeDefinition) .WithService.Select((_, baseTypes) => { return (from t in baseTypes where t.IsGenericType let td = t.GetGenericTypeDefinition() where td == typeof(IHandleEvent <>) select t); })); //.Configure(c => c.LifestylePerWebRequest())); }
public void Should_methods_have_a_matching_overload_to_guard_against_chaining_and_constraints() { // Arrange / Act List <MethodInfo> shouldOverloads = AllTypes.From(typeof(FluentAssertions.AssertionExtensions).Assembly) .ThatAreClasses() .ThatAreStatic() .Where(t => t.IsPublic) .SelectMany(t => t.GetMethods(BindingFlags.Static | BindingFlags.Public)) .Where(m => m.Name == "Should") .ToList(); List <Type> realOverloads = shouldOverloads .Where(m => !IsGuardOverload(m)) .Select(t => GetMostParentType(t.ReturnType)) .Distinct() .ToList(); List <Type> fakeOverloads = shouldOverloads .Where(m => IsGuardOverload(m)) .Select(e => e.GetParameters()[0].ParameterType) .ToList(); // Assert fakeOverloads.Should().BeEquivalentTo(realOverloads, opt => opt .Using <Type>(ctx => ctx.Subject.Name.Should().Be(ctx.Expectation.Name)) .WhenTypeIs <Type>()); }
public void ValidateFixtures() { // Arrange // Is everything in the assembly either a setup or a test fixture? int vTestFixtureCount = AllTypes .From(_Assembly) .ThatAreDecoratedWith <TestFixtureAttribute>() .Count(); // Act // Assert _SetupFixtureCount .Should() .BeInRange ( 0 , _ALLOWED_SETUP_FIXTURE_COUNT , "there is supposed to be only {0} SetupFixture" , _ALLOWED_SETUP_FIXTURE_COUNT ); int vFixtureCount = AllTypes.From(_Assembly).Count(); vFixtureCount.Should().Be(_SetupFixtureCount + vTestFixtureCount); }
public void FluentAssertions_Conventions() { typeof(MiniOrder).Should().BeDerivedFrom <Order>(); typeof(MiniOrder).Should().Implement <IDisposable>(); typeof(MiniOrder).Should().BeDecoratedWith <AuthorizeAttribute>(); // ValidateAntiForgeryToken attribute in Post methods typeof(RegistrationController).Methods() .ThatReturn <ActionResult>() .ThatAreDecoratedWith <HttpPostAttribute>() .Should() .BeDecoratedWith <ValidateAntiForgeryTokenAttribute>( "because all Actions with HttpPost require ValidateAntiForgeryToken"); // all ViewModels must derive from BaseVM Type baseVmType = typeof(BaseVM); Assembly baseVmAssembly = baseVmType.Assembly; string baseVmNamespace = baseVmType.Namespace; string baseVmFullName = baseVmType.FullName; AllTypes.From(baseVmAssembly) .ThatAreInNamespace(baseVmNamespace) .ThatDoNotDeriveFrom <BaseVM>() .Where(type => type.FullName != baseVmFullName) // exclude BaseVM .Should().BeEmpty(); }
public void When_combining_type_selection_filters_it_should_return_the_correct_types() { //------------------------------------------------------------------------------------------------------------------- // Arrange //------------------------------------------------------------------------------------------------------------------- #if !WINRT Assembly assembly = typeof(ClassWithSomeAttribute).Assembly; #else Assembly assembly = typeof(ClassWithSomeAttribute).GetTypeInfo().Assembly; #endif //------------------------------------------------------------------------------------------------------------------- // Act //------------------------------------------------------------------------------------------------------------------- IEnumerable <Type> types = AllTypes.From(assembly) .ThatAreDecoratedWith <SomeAttribute>() .ThatImplement <ISomeInterface>() .ThatAreInNamespace("Internal.Main.Test"); //------------------------------------------------------------------------------------------------------------------- // Assert //------------------------------------------------------------------------------------------------------------------- types.Should() .HaveCount(1) .And.Contain(typeof(ClassWithSomeAttributeThatImplementsSomeInterface)); }
public void Install(IWindsorContainer container, IConfigurationStore store) { container.Register( AllTypes.From(new[] { typeof(Bar), typeof(Baz) }), Classes.From(new[] { typeof(Bar), typeof(Baz) }), Castle.MicroKernel.Registration.Types.From(new[] { typeof(Bar), typeof(Baz) }) ); }
public void Install(IWindsorContainer container, IConfigurationStore store) { container.Register( AllTypes.From(typeof(Foo), typeof(Bar), typeof(Baz)).BasedOn <IFoo>(), Classes.From(typeof(Foo), typeof(Bar), typeof(Baz)).BasedOn <IFoo>(), Castle.MicroKernel.Registration.Types.From(typeof(Foo), typeof(Bar), typeof(Baz)).BasedOn <IFoo>() ); }
public void AllValueObjectsInCorrectNamespace() { Assembly productionCodeAssembly = typeof(LoanAmount).Assembly; IEnumerable <Type> valueObjectTypes = AllTypes.From(productionCodeAssembly) .ThatDeriveFrom <ValueObject>(); valueObjectTypes.Should().OnlyContain(x => x.Namespace == "Loans.Domain.Applications.Values"); }
public void Setup() { _Assembly = Assembly.GetAssembly(typeof(TestTheTests)); _SetupFixtureCount = AllTypes .From(_Assembly) .ThatAreDecoratedWith <SetUpFixtureAttribute>() .Count(); }
public void Install(IWindsorContainer container, IConfigurationStore store) { var metadataProviderContributorsAssemblies = new[] { typeof(QueryProcessor).Assembly }; container.Register(AllTypes.From(metadataProviderContributorsAssemblies.SelectMany(a => a.GetExportedTypes())) .Where(t => t.Name.EndsWith("Handler") && t.IsAbstract == false) .Configure(x => x.LifestyleSingleton()) ); container.Register(Component.For <IProcessQuery>().ImplementedBy <QueryProcessor>().LifeStyle.Singleton); container.Register(Component.For <IProcessCommand>().ImplementedBy <CommandProcessor>().LifeStyle.Singleton); }
public void Can_make_a_component_fallback_via_AllTypes_2() { Container.Register( AllTypes.From(typeof(EmptyServiceA), typeof(EmptyServiceB)) .BasedOn <IEmptyService>() .WithService.Base() .ConfigureFor <EmptyServiceA>(c => c.IsFallback())); var obj = Container.Resolve <IEmptyService>(); Assert.IsNotInstanceOf <EmptyServiceA>(obj); }
public void RegisterSpecificTypes_WithGenericDefinition_RegisteredInContainer() { Kernel.Register(AllTypes.From(typeof(CustomerRepository)) .Pick() .WithService.FirstInterface() ); var repository = Kernel.Resolve <IRepository <ICustomer> >(); Assert.IsNotNull(repository); }
public void NamespaceContainsOnlyValueObjects() { var productionCodeAssembly = typeof(LoanAmount).Assembly; var nonValueObjectTypesInNameSpace = AllTypes.From(productionCodeAssembly) .ThatAreInNamespace("Loans.Domain.Applications.Values") .ThatDoNotDeriveFrom <ValueObject>() .Where(x => x.GetCustomAttribute <CompilerGeneratedAttribute>() == null); nonValueObjectTypesInNameSpace.Should().BeEmpty(); }
public void RegisterGenericTypes_BasedOnGenericDefinition_RegisteredInContainer() { Kernel.Register(AllTypes.From(typeof(DefaultRepository <>)) .Pick() .WithService.FirstInterface() ); var repository = Kernel.Resolve <ClassComponents.IRepository <CustomerImpl> >(); Assert.IsNotNull(repository); }
public void RegisterTypes_WithLinq_RegisteredInContainer() { Kernel.Register(AllTypes.From(from type in Assembly.GetExecutingAssembly().GetExportedTypes() where type.IsDefined(typeof(SerializableAttribute), true) select type ).BasedOn <CustomerChain1>()); var handlers = Kernel.GetAssignableHandlers(typeof(CustomerChain1)); Assert.AreEqual(2, handlers.Length); }
public void When_selecting_types_from_specific_namespace_it_should_return_the_correct_types() { // Arrange Assembly assembly = typeof(ClassWithSomeAttribute).GetTypeInfo().Assembly; // Act IEnumerable <Type> types = AllTypes.From(assembly).ThatAreInNamespace("Internal.Other.Test"); // Assert types.Should().ContainSingle() .Which.Should().Be(typeof(SomeOtherClass)); }
public void When_selecting_types_that_derive_from_a_specific_class_it_should_return_the_correct_types() { // Arrange Assembly assembly = typeof(ClassDerivedFromSomeBaseClass).Assembly; // Act IEnumerable <Type> types = AllTypes.From(assembly).ThatDeriveFrom <SomeBaseClass>(); // Assert types.Should().ContainSingle() .Which.Should().Be(typeof(ClassDerivedFromSomeBaseClass)); }
public void When_selecting_types_that_derive_from_a_specific_generic_class_it_should_return_the_correct_types() { // Arrange Assembly assembly = typeof(ClassDerivedFromSomeGenericBaseClass).GetTypeInfo().Assembly; // Act TypeSelector types = AllTypes.From(assembly).ThatDeriveFrom <SomeGenericBaseClass <int> >(); // Assert types.ToArray().Should().ContainSingle() .Which.Should().Be(typeof(ClassDerivedFromSomeGenericBaseClass)); }
public void NamespaceContainsOnlyValueObjects() { // valida que tods as classes na pastas domain/applications/values derivam de uma classe ValueObject Assembly productionCodeAssembly = typeof(LoanAmount).Assembly; IEnumerable <Type> nonValueObjectTypesInNameSpace = AllTypes.From(productionCodeAssembly) .ThatAreInNamespace("Loans.Domain.Applications.Values") .ThatDoNotDeriveFrom <ValueObject>() .Where(x => x.GetCustomAttribute <CompilerGeneratedAttribute>() == null); nonValueObjectTypesInNameSpace.Should().BeEmpty(); }
public static void Register(IWindsorContainer container, MultipleBinding binding) { var registration = AllTypes.From(binding.Services).Pick(); if (binding.BindTo.Count > 0) { registration = registration.WithServices(binding.BindTo); } registration = ApplyLifestyle(registration, binding.Lifestyle); container.Register(registration); }
public void When_selecting_types_other_than_from_specific_namespace_or_sub_namespaces_it_should_return_the_correct_types() { // Arrange Assembly assembly = typeof(ClassWithSomeAttribute).GetTypeInfo().Assembly; // Act IEnumerable <Type> types = AllTypes.From(assembly) .ThatAreUnderNamespace("Internal.Other") .ThatAreNotUnderNamespace("Internal.Other.Test"); // Assert types.Should() .BeEmpty(); }
public void When_selecting_types_from_specific_namespace_or_sub_namespaces_it_should_return_the_correct_types() { // Arrange Assembly assembly = typeof(ClassWithSomeAttribute).GetTypeInfo().Assembly; // Act IEnumerable <Type> types = AllTypes.From(assembly).ThatAreUnderNamespace("Internal.Other.Test"); // Assert types.Should() .HaveCount(2) .And.Contain(typeof(SomeOtherClass)) .And.Contain(typeof(SomeCommonClass)); }
public void VerifyNamespace() { const string expectedNs = nameof(NClap); const string expectedNsWithDot = expectedNs + "."; foreach (var type in AllTypes.From(AssemblyUnderTest).Where(t => t.GetTypeInfo().IsPublic)) { var ns = type.Namespace; if (ns != expectedNs) { ns.Should().StartWith(expectedNsWithDot); } } }
public void When_selecting_types_that_do_not_derive_from_a_specific_class_it_should_return_the_correct_types() { // Arrange Assembly assembly = typeof(ClassDerivedFromSomeBaseClass).Assembly; // Act IEnumerable <Type> types = AllTypes.From(assembly) .ThatAreInNamespace("Internal.Main.Test") .ThatDoNotDeriveFrom <SomeBaseClass>(); // Assert types.Should() .HaveCount(12); }
public void Assertions_classes_have_overriden_equals() { // Arrange / Act var equalsOverloads = AllTypes.From(typeof(FluentAssertions.AssertionExtensions).Assembly) .ThatAreClasses() .Where(t => t.IsPublic && t.Name.TrimEnd('`', '1', '2', '3').EndsWith("Assertions", StringComparison.Ordinal)) .Select(e => GetMostParentType(e)) .Distinct() .Select(t => (type: t, overridesEquals: OverridesEquals(t))) .ToList(); // Assert equalsOverloads.Should().OnlyContain(e => e.overridesEquals); }
public void When_selecting_types_that_do_not_implement_a_specific_interface_it_should_return_the_correct_types() { // Arrange Assembly assembly = typeof(ClassImplementingSomeInterface).GetTypeInfo().Assembly; // Act IEnumerable <Type> types = AllTypes.From(assembly) .ThatAreInNamespace("Internal.Main.Test") .ThatDoNotImplement <ISomeInterface>(); // Assert types.Should() .HaveCount(10); }
public void When_selecting_types_that_are_not_decorated_with_a_specific_attribute_it_should_return_the_correct_types() { // Arrange Assembly assembly = typeof(ClassWithSomeAttribute).GetTypeInfo().Assembly; // Act IEnumerable <Type> types = AllTypes.From(assembly).ThatAreNotDecoratedWith <SomeAttribute>(); // Assert types.Should() .NotBeEmpty() .And.NotContain(typeof(ClassWithSomeAttribute)) .And.NotContain(typeof(ClassWithSomeAttributeThatImplementsSomeInterface)); }
public void When_selecting_types_that_do_not_derive_from_a_specific_generic_class_it_should_return_the_correct_types() { // Arrange Assembly assembly = typeof(ClassDerivedFromSomeGenericBaseClass).GetTypeInfo().Assembly; // Act TypeSelector types = AllTypes.From(assembly) .ThatAreInNamespace("Internal.Main.Test") .ThatDoNotDeriveFrom <SomeGenericBaseClass <int> >(); // Assert types.ToArray().Should() .HaveCount(12); }
public void When_selecting_types_that_implement_a_specific_interface_it_should_return_the_correct_types() { // Arrange Assembly assembly = typeof(ClassImplementingSomeInterface).GetTypeInfo().Assembly; // Act IEnumerable <Type> types = AllTypes.From(assembly).ThatImplement <ISomeInterface>(); // Assert types.Should() .HaveCount(2) .And.Contain(typeof(ClassImplementingSomeInterface)) .And.Contain(typeof(ClassWithSomeAttributeThatImplementsSomeInterface)); }
public void When_combining_type_selection_filters_it_should_return_the_correct_types() { // Arrange Assembly assembly = typeof(ClassWithSomeAttribute).GetTypeInfo().Assembly; // Act IEnumerable <Type> types = AllTypes.From(assembly) .ThatAreDecoratedWith <SomeAttribute>() .ThatImplement <ISomeInterface>() .ThatAreInNamespace("Internal.Main.Test"); // Assert types.Should().ContainSingle() .Which.Should().Be(typeof(ClassWithSomeAttributeThatImplementsSomeInterface)); }