示例#1
0
        // GET: Variables/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var executionVariable = await _context.Variables.Include(v => v.Environment)
                                    .FirstOrDefaultAsync(m => m.Id == id);

            if (executionVariable == null)
            {
                return(NotFound());
            }
            var viewModel = new VariableViewModel
            {
                Id              = executionVariable.Id,
                Name            = executionVariable.Name,
                Active          = executionVariable.Active,
                Value           = executionVariable.Value,
                EnvironmentName = executionVariable.Environment?.Name
            };

            return(View(viewModel));
        }
示例#2
0
        // GET: Variables/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var executionVariable = await _context.Variables.Include(v => v.Environment).FirstAsync(m => m.Id == id);

            if (executionVariable == null)
            {
                return(NotFound());
            }
            var viewModel = new VariableViewModel
            {
                Id            = executionVariable.Id,
                Name          = executionVariable.Name,
                Active        = executionVariable.Active,
                Value         = executionVariable.Value,
                EnvironmentId = executionVariable.Environment?.Id ?? 0,
                Environments  = _context.ExecutionEnvironments.ToList()
            };

            return(View(viewModel));
        }
示例#3
0
        public Task ProcessAsync(EnvelopeViewModel envelopeViewModel, SessionViewModel sessionViewModel)
        {
            if (envelopeViewModel == null)
            {
                throw new ArgumentNullException(nameof(envelopeViewModel));
            }
            if (sessionViewModel == null)
            {
                throw new ArgumentNullException(nameof(sessionViewModel));
            }

            var session = envelopeViewModel.Envelope as Session;

            if (session != null && !session.Id.IsNullOrEmpty())
            {
                var sessionIdVariableViewModel = sessionViewModel
                                                 .Variables
                                                 .FirstOrDefault(v => v.Name.Equals("sessionId"));

                if (sessionIdVariableViewModel == null)
                {
                    sessionIdVariableViewModel = new VariableViewModel()
                    {
                        Name = "sessionId"
                    };

                    sessionViewModel.Variables.Add(sessionIdVariableViewModel);
                }

                sessionIdVariableViewModel.Value = session.Id;
            }

            return(Task.FromResult <object>(null));
        }
        public void should_include_reserved_variables_in_available_variable_list()
        {
            // given
            var testFile = new TestFile
            {
                Tests = new[]
                {
                    new Test()
                }
            };

            var reservedVariables = new List <Variable>
            {
                new Variable("some name that should exist", "super awesome description", "evil environment")
            };

            _configurationServiceMock
            .Setup(x => x.GetSystemVariables())
            .Returns(reservedVariables);

            // when
            TestViewModel result = _mapper.BuildTestViewModel(testFile, 0);

            // then
            VariableViewModel variable = result.AvailableVariables.FirstOrDefault(x => x.Name == reservedVariables[0].Name);

            Assert.That(variable, Is.Not.Null);
            Assert.That(variable.Value, Is.EqualTo(reservedVariables[0].Value));
            Assert.That(variable.Environment, Is.EqualTo(reservedVariables[0].Environment.Name));
        }
示例#5
0
        public async Task VariableGrid_ConstructorTest()
        {
            VisualTreeObject actual = null;

            using (var hostScript = new VariableRHostScript()) {
                using (var script = new ControlTestScript(typeof(VariableGridHost))) {
                    DoIdle(100);

                    var result = await hostScript.EvaluateAsync("grid.test <- matrix(1:10, 2, 5)");

                    VariableViewModel wrapper = new VariableViewModel(result, VsAppShell.Current.ExportProvider.GetExportedValue <IObjectDetailsViewerAggregator>());

                    DoIdle(2000);

                    wrapper.Should().NotBeNull();

                    UIThreadHelper.Instance.Invoke(() => {
                        var host = (VariableGridHost)script.Control;
                        host.SetEvaluation(wrapper);
                    });

                    DoIdle(1000);

                    actual = VisualTreeObject.Create(script.Control);
                    ViewTreeDump.CompareVisualTrees(_files, actual, "VariableGrid02");
                }
            }
        }
