예제 #1
0
        public void CanCreateUpdateDeleteVariable()
        {
            using (var context = MockContext.Start(GetType().FullName))
            {
                using (var testFixture = new AutomationTestBase(context))
                {
                    var variableName = TestUtilities.GenerateName("variable");
                    var value        = 10;

                    var variable = testFixture.CreateVariable(variableName, value);
                    Assert.NotNull(variable);

                    variable = testFixture.GetVariable(variable.Name);
                    Assert.NotNull(variable);
                    Assert.Equal(value, Convert.ToInt32(JsonConvert.DeserializeObject <object>(variable.Value)));

                    value                = 20;
                    variable.Value       = JsonConvert.SerializeObject(value);
                    variable.Description = "int typed variable";

                    testFixture.UpdateVariable(variable);
                    var variables = testFixture.GetVariables();
                    Assert.Single(variables.ToList());
                    var updatedVariable = variables.ToList()[0];
                    Assert.Equal(value, Convert.ToInt32(JsonConvert.DeserializeObject <object>(updatedVariable.Value)));
                    Assert.Equal(variable.Description, updatedVariable.Description);

                    testFixture.DeleteVariable(variable.Name);

                    Assert.Throws <ErrorResponseException>(() =>
                    {
                        variable = testFixture.GetVariable(variable.Name);
                    });
                }
            }
        }