mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Fix unit test
--HG-- branch : dev
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Caching;
|
||||
using Orchard.Environment.Extensions.Folders;
|
||||
using Orchard.FileSystems.WebSite;
|
||||
using Orchard.Tests.Stubs;
|
||||
using Yaml.Grammar;
|
||||
|
||||
namespace Orchard.Tests.Environment.Extensions {
|
||||
@@ -58,14 +63,10 @@ namespace Orchard.Tests.Environment.Extensions {
|
||||
|
||||
[Test]
|
||||
public void ModuleTxtShouldBeParsedAndReturnedAsYamlDocument() {
|
||||
var folders = new ModuleFolders(new[] { _tempFolderName },null,null);
|
||||
var sample1 = folders.ParseManifest("Sample1");
|
||||
var mapping = (Mapping)sample1.YamlDocument.Root;
|
||||
var entities = mapping.Entities
|
||||
.Where(x => x.Key is Scalar)
|
||||
.ToDictionary(x => ((Scalar)x.Key).Text, x => x.Value);
|
||||
Assert.That(entities.Keys, Has.Some.EqualTo("name"));
|
||||
Assert.That(entities.Keys, Has.Some.EqualTo("author"));
|
||||
var folders = new ModuleFolders(new[] { _tempFolderName }, new StubCacheManager(), new StubWebSiteFolder());
|
||||
var sample1 = folders.AvailableExtensions().Single(d => d.Name == "Sample1");
|
||||
Assert.That(sample1.Name, Is.Not.Empty);
|
||||
Assert.That(sample1.Author, Is.EqualTo("Bertrand Le Roy"));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1 +1 @@
|
||||
This is another test.txt
|
||||
name: This is another test.txt
|
||||
|
@@ -179,6 +179,8 @@
|
||||
<Compile Include="Environment\ShellBuilders\DefaultShellContextFactoryTests.cs" />
|
||||
<Compile Include="Mvc\Routes\ShellRouteTests.cs" />
|
||||
<Compile Include="Mvc\Routes\UrlPrefixTests.cs" />
|
||||
<Compile Include="Stubs\StubCacheManager.cs" />
|
||||
<Compile Include="Stubs\StubWebSiteFolder.cs" />
|
||||
<Compile Include="Utility\ContainerExtensions.cs" />
|
||||
<Compile Include="Environment\TestDependencies\TestDependency.cs" />
|
||||
<Compile Include="Environment\Topology\DefaultShellDescriptorCacheTests.cs" />
|
||||
|
15
src/Orchard.Tests/Stubs/StubCacheManager.cs
Normal file
15
src/Orchard.Tests/Stubs/StubCacheManager.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using Orchard.Caching;
|
||||
|
||||
namespace Orchard.Tests.Stubs {
|
||||
public class StubCacheManager : ICacheManager {
|
||||
public TResult Get<TKey, TResult>(TKey key, Func<AcquireContext<TKey>, TResult> acquire) {
|
||||
var cache = new Cache<TKey, TResult>();
|
||||
return cache.Get(key, acquire);
|
||||
}
|
||||
|
||||
public ICache<TKey, TResult> GetCache<TKey, TResult>() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@@ -16,6 +16,5 @@ namespace Orchard.Tests.Stubs {
|
||||
public DateTime FutureMoment(TimeSpan span) {
|
||||
return UtcNow.Add(span);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
27
src/Orchard.Tests/Stubs/StubWebSiteFolder.cs
Normal file
27
src/Orchard.Tests/Stubs/StubWebSiteFolder.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Orchard.Caching;
|
||||
using Orchard.FileSystems.WebSite;
|
||||
|
||||
namespace Orchard.Tests.Stubs {
|
||||
public class StubWebSiteFolder : IWebSiteFolder {
|
||||
public IEnumerable<string> ListDirectories(string path) {
|
||||
if (!Directory.Exists(path))
|
||||
return Enumerable.Empty<string>();
|
||||
|
||||
return Directory.GetDirectories(path);
|
||||
}
|
||||
|
||||
public string ReadFile(string path) {
|
||||
if (!File.Exists(path))
|
||||
return null;
|
||||
|
||||
return File.ReadAllText(path);
|
||||
}
|
||||
|
||||
public IVolatileToken WhenPathChanges(string path) {
|
||||
return new WebSiteFolder.Token(path);
|
||||
}
|
||||
}
|
||||
}
|
@@ -88,14 +88,14 @@ namespace Orchard.Environment.Extensions.Folders {
|
||||
}
|
||||
}
|
||||
|
||||
public ParseResult ParseManifest(string name) {
|
||||
public ParseResult ParseManifest(string manifestText) {
|
||||
bool success;
|
||||
var yamlStream = new YamlParser().ParseYamlStream(new TextInput(name), out success);
|
||||
var yamlStream = new YamlParser().ParseYamlStream(new TextInput(manifestText), out success);
|
||||
if (yamlStream == null || !success) {
|
||||
return null;
|
||||
}
|
||||
return new ParseResult {
|
||||
Name = name,
|
||||
Name = manifestText,
|
||||
YamlDocument = yamlStream.Documents.Single()
|
||||
};
|
||||
}
|
||||
@@ -125,14 +125,14 @@ namespace Orchard.Environment.Extensions.Folders {
|
||||
}
|
||||
|
||||
private static IEnumerable<FeatureDescriptor> GetFeaturesForExtension(Mapping features, ExtensionDescriptor extensionDescriptor) {
|
||||
List<FeatureDescriptor> featureDescriptors = new List<FeatureDescriptor>();
|
||||
var featureDescriptors = new List<FeatureDescriptor>();
|
||||
if (features != null) {
|
||||
foreach (var entity in features.Entities) {
|
||||
FeatureDescriptor featureDescriptor = new FeatureDescriptor {
|
||||
var featureDescriptor = new FeatureDescriptor {
|
||||
Extension = extensionDescriptor,
|
||||
Name = entity.Key.ToString(),
|
||||
};
|
||||
Mapping featureMapping = (Mapping)entity.Value;
|
||||
var featureMapping = (Mapping)entity.Value;
|
||||
foreach (var featureEntity in featureMapping.Entities) {
|
||||
if (String.Equals(featureEntity.Key.ToString(), "description", StringComparison.OrdinalIgnoreCase)) {
|
||||
featureDescriptor.Description = featureEntity.Value.ToString();
|
||||
|
Reference in New Issue
Block a user