Esempio n. 1
0
        public void ModifyProperty()
        {
            if (!_registerPropertyTestRan)
            {
                Assert.Inconclusive("RegisterProperty did not run yet.\nMake sure to test on PropertyTest instead of ModifyProperty.");
            }

            // Checking if the property gets edited correctly and throws properly
            Assert.Throws(typeof(PropertyHandlerException), () => PropertyHandler.ModifyProperty("Bla", "New Value"));
            Assert.Throws(typeof(TypeMismatchException), () => PropertyHandler.ModifyProperty("UnitTest", 123));
            Assert.DoesNotThrow(() => PropertyHandler.ModifyProperty("UnitTest", "New Value"));
            Assert.AreEqual("New Value", testProp.Value);
        }
Esempio n. 2
0
 /// <summary>
 /// Attempts to modify a <see cref="Property"/>
 /// </summary>
 /// <param name="prop">Name of the <see cref="Property"/> to set</param>
 /// <param name="output">Value to set</param>
 /// <param name="outputStringRep"><see cref="String"/> representation of the value</param>
 /// <returns>Output message</returns>
 /// <exception cref="CommandInputException">Error message</exception>
 private static string TryModifyProperty(string prop, dynamic output, string outputStringRep)
 {
     try
     {
         PropertyHandler.ModifyProperty(prop, output);
         return($"Property \"{prop}\" set as ({outputStringRep})");
     }
     catch (PropertyHandlerException)
     {
         throw new CommandInputException($"Unknown property \"{prop}\"");
     }
     catch (TypeMismatchException)
     {
         throw new CommandInputException($"Property \"{prop}\" is not of type {output.GetType().Name}");
     }
 }