public async Task <IActionResult> UpdateAsset(int assetId, [FromBody] UpdateAssetRequest request)
        {
            var updateServiceCommand = new UpdateAssetCommand(assetId, request);
            var result = await mediator.Send(updateServiceCommand);

            return(StatusCode((int)result.Code, result.Value));
        }
예제 #2
0
        public async void UpdatesJsonAsset()
        {
            _engine      = new AutomationEngineInstance(null);
            _updateAsset = new UpdateAssetCommand();
            _getAsset    = new GetAssetCommand();

            string assetName = "testJsonAsset";
            string newAsset  = "{ \"text\": \"newText\" }";

            VariableMethods.CreateTestVariable(assetName, _engine, "assetName", typeof(string));
            VariableMethods.CreateTestVariable(newAsset, _engine, "newAsset", typeof(string));
            VariableMethods.CreateTestVariable(null, _engine, "output", typeof(string));

            _updateAsset.v_AssetName     = "{assetName}";
            _updateAsset.v_AssetType     = "Json";
            _updateAsset.v_AssetFilePath = "";
            _updateAsset.v_AssetValue    = "{newAsset}";

            _updateAsset.RunCommand(_engine);

            _getAsset.v_AssetName = "{assetName}";
            _getAsset.v_AssetType = "Json";
            _getAsset.v_OutputUserVariableName = "{output}";

            _getAsset.RunCommand(_engine);

            JObject outputAsset = (JObject)await "{output}".EvaluateCode(_engine);

            Assert.Equal("newText", outputAsset["text"]);

            resetAsset(assetName, "{ \"text\": \"testText\" }", "Json");
        }
        public void UpdatesJSONAsset()
        {
            _engine      = new AutomationEngineInstance(null);
            _updateAsset = new UpdateAssetCommand();
            _getAsset    = new GetAssetCommand();

            string assetName = "testJSONAsset";
            string newAsset  = "{ \"text\": \"newText\" }";

            VariableMethods.CreateTestVariable(assetName, _engine, "assetName", typeof(string));
            VariableMethods.CreateTestVariable(newAsset, _engine, "newAsset", typeof(string));
            VariableMethods.CreateTestVariable(null, _engine, "output", typeof(string));

            _updateAsset.v_AssetName     = "{assetName}";
            _updateAsset.v_AssetType     = "JSON";
            _updateAsset.v_AssetFilePath = "";
            _updateAsset.v_AssetValue    = "{newAsset}";

            _updateAsset.RunCommand(_engine);

            _getAsset.v_AssetName = "{assetName}";
            _getAsset.v_AssetType = "JSON";
            _getAsset.v_OutputUserVariableName = "{output}";

            _getAsset.RunCommand(_engine);

            JObject outputAsset = JObject.Parse("{output}".ConvertUserVariableToString(_engine));

            Assert.Equal("newText", outputAsset["text"]);

            resetAsset(assetName, "{ \"text\": \"testText\" }", "JSON");
        }
예제 #4
0
        public async void UpdatesNumberAsset()
        {
            _engine      = new AutomationEngineInstance(null);
            _updateAsset = new UpdateAssetCommand();
            _getAsset    = new GetAssetCommand();

            string assetName = "testNumberAsset";
            string newAsset  = "70";

            VariableMethods.CreateTestVariable(assetName, _engine, "assetName", typeof(string));
            VariableMethods.CreateTestVariable(newAsset, _engine, "newAsset", typeof(string));
            VariableMethods.CreateTestVariable(null, _engine, "output", typeof(string));

            _updateAsset.v_AssetName     = "{assetName}";
            _updateAsset.v_AssetType     = "Number";
            _updateAsset.v_AssetFilePath = "";
            _updateAsset.v_AssetValue    = "{newAsset}";

            _updateAsset.RunCommand(_engine);

            _getAsset.v_AssetName = "{assetName}";
            _getAsset.v_AssetType = "Number";
            _getAsset.v_OutputUserVariableName = "{output}";

            _getAsset.RunCommand(_engine);

            string outputAsset = (string)await "{output}".EvaluateCode(_engine);

            Assert.Equal("70", outputAsset);

            resetAsset(assetName, "42", "Number");
        }
        private void resetAsset(string assetName, string assetValue, string type)
        {
            _engine      = new AutomationEngineInstance(null);
            _updateAsset = new UpdateAssetCommand();

            _updateAsset.v_AssetName  = assetName;
            _updateAsset.v_AssetType  = type;
            _updateAsset.v_AssetValue = assetValue;

            _updateAsset.RunCommand(_engine);
        }
        public async Task <IActionResult> Put(int id, [FromBody] UpdateAssetCommand command)
        {
            if (id != command.Id)
            {
                return(BadRequest());
            }

            await _mediator.Send(command);

            return(NoContent());
        }
