Exemple #1
0
        public void ConfigRetriever_ManualWithUrl()
        {
            var url             = $"{ConsulHttpSchema}://{ConsulHost}:{ConsulPort}";
            var retriever       = new ConsulRetriever(url, ConsulAclToken);
            var logger          = new StdoutLogger();
            var configRetriever = new ConfigRetriever <TestClass1>(retriever, logger);

            var resultTask = configRetriever.Fill();
            var result     = resultTask.Result;

            var expected = new TestClass1()
            {
                PropTestClass1_1 = new TestClass1_1()
                {
                    PropInt    = 10,
                    PropDouble = 10.10
                },
                PropTestClass2 = new TestClass2()
                {
                    PropString     = "some string",
                    PropTestClass3 = new TestClass3()
                    {
                        PropBool   = true,
                        PropLong   = 1000,
                        PropString = "some string"
                    }
                }
            };

            result.Should().BeEquivalentTo(expected);
        }
        public void Fill_AvailableInRetriever()
        {
            string value;

            var retrieverMock = new Mock <IRetriever>();

            value = "some value";

            // Class1
            retrieverMock.Setup(retriever => retriever.Retrieve(
                                    new [] { "FakePathLevel0", "FakePathLevel1", "TestClass1", "PropString" }))
            .Returns(Task.FromResult(value));

            // Class1_1
            retrieverMock.Setup(retriever => retriever.Retrieve(
                                    new [] { "FakePathLevel0", "FakePathLevel1", "TestClass1", "TestClass1_1Name", "PropString" }))
            .Returns(Task.FromResult(value));

            // Class2
            retrieverMock.Setup(retriever => retriever.Retrieve(
                                    new [] { "FakePathLevel0", "FakePathLevel1", "TestClass2", "PropString" }))
            .Returns(Task.FromResult(value));

            retrieverMock.Setup(retriever => retriever.Retrieve(
                                    new [] { "FakePathLevel0", "TestClass2", "PropString" }))
            .Returns(Task.FromResult(value));

            // Class3
            retrieverMock.Setup(retriever => retriever.Retrieve(
                                    new [] { "FakePathLevel0", "FakePathLevel1", "TestClass2", "TestClass3", "PropString" }))
            .Returns(Task.FromResult(value));

            retrieverMock.Setup(retriever => retriever.Retrieve(
                                    new [] { "FakePathLevel0", "TestClass2", "TestClass3", "PropString" }))
            .Returns(Task.FromResult(value));

            retrieverMock.Setup(retriever => retriever.Retrieve(
                                    new [] { "FakePathLevel0", "TestClass3", "PropString" }))
            .Returns(Task.FromResult(value));

            // =========

            var expected = new TestClass1()
            {
                PropString       = value,
                PropTestClass1_1 = new TestClass1_1()
                {
                    PropString = value
                },
                TestClass2 = new TestClass2()
                {
                    PropString     = value,
                    PropTestClass3 = new TestClass3()
                    {
                        PropString = value
                    }
                }
            };

            var configRetriever = new ConfigRetriever <TestClass1>(retrieverMock.Object);

            var resultTask = configRetriever.Fill();
            var result     = resultTask.Result;

            result.Should().BeEquivalentTo(expected);
        }