public void ContainsOnly_WithNullTypeMatch_Throws()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact(null)));
     Assert.Throws <ArgumentNullException>(() =>
                                           EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EcsTestData>(null)));
 }
Exemplo n.º 2
0
        public void ContainsOnly_WithDataComparison()
        {
            var entity = m_Manager.CreateEntity(typeof(EcsTestData), typeof(EcsTestData2));

            m_Manager.SetComponentData(entity, new EcsTestData2(5));

            Assert.DoesNotThrow(() =>
                                EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EcsTestData, EcsTestData2>(entity)));
            Assert.DoesNotThrow(() =>
                                EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EcsTestData, EcsTestData2>()));
            Assert.DoesNotThrow(() =>
                                EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EcsTestData>(entity, new EcsTestData2(5))));
            Assert.DoesNotThrow(() =>
                                EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EcsTestData>(new EcsTestData2(5), entity)));

            Assert.Throws <AssertionException>(() =>
                                               EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EcsTestData, EcsTestData2>(entity, new EcsTestData2(6))));
            Assert.Throws <AssertionException>(() =>
                                               EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EcsTestData, EcsTestData2>(new EcsTestData2(6), entity)));

            Assert.Throws <AssertionException>(() =>
                                               EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EcsTestData, EcsTestData2>(entity, new EcsTestData2(5))));
            Assert.Throws <AssertionException>(() =>
                                               EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EcsTestData, EcsTestData2>(new EcsTestData2(5), entity)));
        }
Exemplo n.º 3
0
        public void ContainsOnly_WithMatchingCustomMatcher_DoesNotAssert()
        {
            m_Manager.CreateEntity();

            Assert.DoesNotThrow(() =>
                                EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Where(() => "Matcher #0", _ => true)));
        }
Exemplo n.º 4
0
        public void ContainsOnly_WithNonEmptyEntity()
        {
            var entity = m_Manager.CreateEntity(typeof(EcsTestData), typeof(EcsTestData2));

            Assert.DoesNotThrow(() =>
                                EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Any(entity)));

            Assert.Throws <AssertionException>(() =>
                                               EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EcsTestData>(entity)));
            Assert.DoesNotThrow(() =>
                                EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Partial <EcsTestData>(entity)));
            Assert.DoesNotThrow(() =>
                                EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EcsTestData, EcsTestData2>(entity)));
            Assert.DoesNotThrow(() =>
                                EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Partial <EcsTestData, EcsTestData2>(entity)));
            Assert.Throws <AssertionException>(() =>
                                               EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EcsTestData, EcsTestData2, EcsTestData3>(entity)));
            Assert.Throws <AssertionException>(() =>
                                               EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Partial <EcsTestData, EcsTestData2, EcsTestData3>(entity)));

            Assert.Throws <AssertionException>(() =>
                                               EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EcsTestData>()));
            Assert.DoesNotThrow(() =>
                                EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Partial <EcsTestData>()));
            Assert.DoesNotThrow(() =>
                                EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EcsTestData, EcsTestData2>()));
            Assert.DoesNotThrow(() =>
                                EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Partial <EcsTestData, EcsTestData2>()));
            Assert.Throws <AssertionException>(() =>
                                               EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EcsTestData, EcsTestData2, EcsTestData3>()));
            Assert.Throws <AssertionException>(() =>
                                               EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Partial <EcsTestData, EcsTestData2, EcsTestData3>()));
        }
Exemplo n.º 5
0
        public void Contains_WithNoMatchers_Throws()
        {
            var ex = Assert.Throws <ArgumentException>(() =>
                                                       EntitiesAssert.Contains(m_Manager));

            StringAssert.Contains("Use IsEmpty", ex.Message);
        }
Exemplo n.º 6
0
        public void IsEmpty_WithNonEmptyEcs_Asserts()
        {
            m_Manager.CreateEntity();

            Assert.Throws <AssertionException>(() =>
                                               EntitiesAssert.IsEmpty(m_Manager));
        }
Exemplo n.º 7
0
        public void ContainsOnly_WithNonMatchingCustomMatcher_Asserts()
        {
            m_Manager.CreateEntity();

            var ex = Assert.Throws <AssertionException>(() =>
                                                        EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Where(() => "Matcher #0", _ => false)));

            StringAssert.Contains("Matcher #0", ex.Message);
        }
