Пример #1
0
        public void CreateNewScript()
        {
            var verifier = new Mock <ISyntaxVerifier>();

            var scriptHost = new Mock <IHostScripts>();
            {
                scriptHost.Setup(s => s.IsExecutingScript)
                .Returns(true);
                scriptHost.Setup(s => s.VerifySyntax(It.IsAny <ScriptLanguage>()))
                .Returns(verifier.Object)
                .Verifiable();
            }

            var context = new Mock <IContextAware>();
            var model   = new ScriptDescriptionModel(context.Object, ScriptLanguage.IronPython);

            Func <Tuple <FileInfo, ScriptDescriptionModel> > selectScript =
                () => new Tuple <FileInfo, ScriptDescriptionModel>(new FileInfo(@"c:\temp\file.txt"), model);
            Action <ScriptDescriptionModel, FileInfo, ISyntaxVerifier> storeScript =
                (s, f, v) =>
            {
                Assert.AreSame(model, s);
                Assert.AreSame(verifier.Object, v);
            };
            Func <string, IDisposable> timerFunc = s => new MockDisposable();

            var command = new OpenScriptCommand(scriptHost.Object, selectScript, storeScript, timerFunc);

            command.Execute(null);
        }
Пример #2
0
        public void CanLoadScriptWithNullHost()
        {
            Func <Tuple <FileInfo, ScriptDescriptionModel> > selectScript =
                () => new Tuple <FileInfo, ScriptDescriptionModel>(new FileInfo(@"c:\temp\file.txt"), null);
            Action <ScriptDescriptionModel, FileInfo, ISyntaxVerifier> storeScript = (s, f, v) => { };
            Func <string, IDisposable> timerFunc = s => new MockDisposable();

            var command = new OpenScriptCommand(null, selectScript, storeScript, timerFunc);

            Assert.IsFalse(command.CanExecute(null));
        }
Пример #3
0
        public void CreateNewScriptWithoutSelectingScriptLanguage()
        {
            var scriptHost = new Mock <IHostScripts>();
            {
                scriptHost.Setup(s => s.IsExecutingScript)
                .Returns(true);
            }

            Func <Tuple <FileInfo, ScriptDescriptionModel> >           selectScript = () => new Tuple <FileInfo, ScriptDescriptionModel>(null, null);
            Action <ScriptDescriptionModel, FileInfo, ISyntaxVerifier> storeScript  = (s, f, v) => { };
            Func <string, IDisposable> timerFunc = s => new MockDisposable();

            var command = new OpenScriptCommand(scriptHost.Object, selectScript, storeScript, timerFunc);

            Assert.Throws <LoadingOfScriptCanceledException>(() => command.Execute(null));
        }
Пример #4
0
        public void CanLoadScriptWhileHostIsExecuting()
        {
            var scriptHost = new Mock <IHostScripts>();
            {
                scriptHost.Setup(s => s.IsExecutingScript)
                .Returns(true);
            }

            Func <Tuple <FileInfo, ScriptDescriptionModel> > selectScript =
                () => new Tuple <FileInfo, ScriptDescriptionModel>(new FileInfo(@"c:\temp\file.txt"), null);
            Action <ScriptDescriptionModel, FileInfo, ISyntaxVerifier> storeScript = (s, f, v) => { };
            Func <string, IDisposable> timerFunc = s => new MockDisposable();

            var command = new OpenScriptCommand(scriptHost.Object, selectScript, storeScript, timerFunc);

            Assert.IsFalse(command.CanExecute(null));
        }