void assertHasComponentA(Entity e, IComponent component = null) {
        if (component == null) {
            component = Component.A;
        }

        e.GetComponentA().should_be_same(component);
        var components = e.GetComponents();
        components.Length.should_be(1);
        components.should_contain(component);
        var indices = e.GetComponentIndices();
        indices.Length.should_be(1);
        indices.should_contain(CID.ComponentA);
        e.HasComponentA().should_be_true();
        e.HasComponents(_indicesA).should_be_true();
        e.HasAnyComponent(_indicesA).should_be_true();
    }
Exemple #2
0
    void assertHasComponentA(Entity e, IComponent component = null)
    {
        if (component == null)
        {
            component = Component.A;
        }

        e.GetComponentA().should_be_same(component);
        var components = e.GetComponents();

        components.Length.should_be(1);
        components.should_contain(component);
        var indices = e.GetComponentIndices();

        indices.Length.should_be(1);
        indices.should_contain(CID.ComponentA);
        e.HasComponentA().should_be_true();
        e.HasComponents(_indicesA).should_be_true();
        e.HasAnyComponent(_indicesA).should_be_true();
    }
Exemple #3
0
    void when_created()
    {
        Entity e = null;

        before = () => {
            e = this.CreateEntity();
        };

        context["initial state"] = () => {
            it["throws when attempting to get component of type which hasn't been added"] = expect <EntityDoesNotHaveComponentException>(() => {
                e.GetComponentA();
            });

            it["gets empty array of components when no components were added"] = () => {
                e.GetComponents().should_be_empty();
            };

            it["gets empty array of component indices when no components were added"] = () => {
                e.GetComponentIndices().should_be_empty();
            };

            it["doesn't have component of type when no component of that type was added"] = () => {
                e.HasComponentA().should_be_false();
            };

            it["doesn't have components of types when no components of these types were added"] = () => {
                e.HasComponents(_indicesA).should_be_false();
            };

            it["doesn't have any components of types when no components of these types were added"] = () => {
                e.HasAnyComponent(_indicesA).should_be_false();
            };

            it["returns entity when adding a component"] = () => {
                e.AddComponent(0, null).should_be_same(e);
            };

            it["adds a component"] = () => {
                e.AddComponentA();
                assertHasComponentA(e);
            };

            it["throws when attempting to remove a component of type which hasn't been added"] = expect <EntityDoesNotHaveComponentException>(() => {
                e.RemoveComponentA();
            });

            it["replacing a non existing component adds component"] = () => {
                e.ReplaceComponentA(Component.A);
                assertHasComponentA(e);
            };
        };

        context["when component added"] = () => {
            before = () => {
                e.AddComponentA();
            };

            it["throws when adding a component of the same type twice"] = expect <EntityAlreadyHasComponentException>(() => {
                e.AddComponentA();
                e.AddComponentA();
            });

            it["returns entity when removing a component"] = () => {
                e.RemoveComponent(CID.ComponentA).should_be_same(e);
            };

            it["removes a component of type"] = () => {
                e.RemoveComponentA();
                assertHasNotComponentA(e);
            };

            it["returns entity when replacing a component"] = () => {
                e.ReplaceComponent(CID.ComponentA, null).should_be_same(e);
            };

            it["replaces existing component"] = () => {
                var newComponentA = new ComponentA();
                e.ReplaceComponentA(newComponentA);
                assertHasComponentA(e, newComponentA);
            };

            it["doesn't have components of types when not all components of these types were added"] = () => {
                e.HasComponents(_indicesAB).should_be_false();
            };

            it["has any components of types when any component of these types was added"] = () => {
                e.HasAnyComponent(_indicesAB).should_be_true();
            };

            context["when adding another component"] = () => {
                before = () => {
                    e.AddComponentB();
                };

                it["gets all components"] = () => {
                    var components = e.GetComponents();
                    components.Length.should_be(2);
                    components.should_contain(Component.A);
                    components.should_contain(Component.B);
                };

                it["gets all component indices"] = () => {
                    var componentIndices = e.GetComponentIndices();
                    componentIndices.Length.should_be(2);
                    componentIndices.should_contain(CID.ComponentA);
                    componentIndices.should_contain(CID.ComponentB);
                };

                it["has other component"] = () => {
                    e.HasComponentB().should_be_true();
                };

                it["has components of types when all components of these types were added"] = () => {
                    e.HasComponents(_indicesAB).should_be_true();
                };

                it["removes all components"] = () => {
                    e.RemoveAllComponents();
                    e.HasComponentA().should_be_false();
                    e.HasComponentB().should_be_false();
                    e.GetComponents().should_be_empty();
                    e.GetComponentIndices().should_be_empty();
                };

                it["can ToString"] = () => {
                    e.AddComponent(0, new SomeComponent());
                    e.ToString().should_be("Entity_0(Some, ComponentA, ComponentB)");
                };
            };
        };

        context["events"] = () => {
            int didDispatch = 0;

            before = () => {
                didDispatch = 0;
            };

            it["dispatches OnComponentAdded when adding a component"] = () => {
                e.OnComponentAdded += (entity, index, component) => {
                    didDispatch += 1;
                    entity.should_be_same(e);
                    index.should_be(CID.ComponentA);
                    component.should_be_same(Component.A);
                };
                e.OnComponentRemoved  += (entity, index, component) => this.Fail();
                e.OnComponentReplaced += (entity, index, previousComponent, newComponent) => this.Fail();

                e.AddComponentA();
                didDispatch.should_be(1);
            };

            it["dispatches OnComponentRemoved when removing a component"] = () => {
                e.AddComponentA();
                e.OnComponentRemoved += (entity, index, component) => {
                    didDispatch += 1;
                    entity.should_be_same(e);
                    index.should_be(CID.ComponentA);
                    component.should_be_same(Component.A);
                };
                e.OnComponentAdded    += (entity, index, component) => this.Fail();
                e.OnComponentReplaced += (entity, index, previousComponent, newComponent) => this.Fail();

                e.RemoveComponentA();
                didDispatch.should_be(1);
            };

            it["dispatches OnComponentReplaced when replacing a component"] = () => {
                e.AddComponentA();
                var newComponentA = new ComponentA();
                e.OnComponentReplaced += (entity, index, previousComponent, newComponent) => {
                    didDispatch += 1;
                    entity.should_be_same(e);
                    index.should_be(CID.ComponentA);
                    previousComponent.should_be_same(Component.A);
                    newComponent.should_be_same(newComponentA);
                };
                e.OnComponentAdded   += (entity, index, component) => this.Fail();
                e.OnComponentRemoved += (entity, index, component) => this.Fail();

                e.ReplaceComponentA(newComponentA);
                didDispatch.should_be(1);
            };

            it["provides previous and new component OnComponentReplaced when replacing with different component"] = () => {
                var prevComp = new ComponentA();
                var newComp  = new ComponentA();
                e.OnComponentReplaced += (entity, index, previousComponent, newComponent) => {
                    didDispatch += 1;
                    entity.should_be_same(e);
                    previousComponent.should_be_same(prevComp);
                    newComponent.should_be_same(newComp);
                };

                e.AddComponent(CID.ComponentA, prevComp);
                e.ReplaceComponent(CID.ComponentA, newComp);
                didDispatch.should_be(1);
            };

            it["provides previous and new component OnComponentReplaced when replacing with same component"] = () => {
                e.OnComponentReplaced += (entity, index, previousComponent, newComponent) => {
                    didDispatch += 1;
                    entity.should_be_same(e);
                    previousComponent.should_be_same(Component.A);
                    newComponent.should_be_same(Component.A);
                };

                e.AddComponentA();
                e.ReplaceComponentA(Component.A);
                didDispatch.should_be(1);
            };

            it["doesn't dispatch anything when replacing a non existing component with null"] = () => {
                e.OnComponentAdded    += (entity, index, component) => this.Fail();
                e.OnComponentReplaced += (entity, index, previousComponent, newComponent) => this.Fail();
                e.OnComponentRemoved  += (entity, index, component) => this.Fail();

                e.ReplaceComponentA(null);
            };

            it["dispatches OnComponentAdded when attempting to replace a component which hasn't been added"] = () => {
                var newComponentA = new ComponentA();
                e.OnComponentAdded += (entity, index, component) => {
                    didDispatch += 1;
                    entity.should_be_same(e);
                    index.should_be(CID.ComponentA);
                    component.should_be_same(newComponentA);
                };
                e.OnComponentReplaced += (entity, index, previousComponent, newComponent) => this.Fail();
                e.OnComponentRemoved  += (entity, index, component) => this.Fail();

                e.ReplaceComponentA(newComponentA);
                didDispatch.should_be(1);
            };

            it["dispatches OnComponentRemoved when replacing a component with null"] = () => {
                e.AddComponentA();
                e.OnComponentRemoved += (entity, index, component) => {
                    didDispatch += 1;
                };
                e.OnComponentAdded    += (entity, index, component) => this.Fail();
                e.OnComponentReplaced += (entity, index, previousComponent, newComponent) => this.Fail();

                e.ReplaceComponentA(null);
                didDispatch.should_be(1);
            };

            it["dispatches OnComponentRemoved when removing all components"] = () => {
                e.AddComponentA();
                e.AddComponentB();
                e.OnComponentRemoved += (entity, index, component) => didDispatch += 1;
                e.RemoveAllComponents();
                didDispatch.should_be(2);
            };
        };

        context["reference counting"] = () => {
            it["retains entity"] = () => {
                e.RefCount().should_be(0);
                e.Retain();
                e.RefCount().should_be(1);
            };

            it["releases entity"] = () => {
                e.Retain();
                e.Release();
                e.RefCount().should_be(0);
            };

            it["throws when releasing more than it has been retained"] = expect <EntityIsAlreadyReleasedException>(() => {
                e.Retain();
                e.Release();
                e.Release();
            });

            context["events"] = () => {
                it["doesn't dispatch OnEntityReleased when retaining"] = () => {
                    e.OnEntityReleased += entity => this.Fail();
                    e.Retain();
                };

                it["dispatches OnEntityReleased when retain and release"] = () => {
                    var didDispatch = 0;
                    e.OnEntityReleased += entity => {
                        didDispatch += 1;
                        entity.should_be_same(e);
                    };
                    e.Retain();
                    e.Release();
                };
            };
        };

        context["internal caching"] = () => {
            context["components"] = () => {
                IComponent[] cache = null;
                before = () => {
                    e.AddComponentA();
                    cache = e.GetComponents();
                };

                it["caches components"] = () => {
                    e.GetComponents().should_be_same(cache);
                };

                it["updates cache when a new component was added"] = () => {
                    e.AddComponentB();
                    e.GetComponents().should_not_be_same(cache);
                };

                it["updates cache when a component was removed"] = () => {
                    e.RemoveComponentA();
                    e.GetComponents().should_not_be_same(cache);
                };

                it["updates cache when a component was replaced"] = () => {
                    e.ReplaceComponentA(new ComponentA());
                    e.GetComponents().should_not_be_same(cache);
                };

                it["doesn't update cache when a component was replaced with same component"] = () => {
                    e.ReplaceComponentA(Component.A);
                    e.GetComponents().should_be_same(cache);
                };

                it["updates cache when all components were removed"] = () => {
                    e.RemoveAllComponents();
                    e.GetComponents().should_not_be_same(cache);
                };
            };

            context["component indices"] = () => {
                int[] cache = null;
                before = () => {
                    e.AddComponentA();
                    cache = e.GetComponentIndices();
                };

                it["caches component indices"] = () => {
                    e.GetComponentIndices().should_be_same(cache);
                };

                it["updates cache when a new component was added"] = () => {
                    e.AddComponentB();
                    e.GetComponentIndices().should_not_be_same(cache);
                };

                it["updates cache when a component was removed"] = () => {
                    e.RemoveComponentA();
                    e.GetComponentIndices().should_not_be_same(cache);
                };

                it["doesn't update cache when a component was replaced"] = () => {
                    e.ReplaceComponentA(new ComponentA());
                    e.GetComponentIndices().should_be_same(cache);
                };

                it["updates cache when adding a new component with ReplaceComponent"] = () => {
                    e.ReplaceComponentC(Component.C);
                    e.GetComponentIndices().should_not_be_same(cache);
                };

                it["updates cache when all components were removed"] = () => {
                    e.RemoveAllComponents();
                    e.GetComponentIndices().should_not_be_same(cache);
                };
            };

            context["ToString"] = () => {
                context["when component was added"] = () => {
                    string cache = null;
                    before = () => {
                        e.AddComponentA();
                        cache = e.ToString();
                    };

                    it["caches entity description"] = () => {
                        e.ToString().should_be_same(cache);
                    };

                    it["updates cache when a new component was added"] = () => {
                        e.AddComponentB();
                        e.ToString().should_not_be_same(cache);
                    };

                    it["updates cache when a component was removed"] = () => {
                        e.RemoveComponentA();
                        e.ToString().should_not_be_same(cache);
                    };

                    it["doesn't update cache when a component was replaced"] = () => {
                        e.ReplaceComponentA(new ComponentA());
                        e.ToString().should_be_same(cache);
                    };

                    it["updates cache when all components were removed"] = () => {
                        e.RemoveAllComponents();
                        e.ToString().should_not_be_same(cache);
                    };
                };

                it["updates cache when RemoveAllComponents is called, even if entity has no components"] = () => {
                    var str = e.ToString();
                    e.RemoveAllComponents();
                    e.ToString().should_not_be_same(str);
                };
            };
        };
    }
    void when_entity()
    {
        context["when adding ComponentSuffix"] = () => {
            it["doesn't add component suffix to string ending with ComponentSuffix"] = () => {
                const string str = "Position" + EntityExtension.COMPONENT_SUFFIX;
                str.AddComponentSuffix().should_be_same(str);
            };

            it["add ComponentSuffix to string not ending with ComponentSuffix"] = () => {
                const string str = "Position";
                str.AddComponentSuffix().should_be("Position" + EntityExtension.COMPONENT_SUFFIX);
            };
        };

        context["when removeing ComponentSuffix"] = () => {
            it["doesn't change string when not ending with ComponentSuffix"] = () => {
                const string str = "Position";
                str.RemoveComponentSuffix().should_be_same(str);
            };

            it["removes ComponentSuffix when ending with ComponentSuffix"] = () => {
                const string str = "Position" + EntityExtension.COMPONENT_SUFFIX;
                str.RemoveComponentSuffix().should_be("Position");
            };
        };

        context["when copying components"] = () => {
            Pool             pool    = null;
            Entity           entity  = null;
            Entity           target  = null;
            NameAgeComponent nameAge = null;

            before = () => {
                pool    = new Pool(CID.TotalComponents);
                entity  = pool.CreateEntity();
                target  = pool.CreateEntity();
                nameAge = new NameAgeComponent {
                    name = "Max", age = 42
                };
            };

            it["doesn't change entity if original doesn't have any components"] = () => {
                entity.CopyTo(target);

                entity.creationIndex.should_be(0);
                target.creationIndex.should_be(1);

                target.GetComponents().Length.should_be(0);
            };

            it["adds copies of all components to target entity"] = () => {
                entity.AddComponentA();
                entity.AddComponent(CID.ComponentB, nameAge);

                entity.CopyTo(target);

                target.GetComponents().Length.should_be(2);
                target.HasComponentA().should_be_true();
                target.HasComponentB().should_be_true();
                target.GetComponentA().should_not_be_same(Component.A);
                target.GetComponent(CID.ComponentB).should_not_be_same(nameAge);

                var clonedComponent = (NameAgeComponent)target.GetComponent(CID.ComponentB);

                clonedComponent.name.should_be(nameAge.name);
                clonedComponent.age.should_be(nameAge.age);
            };

            it["throws when target already has a component at index"] = base.expect <EntityAlreadyHasComponentException>(() => {
                entity.AddComponentA();
                entity.AddComponent(CID.ComponentB, nameAge);
                var component = new NameAgeComponent();
                target.AddComponent(CID.ComponentB, component);

                entity.CopyTo(target);
            });

            it["replaces existing components when overwrite is set"] = () => {
                entity.AddComponentA();
                entity.AddComponent(CID.ComponentB, nameAge);
                var component = new NameAgeComponent();
                target.AddComponent(CID.ComponentB, component);

                entity.CopyTo(target, true);

                var copy = target.GetComponent(CID.ComponentB);
                copy.should_not_be_same(nameAge);
                copy.should_not_be_same(component);
                ((NameAgeComponent)copy).name.should_be(nameAge.name);
                ((NameAgeComponent)copy).age.should_be(nameAge.age);
            };

            it["only adds copies of specified components to target entity"] = () => {
                entity.AddComponentA();
                entity.AddComponentB();
                entity.AddComponentC();

                entity.CopyTo(target, false, CID.ComponentB, CID.ComponentC);

                target.GetComponents().Length.should_be(2);
                target.HasComponentB().should_be_true();
                target.HasComponentC().should_be_true();
            };

            it["uses component pool"] = () => {
                entity.AddComponentA();

                var component = new ComponentA();
                target.GetComponentPool(CID.ComponentA).Push(component);

                entity.CopyTo(target);

                target.GetComponentA().should_be_same(component);
            };
        };
    }