예제 #7
0
        public async Task <IActionResult> PutAsset(Guid id, AssetUpdateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var command = new UpdateAssetCommand
            {
                Id    = id,
                Input = model
            };

            return(await ExecuteRequest(command).ConfigureAwait(false));
        }
예제 #8
0
        public async System.Threading.Tasks.Task HandlesNonexistentAsset()
        {
            _engine      = new AutomationEngineInstance(null);
            _updateAsset = new UpdateAssetCommand();
            _getAsset    = new GetAssetCommand();

            string assetName = "noAsset";
            string newAsset  = "newText";

            VariableMethods.CreateTestVariable(assetName, _engine, "{assetName}", typeof(string));
            VariableMethods.CreateTestVariable(newAsset, _engine, "{newAsset}", typeof(string));

            _updateAsset.v_AssetName     = "{assetName}";
            _updateAsset.v_AssetType     = "Text";
            _updateAsset.v_AssetFilePath = "";
            _updateAsset.v_AssetValue    = "{newAsset}";

            Assert.ThrowsAsync <ArgumentNullException>(() => _updateAsset.RunCommand(_engine));
        }
예제 #9
0
        private void resetAsset(string assetName, string assetVal, string type)
        {
            _engine      = new AutomationEngineInstance(null);
            _updateAsset = new UpdateAssetCommand();

            VariableMethods.CreateTestVariable(assetName, _engine, "assetName", typeof(string));
            VariableMethods.CreateTestVariable(assetVal, _engine, "assetVal", typeof(string));
            VariableMethods.CreateTestVariable(null, _engine, "output", typeof(string));

            _updateAsset.v_AssetName  = "{assetName}";
            _updateAsset.v_AssetType  = type;
            _updateAsset.v_AssetValue = "{assetVal}";

            if (type == "File")
            {
                _updateAsset.v_AssetFilePath = assetVal;
            }

            _updateAsset.RunCommand(_engine);
        }
예제 #10
0
        public void UpdatesFileAsset()
        {
            _engine      = new AutomationEngineInstance(null);
            _updateAsset = new UpdateAssetCommand();
            _getAsset    = new GetAssetCommand();

            string projectDirectory = Directory.GetParent(Environment.CurrentDirectory).Parent.FullName;
            string filepath         = Path.Combine(projectDirectory, @"Resources\");
            string assetName        = "testUpdateFileAsset";
            string newAsset         = filepath + @"Upload\newtest.txt";

            VariableMethods.CreateTestVariable(assetName, _engine, "assetName", typeof(string));
            VariableMethods.CreateTestVariable(newAsset, _engine, "newAsset", typeof(string));

            _updateAsset.v_AssetName     = "{assetName}";
            _updateAsset.v_AssetType     = "File";
            _updateAsset.v_AssetFilePath = "{newAsset}";

            _updateAsset.RunCommand(_engine);

            _getAsset.v_AssetName           = "{assetName}";
            _getAsset.v_AssetType           = "File";
            _getAsset.v_OutputDirectoryPath = filepath + @"Download\";

            if (!Directory.Exists(_getAsset.v_OutputDirectoryPath))
            {
                Directory.CreateDirectory(_getAsset.v_OutputDirectoryPath);
            }

            _getAsset.RunCommand(_engine);

            Assert.True(File.Exists(filepath + @"Download\newtest.txt"));

            File.Delete(filepath + @"Download\newtest.txt");
            resetAsset(assetName, filepath + @"Upload\oldtest.txt", "File");
        }
        public async Task <IActionResult> Put([FromBody] UpdateAssetCommand request)
        {
            var response = await _mediator.Send(request);

            return(Ok(response));
        }