Exemple #1
0
        public async Task TestValidateConstraint()
        {
            await CreateDomain();

            schema.Definition.Library.AddConstraint <Library>(self => self.Name != "abcd").Message("error").Category("test").Register();

            Library lib;

            using (var session = store.BeginSession())
            {
                lib       = new Library(domain);
                lib.Name  = "abcd";                 // Failed
                lib.Email = "*****@*****.**"; // OK
                session.AcceptChanges();
            }

            var result = schema.Constraints.Validate(domain.GetElements());

            Assert.Equal(1, result.Messages.Count());
            Assert.Equal("error for element abcd (lib:1).", result.Messages.First().Message);

            result = schema.Constraints.Validate(domain.GetElements(), "test");     // With a valid category
            Assert.Equal(1, result.Messages.Count());
            Assert.Equal("error for element abcd (lib:1).", result.Messages.First().Message);


            result = schema.Constraints.Validate(domain.GetElements(), "test2");     // Unknow category
            Assert.Equal(0, result.Messages.Count());
        }
 ///-------------------------------------------------------------------------------------------------
 /// <summary>
 ///  true this instance to the given stream.
 /// </summary>
 /// <param name="stream">
 ///  The stream.
 /// </param>
 /// <param name="domain">
 ///  The domain.
 /// </param>
 /// <param name="option">
 ///  (Optional) the option.
 /// </param>
 ///-------------------------------------------------------------------------------------------------
 public static void Serialize(Stream stream, IDomainModel domain, JSonSerializationOption option = JSonSerializationOption.Json)
 {
     using (var sw = new StreamWriter(stream))
     {
         var ser = new JSonSerializer(sw, new JSonSerializationSettings {
             Options = option
         });
         ser.Serialize(domain.GetElements());
     }
 }
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  true this instance to the given stream.
        /// </summary>
        /// <param name="domain">
        ///  The domain.
        /// </param>
        /// <param name="settings">
        ///  Options for controlling the operation.
        /// </param>
        /// <returns>
        ///  A string.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        public static string Serialize(IDomainModel domain, JSonSerializationSettings settings)
        {
            Contract.Requires(domain, "domain");

            // Force hyperstore format
            if (settings == null)
            {
                settings = new JSonSerializationSettings();
            }
            settings.Options |= JSonSerializationOption.Hyperstore;
            settings.Options &= ~JSonSerializationOption.SerializeGraphObject;
            return(Serialize(domain.GetElements(), settings));
        }
Exemple #4
0
 ///-------------------------------------------------------------------------------------------------
 /// <summary>
 ///  Validates.
 /// </summary>
 /// <param name="domain">
 ///  The domain.
 /// </param>
 /// <param name="category">
 ///  (Optional) the category.
 /// </param>
 /// <returns>
 ///  An ISessionResult.
 /// </returns>
 ///-------------------------------------------------------------------------------------------------
 public ISessionResult Validate(IDomainModel domain, string category = null)
 {
     Contract.Requires(domain, "domain");
     return(Validate(domain.GetElements()));
 }