Ejemplo n.º 1
0
        public void GetKey_ReturnsValue()
        {
            var    fixture   = new Fixture();
            string serverUri = fixture.Create <string>();
            string key       = fixture.Create <string>();
            string value1    = fixture.Create <string>();
            string value2    = fixture.Create <string>();

            Mock <IEtcdCompoundClient> clientMock = new Mock <IEtcdCompoundClient>();

            clientMock.Setup(p => p.Get(It.IsAny <string>())).Returns
            (
                new RangeResponse
            {
                Count = 2,
                Kvs   =
                {
                    new RepeatedField <KeyValue> {
                        new KeyValue             {
                            Value = ByteString.CopyFromUtf8(value1)
                        }
                    },
                    new RepeatedField <KeyValue> {
                        new KeyValue             {
                            Value = ByteString.CopyFromUtf8(value2)
                        }
                    }
                }
            }
            );

            Mock <IEtcdCompoundClientFactory> etcdCompoundClientFactoryMock = new Mock <IEtcdCompoundClientFactory>();

            etcdCompoundClientFactoryMock.Setup(p => p.CreateClient(It.IsAny <string>())).Returns(clientMock.Object);

            EtcdWrapper wrapper = new EtcdWrapper(etcdCompoundClientFactoryMock.Object);

            string value = wrapper.GetKey(serverUri, key);

            etcdCompoundClientFactoryMock.Verify(p => p.CreateClient(serverUri), Times.Once);
            Assert.AreEqual(value1, value);
            clientMock.Verify(p => p.Get(key), Times.Once);
        }
Ejemplo n.º 2
0
        public void GetKey_Exception()
        {
            var    fixture   = new Fixture();
            string serverUri = fixture.Create <string>();
            string key       = fixture.Create <string>();

            Mock <IEtcdCompoundClient> clientMock = new Mock <IEtcdCompoundClient>();

            clientMock.Setup(p => p.Get(It.IsAny <string>())).Callback <string>(s => throw new InvalidCastException("whatever"));

            Mock <IEtcdCompoundClientFactory> etcdCompoundClientFactoryMock = new Mock <IEtcdCompoundClientFactory>();

            etcdCompoundClientFactoryMock.Setup(p => p.CreateClient(It.IsAny <string>())).Returns(clientMock.Object);

            EtcdWrapper wrapper = new EtcdWrapper(etcdCompoundClientFactoryMock.Object);

            string value = wrapper.GetKey(serverUri, key);

            etcdCompoundClientFactoryMock.Verify(p => p.CreateClient(serverUri), Times.Once);
            Assert.IsNull(value);
            clientMock.Verify(p => p.Get(key), Times.Once);
        }
Ejemplo n.º 3
0
        public void GetKey_NoValue()
        {
            var    fixture   = new Fixture();
            string serverUri = fixture.Create <string>();
            string key       = fixture.Create <string>();

            Mock <IEtcdCompoundClient> clientMock = new Mock <IEtcdCompoundClient>();

            clientMock.Setup(p => p.Get(It.IsAny <string>())).Returns(new RangeResponse());

            Mock <IEtcdCompoundClientFactory> etcdCompoundClientFactoryMock = new Mock <IEtcdCompoundClientFactory>();

            etcdCompoundClientFactoryMock.Setup(p => p.CreateClient(It.IsAny <string>())).Returns(clientMock.Object);

            EtcdWrapper wrapper = new EtcdWrapper(etcdCompoundClientFactoryMock.Object);

            string value = wrapper.GetKey(serverUri, key);

            etcdCompoundClientFactoryMock.Verify(p => p.CreateClient(serverUri), Times.Once);
            Assert.IsNull(value);
            clientMock.Verify(p => p.Get(key), Times.Once);
        }