lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [41/52] [abbrv] lucenenet git commit: BUG: Lucene.Net.Tests.Analysis.Common.Analysis.Util.TestFilesystemResourceLoader: Changed test to write the embedded resource to a known location rather than being dependent on an external file that may/may not be in
Date Tue, 25 Apr 2017 11:51:22 GMT
BUG: Lucene.Net.Tests.Analysis.Common.Analysis.Util.TestFilesystemResourceLoader: Changed test
to write the embedded resource to a known location rather than being dependent on an external
file that may/may not be in the file system.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/c8b8de93
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/c8b8de93
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/c8b8de93

Branch: refs/heads/master
Commit: c8b8de93f978ba4fe42c526e0489adea945843dd
Parents: cf19759
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Mon Apr 24 09:03:31 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Mon Apr 24 09:03:31 2017 +0700

----------------------------------------------------------------------
 .../Util/TestFilesystemResourceLoader.cs        | 45 ++++++--------------
 1 file changed, 14 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c8b8de93/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestFilesystemResourceLoader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestFilesystemResourceLoader.cs
b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestFilesystemResourceLoader.cs
index d26b78c..7a5f12f 100644
--- a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestFilesystemResourceLoader.cs
+++ b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestFilesystemResourceLoader.cs
@@ -1,10 +1,11 @@
-´╗┐using System;
-using System.Text;
-using NUnit.Framework;
+´╗┐using Lucene.Net.Support;
 using Lucene.Net.Util;
+using NUnit.Framework;
+using System;
 using System.IO;
 using System.Linq;
 using System.Reflection;
+using System.Text;
 
 namespace Lucene.Net.Analysis.Util
 {
@@ -51,39 +52,21 @@ namespace Lucene.Net.Analysis.Util
 
         private void assertClasspathDelegation(IResourceLoader rl)
         {
-            const string LuceneNetAnalysisCommon = "Lucene.Net.Analysis.Common";
-            var assemblyDirectory = System.IO.Path.GetDirectoryName(typeof(TestFilesystemResourceLoader).GetTypeInfo().Assembly.Location);
-            var current = new DirectoryInfo(assemblyDirectory);
-
-            DirectoryInfo analysisCommonFolder = null;
-
-            // LUCENENET: Searching upwards for the parent rather than using a
-            // relative path because in .NET Core, the base directory is not
-            // always under bin\Debug\. The program may be running from
-            // bin\Debug\netcoreapp1.0\win7-x64\.
-            while (current != null)
+            //var englishStopText = System.IO.Path.Combine(analysisCommonFolder.FullName,
@"Analysis\Snowball\english_stop.txt");
+            // LUCENENET specific - rather than being completely dependent on the location
of the file
+            // in the file system, we use the embedded resource to write the file to a known
location
+            // before passing it to our resource loader.
+            string englishStopFile = "english_stop.txt";
+            var file = CreateTempFile(System.IO.Path.GetFileNameWithoutExtension(englishStopFile),
System.IO.Path.GetExtension(englishStopFile));
+            using (var stream = typeof(Snowball.SnowballFilter).GetTypeInfo().Assembly.FindAndGetManifestResourceStream(typeof(Snowball.SnowballFilter),
englishStopFile))
             {
-                var matching = current.GetDirectories(LuceneNetAnalysisCommon, SearchOption.TopDirectoryOnly);
-
-                if (matching == null || matching.Length == 0)
+                using (var outputStream = new FileStream(file.FullName, FileMode.OpenOrCreate,
FileAccess.Write))
                 {
-                    current = Directory.GetParent(current.FullName);
+                    stream.CopyTo(outputStream);
                 }
-                else
-                {
-                    analysisCommonFolder = matching.First();
-                    break;
-                }
-            }
-
-            if (analysisCommonFolder == null)
-            {
-                throw new InvalidOperationException("Should have been able to find " + LuceneNetAnalysisCommon
+ " as a parent of " + typeof(TestFilesystemResourceLoader).GetTypeInfo().Assembly.Location);
             }
-
-            var englishStopText = System.IO.Path.Combine(analysisCommonFolder.FullName, @"Analysis\Snowball\english_stop.txt");
             // try a stopwords file from classpath
-            CharArraySet set = WordlistLoader.GetSnowballWordSet(new System.IO.StreamReader(rl.OpenResource(englishStopText),
Encoding.UTF8), TEST_VERSION_CURRENT);
+            CharArraySet set = WordlistLoader.GetSnowballWordSet(new System.IO.StreamReader(rl.OpenResource(file.FullName),
Encoding.UTF8), TEST_VERSION_CURRENT);
             assertTrue(set.contains("you"));
             // try to load a class; we use string comparison because classloader may be different...
             assertEquals("Lucene.Net.Analysis.Util.RollingCharBuffer", rl.NewInstance<object>("Lucene.Net.Analysis.Util.RollingCharBuffer").ToString());


Mime
View raw message