Esempio n. 1
0
        public static void ReadConfigHotUpdate()
        {
            var builder = new ConfigurationBuilder()
                          //optional:是否可选
                          //reloadOnChange:修改后重新更新(热更新)
                          .AddJsonFile("ConfigTest.json", false, true);
            ConfigTest configTest = new ConfigTest();
            var        config     = builder.Build();

            //Microsoft.Extensions.Configuration.Binder
            config.Bind(configTest);
            Console.WriteLine(configTest.TotalCount);
            Console.WriteLine(configTest.Students[0].Name);
            Console.WriteLine(configTest.Students[0].Sex);
            Console.WriteLine(configTest.Students[1].Name);
            Console.WriteLine(configTest.Students[1].Sex);
            while (true)
            {
                Console.ReadLine();
                //修改bin目录下的config数据,重新读一次,TotalCount生效,Students不生效
                config = builder.Build();
                //Microsoft.Extensions.Configuration.Binder
                config.Bind(configTest);
                Console.WriteLine(configTest.TotalCount);
                Console.WriteLine(configTest.Students[0].Name);
                Console.WriteLine(configTest.Students[0].Sex);
                Console.WriteLine(configTest.Students[1].Name);
                Console.WriteLine(configTest.Students[1].Sex);
            }
        }
 public IActionResult Index()
 {
     //GetSection:必须先读节点
     //ConfigTest实现接口IOptions<ConfigTest>
     _configTestByOptions = _configuration.GetSection("MyData").Get <ConfigTest>();
     return(View());
 }
        public void Setup()
        {
            _config = new ConfigTest().CreateMapper(AutoMapperConfiguration.RegisterMappings());

            repositorioMock = new Mock <IAmigoRepositorio>();

            servicoMock = new AmigoServico(repositorioMock.Object, _config.Mappe);
        }
Esempio n. 4
0
    void Start()
    {
        Instance = this;

        //var r = Type.GetType("RedController");
        //Debug.Log(r);
        Init();
    }
Esempio n. 5
0
        public BaseClientTest()
        {
            ConfigTest config = new ConfigTest
            {
                AppKey    = "accessKeyID",
                AppSecret = "",
                Domain    = "domain"
            };

            client = new BaseClient(config.ToMap());
        }
Esempio n. 6
0
        /// <summary>
        ///  This method return and test a kind of Client Configuration <see cref="ConfigTest"/> for calling the API.
        /// </summary>
        public Configuration GetClientConfig()
        {
            ConfigTest configTest = new ConfigTest();
            var        client     = new ApiClient(configTest.BasePath);

            var configuration = new Configuration(client);

            configuration.ApiKey.Add(configTest.ApiKeyPrefix, configTest.ApiKey);
            configuration.AddDefaultHeader(configTest.ApiKeyPrefix, configTest.ApiKey);
            Assert.NotNull(configuration);
            return(configuration);
        }
Esempio n. 7
0
        public void Test_ConfigBase_EnableBackoffEnabled()
        {
            // Arrange
            var config = new ConfigTest();

            // Act/Assert - backoff can only be set when both receiver and sender has been setup.
            config.EnableAutobackOff.Should().BeFalse();
            config.EnableAutobackOff = true;
            config.EnableAutobackOff.Should().BeFalse();
            config.Receiver = new ReceiverSetup();
            config.EnableAutobackOff.Should().BeFalse();
            config.Sender = new SenderSetup();
            config.EnableAutobackOff.Should().BeTrue();
        }
Esempio n. 8
0
        public static void ReadConfigByBind()
        {
            var builder = new ConfigurationBuilder()
                          .AddJsonFile("ConfigTest.json");
            ConfigTest configTest = new ConfigTest();
            var        config     = builder.Build();

            //Microsoft.Extensions.Configuration.Binder
            config.Bind(configTest);
            Console.WriteLine(configTest.TotalCount);
            Console.WriteLine(configTest.Students[0].Name);
            Console.WriteLine(configTest.Students[0].Sex);
            Console.WriteLine(configTest.Students[1].Name);
            Console.WriteLine(configTest.Students[1].Sex);
        }
        public async Task SaveNotExistsConfigurationAsync()
        {
            var config = new ConfigTest()
            {
                Description = "Test",
                Name        = "Test"
            };

            _mockedStorageService.Setup(x => x.Exists(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(() => false);
            _mockedStorageService.Setup(x => x.Store(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(() => Task.FromResult("NoPath"));

            var manager = new ConfigurationManager(_mockedStorageService.Object);
            var result  = await manager.Save(config);

            Assert.AreEqual(result, true);

            _mockedStorageService.Verify(x => x.Exists(It.IsAny <string>(), It.IsAny <string>()));
            _mockedStorageService.Verify(x => x.DeleteFile(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
            _mockedStorageService.Verify(x => x.Store(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()));
        }
        public async Task LoadConfigurationAsync()
        {
            var config = new ConfigTest()
            {
                Description = "Test",
                Name        = "Test"
            };

            _mockedStorageService.Setup(x => x.ReadAsText(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(() => Task.FromResult(JsonConvert.SerializeObject(config)));
            _mockedStorageService.Setup(x => x.Exists(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(() => true);

            var manager      = new ConfigurationManager(_mockedStorageService.Object);
            var loadedConfig = await manager.Load <ConfigTest>();

            Assert.IsNotNull(loadedConfig);
            Assert.AreEqual(config.Description, loadedConfig.Description);
            Assert.AreEqual(config.Name, loadedConfig.Name);

            _mockedStorageService.Verify(x => x.ReadAsText(It.IsAny <string>(), It.IsAny <string>()));
            _mockedStorageService.Verify(x => x.Exists(It.IsAny <string>(), It.IsAny <string>()));
        }