Files
Orchard/src/Orchard.Tests.Modules/CodeGeneration/Commands/CodeGenerationCommandsTests.cs
Benedek Farkas 75a4fd59a2
Some checks failed
Build Crowdin Translation Packages / build-crowdin-translation-packages (push) Has been cancelled
Compile / Compile .NET solution (push) Has been cancelled
Compile / Compile Client-side Assets (push) Has been cancelled
SpecFlow Tests / SpecFlow Tests (push) Has been cancelled
#8208: Adopt the Orchard Core .editorconfig (#8868)
* Updating .editorconfig from Orchard Core

* VS code cleanup, round 1

- Apply expression/block body preference
- Apply language/framework type preferences
- Apply null checking preferences
- Apply using directive placement preferences
- Apply using statement preferences
- Format document
- Remove unnecessary imports or usings
- Sort Imports or usings

* VS code cleanup: Apply auto property preferences

* VS code cleanup: Apply parenthesis preferences

* VS code cleanup: Apply object/collection initializer preferences

* Reverting NHibernate.Linq changes

* Removing commented out RecipeResultRecord class
2025-10-31 23:50:28 +01:00

79 lines
3.6 KiB
C#

using System.Collections.Generic;
using System.IO;
using Autofac;
using Autofac.Features.Metadata;
using NUnit.Framework;
using Orchard.Caching;
using Orchard.CodeGeneration.Commands;
using Orchard.Commands;
using Orchard.Data;
using Orchard.Data.Migration.Generator;
using Orchard.Data.Providers;
using Orchard.Environment;
using Orchard.Environment.Configuration;
using Orchard.Environment.Extensions;
using Orchard.Environment.ShellBuilders;
using Orchard.Environment.ShellBuilders.Models;
using Orchard.FileSystems.AppData;
using Orchard.Tests.Environment;
using Orchard.Tests.FileSystems.AppData;
using Orchard.Tests.Stubs;
namespace Orchard.Tests.Modules.CodeGeneration.Commands
{
[TestFixture]
public class CodeGenerationCommandsTests
{
private IContainer _container;
private IExtensionManager _extensionManager;
private ISchemaCommandGenerator _schemaCommandGenerator;
[SetUp]
public void Init()
{
string databaseFileName = Path.GetTempFileName();
IDataServicesProviderFactory dataServicesProviderFactory = new DataServicesProviderFactory(new[] {
new Meta<CreateDataServicesProvider>(
(dataFolder, connectionString) => new SqlCeDataServicesProvider(dataFolder, connectionString),
new Dictionary<string, object> {{"ProviderName", "SqlCe"}})
});
var builder = new ContainerBuilder();
builder.RegisterInstance(new ShellBlueprint());
builder.RegisterInstance(new ShellSettings { Name = ShellSettings.DefaultName, DataTablePrefix = "Test", DataProvider = "SqlCe" });
builder.RegisterInstance(dataServicesProviderFactory).As<IDataServicesProviderFactory>();
builder.RegisterInstance(AppDataFolderTests.CreateAppDataFolder(Path.GetDirectoryName(databaseFileName))).As<IAppDataFolder>();
builder.RegisterType<SqlCeDataServicesProvider>().As<IDataServicesProvider>();
builder.RegisterType<SessionConfigurationCache>().As<ISessionConfigurationCache>();
builder.RegisterType<SessionFactoryHolder>().As<ISessionFactoryHolder>();
builder.RegisterType<DefaultDatabaseCacheConfiguration>().As<IDatabaseCacheConfiguration>();
builder.RegisterType<CompositionStrategy>().As<ICompositionStrategy>();
builder.RegisterType<ExtensionManager>().As<IExtensionManager>();
builder.RegisterType<SchemaCommandGenerator>().As<ISchemaCommandGenerator>();
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
builder.RegisterType<StubParallelCacheContext>().As<IParallelCacheContext>();
builder.RegisterType<StubAsyncTokenProvider>().As<IAsyncTokenProvider>();
builder.RegisterType<StubHostEnvironment>().As<IHostEnvironment>();
_container = builder.Build();
_extensionManager = _container.Resolve<IExtensionManager>();
_schemaCommandGenerator = _container.Resolve<ISchemaCommandGenerator>();
}
[Test]
public void CreateDataMigrationTestNonExistentFeature()
{
CodeGenerationCommands codeGenerationCommands = new CodeGenerationCommands(_extensionManager,
_schemaCommandGenerator);
TextWriter textWriterOutput = new StringWriter();
codeGenerationCommands.Context = new CommandContext { Output = textWriterOutput };
codeGenerationCommands.CreateDataMigration("feature");
Assert.That(textWriterOutput.ToString(), Does.Contain("Creating data migration failed"));
}
}
}