lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [lucenenet] NightOwl888 commented on a change in pull request #287: Implemenation of "System Properties" in .NET (addresses #254)
Date Mon, 25 May 2020 07:17:57 GMT

NightOwl888 commented on a change in pull request #287:
URL: https://github.com/apache/lucenenet/pull/287#discussion_r429769598



##########
File path: src/Lucene.Net.Tests.TestFramework/Configuration/TestConfigurationSetting.cs
##########
@@ -0,0 +1,115 @@
+´╗┐using Lucene.Net.Util;
+using Microsoft.Extensions.Configuration;
+using NUnit.Framework;
+using System;
+using System.IO;
+using System.Reflection;
+
+namespace Lucene.Net.Configuration
+{
+    /*
+     * Licensed to the Apache Software Foundation (ASF) under one or more
+     * contributor license agreements.  See the NOTICE file distributed with
+     * this work for additional information regarding copyright ownership.
+     * The ASF licenses this file to You under the Apache License, Version 2.0
+     * (the "License"); you may not use this file except in compliance with
+     * the License.  You may obtain a copy of the License at
+     *
+     *     http://www.apache.org/licenses/LICENSE-2.0
+     *
+     * Unless required by applicable law or agreed to in writing, software
+     * distributed under the License is distributed on an "AS IS" BASIS,
+     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     * See the License for the specific language governing permissions and
+     * limitations under the License.
+     */
+
+    [TestFixture]
+    class TestConfigurationSettings : LuceneTestCase
+    {
+
+        internal class UnitTestConfigurationRootFactory : IConfigurationRootFactory
+        {
+            public bool IgnoreSecurityExceptionsOnRead { get; set; }
+            /// <summary>
+            /// PAth to be used for configuration settings
+            /// </summary>
+            public static string JsonTestSettingsFolderName { get; set; } = @"Configuration";
+            /// <summary>
+            /// Filename to be used for configuration settings
+            /// </summary>
+            public static string JsonTestSettingsFileName { get; set; } = @"lucene.testsettings.json";
+
+            static string JsonTestPath =
+#if TESTFRAMEWORK_NUNIT
+            NUnit.Framework.TestContext.CurrentContext.TestDirectory;
+#else
+                            AppDomain.CurrentDomain.BaseDirectory;
+#endif
+            public UnitTestConfigurationRootFactory()
+            {
+            }
+
+            protected IConfigurationRoot configuration = new ConfigurationBuilder().Add(new
LuceneDefaultConfigurationSource() { Prefix = "lucene:", IgnoreSecurityExceptionsOnRead =
false }
+            ).AddJsonFile(Path.Combine(new string[] { JsonTestPath, JsonTestSettingsFolderName,
JsonTestSettingsFileName })).Build();
+
+            public virtual IConfigurationRoot CurrentConfiguration
+            {
+                get
+                {
+                    return configuration;
+                }
+            }
+        }
+
+        public static IConfigurationRootFactory TestConfigurationFactory;
+
+        [OneTimeSetUp]
+        public override void BeforeClass()
+        {
+            base.BeforeClass();
+            // set an Enviroment variable used in the test
+            string testKey = "lucene:tests:setup";
+            string testValue = "setup";
+            Environment.SetEnvironmentVariable(testKey, testValue);
+            ConfigurationSettings.SetConfigurationRootFactory(new UnitTestConfigurationRootFactory());

Review comment:
       Note you can factor out `UnitTestConfigurationRootFactory` here, too, since its only
purpose seems to be to plug the `LuceneDefaultConfigurationSource` into `ConfigurationSettings`,
which is not something that needs to happen to test `LuceneDefaultConfigurationSource`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message