public void Registers_service_with_name()
        {
            var serviceManager = new Mock<IServiceManager>();

            IDictionary<string,Type> contractTypes = new Dictionary<string, Type>();

            serviceManager.Setup(manager => manager.AddService(It.IsAny<Type>(), It.IsAny<Type>(), It.IsAny<string>(), It.IsAny<LifestyleType>()))
                .Callback<Type, Type, string, LifestyleType>((arg1, arg2, arg3, arg4) => contractTypes.Add(arg3, arg1));

            var registration = new ServiceRegistration(serviceManager.Object);

            registration.RegisterService(typeof(NamedService));

            Assert.AreEqual(1, contractTypes.Count);
            Assert.IsTrue(contractTypes.ContainsKey("Named Service"));
        }
        public void Registering_UserControl_ignores_dynamic_interface_for_service_contract()
        {
            var serviceManager = new Mock<IServiceManager>();

            IList<Type> contractTypes = new List<Type>();

            serviceManager.Setup(manager => manager.AddService(It.IsAny<Type>(), It.IsAny<Type>(), It.IsAny<string>(), It.IsAny<LifestyleType>()))
                .Callback<Type, Type, string, LifestyleType>((arg1, arg2, arg3, arg4) => contractTypes.Add(arg1));

            var registration = new ServiceRegistration(serviceManager.Object);

            registration.RegisterService(typeof (TestUserControl));

            Assert.AreEqual(2, contractTypes.Count);
            Assert.IsTrue(contractTypes.Contains(typeof(IUserControlInterface)));
            Assert.IsTrue(contractTypes.Contains(typeof(IUserControlInterface2)));
        }
        public void A_service_can_register_for_more_than_1_contract_by_having_multiple_RegisterService_attributes()
        {
            var serviceManager = new Mock<IServiceManager>();

            IList<Type> contractTypes = new List<Type>();

            serviceManager.Setup(manager => manager.AddService(It.IsAny<Type>(), It.IsAny<Type>(), It.IsAny<string>(), It.IsAny<LifestyleType>()))
                .Callback<Type, Type, string, LifestyleType>((arg1, arg2, arg3, arg4) => contractTypes.Add(arg1) );

            var registration = new ServiceRegistration(serviceManager.Object);

            registration.RegisterService(typeof(TestUserControl));

            Assert.AreEqual(2, contractTypes.Count);
            Assert.IsTrue(contractTypes.Contains(typeof(IUserControlInterface)));
            Assert.IsTrue(contractTypes.Contains(typeof(IUserControlInterface2)));
        }
Пример #4
0
 /// <summary>
 /// Automatically discovers and registers any types marked up with
 /// <see cref="RegisterComponentAttribute"/> or its derivatives.
 /// </summary>
 /// <param name="path">The path to probe for assemblies.</param>
 public static void AutoRegistration(string path)
 {
     var types = DiscoverTypes.FromDirectory(path).WithAttribute<RegisterComponentAttribute>().ToList();
     var registration = new ServiceRegistration(Instance);
     registration.RegisterServices( types );
 }