Пример #1
0
 public HomeController(IConfigurationRoot configuration, IOptions<OtherSettings> otherSettings, ILogger<HomeController> logger, IMemoryCache memoryCache)
 {
     _configuration = configuration;
     _otherSettings = otherSettings.Value;
     _logger = logger;
     _memoryCache = memoryCache;
 }
Пример #2
0
        public void Contact()
        {
            // Arrange
            var config = new ConfigurationRoot(new List<IConfigurationProvider> {new MemoryConfigurationProvider(new MemoryConfigurationSource())});
            config["kEY1"] = "keyValue1";
            config["key2"] = "keyValue2";
            config["USERNAME"] = "******";
            var otherSettings = new OtherSettings { Numbers = new int[] { 234, 567 } };
            var options = new OptionsWrapper<OtherSettings>(otherSettings);
            var loggerFactory = new LoggerFactory();
            var logger = loggerFactory.CreateLogger<HomeController>();
            IMemoryCache cache = new MemoryCache(new MemoryCacheOptions());

            HomeController controller = new HomeController(config, options, logger, cache);

            // Act
            ViewResult result = controller.Contact() as ViewResult;

            // Assert
            Assert.Equal("keyValue1 SNeagu 234, 567", result.ViewBag.Message);
        }