Exemplo n.º 1
0
        public void TestConfigurationManagerFindAllComponentsOfTypeInvalidApp()
        {
            ConfigurationManager manager = new ConfigurationManager();

            Mock <IApp> app1 = new Mock <IApp>(MockBehavior.Strict);

            app1.Setup(s => s.IsValid).Returns(false);
            manager.AddComponent(app1.Object);

            Mock <IApp> app2 = new Mock <IApp>(MockBehavior.Strict);

            app2.Setup(s => s.IsValid).Returns(false);
            manager.AddComponent(app2.Object);

            Mock <IIOInterface> ioInterface = new Mock <IIOInterface>(MockBehavior.Strict);

            manager.AddComponent(ioInterface.Object);

            IEnumerable <IParseable> foundComponents = manager.FindAllComponentsOfType <IApp>().ToList();

            Assert.AreEqual(0, foundComponents.Count());

            app1.Verify(s => s.IsValid, Times.Exactly(1));
            app2.Verify(s => s.IsValid, Times.Exactly(1));
        }
Exemplo n.º 2
0
        public void TestConfigurationManagerFindAllComponentsOfTypeMultipleIOInterfaces()
        {
            ConfigurationManager manager = new ConfigurationManager();

            Mock <IApp> app = new Mock <IApp>(MockBehavior.Strict);

            manager.AddComponent(app.Object);

            Mock <IIOInterface> ioInterface1 = new Mock <IIOInterface>(MockBehavior.Strict);

            ioInterface1.Setup(s => s.IsValid).Returns(true);
            manager.AddComponent(ioInterface1.Object);

            Mock <IIOInterface> ioInterface2 = new Mock <IIOInterface>(MockBehavior.Strict);

            ioInterface2.Setup(s => s.IsValid).Returns(true);
            manager.AddComponent(ioInterface2.Object);

            IEnumerable <IParseable> foundComponents = manager.FindAllComponentsOfType <IIOInterface>().ToList();

            Assert.AreEqual(2, foundComponents.Count());
            Assert.IsTrue(foundComponents.Contains(ioInterface1.Object));
            Assert.IsTrue(foundComponents.Contains(ioInterface2.Object));

            ioInterface1.Verify(s => s.IsValid, Times.Exactly(1));
            ioInterface2.Verify(s => s.IsValid, Times.Exactly(1));
        }