示例#6
0
        // GET: Variables/Create
        public async Task <IActionResult> Create()
        {
            var model = new VariableViewModel
            {
                Environments = await _context.ExecutionEnvironments.ToListAsync()
            };

            return(View(model));
        }
示例#7
0
        public ActionResult AddVariableItem()
        {
            var model = new VariableViewModel
            {
                AvailableEnvironments = GetEnvironmentsDropDown()
            };

            return(PartialView("EditorTemplates/VariableViewModel", model));
        }
示例#8
0
        public AddVariableView(VariableViewModel variable)
        {
            InitializeComponent();

            nameBox.Text      = variable.Variable;
            nameBox.IsEnabled = false;
            valueBox.Text     = Convert.ToString(variable.Value, CultureInfo.InvariantCulture);

            nameBox.Focus();
        }
示例#9
0
        public async Task <bool> SetVariable(VariableViewModel variable)
        {
            var content = new StringContent(JsonConvert.SerializeObject(variable), System.Text.Encoding.UTF8, "application/json");

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");


            var response = await this._httpClient.PutAsync($"{ENDPOINT}/variable/{variable.Name}", content);

            return(response.StatusCode == HttpStatusCode.OK);
        }
示例#10
0
        private void ToggleVariableArea(VariableViewModel selectedVariableViewModel)
        {
            selectedVariableViewModel.SliderSettingsVisible = !selectedVariableViewModel.SliderSettingsVisible;

            // Collapse all other slider settings that are open
            foreach (var variableViewModel in Variables)
            {
                if (variableViewModel != selectedVariableViewModel)
                {
                    variableViewModel.SliderSettingsVisible = false;
                }
            }
        }
示例#11
0
        public void TestVariableViewModel()
        {
            var viewmodel = new VariableViewModel(variableService);

            ObservableCollection <Variable> expectedData = new ObservableCollection <Variable>(variableService.All());

            var variable = variableService.Find(1);

            viewmodel.SelectedVariable = variable;

            Assert.AreEqual(expectedData.Count, viewmodel.Variables.Count);
            Assert.IsNotNull(viewmodel.SelectedVariable);
            Assert.AreEqual(1, viewmodel.SelectedVariable.Variable_id);
        }
示例#12
0
        public async Task DoesNotExist()
        {
            // This is the equivalent of what we get when we fetch a variable
            // for a data grid after that variable is no longer available (rm or reset).
            var script           = "idonotexist";
            var evaluationResult = await _hostScript.EvaluateAsync(script);

            evaluationResult.Name.Should().BeNull();
            evaluationResult.Expression.Should().Be("idonotexist");

            var model = new VariableViewModel(evaluationResult, Substitute.For <IServiceContainer>());

            model.TypeName.Should().BeNull();
            model.Value.Should().BeNull();
        }
示例#13
0
        public AddVariableView(VariableViewModel variable)
        {
            InitializeComponent();

            nameBox.Text      = variable.Variable;
            nameBox.IsEnabled = false;
            valueBox.Text     = Convert.ToString(variable.Value, CultureInfo.InvariantCulture);
            if (variable.Type != ParameterType.Normal)
            {
                valueBox.IsEnabled = false;
            }
            readOnlyBox.IsEnabled = false;

            nameBox.Focus();
        }
示例#14
0
        public void Execute(object parameter)
        {
            var shell = IoC.Get<IShell>();
            //shell.OpenDocument(new VariableViewModel(new VariableModelProxy(new SMA.Variable())));
            //MessageBox.Show("Reimplement this with support for both Azure and SMA!");

            var context = IoC.Get<EnvironmentExplorerViewModel>().GetCurrentContext();
            var viewModel = default(VariableViewModel);
            
            if (context.Service is AzureService || context.Service is AzureRMService)
                viewModel = new VariableViewModel(new VariableModelProxy(new Vendor.Azure.Variable(), context));
            else
                viewModel = new VariableViewModel(new VariableModelProxy(new SMA.Variable(), context));

            shell.OpenDocument(viewModel);
        }
