Exemple #1
0
        // checks that a given STON text parses to a simple value with the given data type and content string
        private void ExpectParsedValue(string ston, StonDataType dataType, string content)
        {
            var entity = RegularStonReader.Default.ParseEntity(ston) as IStonSimpleEntity;

            Assert.AreEqual(dataType, entity.Value.DataType);
            Assert.AreEqual(content, entity.Value.Content);
        }
Exemple #2
0
 // checks that a given data type and content string form a valid simple value of a given canonical form
 private void ExpectValidValue(StonDataType dataType, string content, string canonicalForm)
 {
     try
     {
         new StonSimpleEntity(new StonSimpleValue(dataType, content)).ToCanonicalForm();
     }
     catch (StonException ex)
     {
         Assert.Fail(ex.Message);
     }
 }
Exemple #3
0
 // checks that a given data type and content string form an invalid simple value
 // and that the validation throws a specific error message
 private void ExpectInvalidValue(StonDataType dataType, string content, string message)
 {
     try
     {
         new StonSimpleEntity(new StonSimpleValue(dataType, content));
         Assert.Fail("The value is valid. This should *not* have happened.");
     }
     catch (StonException ex)
     {
         Assert.AreEqual(message, ex.Message);
     }
 }
Exemple #4
0
 // checks a content validity before trying to write it
 private void CheckContentValidity(StonDataType type, string content)
 {
     if (content == null)
     {
         throw new ArgumentNullException("content");
     }
     try
     {
         Validator.ValidateSimpleValue(new StonSimpleValue(type, content));
     }
     catch (StonException ex)
     {
         throw new ArgumentException(ex.Message);
     }
 }
Exemple #5
0
 /// <summary>
 /// Creates a new simple value, given a data type and content string.
 /// </summary>
 /// <param name="dataType">The data type of the value.</param>
 /// <param name="content">The content string of the value.</param>
 public StonSimpleValue(StonDataType dataType, string content)
 {
     DataType = dataType;
     Content  = content;
 }
 /// <summary>
 /// Creates a new simple value, given a data type and content string.
 /// </summary>
 /// <param name="dataType">The data type of the value.</param>
 /// <param name="content">The content string of the value.</param>
 /// <returns>The new STON simple value.</returns>
 public IStonSimpleValue CreateSimpleValue(StonDataType dataType, string content)
 => new StonSimpleValue(dataType, content);