Exemple #5
0
    void when_created()
    {
        Entity e = null;

        before = () => {
            e = this.CreateEntity();
        };

        it["has component of type when component of that type was added"] = () => {
            e.AddComponentA();
            e.HasComponentA().should_be_true();
        };

        it["returns entity when adding a component"] = () => {
            e.AddComponent(0, null).should_be_same(e);
        };

        it["doesn't have component of type when no component of that type was added"] = () => {
            e.HasComponentA().should_be_false();
        };

        it["doesn't have components of types when no components of these types were added"] = () => {
            e.HasComponents(new [] { CID.ComponentA }).should_be_false();
        };

        it["doesn't have components of types when not all components of these types were added"] = () => {
            e.AddComponentA();
            e.HasComponents(new [] { CID.ComponentA, CID.ComponentB }).should_be_false();
        };

        it["has components of types when all components of these types were added"] = () => {
            e.AddComponentA();
            e.AddComponentB();
            e.HasComponents(new [] { CID.ComponentA, CID.ComponentB }).should_be_true();
        };

        it["doesn't have any components of types when no components of these types were added"] = () => {
            e.HasAnyComponent(new [] { CID.ComponentA }).should_be_false();
        };

        it["has any components of types when any component of these types was added"] = () => {
            e.AddComponentA();
            e.HasAnyComponent(new [] {
                CID.ComponentA,
                CID.ComponentB
            }).should_be_true();
        };

        it["removes a component of type"] = () => {
            e.AddComponentA();
            e.RemoveComponentA();
            e.HasComponentA().should_be_false();
        };

        it["returns entity when removing a component"] = () => {
            e.AddComponentA();
            e.RemoveComponent(1).should_be_same(e);
        };

        it["gets a component of type"] = () => {
            e.AddComponentA();
            e.GetComponentA().should_be_same(Component.A);
        };

        it["replaces existing component"] = () => {
            e.AddComponentA();
            var newComponentA = new ComponentA();
            e.ReplaceComponentA(newComponentA);
            e.GetComponentA().should_be_same(newComponentA);
        };

        it["returns entity when replacing a component"] = () => {
            e.ReplaceComponent(1, null).should_be_same(e);
        };

        it["replacing a non existing component adds component"] = () => {
            var newComponentA = new ComponentA();
            e.ReplaceComponentA(newComponentA);
            e.GetComponentA().should_be_same(newComponentA);
        };

        it["gets empty array of components when no components were added"] = () => {
            e.GetComponents().should_be_empty();
        };

        it["gets empty array of component indices when no components were added"] = () => {
            e.GetComponentIndices().should_be_empty();
        };

        it["gets all components"] = () => {
            e.AddComponentA();
            e.AddComponentB();
            var allComponents = e.GetComponents();
            allComponents.should_contain(Component.A);
            allComponents.should_contain(Component.B);
            allComponents.Length.should_be(2);
        };

        it["gets all component indices"] = () => {
            e.AddComponentA();
            e.AddComponentB();
            var allComponentIndices = e.GetComponentIndices();
            allComponentIndices.should_contain(CID.ComponentA);
            allComponentIndices.should_contain(CID.ComponentB);
            allComponentIndices.Length.should_be(2);
        };

        it["removes all components"] = () => {
            e.AddComponentA();
            e.AddComponentB();
            e.RemoveAllComponents();
            e.HasComponentA().should_be_false();
            e.HasComponentB().should_be_false();
            e.GetComponents().should_be_empty();
            e.GetComponentIndices().should_be_empty();
        };

        it["can ToString"] = () => {
            e.AddComponentA();
            e.AddComponentB();
            e.ToString().should_be("Entity_0(ComponentA, ComponentB)");
        };

        context["events"] = () => {
            Entity     eventEntity    = null;
            int        eventIndex     = CID.None;
            IComponent eventComponent = null;

            before = () => {
                eventEntity    = null;
                eventIndex     = CID.None;
                eventComponent = null;
            };

            it["dispatches OnComponentAdded when adding a component"] = () => {
                e.OnComponentAdded += (entity, index, component) => {
                    eventEntity    = entity;
                    eventIndex     = index;
                    eventComponent = component;
                };
                e.OnComponentReplaced      += (entity, index, component) => this.Fail();
                e.OnComponentWillBeRemoved += (entity, index, component) => this.Fail();
                e.OnComponentRemoved       += (entity, index, component) => this.Fail();

                e.AddComponentA();
                eventEntity.should_be_same(e);
                eventIndex.should_be(CID.ComponentA);
                eventComponent.should_be_same(Component.A);
            };

            it["dispatches OnComponentRemoved when removing a component"] = () => {
                e.AddComponentA();
                e.OnComponentAdded    += (entity, index, component) => this.Fail();
                e.OnComponentReplaced += (entity, index, component) => this.Fail();
                e.OnComponentRemoved  += (entity, index, component) => {
                    eventEntity    = entity;
                    eventIndex     = index;
                    eventComponent = component;
                };

                e.RemoveComponentA();
                eventEntity.should_be_same(e);
                eventIndex.should_be(CID.ComponentA);
                eventComponent.should_be_same(Component.A);
            };

            it["dispatches OnComponentWillBeRemoved when removing a component"] = () => {
                e.AddComponentA();
                e.OnComponentWillBeRemoved += (entity, index, component) => {
                    eventEntity    = entity;
                    eventIndex     = index;
                    eventComponent = component;
                };

                e.RemoveComponentA();
                eventEntity.should_be_same(e);
                eventIndex.should_be(CID.ComponentA);
                eventComponent.should_be_same(Component.A);
            };

            it["dispatches OnComponentReplaced when replacing a component"] = () => {
                e.AddComponentA();
                var newComponentA = new ComponentA();
                var didReplace    = 0;
                e.OnComponentAdded    += (entity, index, component) => this.Fail();
                e.OnComponentReplaced += (entity, index, component) => {
                    entity.should_be_same(entity);
                    index.should_be(CID.ComponentA);
                    component.should_be_same(newComponentA);
                    didReplace++;
                };
                e.OnComponentWillBeRemoved += (entity, index, component) => this.Fail();
                e.OnComponentRemoved       += (entity, index, component) => this.Fail();

                e.ReplaceComponentA(newComponentA);
                didReplace.should_be(1);
            };

            it["doesn't dispatch anything when replacing a non existing component with null"] = () => {
                e.OnComponentAdded         += (entity, index, component) => this.Fail();
                e.OnComponentReplaced      += (entity, index, component) => this.Fail();
                e.OnComponentWillBeRemoved += (entity, index, component) => this.Fail();
                e.OnComponentRemoved       += (entity, index, component) => this.Fail();

                e.ReplaceComponentA(null);
            };

            it["dispatches OnComponentWillBeRemoved when called manually and component exists"] = () => {
                e.AddComponentA();
                e.OnComponentWillBeRemoved += (entity, index, component) => {
                    eventEntity    = entity;
                    eventIndex     = index;
                    eventComponent = component;
                };

                e.WillRemoveComponent(CID.ComponentA);
                eventEntity.should_be_same(e);
                eventIndex.should_be(CID.ComponentA);
                eventComponent.should_be_same(Component.A);
            };

            it["doesn't dispatch OnComponentWillBeRemoved when called manually and entity doesn't have"] = () => {
                e.OnComponentWillBeRemoved += (entity, index, component) => {
                    eventEntity    = entity;
                    eventIndex     = index;
                    eventComponent = component;
                };

                e.WillRemoveComponent(CID.ComponentA);
                eventEntity.should_be_null();
                eventIndex.should_be(CID.None);
                eventComponent.should_be_null();
            };

            it["dispatches OnComponentAdded when attempting to replace a component which hasn't been added"] = () => {
                e.OnComponentAdded += (entity, index, component) => {
                    eventEntity    = entity;
                    eventIndex     = index;
                    eventComponent = component;
                };
                e.OnComponentReplaced      += (entity, index, component) => this.Fail();
                e.OnComponentWillBeRemoved += (entity, index, component) => this.Fail();
                e.OnComponentRemoved       += (entity, index, component) => this.Fail();

                var newComponentA = new ComponentA();
                e.ReplaceComponentA(newComponentA);
                eventEntity.should_be_same(e);
                eventIndex.should_be(CID.ComponentA);
                eventComponent.should_be_same(newComponentA);
            };

            it["dispatches OnComponentRemoved when removing all components"] = () => {
                var removed = 0;
                e.AddComponentA();
                e.AddComponentB();
                e.OnComponentRemoved += (entity, index, component) => removed++;
                e.RemoveAllComponents();
                removed.should_be(2);
            };
        };

        context["invalid operations"] = () => {
            it["throws when adding a component of the same type twice"] = expect <EntityAlreadyHasComponentException>(() => {
                e.AddComponentA();
                e.AddComponentA();
            });

            it["throws when attempting to remove a component of type which hasn't been added"] = expect <EntityDoesNotHaveComponentException>(() => {
                e.RemoveComponentA();
            });

            it["throws when attempting to get component of type which hasn't been added"] = expect <EntityDoesNotHaveComponentException>(() => {
                e.GetComponentA();
            });
        };

        context["internal caching"] = () => {
            context["components"] = () => {
                it["caches components"] = () => {
                    e.AddComponentA();
                    var c = e.GetComponents();
                    e.GetComponents().should_be_same(c);
                };

                it["updates cache when a new component was added"] = () => {
                    e.AddComponentA();
                    var c = e.GetComponents();
                    e.AddComponentB();
                    e.GetComponents().should_not_be_same(c);
                };

                it["updates cache when a component was removed"] = () => {
                    e.AddComponentA();
                    e.AddComponentB();
                    var c = e.GetComponents();
                    e.RemoveComponentA();
                    e.GetComponents().should_not_be_same(c);
                };

                it["updates cache when a component was replaced"] = () => {
                    e.AddComponentA();
                    e.AddComponentB();
                    var c = e.GetComponents();
                    e.ReplaceComponentA(new ComponentA());
                    e.GetComponents().should_not_be_same(c);
                };

                it["doesn't update cache when a component was replaced with same component"] = () => {
                    e.AddComponentA();
                    e.AddComponentB();
                    var c = e.GetComponents();
                    e.ReplaceComponentA(Component.A);
                    e.GetComponents().should_be_same(c);
                };

                it["updates cache when all components were removed"] = () => {
                    e.AddComponentA();
                    e.AddComponentB();
                    var c = e.GetComponents();
                    e.RemoveAllComponents();
                    e.GetComponents().should_not_be_same(c);
                };
            };

            context["component indices"] = () => {
                it["caches component indices"] = () => {
                    e.AddComponentA();
                    var c = e.GetComponentIndices();
                    e.GetComponentIndices().should_be_same(c);
                };

                it["updates cache when a new component was added"] = () => {
                    e.AddComponentA();
                    var c = e.GetComponentIndices();
                    e.AddComponentB();
                    e.GetComponentIndices().should_not_be_same(c);
                };

                it["updates cache when a component was removed"] = () => {
                    e.AddComponentA();
                    e.AddComponentB();
                    var c = e.GetComponentIndices();
                    e.RemoveComponentA();
                    e.GetComponentIndices().should_not_be_same(c);
                };

                it["doesn't update cache when a component was replaced"] = () => {
                    e.AddComponentA();
                    e.AddComponentB();
                    var c = e.GetComponentIndices();
                    e.ReplaceComponentA(new ComponentA());
                    e.GetComponentIndices().should_be_same(c);
                };

                it["updates cache when adding a new component with ReplaceComponent"] = () => {
                    e.AddComponentA();
                    e.AddComponentB();
                    var c = e.GetComponentIndices();
                    e.ReplaceComponentC(Component.C);
                    e.GetComponentIndices().should_not_be_same(c);
                };

                it["updates cache when all components were removed"] = () => {
                    e.AddComponentA();
                    e.AddComponentB();
                    var c = e.GetComponentIndices();
                    e.RemoveAllComponents();
                    e.GetComponentIndices().should_not_be_same(c);
                };
            };
        };
    }
