public void TryUpdateWithApprovalUnderWay()
        {
            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();

            Assert.IsTrue(storage.TryAdd(endpoint, connection));
            Assert.IsTrue(storage.TryStartApproval(endpoint, description));

            var newConnection = new EndpointInformation(
                endpoint,
                new DiscoveryInformation(new Uri("http://other/discovery/invalid")),
                new ProtocolInformation(
                    new Version(),
                    new Uri("http://other/protocol/invalid")));

            Assert.IsTrue(storage.TryUpdate(newConnection));

            EndpointInformation storedConnection;

            storage.TryGetConnectionFor(endpoint, out storedConnection);
            Assert.AreSame(newConnection, storedConnection);
        }
        public void TryUpdateWithContactedEndpoint()
        {
            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 storage = new EndpointInformationStorage();

            Assert.IsTrue(storage.TryAdd(endpoint, connection));

            var newConnection = new EndpointInformation(
                endpoint,
                new DiscoveryInformation(new Uri("http://other/discovery/invalid")),
                new ProtocolInformation(
                    new Version(),
                    new Uri("http://other/protocol/invalid")));

            Assert.IsTrue(storage.TryUpdate(newConnection));

            EndpointInformation storedConnection;

            storage.TryGetConnectionFor(endpoint, out storedConnection);
            Assert.AreSame(newConnection, storedConnection);
        }
        public void TryUpdateWithApprovedEndpoint()
        {
            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.IsTrue(storage.TryStartApproval(endpoint, description));
            Assert.IsTrue(storage.TryCompleteApproval(endpoint));
            Assert.IsTrue(wasApproved);

            var newConnection = new EndpointInformation(
                endpoint,
                new DiscoveryInformation(new Uri("http://other/discovery/invalid")),
                new ProtocolInformation(
                    new Version(),
                    new Uri("http://other/protocol/invalid")));

            Assert.IsFalse(storage.TryUpdate(newConnection));
        }
        public void TryUpdateWithNullInformation()
        {
            var storage = new EndpointInformationStorage();

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