Exemplo n.º 8
0
        public void GetAllEntities_WithEmptyEntity()
        {
            var entity = m_Manager.CreateEntity();

            var debugEntities = DebugEntity.GetAllEntities(m_Manager);

            EntitiesAssert.AreEqual(
                new[] { new DebugEntity(entity) },
                debugEntities);
        }
        public void ContainsOnly_WithEmptyEntity()
        {
            var entity = m_Manager.CreateEntity();

            Assert.DoesNotThrow(() =>
                                EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Any(entity)));
            Assert.DoesNotThrow(() =>
                                EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact(entity)));
            Assert.Throws <AssertionException>(() =>
                                               EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EcsTestData>(entity)));
        }
        public void ContainsOnly_WithMultipleEntityMatches_Throws()
        {
            var ex = Assert.Throws <ArgumentException>(() =>
                                                       EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact(new Entity {
                Index = 1
            }, new Entity {
                Index = 2
            })));

            StringAssert.Contains("multiple Entity", ex.Message);
        }
Exemplo n.º 11
0
        public void Contains_WithPartialMatch_DoesNotAssert()
        {
            var entity1 = m_Manager.CreateEntity(typeof(EcsTestData));
            var entity2 = m_Manager.CreateEntity();

            Assert.DoesNotThrow(() =>
                                EntitiesAssert.Contains(m_Manager, EntityMatch.Any(entity1)));
            Assert.DoesNotThrow(() =>
                                EntitiesAssert.Contains(m_Manager, EntityMatch.Exact <EcsTestData>()));
            Assert.DoesNotThrow(() =>
                                EntitiesAssert.Contains(m_Manager, EntityMatch.Exact(entity2)));
        }
Exemplo n.º 12
0
        public void GetAllEntities_WithTaggedEntity()
        {
            var entity = m_Manager.CreateEntity(typeof(EcsTestTag));

            var debugEntities = DebugEntity.GetAllEntities(m_Manager);

            EntitiesAssert.AreEqual(
                new[] { new DebugEntity(entity, new DebugComponent {
                    Type = typeof(EcsTestTag), Data = new EcsTestTag()
                }) },
                debugEntities);
        }
        public void SystemStateSharedKeepsValueAfterDestroy()
        {
            var entity = m_Manager.CreateEntity();

            m_Manager.AddSharedComponentData(entity, new SystemShared {
                Value = 123
            });
            m_Manager.DestroyEntity(entity);
            EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <CleanupEntity>(new SystemShared {
                Value = 123
            }));
        }
Exemplo n.º 14
0
        public void ContainsOnly_WithParamTypeComparison()
        {
            var entity = m_Manager.CreateEntity(typeof(EcsTestData), typeof(EcsTestData2));

            Assert.DoesNotThrow(() =>
                                EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact(typeof(EcsTestData2), entity, typeof(EcsTestData))));
            Assert.DoesNotThrow(() =>
                                EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact(typeof(EcsTestData), new[] { typeof(EcsTestData2) })));
            Assert.DoesNotThrow(() =>
                                EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact(entity, new[] { typeof(EcsTestData), typeof(EcsTestData2) })));

            Assert.Throws <AssertionException>(() =>
                                               EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EcsTestData2>(new[] { typeof(EcsTestData2) }, typeof(EcsTestData))));
        }
Exemplo n.º 15
0
        public void ContainsOnly_WithCustomMatcher_OnlyCalledOnce()
        {
            m_Manager.CreateEntity();
            m_Manager.CreateEntity();

            var(count0, count1) = (0, 10);
            Assert.DoesNotThrow(() =>
                                EntitiesAssert.ContainsOnly(m_Manager,
                                                            EntityMatch.Where(() => "Matcher #0", _ => { ++count0; return(true); }),
                                                            EntityMatch.Where(() => "Matcher #1", _ => { ++count1; return(true); })));

            Assert.AreEqual(1, count0);
            Assert.AreEqual(11, count1);
        }
Exemplo n.º 16
0
        public void RemoveComponentTwiceIgnored()
        {
            var entity = m_Manager.CreateEntity();

            m_Manager.AddComponent <EcsTestData>(entity);

            EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EcsTestData>(entity));
            var removed0 = m_Manager.RemoveComponent <EcsTestData>(entity);

            EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact(entity));
            var removed1 = m_Manager.RemoveComponent <EcsTestData>(entity);

            EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact(entity));

            Assert.That(removed0, Is.True);
            Assert.That(removed1, Is.False);
        }
Exemplo n.º 17
0
        public void GetAllEntities_WithBufferElementData()
        {
            var entity = m_Manager.CreateEntity();
            var buffer = m_Manager.AddBuffer <EcsIntElement>(entity);

            buffer.Add(1);
            buffer.Add(5);
            buffer.Add(9);

            var debugEntities = DebugEntity.GetAllEntities(m_Manager);

            EntitiesAssert.AreEqual(
                new[] { new DebugEntity(entity,
                                        new DebugComponent {
                    Type = typeof(EcsIntElement), Data = new EcsIntElement[] { 1, 5, 9 }
                }) },
                debugEntities);
        }
