| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using qdr.fnd.core.qconsole.test.Commands;
- using qdr.fnd.core.qconsole.test.Contexts;
- using Quadarax.Foundation.Core.IO.FileSystem.Memory;
- using Quadarax.Foundation.Core.QConsole;
- using Quadarax.Foundation.Core.QConsole.Configuration;
- using System.Reflection;
- using System.Threading;
- using System.Threading.Tasks;
- namespace qdr.fnd.core.qconsole.test
- {
- public class Tests
- {
- private StartupConfiguration? _configuration;
- [SetUp]
- public void Setup()
- {
- _configuration = new StartupConfiguration("Quadarax QConsole Test",Version.Parse("1.0.0.0"))
- {
- ConsoleCopyright = "Me",
- AllowInteractive = false,
- WaitOnKeyInNonInteractiveMode = false,
- CommandDefinitionAssembly = new Assembly[] { Assembly.GetExecutingAssembly()! }
- };
- _configuration.DisableDefaultCommands();
- _configuration.ShowStatusOnEveryCommand = false;
- _configuration.IsConsoleDebug = false;
- _configuration.ThrowExceptionWhenNotSuccess = true;
- }
- [Test]
- public void DummyCommandOk()
- {
- var arguments = new string[] { DummyCmd.CommandName };
- var engine = CreateEngine(arguments);
- engine.Start();
- }
- [Test]
- public void DummyCommandFailed()
- {
- var arguments = new string[] { DummyCmd.CommandName, "-result:false" };
- var engine = CreateEngine(arguments);
- Assert.Throws<AggregateException>(() => engine.Start(),"Dummy command execution failed by user request.");
- }
- [Test]
- public void DummyOrdinalCommandQuotedOk()
- {
- var filename = "D:\\temp\\file-some.dat";
- var arguments = new string[] { DummyOrdinalCmd.CommandName, "\"" + filename + "\"" };
- var engine = CreateEngine(arguments);
- engine.Start();
- Assert.That(engine.GetCommand(DummyOrdinalCmd.CommandName)?.Arguments.First(s=>s.Code == DummyOrdinalCmd.ArgOrdName).Value.AsString(), Is.EqualTo(filename));
- }
- private Engine CreateEngine(string[] args)
- {
- if (_configuration == null)
- {
- throw new InvalidOperationException("Configuration is not initialized.");
- }
- return new Engine(_configuration, new BasicEngineContext(new MemoryFileSystem()), args);
- }
- }
- }
|