Exemple #6
0
 void handleAddEA(Entity entity)
 {
     handle(entity, CID.ComponentA, entity.GetComponentA());
 }
Exemple #7
0
    void when_created()
    {
        Entity eA1 = null;
        Entity eA2 = null;

        before = () => {
            _groupA = new Group(Matcher.AllOf(CID.ComponentA));
            eA1     = this.CreateEntity().AddComponentA();
            eA2     = this.CreateEntity().AddComponentA();
        };

        context["initial state"] = () => {
            it["doesn't have entities which haven't been added"] = () => {
                _groupA.GetEntities().should_be_empty();
            };

            it["is empty"] = () => {
                _groupA.count.should_be(0);
            };

            it["doesn't contain entity"] = () => {
                _groupA.ContainsEntity(eA1).should_be_false();
            };
        };

        context["when entity is matching"] = () => {
            before = () => {
                handleSilently(eA1);
            };

            it["adds matching entity"] = () => {
                assertContains(eA1);
            };

            it["doesn't add same entity twice"] = () => {
                handleSilently(eA1);
                assertContains(eA1);
            };

            context["when entity doesn't match anymore"] = () => {
                it["removes entity"] = () => {
                    eA1.RemoveComponentA();
                    handleSilently(eA1);

                    assertContainsNot(eA1);
                };
            };
        };

        it["doesn't add entity when not matching"] = () => {
            var e = this.CreateEntity().AddComponentB();
            handleSilently(e);
            assertContainsNot(e);
        };

        it["gets null when single entity does not exist"] = () => {
            _groupA.GetSingleEntity().should_be_null();
        };

        it["gets single entity"] = () => {
            handleSilently(eA1);
            _groupA.GetSingleEntity().should_be_same(eA1);
        };

        it["throws when attempting to get single entity and multiple matching entities exist"] = expect <GroupSingleEntityException>(() => {
            handleSilently(eA1);
            handleSilently(eA2);
            _groupA.GetSingleEntity();
        });

        context["events"] = () => {
            var didDispatch = 0;

            before = () => {
                didDispatch = 0;
            };

            it["dispatches OnEntityAdded when matching entity added"] = () => {
                _groupA.OnEntityAdded += (group, entity, index, component) => {
                    didDispatch++;
                    group.should_be_same(_groupA);
                    entity.should_be_same(eA1);
                    index.should_be(CID.ComponentA);
                    component.should_be_same(Component.A);
                };
                _groupA.OnEntityRemoved += delegate { this.Fail(); };
                _groupA.OnEntityUpdated += delegate { this.Fail(); };

                handleAddEA(eA1);
                didDispatch.should_be(1);
            };

            it["doesn't dispatches OnEntityAdded when matching entity already has been added"] = () => {
                handleAddEA(eA1);
                _groupA.OnEntityAdded   += delegate { this.Fail(); };
                _groupA.OnEntityRemoved += delegate { this.Fail(); };
                _groupA.OnEntityUpdated += delegate { this.Fail(); };
                handleAddEA(eA1);
                didDispatch.should_be(0);
            };

            it["doesn't dispatches OnEntityAdded when entity is not matching"] = () => {
                var e = this.CreateEntity().AddComponentB();
                _groupA.OnEntityAdded   += delegate { this.Fail(); };
                _groupA.OnEntityRemoved += delegate { this.Fail(); };
                _groupA.OnEntityUpdated += delegate { this.Fail(); };
                handleAddEB(e);
            };

            it["dispatches OnEntityRemoved when entity got removed"] = () => {
                handleSilently(eA1);
                _groupA.OnEntityRemoved += (group, entity, index, component) => {
                    didDispatch++;
                    group.should_be_same(_groupA);
                    entity.should_be_same(eA1);
                    index.should_be(CID.ComponentA);
                    component.should_be_same(Component.A);
                };
                _groupA.OnEntityAdded   += delegate { this.Fail(); };
                _groupA.OnEntityUpdated += delegate { this.Fail(); };

                eA1.RemoveComponentA();
                handleRemoveEA(eA1, Component.A);

                didDispatch.should_be(1);
            };

            it["doesn't dispatch OnEntityRemoved when entity didn't get removed"] = () => {
                _groupA.OnEntityRemoved += delegate { this.Fail(); };
                eA1.RemoveComponentA();
                handleRemoveEA(eA1, Component.A);
            };

            it["dispatches OnEntityRemoved, OnEntityAdded and OnEntityUpdated when updating"] = () => {
                handleSilently(eA1);

                var removed       = 0;
                var added         = 0;
                var updated       = 0;
                var newComponentA = new ComponentA();

                _groupA.OnEntityRemoved += (group, entity, index, component) => {
                    removed += 1;
                    group.should_be(_groupA);
                    entity.should_be(eA1);
                    index.should_be(CID.ComponentA);
                    component.should_be_same(Component.A);
                };
                _groupA.OnEntityAdded += (group, entity, index, component) => {
                    added += 1;
                    group.should_be(_groupA);
                    entity.should_be(eA1);
                    index.should_be(CID.ComponentA);
                    component.should_be_same(newComponentA);
                };
                _groupA.OnEntityUpdated += (group, entity, index, previousComponent, newComponent) => {
                    updated += 1;
                    group.should_be(_groupA);
                    entity.should_be(eA1);
                    index.should_be(CID.ComponentA);
                    previousComponent.should_be_same(Component.A);
                    newComponent.should_be_same(newComponentA);
                };

                updateEA(eA1, newComponentA);

                removed.should_be(1);
                added.should_be(1);
                updated.should_be(1);
            };

            it["doesn't dispatch OnEntityRemoved and OnEntityAdded when updating when group doesn't contain entity"] = () => {
                _groupA.OnEntityRemoved += delegate { this.Fail(); };
                _groupA.OnEntityAdded   += delegate { this.Fail(); };
                _groupA.OnEntityUpdated += delegate { this.Fail(); };
                updateEA(eA1, new ComponentA());
            };

            it["removes all event handlers"] = () => {
                _groupA.OnEntityAdded   += delegate { this.Fail(); };
                _groupA.OnEntityRemoved += delegate { this.Fail(); };
                _groupA.OnEntityUpdated += delegate { this.Fail(); };

                _groupA.RemoveAllEventHandlers();

                handleAddEA(eA1);

                var cA = eA1.GetComponentA();
                eA1.RemoveComponentA();
                handleRemoveEA(eA1, cA);

                eA1.AddComponentA();
                handleAddEA(eA1);
                updateEA(eA1, Component.A);
            };
        };

        context["internal caching"] = () => {
            context["GetEntities()"] = () => {
                Entity[] cache = null;

                before = () => {
                    handleSilently(eA1);
                    cache = _groupA.GetEntities();
                };

                it["gets cached entities"] = () => {
                    _groupA.GetEntities().should_be_same(cache);
                };

                it["updates cache when adding a new matching entity"] = () => {
                    handleSilently(eA2);
                    _groupA.GetEntities().should_not_be_same(cache);
                };

                it["doesn't update cache when attempting to add a not matching entity"] = () => {
                    var e = this.CreateEntity();
                    handleSilently(e);
                    _groupA.GetEntities().should_be_same(cache);
                };

                it["updates cache when removing an entity"] = () => {
                    eA1.RemoveComponentA();
                    handleSilently(eA1);
                    _groupA.GetEntities().should_not_be_same(cache);
                };

                it["doesn't update cache when attempting to remove an entity that wasn't added before"] = () => {
                    eA2.RemoveComponentA();
                    handleSilently(eA2);
                    _groupA.GetEntities().should_be_same(cache);
                };

                it["doesn't update cache when updating an entity"] = () => {
                    updateEA(eA1, new ComponentA());
                    _groupA.GetEntities().should_be_same(cache);
                };
            };

            context["SingleEntity()"] = () => {
                Entity cache = null;

                before = () => {
                    handleSilently(eA1);
                    cache = _groupA.GetSingleEntity();
                };

                it["gets cached singleEntities"] = () => {
                    _groupA.GetSingleEntity().should_be_same(cache);
                };

                it["updates cache when new single entity was added"] = () => {
                    eA1.RemoveComponentA();
                    handleSilently(eA1);
                    handleSilently(eA2);
                    _groupA.GetSingleEntity().should_not_be_same(cache);
                };

                it["updates cache when single entity is removed"] = () => {
                    eA1.RemoveComponentA();
                    handleSilently(eA1);
                    _groupA.GetSingleEntity().should_not_be_same(cache);
                };

                it["doesn't update cache when single entity is updated"] = () => {
                    updateEA(eA1, new ComponentA());
                    _groupA.GetSingleEntity().should_be_same(cache);
                };
            };
        };

        context["reference counting"] = () => {
            it["retains matched entity"] = () => {
                eA1.retainCount.should_be(0);
                handleSilently(eA1);
                eA1.retainCount.should_be(1);
            };

            it["releases removed entity"] = () => {
                handleSilently(eA1);
                eA1.RemoveComponentA();
                handleSilently(eA1);
                eA1.retainCount.should_be(0);
            };

            it["invalidates entitiesCache (silent mode)"] = () => {
                var didExecute = 0;
                eA1.OnEntityReleased += entity => {
                    didExecute += 1;
                    _groupA.GetEntities().Length.should_be(0);
                };
                handleSilently(eA1);
                _groupA.GetEntities();
                eA1.RemoveComponentA();
                handleSilently(eA1);
                didExecute.should_be(1);
            };

            it["invalidates entitiesCache"] = () => {
                var didExecute = 0;
                eA1.OnEntityReleased += entity => {
                    didExecute += 1;
                    _groupA.GetEntities().Length.should_be(0);
                };
                handleAddEA(eA1);
                _groupA.GetEntities();
                eA1.RemoveComponentA();
                handleRemoveEA(eA1, Component.A);
                didExecute.should_be(1);
            };

            it["invalidates singleEntityCache (silent mode)"] = () => {
                var didExecute = 0;
                eA1.OnEntityReleased += entity => {
                    didExecute += 1;
                    _groupA.GetSingleEntity().should_be_null();
                };
                handleSilently(eA1);
                _groupA.GetSingleEntity();
                eA1.RemoveComponentA();
                handleSilently(eA1);
                didExecute.should_be(1);
            };

            it["invalidates singleEntityCache"] = () => {
                var didExecute = 0;
                eA1.OnEntityReleased += entity => {
                    didExecute += 1;
                    _groupA.GetSingleEntity().should_be_null();
                };
                handleAddEA(eA1);
                _groupA.GetSingleEntity();
                eA1.RemoveComponentA();
                handleRemoveEA(eA1, Component.A);
                didExecute.should_be(1);
            };

            it["retains entity until after event handlers were called"] = () => {
                handleAddEA(eA1);
                var didDispatch = 0;
                _groupA.OnEntityRemoved += (group, entity, index, component) => {
                    didDispatch += 1;
                    entity.retainCount.should_be(1);
                };
                eA1.RemoveComponentA();
                handleRemoveEA(eA1, Component.A);

                didDispatch.should_be(1);
                eA1.retainCount.should_be(0);
            };
        };

        it["can ToString"] = () => {
            var m     = Matcher.AllOf(Matcher.AllOf(0), Matcher.AllOf(1));
            var group = new Group(m);
            group.ToString().should_be("Group(AllOf(0, 1))");
        };
    }
 void handleAddEA(Entity entity)
 {
     handle(entity, CID.ComponentA, entity.GetComponentA());
 }
    void when_creating()
    {
        Pool   pool   = null;
        Entity entity = null;

        before = () => {
            pool   = new Pool(CID.TotalComponents);
            entity = pool.CreateEntity();
        };

        context["ComponentBlueprint"] = () => {
            it["creates a component blueprint from a component without members"] = () => {
                var component = new ComponentA();

                const int index = 42;

                var componentBlueprint = new ComponentBlueprint(index, component);
                componentBlueprint.index.should_be(index);
                componentBlueprint.fullTypeName.should_be(component.GetType().FullName);
                componentBlueprint.members.Length.should_be(0);
            };

            it["throws when unknown type"] = expect <ComponentBlueprintException>(() => {
                var componentBlueprint          = new ComponentBlueprint();
                componentBlueprint.fullTypeName = "UnknownType";
                componentBlueprint.CreateComponent(null);
            });

            it["throws when type doesn't implement IComponent"] = expect <ComponentBlueprintException>(() => {
                var componentBlueprint          = new ComponentBlueprint();
                componentBlueprint.fullTypeName = "string";
                componentBlueprint.CreateComponent(null);
            });

            it["creates a component blueprint from a component with members"] = () => {
                var component = new NameAgeComponent();
                component.name = "Max";
                component.age  = 42;

                const int index = 24;

                var componentBlueprint = new ComponentBlueprint(index, component);
                componentBlueprint.index.should_be(index);
                componentBlueprint.fullTypeName.should_be(component.GetType().FullName);
                componentBlueprint.members.Length.should_be(2);

                componentBlueprint.members[0].name.should_be("name");
                componentBlueprint.members[0].value.should_be(component.name);

                componentBlueprint.members[1].name.should_be("age");
                componentBlueprint.members[1].value.should_be(component.age);
            };

            it["creates a component and sets members values"] = () => {
                var componentBlueprint = new ComponentBlueprint();
                componentBlueprint.fullTypeName = typeof(ComponentWithFieldsAndProperties).FullName;
                componentBlueprint.index        = CID.ComponentB;
                componentBlueprint.members      = new [] {
                    new SerializableMember("publicField", "publicFieldValue"),
                    new SerializableMember("publicProperty", "publicPropertyValue")
                };

                var component = (ComponentWithFieldsAndProperties)componentBlueprint.CreateComponent(entity);
                component.publicField.should_be("publicFieldValue");
                component.publicProperty.should_be("publicPropertyValue");
            };

            it["throws when invalid member name"] = expect <ComponentBlueprintException>(() => {
                var componentBlueprint          = new ComponentBlueprint();
                componentBlueprint.index        = 0;
                componentBlueprint.fullTypeName = typeof(NameAgeComponent).FullName;
                componentBlueprint.members      = new [] {
                    new SerializableMember("xxx", "publicFieldValue"),
                    new SerializableMember("publicProperty", "publicPropertyValue")
                };
                componentBlueprint.CreateComponent(entity);
            });
        };

        context["Blueprint"] = () => {
            it["creates a blueprint from an entity"] = () => {
                entity.AddComponentA();

                var component = new NameAgeComponent();
                component.name = "Max";
                component.age  = 42;

                entity.AddComponent(CID.ComponentB, component);

                var blueprint = new Blueprint("My Pool", "Hero", entity);
                blueprint.poolIdentifier.should_be("My Pool");
                blueprint.name.should_be("Hero");
                blueprint.components.Length.should_be(2);

                blueprint.components[0].index.should_be(CID.ComponentA);
                blueprint.components[0].fullTypeName.should_be(Component.A.GetType().FullName);

                blueprint.components[1].index.should_be(CID.ComponentB);
                blueprint.components[1].fullTypeName.should_be(component.GetType().FullName);
            };

            context["when applying blueprint"] = () => {
                Blueprint blueprint = null;

                before = () => {
                    var component1 = new ComponentBlueprint();
                    component1.index        = CID.ComponentA;
                    component1.fullTypeName = typeof(ComponentA).FullName;
                    component1.members      = new SerializableMember[0];

                    var component2 = new ComponentBlueprint();
                    component2.index        = CID.ComponentB;
                    component2.fullTypeName = typeof(NameAgeComponent).FullName;
                    component2.members      = new [] {
                        new SerializableMember("name", "Max"),
                        new SerializableMember("age", 42)
                    };

                    blueprint            = new Blueprint();
                    blueprint.name       = "Hero";
                    blueprint.components = new [] { component1, component2 };
                };

                it["applies blueprint to entity"] = () => {
                    entity.ApplyBlueprint(blueprint).should_be(entity);

                    entity.GetComponents().Length.should_be(2);

                    entity.GetComponent(CID.ComponentA).GetType().should_be(typeof(ComponentA));

                    var nameAgeComponent = (NameAgeComponent)entity.GetComponent(CID.ComponentB);
                    nameAgeComponent.GetType().should_be(typeof(NameAgeComponent));
                    nameAgeComponent.name.should_be("Max");
                    nameAgeComponent.age.should_be(42);
                };

                it["throws when entity already has a component which should be added from blueprint"] = expect <EntityAlreadyHasComponentException>(() => {
                    entity.AddComponentA();
                    entity.ApplyBlueprint(blueprint);
                });

                it["can overwrite existing components"] = () => {
                    var nameAgeComponent = new NameAgeComponent();
                    nameAgeComponent.name = "Jack";
                    nameAgeComponent.age  = 24;
                    entity.AddComponent(CID.ComponentB, nameAgeComponent);

                    entity.ApplyBlueprint(blueprint, true);
                };

                it["uses component from componentPool"] = () => {
                    var component = new ComponentBlueprint();
                    component.index        = CID.ComponentA;
                    component.fullTypeName = typeof(ComponentA).FullName;
                    component.members      = new SerializableMember[0];

                    blueprint            = new Blueprint();
                    blueprint.name       = "Hero";
                    blueprint.components = new [] { component };

                    var componentA = entity.CreateComponent <ComponentA>(CID.ComponentA);
                    entity.AddComponent(CID.ComponentA, componentA);
                    entity.RemoveComponentA();

                    entity.ApplyBlueprint(blueprint);

                    entity.GetComponentA().should_be_same(componentA);
                };
            };
        };
    }
    void when_throwing()
    {
        Pool   pool   = null;
        Entity entity = null;

        before = () => {
            var componentNames = new [] { "Health", "Position", "View" };
            var metaData       = new PoolMetaData("My Pool", componentNames, null);
            pool   = new Pool(componentNames.Length, 42, metaData);
            entity = pool.CreateEntity();
        };

        it["creates exception with hint separated by newLine"] = () => {
            var msg  = "Message";
            var hint = "Hint";
            var ex   = new EntitasException(msg, hint);
            ex.Message.should_be(msg + "\n" + hint);
        };

        it["ignores hint when null"] = () => {
            var    msg  = "Message";
            string hint = null;
            var    ex   = new EntitasException(msg, hint);
            ex.Message.should_be(msg);
        };

        context["Entity"] = () => {
            context["when not enabled"] = () => {
                before = () => {
                    pool.DestroyEntity(entity);
                };

                it["add a component"]     = () => printErrorMessage(() => entity.AddComponentA());
                it["remove a component"]  = () => printErrorMessage(() => entity.RemoveComponentA());
                it["replace a component"] = () => printErrorMessage(() => entity.ReplaceComponentA(Component.A));
            };

            context["when enabled"] = () => {
                it["add a component twice"] = () => printErrorMessage(() => {
                    entity.AddComponentA();
                    entity.AddComponentA();
                });

                it["remove a component that doesn't exist"] = () => printErrorMessage(() => {
                    entity.RemoveComponentA();
                });

                it["get a component that doesn't exist"] = () => printErrorMessage(() => {
                    entity.GetComponentA();
                });

                it["retain an entity twice"] = () => printErrorMessage(() => {
                    var owner = new object();
                    entity.Retain(owner);
                    entity.Retain(owner);
                });

                it["release an entity with wrong owner"] = () => printErrorMessage(() => {
                    var owner = new object();
                    entity.Release(owner);
                });
            };
        };

        context["Group"] = () => {
            it["get single entity when multiple exist"] = () => printErrorMessage(() => {
                pool.CreateEntity().AddComponentA();
                pool.CreateEntity().AddComponentA();
                var matcher            = (Matcher)Matcher.AllOf(CID.ComponentA);
                matcher.componentNames = new [] { "Health", "Position", "View" };
                var group = pool.GetGroup(matcher);
                group.GetSingleEntity();
            });
        };


        context["GroupObserver"] = () => {
            it["unbalanced goups"] = () => printErrorMessage(() => {
                var g1 = new Group(Matcher.AllOf(CID.ComponentA));
                var g2 = new Group(Matcher.AllOf(CID.ComponentB));
                var e1 = GroupEventType.OnEntityAdded;

                new GroupObserver(new [] { g1, g2 }, new [] { e1 });
            });
        };

        context["Pool"] = () => {
            it["wrong PoolMetaData componentNames count"] = () => printErrorMessage(() => {
                var componentNames = new [] { "Health", "Position", "View" };
                var metaData       = new PoolMetaData("My Pool", componentNames, null);
                new Pool(1, 0, metaData);
            });

            it["destroy entity which is not in pool"] = () => printErrorMessage(() => {
                pool.DestroyEntity(new Entity(0, null));
            });

            it["destroy retained entities"] = () => printErrorMessage(() => {
                pool.CreateEntity().Retain(this);
                pool.DestroyAllEntities();
            });

            it["releases entity before destroy"] = () => printErrorMessage(() => {
                entity.Release(pool);
            });
        };

        context["CollectionExtension"] = () => {
            it["get single entity when more than one exist"] = () => printErrorMessage(() => {
                new Entity[2].SingleEntity();
            });
        };


        // TODO
//        context["ComponentBlueprint"] = () => {
//
//            it["type doesn't implement IComponent"] = () => printErrorMessage(() => {
//                new ComponentBlueprint(42, typeof(FakeComponent).FullName, null);
//            });
//
//            it["type doesn't exist"] = () => printErrorMessage(() => {
//                new ComponentBlueprint(42, "UnknownType", null);
//            });
//
//            it["invalid field name"] = () => printErrorMessage(() => {
//                new ComponentBlueprint(42, typeof(ComponentA).FullName, new SerializableField {
//                    fieldName = "unknownField",
//                    value = 42
//                });
//            });
//
//            it["mssing [SerializableAttribute]"] = () => printErrorMessage(() => {
//                new ComponentBlueprint(1, new ComponentA());
//            });
//        };
    }