Exemplo n.º 18
0
        public void GetAllEntities_WithSharedTagEntity()
        {
            var entity = m_Manager.CreateEntity(typeof(EcsTestSharedTag));

            var debugEntities = DebugEntity.GetAllEntities(m_Manager);

            #if NET_DOTS
            // until ManagedComponentStore.GetSharedComponentDataBoxed supports an alternative to Activator to construct
            // a default instance of T, we can't support it here. once implemented, remove this special case to the test
            // and drop the try/catch from DebugComponent ctor.
            Assert.That(
                debugEntities[0].Components[0].Data,
                Is.InstanceOf <Exception>().With.Message.Match("Implement TypeManager.*DefaultValue"));
            #else
            EntitiesAssert.AreEqual(
                new[] { new DebugEntity(entity, new DebugComponent {
                    Type = typeof(EcsTestSharedTag), Data = new EcsTestSharedTag()
                }) },
                debugEntities);
            #endif
        }
Exemplo n.º 19
0
        public void GetAllEntities_WithSharedComponentData()
        {
            var entity = m_Manager.CreateEntity();

            m_Manager.AddSharedComponentData(entity, new EcsTestSharedComp(5));

            var debugEntities = DebugEntity.GetAllEntities(m_Manager);

            EntitiesAssert.AreEqual(
                new[] { new DebugEntity(entity,
                                        new DebugComponent {
                    Type = typeof(EcsTestSharedComp), Data = new EcsTestSharedComp(5)
                }) },
                debugEntities);

            EntitiesAssert.AreNotEqual(
                new[] { new DebugEntity(entity,
                                        new DebugComponent {
                    Type = typeof(EcsTestSharedComp), Data = new EcsTestSharedComp(6)
                }) },
                debugEntities);
        }
Exemplo n.º 20
0
        public void ContainsOnly_WithBufferElementData()
        {
            var entity = m_Manager.CreateEntity();
            var buffer = m_Manager.AddBuffer <EcsIntElement>(entity);

            buffer.Add(1);
            buffer.Add(5);
            buffer.Add(9);

            Assert.DoesNotThrow(() =>
                                EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EcsIntElement>()));
            Assert.Throws <AssertionException>(() =>
                                               EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EcsIntElement[]>()));
            Assert.Throws <AssertionException>(() =>
                                               EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <List <EcsIntElement> >()));
            Assert.DoesNotThrow(() =>
                                EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact(new EcsIntElement[] { 1, 5, 9 })));
            Assert.DoesNotThrow(() =>
                                EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact(EntityMatch.Component((EcsIntElement[] match) => match.Length == 3))));
            Assert.Throws <AssertionException>(() =>
                                               EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact(EntityMatch.Component((EcsIntElement[] match) => match.Length == 2))));
        }
Exemplo n.º 21
0
        public void GetAllEntities_WithComponentObject()
        {
            var entity    = m_Manager.CreateEntity();
            var component = new TestClassComponent {
                Value = 5
            };

            m_Manager.AddComponentObject(entity, component);

            var debugEntities = DebugEntity.GetAllEntities(m_Manager);

            EntitiesAssert.AreEqual(
                new[] { new DebugEntity(entity,
                                        new DebugComponent {
                    Type = typeof(TestClassComponent), Data = component
                }) },
                debugEntities);

            // currently we are doing Equals comparisons, so validate it
            EntitiesAssert.AreEqual(
                new[] { new DebugEntity(entity,
                                        new DebugComponent {
                    Type = typeof(TestClassComponent), Data = new TestClassComponent {
                        Value = 5
                    }
                }) },
                debugEntities);
            EntitiesAssert.AreNotEqual(
                new[] { new DebugEntity(entity,
                                        new DebugComponent {
                    Type = typeof(TestClassComponent), Data = new TestClassComponent {
                        Value = 6
                    }
                }) },
                debugEntities);
        }
Exemplo n.º 22
0
 public void IsEmpty_WithEmptyEcs_DoesNotAssert()
 {
     Assert.DoesNotThrow(() =>
                         EntitiesAssert.IsEmpty(m_Manager));
 }
Exemplo n.º 23
0
 public void ContainsOnly_WithEmptyEcs_Asserts()
 {
     Assert.Throws <AssertionException>(() =>
                                        EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Where(() => "", _ => true)));
 }