示例#15
0
        private async Task PrepareControl(VariableRHostScript hostScript, ControlTestScript script, string expression)
        {
            DoIdle(100);

            var result = await hostScript.EvaluateAsync(expression);

            VariableViewModel wrapper = new VariableViewModel(result, VsAppShell.Current.Services);

            DoIdle(2000);
            wrapper.Should().NotBeNull();

            UIThreadHelper.Instance.Invoke(() => {
                var host = (VariableGridHost)script.Control;
                host.SetEvaluation(wrapper);
            });

            DoIdle(1000);
        }
示例#16
0
        public static Variable ToVariable(VariableViewModel model)
        {
            if (model == null)
            {
                return(null);
            }

            return(new Variable
            {
                Id = model.Id,
                ParentVariableId = model.ParentVariable?.Id,
                Type = model.Type,
                Name = model.Name,
                PropertyName = model.PropertyName,
                ConstantValue = model.ConstantValue,
                ParentVariable = ToVariable(model.ParentVariable)
            });
        }
示例#17
0
        public Task ProcessAsync(EnvelopeViewModel envelopeViewModel, SessionViewModel sessionViewModel)
        {
            if (envelopeViewModel == null)
            {
                throw new ArgumentNullException(nameof(envelopeViewModel));
            }
            if (sessionViewModel == null)
            {
                throw new ArgumentNullException(nameof(sessionViewModel));
            }

            var session = envelopeViewModel.Envelope as Session;

            if (session != null &&
                !session.Id.IsNullOrEmpty() &&
                session.State == SessionState.Authenticating)
            {
                var sessionIdVariableViewModel = sessionViewModel
                                                 .Variables
                                                 .FirstOrDefault(v => v.Name.Equals(GUEST_IDENTITY_VARIABLE));

                if (sessionIdVariableViewModel == null)
                {
                    sessionIdVariableViewModel = new VariableViewModel()
                    {
                        Name = GUEST_IDENTITY_VARIABLE
                    };

                    sessionViewModel.Variables.Add(sessionIdVariableViewModel);
                }

                var guestNode = new Node
                {
                    Domain = session.From.Domain,
                    Name   = EnvelopeId.NewId()
                };

                sessionIdVariableViewModel.Value = guestNode.ToString();
            }

            return(Task.FromResult <object>(null));
        }
示例#18
0
        public async Task <IActionResult> Create([Bind("Id,Name,Value,Active,EnvironmentId")] VariableViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var environment = await _context.ExecutionEnvironments.FindAsync(viewModel.EnvironmentId);

                var entity = new ExecutionVariable
                {
                    Name        = viewModel.Name,
                    Active      = viewModel.Active,
                    Environment = environment,
                    Value       = viewModel.Value
                };
                _context.Add(entity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(viewModel));
        }
        public void Execute(object parameter)
        {
            var shell = IoC.Get <IShell>();
            //shell.OpenDocument(new VariableViewModel(new VariableModelProxy(new SMA.Variable())));
            //MessageBox.Show("Reimplement this with support for both Azure and SMA!");

            var context   = IoC.Get <EnvironmentExplorerViewModel>().GetCurrentContext();
            var viewModel = default(VariableViewModel);

            if (context.Service is AzureService || context.Service is AzureRMService)
            {
                viewModel = new VariableViewModel(new VariableModelProxy(new Vendor.Azure.Variable(), context));
            }
            else
            {
                viewModel = new VariableViewModel(new VariableModelProxy(new SMA.Variable(), context));
            }

            shell.OpenDocument(viewModel);
        }
 public ActionResult Index(VariableViewModel model, string command)
 {
     if (command == "add")
     {
         model.Result = model.A + model.B;
     }
     if (command == "sub")
     {
         model.Result = model.A - model.B;
     }
     if (command == "mul")
     {
         model.Result = model.A * model.B;
     }
     if (command == "div")
     {
         model.Result = model.A / model.B;
     }
     return(View(model));
 }
