public void should_execute_system_without_predicate()
        {
            var fakeEntities = new List <IEntity>
            {
                Substitute.For <IEntity>(),
                Substitute.For <IEntity>()
            };

            var mockObservableGroup = Substitute.For <IObservableGroup>();

            mockObservableGroup.GetEnumerator().Returns(fakeEntities.GetEnumerator());

            var mockCollectionManager = Substitute.For <IEntityCollectionManager>();
            var threadHandler         = Substitute.For <IThreadHandler>();

            var fakeGroup = new Group();

            mockCollectionManager.GetObservableGroup(Arg.Is(fakeGroup), Arg.Any <int[]>()).Returns(mockObservableGroup);

            var observableSubject = new Subject <IObservableGroup>();
            var mockSystem        = Substitute.For <IReactToGroupSystem>();

            mockSystem.Group.Returns(fakeGroup);
            mockSystem.ReactToGroup(Arg.Is(mockObservableGroup)).Returns(observableSubject);

            var systemHandler = new ReactToGroupSystemHandler(mockCollectionManager, threadHandler);

            systemHandler.SetupSystem(mockSystem);

            observableSubject.OnNext(mockObservableGroup);

            mockSystem.ReceivedWithAnyArgs(2).Process(Arg.Any <IEntity>());
            Assert.Equal(1, systemHandler._systemSubscriptions.Count);
            Assert.NotNull(systemHandler._systemSubscriptions[mockSystem]);
        }
        public void should_execute_system_without_predicate()
        {
            var fakeEntities = new[]
            {
                Substitute.For <IEntity>(),
                Substitute.For <IEntity>()
            };

            var mockObservableGroup = Substitute.For <IObservableGroup>();

            mockObservableGroup.Entities.Returns(fakeEntities);

            var mockCollectionManager = Substitute.For <IEntityCollectionManager>();

            var fakeGroup = new Group();

            mockCollectionManager.CreateObservableGroup(Arg.Is(fakeGroup)).Returns(mockObservableGroup);

            var observableSubject = new Subject <IObservableGroup>();
            var mockSystem        = Substitute.For <IReactToGroupSystem>();

            mockSystem.TargetGroup.Returns(fakeGroup);
            mockSystem.ReactToGroup(Arg.Is(mockObservableGroup)).Returns(observableSubject);

            var systemHandler = new ReactToGroupSystemHandler(mockCollectionManager);

            systemHandler.SetupSystem(mockSystem);

            observableSubject.OnNext(mockObservableGroup);

            mockSystem.ReceivedWithAnyArgs(2).Execute(Arg.Any <IEntity>());
            Assert.Equal(1, systemHandler._systemSubscriptions.Count);
            Assert.NotNull(systemHandler._systemSubscriptions[mockSystem]);
        }
示例#3
0
        public void should_only_execute_system_when_predicate_met()
        {
            var entityToMatch = Substitute.For <IEntity>();
            var idToMatch     = 1;

            entityToMatch.Id.Returns(idToMatch);

            var fakeEntities = new List <IEntity>
            {
                entityToMatch,
                Substitute.For <IEntity>()
            };


            var mockObservableGroup = Substitute.For <IObservableGroup>();

            mockObservableGroup.GetEnumerator().Returns(fakeEntities.GetEnumerator());

            var observableGroupManager = Substitute.For <IObservableGroupManager>();
            var threadHandler          = Substitute.For <IThreadHandler>();

            var fakeGroup = new GroupWithPredicate(x => x.Id == idToMatch);

            observableGroupManager.GetObservableGroup(Arg.Is(fakeGroup), Arg.Any <int[]>()).Returns(mockObservableGroup);

            var observableSubject = new Subject <IObservableGroup>();
            var mockSystem        = Substitute.For <IReactToGroupSystem>();

            mockSystem.Group.Returns(fakeGroup);
            mockSystem.ReactToGroup(Arg.Is(mockObservableGroup)).Returns(observableSubject);

            var systemHandler = new ReactToGroupSystemHandler(observableGroupManager, threadHandler);

            systemHandler.SetupSystem(mockSystem);

            observableSubject.OnNext(mockObservableGroup);

            mockSystem.ReceivedWithAnyArgs(1).Process(Arg.Is(entityToMatch));
            Assert.Equal(1, systemHandler._systemSubscriptions.Count);
            Assert.NotNull(systemHandler._systemSubscriptions[mockSystem]);
        }
        public void should_only_execute_system_when_predicate_met()
        {
            var entityToMatch = Substitute.For <IEntity>();
            var guidToMatch   = Guid.NewGuid();

            entityToMatch.Id.Returns(guidToMatch);

            var fakeEntities = new[]
            {
                entityToMatch,
                Substitute.For <IEntity>()
            };


            var mockObservableGroup = Substitute.For <IObservableGroup>();

            mockObservableGroup.Entities.Returns(fakeEntities);

            var mockCollectionManager = Substitute.For <IEntityCollectionManager>();

            var fakeGroup = new Group(x => x.Id == guidToMatch);

            mockCollectionManager.CreateObservableGroup(Arg.Is(fakeGroup)).Returns(mockObservableGroup);

            var observableSubject = new Subject <IObservableGroup>();
            var mockSystem        = Substitute.For <IReactToGroupSystem>();

            mockSystem.TargetGroup.Returns(fakeGroup);
            mockSystem.ReactToGroup(Arg.Is(mockObservableGroup)).Returns(observableSubject);

            var systemHandler = new ReactToGroupSystemHandler(mockCollectionManager);

            systemHandler.SetupSystem(mockSystem);

            observableSubject.OnNext(mockObservableGroup);

            mockSystem.ReceivedWithAnyArgs(1).Execute(Arg.Is(entityToMatch));
            Assert.Equal(1, systemHandler._systemSubscriptions.Count);
            Assert.NotNull(systemHandler._systemSubscriptions[mockSystem]);
        }