示例#1
0
        public void TestRegisterOverrideExistingRegisted()
        {
            var hostServices = new HostServices();
            var rot          = new MockRunningObjectTable();

            hostServices.SetTestRunningObjectTable(rot);

            var moniker    = Guid.NewGuid().ToString();
            var remoteHost = new MockRemoteHostObject(1);

            rot.Register(moniker, remoteHost);
            var newMoniker    = Guid.NewGuid().ToString();
            var newRemoteHost = new MockRemoteHostObject(2);

            rot.Register(newMoniker, newRemoteHost);
            hostServices.RegisterHostObject(
                "WithOutOfProc.targets",
                "DisplayMessages",
                "ATask",
                remoteHost);

            hostServices.RegisterHostObject("project", "test", "Message", moniker);
            hostServices.RegisterHostObject("project", "test", "Message", newMoniker);
            var resultObject = (ITestRemoteHostObject)hostServices.GetHostObject("project", "test", "Message");

            resultObject.GetState().ShouldBe(2);
        }
示例#2
0
        public void TestTranslationRemoteHostObjects()
        {
            var stateInHostObject = 3;

            var hostServices = new HostServices();
            var rot          = new MockRunningObjectTable();

            hostServices.SetTestRunningObjectTable(rot);
            var moniker    = nameof(TestTranslationRemoteHostObjects) + Guid.NewGuid();
            var remoteHost = new MockRemoteHostObject(stateInHostObject);

            using (var result = rot.Register(moniker, remoteHost))
            {
                hostServices.RegisterHostObject(
                    "WithOutOfProc.targets",
                    "DisplayMessages",
                    "ATask",
                    moniker);

                BuildRequest request = new BuildRequest(
                    submissionId: 1,
                    _nodeRequestId++,
                    1,
                    new string[] { "alpha", "omega" },
                    hostServices: hostServices,
                    BuildEventContext.Invalid,
                    parentRequest: null);

                ((ITranslatable)request).Translate(TranslationHelpers.GetWriteTranslator());
                INodePacket packet = BuildRequest.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

                BuildRequest deserializedRequest = packet as BuildRequest;
                deserializedRequest.HostServices.SetTestRunningObjectTable(rot);
                var hostObject = deserializedRequest.HostServices.GetHostObject(
                    "WithOutOfProc.targets",
                    "DisplayMessages",
                    "ATask") as ITestRemoteHostObject;

                hostObject.GetState().ShouldBe(stateInHostObject);
            }
        }