Пример #1
0
        public void CreateStub_WhenArgumentsValid_ReturnsHandleWithStubbedDescriptor()
        {
            var componentId = "componentId";
            var component   = MockRepository.GenerateStub <DummyService>();
            var traits      = new DummyTraits();

            var handle = ComponentHandle.CreateStub <DummyService, DummyTraits>(componentId, component, traits);

            Assert.Multiple(() =>
            {
                Assert.AreEqual(componentId, handle.Id);
                Assert.AreEqual(typeof(DummyService), handle.ServiceType);
                Assert.AreEqual(typeof(DummyTraits), handle.TraitsType);
                Assert.AreSame(component, handle.GetComponent());
                Assert.AreSame(traits, handle.GetTraits());

                object x = null;
                Assert.Throws <NotSupportedException>(() => x = handle.Descriptor.Plugin);
                Assert.Throws <NotSupportedException>(() => x = handle.Descriptor.Service);
                Assert.AreEqual(componentId, handle.Descriptor.ComponentId);
                Assert.AreEqual(new TypeName(component.GetType()), handle.Descriptor.ComponentTypeName);
                Assert.Throws <NotSupportedException>(() => x = handle.Descriptor.ComponentHandlerFactory);
                Assert.Throws <NotSupportedException>(() => x = handle.Descriptor.ComponentProperties);
                Assert.Throws <NotSupportedException>(() => x = handle.Descriptor.TraitsProperties);
                Assert.IsFalse(handle.Descriptor.IsDisabled);
                Assert.Throws <InvalidOperationException>(() => x = handle.Descriptor.DisabledReason);
                Assert.AreEqual(component.GetType(), handle.Descriptor.ResolveComponentType());
                Assert.Throws <NotSupportedException>(() => handle.Descriptor.ResolveComponentHandler());
                Assert.AreSame(component, handle.Descriptor.ResolveComponent());
                Assert.Throws <NotSupportedException>(() => handle.Descriptor.ResolveTraitsHandler());
                Assert.AreSame(traits, handle.Descriptor.ResolveTraits());
            });
        }
Пример #2
0
        public void CreateStub_WhenComponentIdIsNull_Throws()
        {
            var component = MockRepository.GenerateStub <DummyService>();
            var traits    = new DummyTraits();

            Assert.Throws <ArgumentNullException>(() => ComponentHandle.CreateStub <DummyService, DummyTraits>(null, component, traits));
        }
Пример #3
0
        public void CreateStub_WhenComponentIsNull_Throws()
        {
            var componentId = "componentId";
            var traits      = new DummyTraits();

            Assert.Throws <ArgumentNullException>(() => ComponentHandle.CreateStub <DummyService, DummyTraits>(componentId, null, traits));
        }
Пример #4
0
 private static ComponentHandle <IFileTypeRecognizer, FileTypeRecognizerTraits>[] CreateRecognizerHandles(
     params RecognizerInfo[] recognizerInfos)
 {
     return(GenericCollectionUtils.ConvertAllToArray(recognizerInfos, recognizerInfo =>
                                                     ComponentHandle.CreateStub("component",
                                                                                recognizerInfo.Recognizer ?? MockRepository.GenerateStub <IFileTypeRecognizer>(),
                                                                                recognizerInfo.Traits ?? new FileTypeRecognizerTraits("Dummy", "Dummy"))));
 }