Exemple #1
0
        public void Should_ReturnHost_When_QueryPlanMoveNextReturnsTrueAndCurrentReturnsHost()
        {
            var sessionMock = Mock.Of <IInternalSession>();
            var lbpMock     = Mock.Of <ILoadBalancingPolicy>();

            Mock.Get(sessionMock).SetupGet(m => m.Cluster.Configuration).Returns(RequestHandlerMockTests.GetConfig(lbpMock));
            var enumerable = Mock.Of <IEnumerable <Host> >();
            var enumerator = Mock.Of <IEnumerator <Host> >();

            var host = new Host(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9047));

            Mock.Get(enumerator).Setup(m => m.MoveNext()).Returns(true);
            Mock.Get(enumerator).SetupGet(m => m.Current).Returns(host);
            Mock.Get(enumerable).Setup(m => m.GetEnumerator()).Returns(enumerator);
            Mock.Get(lbpMock)
            .Setup(m => m.NewQueryPlan(It.IsAny <string>(), It.IsAny <IStatement>()))
            .Returns(enumerable);
            Mock.Get(lbpMock).Setup(m => m.Distance(host)).Returns(HostDistance.Local);
            var triedHosts = new Dictionary <IPEndPoint, Exception>();

            var sut       = new RequestHandler(sessionMock, new Serializer(ProtocolVersion.V4));
            var validHost = sut.GetNextValidHost(triedHosts);

            Assert.NotNull(validHost);
            Assert.AreEqual(host, validHost.Host);
        }
Exemple #2
0
        public void Should_ThrowNoHostAvailableException_When_QueryPlanMoveNextReturnsFalse()
        {
            var sessionMock = Mock.Of <IInternalSession>();
            var lbpMock     = Mock.Of <ILoadBalancingPolicy>();

            Mock.Get(sessionMock).SetupGet(m => m.Cluster.Configuration).Returns(RequestHandlerMockTests.GetConfig(lbpMock));
            var enumerable = Mock.Of <IEnumerable <Host> >();
            var enumerator = Mock.Of <IEnumerator <Host> >();

            Mock.Get(enumerator).Setup(m => m.MoveNext()).Returns(false);
            Mock.Get(enumerable).Setup(m => m.GetEnumerator()).Returns(enumerator);
            Mock.Get(lbpMock)
            .Setup(m => m.NewQueryPlan(It.IsAny <string>(), It.IsAny <IStatement>()))
            .Returns(enumerable);
            var triedHosts = new Dictionary <IPEndPoint, Exception>();

            var sut = new RequestHandler(sessionMock, new Serializer(ProtocolVersion.V4));

            Assert.Throws <NoHostAvailableException>(() => sut.GetNextValidHost(triedHosts));
        }