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));
        }
        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)));
        }
示例#3
0
 public App()
 {
     _bootstrapper = new AbtBootstrapper(new UnityContainer(), new AttributedTypeDiscoveryService(new AutoAssemblyDiscovery()));
     _bootstrapper.Initialize();
 }