Пример #1
0
        public void Test_GetComponentByString()
        {
            DictionaryComponent dictionary = new DictionaryComponent();
            IComponent          component  = new StubComponent();

            dictionary.Add(component);

            var thisComponent = dictionary.GetComponent("StubComponent");

            Assert.AreSame(component, thisComponent);
        }
Пример #2
0
        public void Test_RemoveComponent()
        {
            DictionaryComponent dictionary = new DictionaryComponent();
            IComponent          component  = new StubComponent();

            dictionary.Remove(component);

            var thisComponent = dictionary.GetComponent <StubComponent>();

            Assert.AreNotSame(thisComponent, component);
        }
Пример #3
0
        public void Test_GetComponentGeneric()
        {
            DictionaryComponent dictionary = new DictionaryComponent();
            IComponent          component  = new StubComponent();

            dictionary.Add(component);

            var thisComponent = dictionary.GetComponent <StubComponent>();

            Assert.AreSame(component, thisComponent);
        }
Пример #4
0
        public void Test_GetComponent()
        {
            DictionaryComponent dictionary = new DictionaryComponent();
            IComponent          component  = new StubComponent();

            dictionary.Add(component);

            // не обрабатывавает имключение, если такого компонента нет в словаре
            var thisComponent = dictionary.GetComponent(typeof(StubComponent));

            Assert.AreSame(component, thisComponent);
        }
Пример #5
0
        public async ValueTask ShouldCreateTest2Async()
        {
            await using (IComponent component = new StubComponent())
            {
                await component.CreateAsync();

                //stubComponent.DisposeAsync();
            }

            await using (IConfigurableComponent component = new StubConfigurableComponent())
            {
                component.Configuration = new StubComponentConfiguration();
                await component.CreateAsync();

                //stubComponent.DisposeAsync();
            }

            await using (ISpecifiableConfigurableComponent component = new StubSpecifiableConfigurableComponent())
            {
                var that = new UnknownComponentConfigurationObject();

                that.ComponentSpecificConfiguration.Add(nameof(StubComponentSpecification.PropA), "test");
                that.ComponentSpecificConfiguration.Add(nameof(StubComponentSpecification.PropB), 100);
                that.ComponentSpecificConfiguration.Add(nameof(StubComponentSpecification.PropC), true);
                that.ComponentSpecificConfiguration.Add(nameof(StubComponentSpecification.PropD), 10.50);

                component.Configuration = new UnknownComponentConfigurationObject <StubComponentSpecification>(that);
                await component.CreateAsync();

                //Assert.AreSame(component.Configuration.ComponentSpecificConfiguration, component.Specification);

                dynamic dynSpecification = component.Specification;
                dynamic dynConfig        = component.Configuration;
                dynamic dynComponentSpecificConfiguration = dynConfig.ComponentSpecificConfiguration;

                Assert.AreEqual("test", dynSpecification.PropA);
                Assert.AreEqual(100, dynSpecification.PropB);
                Assert.AreEqual(true, dynSpecification.PropC);
                Assert.AreEqual(10.50, dynSpecification.PropD);

                Assert.AreEqual("test", dynComponentSpecificConfiguration.PropA);
                Assert.AreEqual(100, dynComponentSpecificConfiguration.PropB);
                Assert.AreEqual(true, dynComponentSpecificConfiguration.PropC);
                Assert.AreEqual(10.50, dynComponentSpecificConfiguration.PropD);

                //stubComponent.DisposeAsync();
            }
        }
Пример #6
0
        public void Test_GetComponentsGeneric()
        {
            DictionaryComponent dictionary = new DictionaryComponent();
            IComponent          component1 = new StubComponent();
            IComponent          component2 = new MockComponent();

            dictionary.Add(component1);
            dictionary.Add(component2);

            var receivedComponents = dictionary.GetComponents <IComponent>();

            IComponent ReceivedComponent1 = receivedComponents[0];
            IComponent ReceivedComponent2 = receivedComponents[1];

            Assert.AreEqual(2, receivedComponents.Length);
            Assert.AreSame(component1, ReceivedComponent1);
            Assert.AreSame(component2, ReceivedComponent2);
        }
Пример #7
0
        public void ShouldCreateTest()
        {
            using (IComponent component = new StubComponent())
            {
                component.Create();

                //stubComponent.Dispose();
            }

            using (IConfigurableComponent <StubComponentConfiguration> component = new StubConfigurableComponent())
            {
                component.Configuration = new StubComponentConfiguration();
                component.Create();

                //stubComponent.Dispose();
            }

            using (ISpecifiableConfigurableComponent <UnknownComponentConfigurationObject <StubComponentSpecification>, StubComponentSpecification> component = new StubSpecifiableConfigurableComponent())
            {
                var that = new UnknownComponentConfigurationObject();

                that.ComponentSpecificConfiguration.Add(nameof(StubComponentSpecification.PropA), "test");
                that.ComponentSpecificConfiguration.Add(nameof(StubComponentSpecification.PropB), 100);
                that.ComponentSpecificConfiguration.Add(nameof(StubComponentSpecification.PropC), true);
                that.ComponentSpecificConfiguration.Add(nameof(StubComponentSpecification.PropD), 10.50);

                component.Configuration = new UnknownComponentConfigurationObject <StubComponentSpecification>(that);
                component.Create();

                //Assert.AreSame(component.Configuration.ComponentSpecificConfiguration, component.Specification);

                Assert.AreEqual("test", component.Specification.PropA);
                Assert.AreEqual(100, component.Specification.PropB);
                Assert.AreEqual(true, component.Specification.PropC);
                Assert.AreEqual(10.50, component.Specification.PropD);

                Assert.AreEqual("test", component.Configuration.ComponentSpecificConfiguration.PropA);
                Assert.AreEqual(100, component.Configuration.ComponentSpecificConfiguration.PropB);
                Assert.AreEqual(true, component.Configuration.ComponentSpecificConfiguration.PropC);
                Assert.AreEqual(10.50, component.Configuration.ComponentSpecificConfiguration.PropD);

                //stubComponent.Dispose();
            }
        }
Пример #8
0
        public void Enabled_Changed_CallOnMethods()
        {
            var wc        = Substitute.For <IWorldContext>();
            var logSystem = Substitute.For <ILogSystem>();

            wc.LogSystem.Returns(logSystem);

            var target = new StubComponent(wc, false)
            {
                Enabled = false
            };

            if (!target.Enabled)
            {
                Assert.IsFalse(target.Enabled);
                target.Enabled = true;
            }

            logSystem.ReceivedWithAnyArgs(2).Debug(null);
        }