Пример #1
0
        public void ShouldReturnAllComponentsMatchingPredicate()
        {
            var state = new TestState();
            var fooComp = new FooComponent();
            var customFoo = new FooComponent { Test = "NewFoo" };
            var barComp = new BarComponent();
            var customBar = new BarComponent { Test = "NewBar" };
            state.AddComponent(fooComp);
            state.AddComponent(customFoo);
            state.AddComponent(barComp);
            state.AddComponent(customBar);

            // We have to do some null checking, as we have both Foo and Bar components
            // in the game state.

            Assert.AreEqual(state.GetAllComponents(c =>
            {
                var f = c as FooComponent;
                return f != null && f.Test == "NewFoo";
            }).Count(), 1);

            Assert.IsEmpty(state.GetAllComponents(c =>
            {
                var f = c as FooComponent;
                return f != null && f.Test == "NewBar";
            }));
        }
Пример #2
0
        public void OverridesEqual()
        {
            var foo1 = new FooComponent { I = 1 };
            var foo2 = new FooComponent { I = 1 };

            Assert.Equal(foo1, foo2);
        }
Пример #3
0
            }
        }

        private class BarComponent : IGameComponent
        {
            public bool Enabled { get; set; }

            public string Test = "Bar";
Пример #4
0
            }

            public void Enable()
            {
                
            }

            public void Disable()
Пример #5
0
 public void ShouldHaveComponentOfType()
 {
     var state = new TestState();
     var fooComp = new FooComponent();
     state.AddComponent(fooComp);
     Assert.True(state.HasComponent(typeof(FooComponent)));
     Assert.False(state.HasComponent(typeof(BarComponent)));
 }
Пример #6
0
        public void OverridesGetHashCode()
        {
            var foo = new FooComponent { I = 1 };

            int expectedHash = EqualityExtensions.Equality<Component>(foo).GetHashCode(new object[] { foo.I });

            Assert.Equal(expectedHash, foo.GetHashCode());
        }
Пример #7
0
 public void ShouldHaveComponentMatchingPredicate()
 {
     var state = new TestState();
     var fooComp = new FooComponent();
     state.AddComponent(fooComp);
     Assert.True(state.HasComponent(c => ((FooComponent)c).Test == "Foo"));
     Assert.False(state.HasComponent(c => ((FooComponent)c).Test == "Bar"));
 }
Пример #8
0
            {
                
            }

            public void Enable()
            {
                
            }
Пример #9
0
 public void ShouldRemoveComponentFromGameState()
 {
     var state = new TestState();
     var fooComp = new FooComponent();
     state.AddComponent(fooComp);
     Assert.IsNotEmpty(state.GetAllComponents());
     state.RemoveComponent(fooComp);
     Assert.IsEmpty(state.GetAllComponents());
 }
Пример #10
0
 public void ShouldOnlyHaveExactReferenceToComponent()
 {
     var state = new TestState();
     var fooComp = new FooComponent();
     var fooComp2 = new FooComponent();
     state.AddComponent(fooComp);
     Assert.True(state.HasComponent(fooComp));
     Assert.False(state.HasComponent(fooComp2));
 }
Пример #11
0
        public void GetServiceLocatesInContainerByType()
        {
            BuilderContainer container = new BuilderContainer();
            FooComponent     component = container.BuildUp <FooComponent>("Foo");

            object service = component.GetService <ILifetimeContainer>();

            Assert.IsNotNull(service);
        }
Пример #12
0
        public void OverridesGetHashCode()
        {
            var foo = new FooComponent {
                I = 1
            };

            int expectedHash = EqualityExtensions.Equality <Component>(foo).GetHashCode(new object[] { foo.I });

            Assert.Equal(expectedHash, foo.GetHashCode());
        }
Пример #13
0
        public void ShouldReturnComponentOfType()
        {
            var state = new TestState();
            var fooComp = new FooComponent();
            var customFoo = new FooComponent { Test = "NewFoo" };
            state.AddComponent(fooComp);
            state.AddComponent(customFoo);

            Assert.IsInstanceOf<FooComponent>(state.GetComponent(typeof(FooComponent)));
        }
