public void CreateFromAttributes_Multiple_EntriesAreSortedCorrectly() { var attribute1 = Tuple.Create( typeof(TestMultipleConcreteImplementationAttributesType1), new ImplementationForAttribute(typeof(ITestMultipleConcreteImplementationAttributesType)) { Lifetime = LifetimeKind.Singleton, Position = 0 }); var attribute2 = Tuple.Create( typeof(TestMultipleConcreteImplementationAttributesType2), new ImplementationForAttribute(typeof(ITestMultipleConcreteImplementationAttributesType)) { Lifetime = LifetimeKind.InstancePerDependency, Position = -1 }); var attributes = new[] { attribute1, attribute2 }; var entry = ServiceConfigurationEntry.CreateFromAttributes(typeof(ITestMultipleConcreteImplementationAttributesType), attributes); Assert.That(entry.ServiceType, Is.EqualTo(typeof(ITestMultipleConcreteImplementationAttributesType))); Assert.That(entry.ImplementationInfos.Count, Is.EqualTo(2)); Assert.That(entry.ImplementationInfos[0].ImplementationType, Is.EqualTo(typeof(TestMultipleConcreteImplementationAttributesType2))); Assert.That(entry.ImplementationInfos[0].Lifetime, Is.EqualTo(LifetimeKind.InstancePerDependency)); Assert.That(entry.ImplementationInfos[1].ImplementationType, Is.EqualTo(typeof(TestMultipleConcreteImplementationAttributesType1))); Assert.That(entry.ImplementationInfos[1].Lifetime, Is.EqualTo(LifetimeKind.Singleton)); }
public void CreateFromAttributes_IncompatibleType() { var attribute = Tuple.Create(typeof(object), new ImplementationForAttribute(typeof(ITestSingletonConcreteImplementationAttributeType))); Assert.That( () => ServiceConfigurationEntry.CreateFromAttributes(typeof(ITestSingletonConcreteImplementationAttributeType), new[] { attribute }), Throws.InvalidOperationException.With.Message.EqualTo("The implementation type 'System.Object' does not implement the service type.")); }
public void CreateFromAttributes_Single() { var attribute = new ImplementationForAttribute(typeof(ITestSingletonConcreteImplementationAttributeType)) { Lifetime = LifetimeKind.Singleton }; var entry = ServiceConfigurationEntry.CreateFromAttributes( typeof(ITestSingletonConcreteImplementationAttributeType), new[] { Tuple.Create(typeof(TestConcreteImplementationAttributeType), attribute) }); Assert.That(entry.ServiceType, Is.EqualTo(typeof(ITestSingletonConcreteImplementationAttributeType))); Assert.That(entry.ImplementationInfos.Count, Is.EqualTo(1)); Assert.That(entry.ImplementationInfos[0].ImplementationType, Is.EqualTo(typeof(TestConcreteImplementationAttributeType))); Assert.That(entry.ImplementationInfos[0].Lifetime, Is.EqualTo(LifetimeKind.Singleton)); }
public void CreateFromAttributes_EqualPositions_DifferentRegistrationTypes() { var attribute1 = Tuple.Create( typeof(TestMultipleConcreteImplementationAttributesType1), new ImplementationForAttribute(typeof(ITestMultipleConcreteImplementationAttributesType)) { Lifetime = LifetimeKind.Singleton, Position = 1, RegistrationType = RegistrationType.Compound }); var attribute2 = Tuple.Create( typeof(TestMultipleConcreteImplementationAttributesType2), new ImplementationForAttribute(typeof(ITestMultipleConcreteImplementationAttributesType)) { Lifetime = LifetimeKind.InstancePerDependency, Position = 1, RegistrationType = RegistrationType.Multiple }); var attributes = new[] { attribute1, attribute2 }; ServiceConfigurationEntry.CreateFromAttributes(typeof(ITestMultipleConcreteImplementationAttributesType), attributes); }