Exemplo n.º 1
0
        public void TestTwoCollections()
        {
            var rootToChildCollections = new[]
            {
                GetMock <IAbstractionConfigurationCollection>(),
                GetMock <IAbstractionConfigurationCollection>()
            };
            var compositeCollection = new CompositeCollection(rootToChildCollections, selector);

            selector.Expect(s => s.Select(typeof(int), 1)).Return(1);
            rootToChildCollections[1].Expect(c => c.Add(typeof(int), abstractionConfiguration));
            compositeCollection.Add(typeof(int), abstractionConfiguration);

            selector.Expect(s => s.Select(typeof(int), 1)).Return(0);
            rootToChildCollections[0].Expect(c => c.Get(typeof(int))).Return(abstractionConfiguration);
            Assert.AreSame(abstractionConfiguration, compositeCollection.Get(typeof(int)));

            selector.Expect(s => s.Select(typeof(int), 1)).Return(1);
            rootToChildCollections[1].Expect(c => c.Get(typeof(int))).Return(abstractionConfiguration);
            Assert.AreSame(abstractionConfiguration, compositeCollection.Get(typeof(int)));

            var configs = new[] { GetMock <IAbstractionConfiguration>() };

            rootToChildCollections[1].Expect(c => c.GetAll()).Return(configs);
            Assert.AreSame(configs, compositeCollection.GetAll());
        }
        public void TestTwoCollections()
        {
            var rootToChildCollectionMocks = new[]
            {
                GetMock <IAbstractionConfigurationCollection>(),
                GetMock <IAbstractionConfigurationCollection>()
            };
            var compositeCollection = new CompositeCollection(rootToChildCollectionMocks.Select(x => x.Object).ToArray(), selectorMock.Object);

            selectorMock.Setup(s => s.Select(typeof(int), 1)).Returns(1);
            rootToChildCollectionMocks[1].Setup(c => c.Add(typeof(int), abstractionConfigurationMock.Object));
            compositeCollection.Add(typeof(int), abstractionConfigurationMock.Object);

            selectorMock.Setup(s => s.Select(typeof(int), 1)).Returns(0);
            rootToChildCollectionMocks[0].Setup(c => c.Get(typeof(int))).Returns(abstractionConfigurationMock.Object);
            Assert.AreSame(abstractionConfigurationMock.Object, compositeCollection.Get(typeof(int)));

            selectorMock.Setup(s => s.Select(typeof(int), 1)).Returns(1);
            rootToChildCollectionMocks[1].Setup(c => c.Get(typeof(int))).Returns(abstractionConfigurationMock.Object);
            Assert.AreSame(abstractionConfigurationMock.Object, compositeCollection.Get(typeof(int)));

            var configMocks = new[] { GetMock <IAbstractionConfiguration>() };

            rootToChildCollectionMocks[1].Setup(c => c.GetAll()).Returns(configMocks.Select(x => x.Object).ToArray());
            Assert.AreSame(configMocks.Single().Object, compositeCollection.GetAll().Single());
        }
Exemplo n.º 3
0
        public void TestBadSelector()
        {
            var rootToChildCollections = new[]
            {
                GetMock <IAbstractionConfigurationCollection>(),
                GetMock <IAbstractionConfigurationCollection>()
            };
            var compositeCollection = new CompositeCollection(rootToChildCollections, selector);

            selector.Expect(s => s.Select(typeof(int), 1)).Return(2);
            RunMethodWithException <BadSelectorException>(() => compositeCollection.Get(typeof(int)));

            selector.Expect(s => s.Select(typeof(int), 1)).Return(-1);
            RunMethodWithException <BadSelectorException>(() => compositeCollection.Get(typeof(int)));
        }
        public void TestBadSelector()
        {
            var rootToChildCollectionMocks = new[]
            {
                GetMock <IAbstractionConfigurationCollection>(),
                GetMock <IAbstractionConfigurationCollection>()
            };
            var compositeCollection = new CompositeCollection(rootToChildCollectionMocks.Select(x => x.Object).ToArray(), selectorMock.Object);

            selectorMock.Setup(s => s.Select(typeof(int), 1)).Returns(2);
            RunMethodWithException <BadSelectorException>(() => compositeCollection.Get(typeof(int)));

            selectorMock.Setup(s => s.Select(typeof(int), 1)).Returns(-1);
            RunMethodWithException <BadSelectorException>(() => compositeCollection.Get(typeof(int)));
        }
        public void TestWorkWithIContainer()
        {
            var rootToChildCollectionMocks = new[]
            {
                GetMock <IAbstractionConfigurationCollection>(),
                GetMock <IAbstractionConfigurationCollection>()
            };
            var compositeCollection = new CompositeCollection(rootToChildCollectionMocks.Select(x => x.Object).ToArray(), selectorMock.Object);

            rootToChildCollectionMocks[1].Setup(c => c.Add(typeof(IContainer), abstractionConfigurationMock.Object));
            compositeCollection.Add(typeof(IContainer), abstractionConfigurationMock.Object);

            rootToChildCollectionMocks[1].Setup(c => c.Get(typeof(IContainer))).Returns(abstractionConfigurationMock.Object);
            Assert.AreSame(abstractionConfigurationMock.Object, compositeCollection.Get(typeof(IContainer)));
        }
Exemplo n.º 6
0
        public void TestWorkWithIContainer()
        {
            var rootToChildCollections = new[]
            {
                GetMock <IAbstractionConfigurationCollection>(),
                GetMock <IAbstractionConfigurationCollection>()
            };
            var compositeCollection = new CompositeCollection(rootToChildCollections, selector);

            rootToChildCollections[1].Expect(c => c.Add(typeof(IContainer),
                                                        abstractionConfiguration));
            compositeCollection.Add(typeof(IContainer), abstractionConfiguration);

            rootToChildCollections[1].Expect(c => c.Get(typeof(IContainer))).Return(abstractionConfiguration);
            Assert.AreSame(abstractionConfiguration, compositeCollection.Get(typeof(IContainer)));
        }