Пример #14
0
        public void DeAttach_DeAttachingComponent_WillBeRemoved()
        {
            var component = new FooComponent();
            var entity    = new Entity(0);

            entity.Attach(component);

            entity.DeAttach(component);

            Assert.False(entity.Has <FooComponent>());
        }
Пример #15
0
        public void OverridesEqual()
        {
            var foo1 = new FooComponent {
                I = 1
            };
            var foo2 = new FooComponent {
                I = 1
            };

            Assert.Equal(foo1, foo2);
        }
Пример #16
0
                
            }
        }

        [Test]
        public void ShouldAddComponentToGameState()
        {
            var state = new TestState();
            Assert.False(state.HasComponent(typeof (FooComponent)));
            var comp = state.AddComponent(new FooComponent());
            Assert.True(state.HasComponent(comp));
Пример #17
0
 public void ShouldRemoveAllComponentsOfTypeFromGameState()
 {
     var state = new TestState();
     var fooComp1 = new FooComponent();
     var fooComp2 = new FooComponent();
     state.AddComponent(fooComp1);
     state.AddComponent(fooComp2);
     Assert.AreEqual(state.GetAllComponents().Count(), 2);
     state.RemoveAllComponents(typeof (FooComponent));
     Assert.IsEmpty(state.GetAllComponents());
 }
Пример #18
0
 public void ShouldReturnAllComponentsOfType()
 {
     var state = new TestState();
     var fooComp = new FooComponent();
     var customFoo = new FooComponent { Test = "NewFoo" };
     var barComp = new BarComponent();
     var customBar = new BarComponent { Test = "NewBar" };
     state.AddComponent(fooComp);
     state.AddComponent(customFoo);
     state.AddComponent(barComp);
     state.AddComponent(customBar);
     Assert.AreEqual(state.GetAllComponents(typeof(FooComponent)).Count(), 2);
 }
Пример #19
0
        public void PipelineComponentSettingNotFoundException_Test()
        {
            const string setting   = "TestSetting";
            var          component = new FooComponent();

            component.Initialize(component.GetType().Name, new Dictionary <string, string>());

            var target = new PipelineComponentSettingNotFoundException(component, setting);

            target.Should().NotBeNull();
            target.ThrowingComponent.Should().BeAssignableTo <FooComponent>();
            target.SettingName.Should().Be(setting);
            target.Message.Should().StartWith("Pipeline component named");
        }
Пример #20
0
        public void PipelineExecutionException_Properties_Test()
        {
            var component = new FooComponent();

            component.Initialize(component.GetType().Name, new Dictionary <string, string>());

            var exception = new ArgumentException("TestException");
            var target    = new PipelineExecutionException(component, exception);

            target.Should().NotBeNull();
            target.ThrowingComponent.Should().BeAssignableTo <FooComponent>();
            target.InnerException.Should().BeAssignableTo <ArgumentException>();
            target.InnerException?.Message.Should().Be("TestException");
            target.Message.Should().StartWith("Pipeline execution halted!");
        }
Пример #21
0
        public void ShouldReturnComponentMatchingPredicate()
        {
            var state = new TestState();
            var fooComp = new FooComponent();
            var customFoo = new FooComponent { Test = "NewFoo" };
            state.AddComponent(fooComp);
            state.AddComponent(customFoo);

            // We have to do some null checking, as we have both Foo and Bar components
            // in the game state.

            Assert.AreEqual(state.GetComponent(c =>
            {
                var cf = c as FooComponent;
                return cf != null && cf.Test == "NewFoo";
            }), customFoo);
        }
Пример #22
0
        [Test]
        public void ShouldRemoveComponentFromGameState()
        {
            var state = new TestState();
            var fooComp = new FooComponent();
            state.AddComponent(fooComp);
            Assert.IsNotEmpty(state.GetAllComponents());
            state.RemoveComponent(fooComp);
            Assert.IsEmpty(state.GetAllComponents());
        }

        [Test]
        public void ShouldRemoveAllComponentsFromGameState()
        {
            var state = new TestState();
            var fooComp1 = new FooComponent();
            var fooComp2 = new FooComponent();
            state.AddComponent(fooComp1);
Пример #23
0
        public void ShouldRemoveAllComponentsMatchingPredicateFromGameState()
        {
            var state = new TestState();
            var fooComp1 = new FooComponent();
            var fooComp2 = new FooComponent {Test = "NewFoo"};
            state.AddComponent(fooComp1);
            state.AddComponent(fooComp2);
            Assert.AreEqual(state.GetAllComponents().Count(), 2);

            // This is ok in this code, since we only have a FooComponent in the GameState
            // at the moment. In production code we should probably cast c to FooComponent
            // and make sure it's not null before checking the Test field.
            state.RemoveAllComponents(c => ((FooComponent)c).Test == "Foo");

            // The component should only have one element left, as we changed the value of
            // the Test field on one of the objects.
            Assert.AreEqual(state.GetAllComponents().Count(), 1);
        }
Пример #24
0
        [Test]
        public void ShouldReturnComponentOfType()
        {
            var state = new TestState();
            var fooComp = new FooComponent();
            var customFoo = new FooComponent { Test = "NewFoo" };
            state.AddComponent(fooComp);
            state.AddComponent(customFoo);

            Assert.IsInstanceOf<FooComponent>(state.GetComponent(typeof(FooComponent)));
        }

        [Test]
Пример #25
0
        public void ServiceLocator_Get()
        {
            var component = new FooComponent();

            Assert.Same(ServiceLocator.Instance, component.ServiceLocator);
        }
Пример #26
0
 public void Ctor()
 {
     var component = new FooComponent();
 }
Пример #27
0
        public void ServiceLocator_Get()
        {
            var component = new FooComponent();

            Assert.Same(ServiceLocator.Instance, component.ServiceLocator);
        }
Пример #28
0
            state.RemoveAllComponents(typeof (FooComponent));
            Assert.IsEmpty(state.GetAllComponents());
        }

        [Test]
        public void ShouldRemoveAllComponentsMatchingPredicateFromGameState()
        {
            var state = new TestState();
            var fooComp1 = new FooComponent();
Пример #29
0
        {
            var state = new TestState();
            var fooComp = new FooComponent();
            var fooComp2 = new FooComponent();
            state.AddComponent(fooComp);
            Assert.True(state.HasComponent(fooComp));
            Assert.False(state.HasComponent(fooComp2));
        }

        [Test]
        public void ShouldHaveComponentOfType()
        {
            var state = new TestState();
            var fooComp = new FooComponent();
            state.AddComponent(fooComp);
            Assert.True(state.HasComponent(typeof(FooComponent)));
            Assert.False(state.HasComponent(typeof(BarComponent)));
        }

        [Test]
        public void ShouldHaveComponentMatchingPredicate()
        {
            var state = new TestState();
            var fooComp = new FooComponent();
            state.AddComponent(fooComp);
            Assert.True(state.HasComponent(c => ((FooComponent)c).Test == "Foo"));
            Assert.False(state.HasComponent(c => ((FooComponent)c).Test == "Bar"));
Пример #30
0
 public void Ctor()
 {
     var component = new FooComponent();
 }
Пример #31
0
 var state = new TestState();
 var fooComp = new FooComponent();
 var customFoo = new FooComponent { Test = "NewFoo" };
 var barComp = new BarComponent();
 var customBar = new BarComponent { Test = "NewBar" };
 state.AddComponent(fooComp);
 state.AddComponent(customFoo);
 state.AddComponent(barComp);
 state.AddComponent(customBar);
 Assert.AreEqual(state.GetAllComponents().Count(), 4);
Пример #32
0
            var state = new TestState();
            var fooComp = new FooComponent();
            var customFoo = new FooComponent { Test = "NewFoo" };
            state.AddComponent(fooComp);
            state.AddComponent(customFoo);

            // We have to do some null checking, as we have both Foo and Bar components
            // in the game state.

            Assert.AreEqual(state.GetComponent(c =>
            {
                var cf = c as FooComponent;
                return cf != null && cf.Test == "NewFoo";
            }), customFoo);
        }

        [Test]