public void ShouldResolveTypesAfterAutoWireup()
        {
            // Arrange
            var container           = new UnityContainer();
            var asmDiscovery        = new StubAssemblyDiscovery(Assembly.GetExecutingAssembly().FullName);
            var attributedDiscovery = new AttributedTypeDiscoveryService(asmDiscovery);
            var bootstrapper        = new AbtBootstrapper(container, attributedDiscovery);

            // Act
            bootstrapper.Initialize();

            var exportedType0 = container.Resolve <IExportedType>();
            var exportedType1 = container.Resolve <IExportedType>();

            var exportedSingleton0 = container.Resolve <IExportedSingleton>();
            var exportedSingleton1 = container.Resolve <IExportedSingleton>();

            var exportedConfig0 = container.Resolve <ISomeConfig>();
            var exportedConfig1 = container.Resolve <ISomeConfig>();
            var exportedConfig2 = container.Resolve <ISomeOtherConfig>();
            var exportedConfig3 = container.Resolve <ISomeOtherConfig>();

            var exportedList = container.ResolveAll <IMulti>();

            // Assert
            Assert.That(ReferenceEquals(exportedType0, exportedType1), Is.False);
            Assert.That(ReferenceEquals(exportedSingleton0, exportedSingleton1), Is.True);
            Assert.That(ReferenceEquals(exportedConfig0, exportedConfig1), Is.True);
            Assert.That(ReferenceEquals(exportedConfig2, exportedConfig3), Is.True);
            Assert.That(ReferenceEquals(exportedConfig0, exportedConfig2), Is.True);
            Assert.That(exportedList.Count(), Is.EqualTo(2));
        }
示例#2
0
        public void ShouldDiscoverAttributedClasses()
        {
            var currentAssembly         = Assembly.GetAssembly(typeof(AttributedTypeDiscoveryServiceTests));
            var attributedTypeDiscovery = new AttributedTypeDiscoveryService(new StubAssemblyDiscovery(currentAssembly));

            var myAttributeTypes = attributedTypeDiscovery.DiscoverAttributedTypes <MyAttribute>();

            Assert.That(myAttributeTypes.Count(), Is.EqualTo(2));
            Assert.That(myAttributeTypes.First(), Is.EqualTo(typeof(DummyClass)));
            Assert.That(myAttributeTypes.Last(), Is.EqualTo(typeof(AnotherDummyClass)));

            var otherAttributeTypes = attributedTypeDiscovery.DiscoverAttributedTypes <OtherAttribute>();

            Assert.That(otherAttributeTypes.Count(), Is.EqualTo(2));
            Assert.That(otherAttributeTypes.First(), Is.EqualTo(typeof(AnotherDummyClass)));
            Assert.That(otherAttributeTypes.Last(), Is.EqualTo(typeof(YetAnotherDummyClass)));
        }
        public void ShouldRegisterTypesWithContainer()
        {
            // Arrange
            var container           = new StubContainer();
            var asmDiscovery        = new StubAssemblyDiscovery(Assembly.GetExecutingAssembly().FullName);
            var attributedDiscovery = new AttributedTypeDiscoveryService(asmDiscovery);
            var bootstrapper        = new AbtBootstrapper(container, attributedDiscovery);

            // Act
            bootstrapper.Initialize();

            // Assert
            Assert.That(container.TypeRegistrations.ContainsKey(typeof(IExportedType)));
            Assert.That(container.SingletonRegistrations.ContainsKey(typeof(IExportedSingleton)));
            Assert.That(container.SingletonRegistrations.ContainsKey(typeof(ISomeConfig)));
            Assert.That(container.SingletonRegistrations.ContainsKey(typeof(ISomeOtherConfig)));
        }