示例#21
0
        private void New_Variable_Button_Click(object sender, RoutedEventArgs e)
        {
            object element = this.viewModel.RoboViewModel.SelectedNode;

            if (element != null && element.GetType().Name.Equals("TestSuitViewModel"))
            {
                TestSuitViewModel elementModel = (TestSuitViewModel)element;
                VariableViewModel variable     = new VariableViewModel();
                variable.Name        = "3rd Variable";
                variable.Description = "3rd Variable desc";

                elementModel.AllCollection.Add(variable);
                elementModel.IsExpanded = true;
                variable.IsExpanded     = true;
                variable.IsSelected     = true;
                variable.IsExpanded     = true;
            }
            else
            {
                MessageBox.Show("Please select the suit under which new Variable to be added.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
示例#22
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Value,Active,EnvironmentId")] VariableViewModel viewModel)
        {
            if (id != viewModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var environment = await _context.ExecutionEnvironments.FindAsync(viewModel.EnvironmentId);

                    var entity = new ExecutionVariable
                    {
                        Id          = viewModel.Id,
                        Name        = viewModel.Name,
                        Active      = viewModel.Active,
                        Environment = environment,
                        Value       = viewModel.Value
                    };
                    _context.Update(entity);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ExecutionVariableExists(viewModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(viewModel));
        }
示例#23
0
        public async Task <IREvaluationResultInfo> EvaluateAsync(string rScript)
        {
            // One eval at a time
            await _sem.WaitAsync();

            try {
                var frames = await Session.TracebackAsync();

                var frame = frames.FirstOrDefault(f => f.Index == 0);

                const REvaluationResultProperties properties = ClassesProperty | ExpressionProperty | TypeNameProperty | DimProperty | LengthProperty;
                var result = await frame.TryEvaluateAndDescribeAsync(rScript, properties, RValueRepresentations.Str());

                var globalResult = await frame.TryEvaluateAndDescribeAsync("base::environment()", properties, RValueRepresentations.Str());

                _globalEnv = new VariableViewModel(globalResult, VsAppShell.Current.ExportProvider.GetExportedValue <IObjectDetailsViewerAggregator>());

                return(result);
            } finally {
                _sem.Release();
            }
        }
示例#24
0
        public Task ProcessAsync(EnvelopeViewModel envelopeViewModel, SessionViewModel sessionViewModel)
        {
            if (envelopeViewModel == null)
            {
                throw new ArgumentNullException("envelopeViewModel");
            }

            if (sessionViewModel == null)
            {
                throw new ArgumentNullException("sessionViewModel");
            }

            var session = envelopeViewModel.Envelope as Session;

            if (session != null &&
                session.Id != null &&
                session.State == SessionState.Established)
            {
                var sessionIdVariableViewModel = sessionViewModel
                                                 .Variables
                                                 .FirstOrDefault(v => v.Name.Equals(DOMAIN_VARIABLE));

                if (sessionIdVariableViewModel == null)
                {
                    sessionIdVariableViewModel = new VariableViewModel()
                    {
                        Name = DOMAIN_VARIABLE
                    };

                    sessionViewModel.Variables.Add(sessionIdVariableViewModel);
                }

                sessionIdVariableViewModel.Value = session.From.Domain;
            }

            return(Task.FromResult <object>(null));
        }
示例#25
0
        public bool Serialize(XmlTextWriter w, RoboViewModel robo)
        {
            this.writer = w;

            Type suitCollectionType       = new ObservableCollection <TestSuitViewModel>().GetType();
            Type sequenceCollectionType   = new ObservableCollection <TestSequenceViewModel>().GetType();
            Type stepCollectionType       = new ObservableCollection <TestStepViewModel>().GetType();
            Type appsCollectionType       = new ObservableCollection <AppsViewModel>().GetType();
            Type dataSourceCollectionType = new ObservableCollection <DataSourceViewModel>().GetType();
            Type variableCollectionType   = new ObservableCollection <VariableViewModel>().GetType();
            Type stringType = string.Empty.GetType();
            Type boolType   = bool.TrueString.GetType();
            Type intType    = int.MinValue.GetType();
            Type doubleType = double.MinValue.GetType();
            Type suitType   = new TestSuitViewModel().GetType();
            Type seqType    = new TestSequenceViewModel().GetType();
            Type stepType   = new TestStepViewModel().GetType();
            Type appType    = new AppsViewModel().GetType();
            Type dsType     = new DataSourceViewModel().GetType();
            Type varType    = new VariableViewModel().GetType();

            Type[] types = { suitCollectionType,       sequenceCollectionType, stepCollectionType, appsCollectionType,
                             dataSourceCollectionType, variableCollectionType, stringType,         boolType,          intType, doubleType,
                             suitType,                 seqType,                stepType,           appType,           dsType,  varType };

            writer.WriteStartDocument(true);
            writer.Formatting  = Formatting.Indented;
            writer.Indentation = 2;
            writer.WriteStartElement("Suits");

            AppendNodeRobo(types, robo);

            writer.WriteEndElement();
            writer.WriteEndDocument();
            writer.Close();
            return(true);
        }
示例#26
0
        public Task ProcessAsync(EnvelopeViewModel envelopeViewModel, SessionViewModel sessionViewModel)
        {
            if (envelopeViewModel == null)
            {
                throw new ArgumentNullException(nameof(envelopeViewModel));
            }
            if (sessionViewModel == null)
            {
                throw new ArgumentNullException(nameof(sessionViewModel));
            }

            var session = envelopeViewModel.Envelope as Session;

            if (session != null &&
                !session.Id.IsNullOrEmpty() &&
                session.State == SessionState.Established)
            {
                var sessionIdVariableViewModel = sessionViewModel
                                                 .Variables
                                                 .FirstOrDefault(v => v.Name.Equals(LOCAL_NODE_VARIABLE));

                if (sessionIdVariableViewModel == null)
                {
                    sessionIdVariableViewModel = new VariableViewModel()
                    {
                        Name = LOCAL_NODE_VARIABLE
                    };

                    sessionViewModel.Variables.Add(sessionIdVariableViewModel);
                }

                sessionIdVariableViewModel.Value = session.To.ToString();
            }

            return(Task.FromResult <object>(null));
        }
示例#27
0
 protected override Task InvokeAsync(VariableViewModel variable)
 {
     variable.OpenInCsvAppCommand.Execute(variable);
     return(Task.CompletedTask);
 }
示例#28
0
 protected abstract bool IsEnabled(VariableViewModel variable);
示例#29
0
 protected abstract Task InvokeAsync(VariableViewModel variable);
示例#30
0
 protected override bool IsEnabled(VariableViewModel variable) => variable.CanShowOpenCsv;
示例#31
0
        public void BuildTestViewModel_should_return_correct_model_values_from_test()
        {
            // given
            const int testPosition = 1;

            _configurationServiceMock
            .Setup(x => x.GetScriptSnippetFilenames(ScriptSnippetType.BeforeExecute))
            .Returns(new[] { "snippet1.snippet", "snippet2.snippet" });

            List <Environment> environments = new List <Environment>
            {
                new Environment {
                    Name = "Last", Order = 2
                },
                new Environment {
                    Name = "First", Order = 0
                }
            };

            _environmentServiceMock
            .Setup(x => x.Get())
            .Returns(environments);

            var expectedTest = new Test
            {
                Description            = "Short Description",
                Url                    = "http://www.google.com",
                Method                 = MethodType.GET.ToString(),
                PostBody               = "PostBody",
                ExpectedHttpStatusCode = HttpStatusCode.Accepted,
                Headers                = new List <Syringe.Core.Tests.HeaderItem> {
                    new Syringe.Core.Tests.HeaderItem()
                },
                CapturedVariables = new List <CapturedVariable> {
                    new CapturedVariable {
                        Name = "CV-2"
                    }
                },
                Assertions = new List <Assertion> {
                    new Assertion("Desc", "Val", AssertionType.Negative, AssertionMethod.CssSelector)
                },
                ScriptSnippets = new ScriptSnippets()
                {
                    BeforeExecuteFilename = "// this is some script"
                },
                TestConditions = new TestConditions {
                    RequiredEnvironments = new List <string> {
                        "expected-env", "h3mang-and-d1cks"
                    }
                }
            };

            var testFile = new TestFile
            {
                Filename = "some file name...YURP",
                Tests    = new List <Test>
                {
                    new Test
                    {
                        CapturedVariables = new List <CapturedVariable>
                        {
                            new CapturedVariable("CV-1", "CV-1-Value")
                        }
                    },
                    expectedTest,
                    new Test()
                },
                Variables = new List <Variable>
                {
                    new Variable("V-1", "V-1-Value", null)
                }
            };

            // when
            TestViewModel actualModel = _mapper.BuildTestViewModel(testFile, testPosition);

            // then
            Assert.NotNull(actualModel);
            Assert.That(actualModel.Position, Is.EqualTo(testPosition));
            Assert.That(actualModel.Description, Is.EqualTo(expectedTest.Description));
            Assert.That(actualModel.Url, Is.EqualTo(expectedTest.Url));
            Assert.That(actualModel.PostBody, Is.EqualTo(expectedTest.PostBody));
            Assert.That(actualModel.Method, Is.EqualTo(MethodType.GET));
            Assert.That(actualModel.ExpectedHttpStatusCode, Is.EqualTo(expectedTest.ExpectedHttpStatusCode));
            Assert.That(actualModel.Filename, Is.EqualTo(testFile.Filename));

            Assert.That(actualModel.CapturedVariables.Count, Is.EqualTo(1));
            Assert.That(actualModel.Assertions.Count, Is.EqualTo(1));
            Assert.That(actualModel.Headers.Count, Is.EqualTo(1));

            AssertionViewModel assertionViewModel = actualModel.Assertions.FirstOrDefault();

            Assert.That(assertionViewModel.Description, Is.EqualTo("Desc"));
            Assert.That(assertionViewModel.Value, Is.EqualTo("Val"));
            Assert.That(assertionViewModel.AssertionType, Is.EqualTo(AssertionType.Negative));
            Assert.That(assertionViewModel.AssertionMethod, Is.EqualTo(AssertionMethod.CssSelector));

            Assert.That(actualModel.AvailableVariables.Count, Is.EqualTo(3));

            VariableViewModel capturedVar = actualModel.AvailableVariables.Find(x => x.Name == "CV-1");

            Assert.That(capturedVar, Is.Not.Null);
            Assert.That(capturedVar.Value, Is.EqualTo("CV-1-Value"));

            capturedVar = actualModel.AvailableVariables.Find(x => x.Name == "CV-2");
            Assert.That(capturedVar, Is.Not.Null);

            VariableViewModel testVariable = actualModel.AvailableVariables.Find(x => x.Name == "V-1");

            Assert.That(testVariable, Is.Not.Null);
            Assert.That(testVariable.Value, Is.EqualTo("V-1-Value"));

            Assert.That(actualModel.BeforeExecuteScriptFilename, Is.EqualTo(expectedTest.ScriptSnippets.BeforeExecuteFilename));
            Assert.That(actualModel.BeforeExecuteScriptSnippets.Count(), Is.EqualTo(2));

            Assert.That(actualModel.RequiredEnvironments, Is.EqualTo(expectedTest.TestConditions.RequiredEnvironments));
            Assert.That(actualModel.Environments, Is.EqualTo(new List <string> {
                "First", "Last"
            }));
        }