Exemple #1
0
        public void TestDispose()
        {
            var disposable    = NewMock <IDisposable>();
            var configuration = new InstanceImplementationConfiguration(new TestClassWrapperCreator(), disposable);

            Expect.Once.On(disposable).Method("Dispose");
            configuration.DisposeInstance();
        }
        public void TestDispose()
        {
            var disposableMock = GetMock <IDisposable>();
            var configuration  = new InstanceImplementationConfiguration(new TestClassWrapperCreator(), disposableMock.Object);

            disposableMock.Setup(x => x.Dispose());
            configuration.DisposeInstance();
        }
Exemple #3
0
        public void TestGetInstance()
        {
            var instance      = new object();
            var configuration = new InstanceImplementationConfiguration(new TestClassWrapperCreator(), instance);
            var context       = NewMock <IInjectionContext>();

            context.ExpectReused(instance.GetType());
            Assert.AreSame(instance, configuration.GetOrCreateInstance(context, null));
        }
 public InstanceAbstractionConfiguration(IClassWrapperCreator classWrapperCreator, Type abstractionType, object[] instances)
 {
     if (instances == null || instances.Length == 0)
     {
         throw new ArgumentException("instances");
     }
     implementationConfigurations = new IImplementationConfiguration[instances.Length];
     for (var i = 0; i < implementationConfigurations.Length; i++)
     {
         var type = instances[i].GetType();
         if (!abstractionType.IsAssignableFrom(type))
         {
             throw new ArgumentException($"Instances of type {type} cannot be used as abstraction of type {abstractionType}");
         }
         implementationConfigurations[i] = new InstanceImplementationConfiguration(classWrapperCreator, instances[i]);
     }
 }
Exemple #5
0
 public InstanceAbstractionConfiguration(IClassWrapperCreator classWrapperCreator, Type abstractionType, object[] instances)
 {
     if (instances == null || instances.Length == 0)
     {
         throw new ArgumentException("instances");
     }
     implementationConfigurations = new IImplementationConfiguration[instances.Length];
     for (int i = 0; i < implementationConfigurations.Length; i++)
     {
         Type type = instances[i].GetType();
         if (!abstractionType.IsAssignableFrom(type))
         {
             throw new ArgumentException("Заданная реализация на являются объектами типа " + abstractionType +
                                         " (реальный тип " + type + ")");
         }
         implementationConfigurations[i] = new InstanceImplementationConfiguration(classWrapperCreator, instances[i]);
     }
 }
Exemple #6
0
        public void TestGetFactoryNotSupported()
        {
            var configuration = new InstanceImplementationConfiguration(new TestClassWrapperCreator(), new object());

            RunMethodWithException <NotSupportedException>(() => configuration.GetFactory(null, null));
        }
Exemple #7
0
        public void TestDisposeDoNothingIfNotDisposable()
        {
            var configuration = new InstanceImplementationConfiguration(new TestClassWrapperCreator(), new object());

            configuration.DisposeInstance();
        }