Fix unit test

--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-05-18 14:32:05 -07:00
parent 0f5d492333
commit 803d040732
7 changed files with 62 additions and 18 deletions

View File

@@ -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"));
}
}
}

View File

@@ -1 +1 @@
This is another test.txt
name: This is another test.txt

View File

@@ -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" />

View 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();
}
}
}

View File

@@ -16,6 +16,5 @@ namespace Orchard.Tests.Stubs {
public DateTime FutureMoment(TimeSpan span) {
return UtcNow.Add(span);
}
}
}

View 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);
}
}
}

View File

@@ -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();