public void TryRemoveWithApprovedEndpoint()
        {
            var storage = new EndpointInformationStorage();

            var endpoint   = new EndpointId("a");
            var connection = new EndpointInformation(
                new EndpointId("a"),
                new DiscoveryInformation(new Uri("http://localhost/discovery/invalid")),
                new ProtocolInformation(
                    new Version(),
                    new Uri("http://localhost/protocol/invalid")));

            Assert.IsTrue(storage.TryAdd(endpoint, connection));
            Assert.IsFalse(storage.CanCommunicateWithEndpoint(endpoint));
            Assert.IsTrue(storage.HasBeenContacted(endpoint));
            Assert.IsFalse(storage.IsWaitingForApproval(endpoint));

            var description = new ProtocolDescription(new List <CommunicationSubject>());

            Assert.IsTrue(storage.TryStartApproval(endpoint, description));
            Assert.IsTrue(storage.TryCompleteApproval(endpoint));
            Assert.IsTrue(storage.CanCommunicateWithEndpoint(endpoint));
            Assert.IsFalse(storage.IsWaitingForApproval(endpoint));

            Assert.IsTrue(storage.TryRemoveEndpoint(endpoint));
            Assert.IsFalse(storage.CanCommunicateWithEndpoint(endpoint));
            Assert.IsFalse(storage.IsWaitingForApproval(endpoint));
            Assert.IsFalse(storage.HasBeenContacted(endpoint));
        }
        public void TryApprove()
        {
            var endpoint   = new EndpointId("a");
            var connection = new EndpointInformation(
                new EndpointId("a"),
                new DiscoveryInformation(new Uri("http://localhost/discovery/invalid")),
                new ProtocolInformation(
                    new Version(),
                    new Uri("http://localhost/protocol/invalid")));

            var description = new ProtocolDescription(new List <CommunicationSubject>());
            var storage     = new EndpointInformationStorage();

            var wasApproved = false;

            storage.OnEndpointConnected +=
                (s, e) =>
            {
                wasApproved = true;
                Assert.AreSame(connection.Id, e.Endpoint);
            };

            Assert.IsTrue(storage.TryAdd(endpoint, connection));
            Assert.IsFalse(storage.CanCommunicateWithEndpoint(endpoint));
            Assert.IsTrue(storage.HasBeenContacted(endpoint));
            Assert.IsFalse(storage.IsWaitingForApproval(endpoint));

            Assert.IsTrue(storage.TryStartApproval(endpoint, description));
            Assert.IsTrue(storage.TryCompleteApproval(endpoint));
            Assert.IsTrue(storage.CanCommunicateWithEndpoint(endpoint));
            Assert.IsFalse(storage.HasBeenContacted(endpoint));
            Assert.IsFalse(storage.IsWaitingForApproval(endpoint));
            Assert.IsTrue(wasApproved);
        }
        public void TryApproveWithNonAddedEndpoint()
        {
            var storage = new EndpointInformationStorage();

            var endpoint = new EndpointId("a");

            Assert.IsFalse(storage.TryCompleteApproval(endpoint));
        }
        public void TryApproveWithNullEndpoint()
        {
            var storage = new EndpointInformationStorage();

            Assert.IsFalse(storage.TryCompleteApproval(null));
        }