示例#1
0
        public void ServiceTest()
        {
            Stream      serverPeerStream = new Regulus.Remote.Standalone.Stream();
            IStreamable serverStream     = serverPeerStream;
            IStreamable clientStream     = new ReverseStream(serverPeerStream);

            IBinderProvider entry = NSubstitute.Substitute.For <IBinderProvider>();
            IGpiA           gpia  = new SoulGpiA();

            entry.AssignBinder(NSubstitute.Arg.Do <IBinder>(binder => binder.Bind <IGpiA>(gpia)), NSubstitute.Arg.Any <object>());

            Serialization.ISerializer serializer = new Regulus.Serialization.Dynamic.Serializer();
            IProtocol protocol = ProtocolHelper.CreateProtocol(serializer);

            Soul.IService service   = new Regulus.Remote.Soul.Service(entry, protocol);
            IAgent        agent     = new Regulus.Remote.Ghost.Agent(protocol) as Ghost.IAgent;
            IGpiA         ghostGpia = null;


            service.Join(serverStream);
            agent.Start(clientStream);
            agent.QueryNotifier <IGpiA>().Supply += gpi => ghostGpia = gpi;

            while (ghostGpia == null)
            {
                agent.Update();
            }

            agent.Stop();
            service.Leave(serverStream);

            IDisposable disposable = service;

            disposable.Dispose();
        }
示例#2
0
        private static void _TestService(IBinderProvider entry, ref bool bind, IProtocol protocol)
        {
            bind = false;
            var service = Regulus.Remote.Standalone.Provider.CreateService(protocol, entry);

            Ghost.IAgent agent = new Regulus.Remote.Ghost.Agent(protocol);
            service.Join(agent, null);
            IGpiA retGpiA = null;
            bool  ret     = false;

            agent.QueryNotifier <IGpiA>().Supply += gpi => {
                ret     = true;
                retGpiA = gpi;
            };
            var timer = new Regulus.Utility.TimeCounter();
            var apr   = new Regulus.Utility.AutoPowerRegulator(new Utility.PowerRegulator());

            while (retGpiA == null)
            {
                apr.Operate();
                agent.Update();
                if (timer.Second > 10)
                {
                    throw new System.Exception($"debug agent:{agent.Active} bind:{bind} ");
                }
            }

            service.Leave(agent);
            service.Dispose();

            Assert.AreNotEqual(null, retGpiA);
            Assert.AreEqual(true, bind);
            Assert.AreEqual(true, ret);
        }
示例#3
0
        public void AgentSupplyGpiTest()
        {
            IGpiA retGpiA = null;

            Regulus.Serialization.ISerializer serializer = new Regulus.Serialization.Dynamic.Serializer();
            IProtocol protocol = ProtocolHelper.CreateProtocol(serializer);

            Stream cdClient = new Regulus.Remote.Standalone.Stream();

            Network.IStreamable             peerClient = cdClient;
            PackageWriter <ResponsePackage> writer     = new PackageWriter <ResponsePackage>(serializer);

            writer.Start(new ReverseStream(cdClient));

            Ghost.IAgent agent = new Regulus.Remote.Ghost.Agent(protocol) as Ghost.IAgent;
            agent.QueryNotifier <IGpiA>().Supply += gpi => retGpiA = gpi;
            agent.Start(peerClient);

            writer.ServerToClient(serializer, ServerToClientOpCode.LoadSoul, new Regulus.Remote.PackageLoadSoul()
            {
                EntityId = 1, ReturnType = false, TypeId = 1
            });
            writer.ServerToClient(serializer, ServerToClientOpCode.LoadSoulCompile, new Regulus.Remote.PackageLoadSoulCompile()
            {
                EntityId = 1, TypeId = 1, ReturnId = 0, PassageId = 0
            });
            while (retGpiA == null)
            {
                agent.Update();
            }
            agent.Stop();
            writer.Stop();
            Assert.AreNotEqual(null, retGpiA);
        }
示例#4
0
            public void GhostTest()
            {
                GhostA          ghostA            = new GhostA();
                IGpiA           gpiA              = ghostA;
                IGhost          ghost             = ghostA;
                PropertyInfo    addSupplyProperty = null;
                PassageCallback addSupplyPassage  = null;

                ghost.AddSupplyNoitfierEvent += (property, passage) =>
                {
                    addSupplyProperty = property;
                    addSupplyPassage  = passage;
                };
                IGpiB gPi = null;

                gpiA.GpiBs.Supply += (gpi) =>
                {
                    gPi = gpi;
                };

                SoulB soulB = new SoulB();

                addSupplyPassage(soulB);


                NUnit.Framework.Assert.AreEqual(soulB, gPi);
            }