Example #1
0
        public void GetComponentValidationCollectors_WithFakeTypeDiscoveryService()
        {
            var appliedWithAttributeTypes = new[]
            {
                typeof(IPersonValidationCollector1), typeof(IPersonValidationCollector2),
                typeof(PersonValidationCollector1),
                typeof(CustomerValidationCollector1), typeof(CustomerValidationCollector2)
            };

            _typeDescoveryServiceStub.Stub(stub => stub.GetTypes(typeof(IComponentValidationCollector), true)).Return(appliedWithAttributeTypes);

            var typeCollectorProvider = DiscoveryServiceBasedValidationCollectorReflector.Create(
                _typeDescoveryServiceStub,
                new ClassTypeAwareValidatedTypeResolverDecorator(
                    new GenericTypeAwareValidatedTypeResolverDecorator(new NullValidatedTypeResolver())));

            Assert.That(typeCollectorProvider.GetCollectorsForType(typeof(IPerson)), Is.EqualTo(new[] { typeof(IPersonValidationCollector1) }));

            Assert.That(
                typeCollectorProvider.GetCollectorsForType(typeof(Person)),
                Is.EquivalentTo(new[] { typeof(IPersonValidationCollector2), typeof(PersonValidationCollector1) })); //ApplyWithClass(typeof(Person))!

            Assert.That(
                typeCollectorProvider.GetCollectorsForType(typeof(Customer)),
                Is.EqualTo(new[] { typeof(CustomerValidationCollector1), typeof(CustomerValidationCollector2) }));
        }
Example #2
0
        public void GetValueInfos_Value()
        {
            _typeDiscoveryServiceStub.Stub(stub => stub.GetTypes(null, false)).Return(new[] { typeof(ColorExtensions) });

            var valueInfos = _service.GetValueInfos(new ExtensibleEnumDefinition <Color> (_service));

            Assert.That(valueInfos.Select(info => info.Value).ToArray(),
                        Is.EquivalentTo(new[] { Color.Values.Red(), Color.Values.Green() }));
        }
Example #3
0
        public void GetDefaultConfiguration_TypeDiscoveryService()
        {
            _typeDiscoveryServiceStub.Stub(stub => stub.GetTypes(null, _excludeGlobalTypes))
            .Return(new ArrayList {
                typeof(ITestSingletonConcreteImplementationAttributeType)
            });
            _typeDiscoveryServiceStub.Stub(stub => stub.GetTypes(typeof(ITestSingletonConcreteImplementationAttributeType), true))
            .Return(new ArrayList {
                typeof(TestConcreteImplementationAttributeType)
            });

            var serviceConfigurationEntries = _defaultServiceConfigurationDiscoveryService.GetDefaultConfiguration().ToArray();

            Assert.That(serviceConfigurationEntries, Has.Length.EqualTo(1));
            var serviceConfigurationEntry = serviceConfigurationEntries.Single();

            Assert.That(serviceConfigurationEntry.ServiceType, Is.SameAs(typeof(ITestSingletonConcreteImplementationAttributeType)));

            Assert.That(serviceConfigurationEntry.ImplementationInfos.Count, Is.EqualTo(1));
            Assert.That(serviceConfigurationEntry.ImplementationInfos[0].ImplementationType, Is.EqualTo(typeof(TestConcreteImplementationAttributeType)));
            Assert.That(serviceConfigurationEntry.ImplementationInfos[0].Lifetime, Is.EqualTo(LifetimeKind.Singleton));
        }