Beispiel #1
0
        private void runSchemaValidatorTest(string reportFileName, CultureInfo testCulture)
        {
            // Preserve current culture
            CultureInfo previousCulture = Thread.CurrentThread.CurrentCulture;

            // Enable test culture
            Thread.CurrentThread.CurrentCulture = testCulture;

            try
            {
                string testsDll = "mock-assembly.dll";
                TestSuiteBuilder builder = new TestSuiteBuilder();
                Test suite = builder.Build( new TestPackage( testsDll ) );

                TestResult result = suite.Run(NullListener.NULL);

              XmlResultVisitor visitor = new XmlResultVisitor(reportFileName, result);
                result.Accept(visitor);
                visitor.Write();

                SchemaValidator validator = new SchemaValidator(reportFileName, schemaFile.Path);
                Assert.IsTrue(validator.Validate(), "validate failed");
            }
            finally
            {
                // Restore previous culture
                Thread.CurrentThread.CurrentCulture = previousCulture;
            }
        }
        public void Initialize(
            Func <ISchema> schemaResolver,
            IReadOnlySchemaOptions options)
        {
            if (schemaResolver is null)
            {
                throw new ArgumentNullException(nameof(schemaResolver));
            }

            if (options is null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            // first we are going to find and initialize all types that belong to our schema.
            var typeRegistrar = new TypeDiscoverer(
                _context,
                _typeRegistry,
                _typeLookup,
                _initialTypes,
                _interceptor);

            if (typeRegistrar.DiscoverTypes() is { Count : > 0 } errors)
            {
                throw new SchemaException(errors);
            }

            // next lets tell the type interceptors what types we have initialized.
            if (_interceptor.TriggerAggregations)
            {
                _interceptor.OnTypesInitialized(
                    _typeRegistry.Types.Select(t => t.DiscoveryContext).ToList());
            }

            // before we can start completing type names we need to register the field resolvers.
            RegisterResolvers();

            // now that we have the resolvers sorted and know what types our schema will roughly
            // consist of we are going to have a look if we can infer interface usage
            // from .NET classes that implement .NET interfaces.
            RegisterImplicitInterfaceDependencies();

            // with all types (implicit and explicit) known we complete the type names.
            CompleteNames(schemaResolver);

            // with the type names all known we can now build pairs to bring together types and
            // their type extensions.
            MergeTypeExtensions();

            // external resolvers are resolvers that are defined on the schema and are associated
            // with the types after they have received a name and the extensions are removed.
            RegisterExternalResolvers();

            // with all resolvers in place we compile the once inferred from a C# member.
            CompileResolvers();

            // last we complete the types. Completing types means that we will assign all
            // the fields resolving all missing parts and then making the types immutable.
            CompleteTypes();

            // if we do not have any errors we will validate the types for spec violations.
            if (_errors.Count == 0)
            {
                _errors.AddRange(SchemaValidator.Validate(
                                     _typeRegistry.Types.Select(t => t.Type),
                                     options));
            }

            if (_errors.Count > 0)
            {
                throw new SchemaException(_errors);
            }
        }
Beispiel #3
0
        private void runSchemaValidatorTest(string reportFileName)
        {
            string testsDll = "mock-assembly.dll";
            TestSuiteBuilder builder = new TestSuiteBuilder();
            Test suite = builder.Build( new TestPackage( testsDll ) );

            TestResult result = suite.Run(NullListener.NULL);

            XmlResultVisitor visitor = new XmlResultVisitor(reportFileName, result);
            result.Accept(visitor);
            visitor.Write();

            SchemaValidator validator = new SchemaValidator(reportFileName, schemaFile.Path);
            Assert.IsTrue(validator.Validate(), "validate failed");
        }
Beispiel #4
0
        public void CompatibilityRuleAttributesValidationTest()
        {
            var validator = new SchemaValidator();
            var element   = new Paragraph();
            var run       = new Run();

            element.AppendChild(run);

            var result = validator.Validate(element);

            Assert.True(result.Valid);

            element.AddNamespaceDeclaration("o15", "http://o15.com");
            result = validator.Validate(element);
            Assert.True(result.Valid);

            run.MCAttributes           = new MarkupCompatibilityAttributes();
            run.MCAttributes.Ignorable = "o15";
            result = validator.Validate(element);
            Assert.True(result.Valid);

            run.AddNamespaceDeclaration("w15", "http://w15.com");
            result = validator.Validate(element);
            Assert.True(result.Valid);

            run.MCAttributes.Ignorable = "o15 w15";
            result = validator.Validate(element);
            Assert.True(result.Valid);

            run.MCAttributes.PreserveAttributes = "  o15:id w15:*";
            run.MCAttributes.PreserveElements   = "o15:*  w15:*  ";
            run.MCAttributes.ProcessContent     = "  o15:newE   w15:newW  ";
            result = validator.Validate(element);
            Assert.True(result.Valid);

            run.MCAttributes.PreserveElements = "x15:* ";
            result = validator.Validate(element);
            Assert.False(result.Valid);
            Assert.Equal(1, result.Errors.Count);
            Assert.Equal(ValidationErrorType.MarkupCompatibility, result.Errors[0].ErrorType);
            Assert.Equal("MC_InvalidPreserveElementsAttribute", result.Errors[0].Id);

            run.MCAttributes.Ignorable          = null;
            run.MCAttributes.PreserveAttributes = null;
            run.MCAttributes.PreserveElements   = "w15:*";
            run.MCAttributes.ProcessContent     = "";
            result = validator.Validate(element);
            Assert.False(result.Valid);
            Assert.Equal(1, result.Errors.Count);
            Assert.Equal(ValidationErrorType.MarkupCompatibility, result.Errors[0].ErrorType);
            Assert.Equal("MC_InvalidPreserveElementsAttribute", result.Errors[0].Id);

            run.MCAttributes.Ignorable          = "o15";
            run.MCAttributes.PreserveAttributes = "";
            run.MCAttributes.PreserveElements   = "w15:*";
            result = validator.Validate(element);
            Assert.False(result.Valid);
            Assert.Equal(1, result.Errors.Count);
            Assert.Equal(ValidationErrorType.MarkupCompatibility, result.Errors[0].ErrorType);
            Assert.Equal("MC_InvalidPreserveElementsAttribute", result.Errors[0].Id);
            run.MCAttributes.PreserveElements = null;

            run.MCAttributes.ProcessContent = "w14:newW";
            result = validator.Validate(element);
            Assert.False(result.Valid);
            Assert.Equal(1, result.Errors.Count);
            Assert.Equal(ValidationErrorType.MarkupCompatibility, result.Errors[0].ErrorType);
            Assert.Equal("MC_InvalidProcessContentAttribute", result.Errors[0].Id);
            run.MCAttributes.ProcessContent = null;

            var spaceAttribute = new OpenXmlAttribute("xml:space", "http://www.w3.org/XML/1998/namespace", "preserve");

            run.MCAttributes.ProcessContent = "o15:newP";
            run.SetAttribute(spaceAttribute);
            result = validator.Validate(element);
            Assert.False(result.Valid);
            Assert.Equal(1, result.Errors.Count);
            Assert.Equal(ValidationErrorType.MarkupCompatibility, result.Errors[0].ErrorType);
            Assert.Equal("MC_InvalidXmlAttributeWithProcessContent", result.Errors[0].Id);
            run.MCAttributes.ProcessContent = null;

            run.SetAttribute(new OpenXmlAttribute("o15:id", "http://o15.com", "1"));
            result = validator.Validate(element);
            Assert.True(result.Valid);

            run.MCAttributes.Ignorable = "o15 w15 x15";
            result = validator.Validate(element);
            Assert.False(result.Valid);
            Assert.Equal(1, result.Errors.Count);
            Assert.Equal(ValidationErrorType.MarkupCompatibility, result.Errors[0].ErrorType);
            Assert.Equal("MC_InvalidIgnorableAttribute", result.Errors[0].Id);

            run.MCAttributes.Ignorable = "o15 w15";
            run.SetAttribute(new OpenXmlAttribute("x15:id", "http://x15.com", "1"));
            result = validator.Validate(element);
            Assert.False(result.Valid);
            Assert.Equal(1, result.Errors.Count);
        }
Beispiel #5
0
        public void AcbSyntaxValidationTest()
        {
            var validator  = new SchemaValidator();
            var element    = new Run();
            var acFallback = new AlternateContentFallback();
            var ac         = element.AppendChild(new AlternateContent());
            var errors     = validator.Validate(ac).Errors;

            // Error case: must have one choice, can not have AlternateContent as di
            Assert.Equal(1, errors.Count());
            Assert.Equal("Sch_IncompleteContentExpectingComplex", errors[0].Id);

            ac.AddNamespaceDeclaration("o15", "http://o15.com");
            //ac.NamespaceDeclarations
            ac.AppendChild(new AlternateContentChoice()
            {
                Requires = "o15"
            });
            errors = validator.Validate(ac).Errors;
            Assert.Equal(0, errors.Count());

            ac.AddNamespaceDeclaration("o14", "http://o14.com");
            ac.PrependChild(new AlternateContentChoice()
            {
                Requires = "o14"
            });
            errors = validator.Validate(ac).Errors;
            Assert.Equal(0, errors.Count());

            ac.AppendChild(acFallback);
            errors = validator.Validate(ac).Errors;
            Assert.Equal(0, errors.Count());

            // Error case: should not contains AlternateContent directly as child.
            ac.AppendChild(new AlternateContent());
            errors = validator.Validate(ac).Errors;
            Assert.Equal(1, errors.Count());
            Assert.Equal(ValidationErrorType.MarkupCompatibility, errors.First().ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", errors.First().Id);
            ac.RemoveChild(ac.LastChild);

            // Error case: can only contains one Fallback.
            ac.AppendChild(new AlternateContentFallback());
            errors = validator.Validate(ac).Errors;
            Assert.Equal(1, errors.Count());
            Assert.Equal(ValidationErrorType.MarkupCompatibility, errors.First().ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", errors.First().Id);
            ac.RemoveChild(ac.LastChild);

            ac.RemoveChild(acFallback);
            // Error case: wrong sequence
            ac.PrependChild(acFallback);
            errors = validator.Validate(ac).Errors;
            Assert.Equal(1, errors.Count());
            Assert.Equal(ValidationErrorType.MarkupCompatibility, errors.First().ErrorType);
            Assert.Equal("Sch_IncompleteContentExpectingComplex", errors.First().Id);
            ac.RemoveChild(acFallback);
            ac.Append(acFallback);

            var langAttribute = new OpenXmlAttribute("xml:lang", "http://www.w3.org/XML/1998/namespace", "en-us");

            ac.SetAttribute(langAttribute);
            errors = validator.Validate(ac).Errors;
            Assert.Equal(1, errors.Count());
            Assert.Equal(ValidationErrorType.MarkupCompatibility, errors.First().ErrorType);
            Assert.Equal("MC_InvalidXmlAttribute", errors.First().Id);
            Assert.Equal("The AlternateContent element should not have an xml:lang or xml:space attribute.", errors[0].Description);
            ac.RemoveAttribute(langAttribute.LocalName, langAttribute.NamespaceUri);

            ac.FirstChild.SetAttribute(langAttribute);
            errors = validator.Validate(ac).Errors;
            Assert.Equal(1, errors.Count());
            Assert.Same(ac.FirstChild, errors[0].Node);
            Assert.Equal(ValidationErrorType.MarkupCompatibility, errors.First().ErrorType);
            Assert.Equal("MC_InvalidXmlAttribute", errors.First().Id);
            Assert.Equal("The Choice element should not have an xml:lang or xml:space attribute.", errors[0].Description);
            ac.FirstChild.RemoveAttribute(langAttribute.LocalName, langAttribute.NamespaceUri);

            ac.LastChild.SetAttribute(langAttribute);
            errors = validator.Validate(ac).Errors;
            Assert.Equal(1, errors.Count());
            Assert.Same(ac.LastChild, errors[0].Node);
            Assert.Equal(ValidationErrorType.MarkupCompatibility, errors.First().ErrorType);
            Assert.Equal("MC_InvalidXmlAttribute", errors.First().Id);
            Assert.Equal("The Fallback element should not have an xml:lang or xml:space attribute.", errors[0].Description);
            ac.LastChild.RemoveAttribute(langAttribute.LocalName, langAttribute.NamespaceUri);

            AlternateContentChoice choice1 = ac.FirstChild as AlternateContentChoice;

            choice1.Requires = "o17 o15";
            errors           = validator.Validate(ac).Errors;
            Assert.Equal(1, errors.Count());
            Assert.Equal(ValidationErrorType.MarkupCompatibility, errors.First().ErrorType);
            Assert.Same(choice1, errors[0].Node);
            Assert.Equal("MC_InvalidRequiresAttribute", errors.First().Id);
            Assert.Equal("The Requires attribute is invalid - The value 'o17 o15' contains an invalid prefix that is not defined.", errors[0].Description);

            choice1.Requires = null;
            errors           = validator.Validate(ac).Errors;
            Assert.Equal(ValidationErrorType.MarkupCompatibility, errors.First().ErrorType);
            Assert.Equal(1, errors.Count());
            Assert.Same(choice1, errors[0].Node);
            Assert.Equal("MC_MissedRequiresAttribute", errors.First().Id);
            Assert.Equal("All Choice elements must have a Requires attribute whose value contains a whitespace delimited list of namespace prefixes.", errors[0].Description);
        }
Beispiel #6
0
 public static XmlDocument IsValid(string fileName, bool warningsAsError)
 {
     Assert.IsNotNull(fileName);
     SchemaValidator validator = new SchemaValidator(warningsAsError);
     return validator.Validate(IsWellFormed(fileName));
 }
Beispiel #7
0
        public void ValidateSequences()
        {
            var validator = new SchemaValidator(cfg);

            validator.Validate();
        }
Beispiel #8
0
        public void WhenXmlIsValidShouldReturnNoError()
        {
            var errors = _schemaValidator.Validate(@"..\..\Sources\books.xml");

            Assert.AreEqual(errors.Count, 0);
        }
Beispiel #9
0
        public void SchemaIsCorrectlyMapped()
        {
            var validator = new SchemaValidator(Simply.Do.GetNHibernateConfig());

            validator.Validate();
        }
        private bool RunSingleTest(
            SifVersion parseVersion,
            SifVersion writeVersion,
            string fileName,
            TextWriter output,
            SchemaValidator sv)
        {
            sv.Clear();

            if (VERBOSE)
            {
                output.Write("Running test on " + fileName + "\r\n");
            }

            // 1) Read the object into memory
            SifElement se = null;

            try
            {
                se = AdkObjectParseHelper.ParseFile(fileName, parseVersion);
            }
            catch (AdkException adke)
            {
                // Parsing failed. However, since this unit test is a complete
                // test of all available objects, just emit the problem and allow
                // the test to continue (with a notification of false)
                output
                .WriteLine("Error parsing file " + fileName + "\r\n  - "
                           + adke);
                output.WriteLine();
                return(false);
            }
            catch (Exception re)
            {
                output.WriteLine("Error parsing file " + fileName + "\r\n  - " + re);
                output.WriteLine();
                return(false);
            }

//            if (VERBOSE)
//            {
//                SifWriter writer = new SifWriter(output);
//                writer.Write(se,parseVersion);
//                output.Flush();
//            }

            // Before we can validate with the schema, we need to ensure that the
            // data object is wrapped in a SIF_Message elements, because the SIF
            // Schema makes that assumption
            SifMessagePayload smp = SchemaValidator.MakeSIFMessagePayload(se);

            String tmpFileName = fileName + "." + writeVersion.ToString() + ".adk";

            // 2) Write the message out to a file
            SchemaValidator.WriteObject(writeVersion, tmpFileName, smp);

            // 3) Validate the file
            bool validated = sv.Validate(tmpFileName);

            // 4) If validation failed, write the object out for tracing purposes
            if (!validated)
            {
                if (VERBOSE)
                {
                    SifWriter outWriter = new SifWriter(output);
                    outWriter.Write(se, writeVersion);
                    outWriter.Flush();
                }
                output.WriteLine("Validation failed on " + tmpFileName);
                sv.PrintProblems(output);
                return(false);
            }

            // 5) Read the object again into memory
            try
            {
                se = AdkObjectParseHelper.ParseFile(fileName, parseVersion);
            }
            catch (AdkException adke)
            {
                // Parsing failed. However, since this unit test is a complete
                // test of all available objects, just emit the problem and allow
                // the test to continue (with a notification of false)
                output.WriteLine("Error parsing file " + fileName + ": "
                                 + adke.Message);
                return(false);
            }
            catch (Exception re)
            {
                output.Write("Error parsing file " + fileName + ": "
                             + re.Message + "\r\n");
                return(false);
            }

            return(validated);
        }
        public void ValidateSchema()
        {
            var schemaValidator = new SchemaValidator(_cfg);

            schemaValidator.Validate();
        }
        public void ValidateSchema()
        {
            SchemaValidator validator = new SchemaValidator(configuration.BuildConfiguration());

            validator.Validate();
        }
        private bool RunSingleTest(
            SifVersion parseVersion, 
            SifVersion writeVersion, 
            string fileName, 
            TextWriter output, 
            SchemaValidator sv)
        {
            sv.Clear();

            if (VERBOSE)
            {
                output.Write("Running test on " + fileName + "\r\n");
            }

            // 1) Read the object into memory
            SifElement se = null;
            try
            {
                se = AdkObjectParseHelper.ParseFile(fileName, parseVersion);
            }
            catch (AdkException adke)
            {
                // Parsing failed. However, since this unit test is a complete
                // test of all available objects, just emit the problem and allow
                // the test to continue (with a notification of false)
                output
                        .WriteLine("Error parsing file " + fileName + "\r\n  - "
                                + adke);
                output.WriteLine();
                return false;
            }
            catch (Exception re)
            {
                output.WriteLine("Error parsing file " + fileName + "\r\n  - " + re);
                output.WriteLine();
                return false;
            }

            //            if (VERBOSE)
            //            {
            //                SifWriter writer = new SifWriter(output);
            //                writer.Write(se,parseVersion);
            //                output.Flush();
            //            }

            // Before we can validate with the schema, we need to ensure that the
            // data object is wrapped in a SIF_Message elements, because the SIF
            // Schema makes that assumption
            SifMessagePayload smp = SchemaValidator.MakeSIFMessagePayload(se);

            String tmpFileName = fileName + "." + writeVersion.ToString() + ".adk";

            // 2) Write the message out to a file
            SchemaValidator.WriteObject(writeVersion, tmpFileName, smp);

            // 3) Validate the file
            bool validated = sv.Validate(tmpFileName);

            // 4) If validation failed, write the object out for tracing purposes
            if (!validated)
            {
                if (VERBOSE)
                {
                    SifWriter outWriter = new SifWriter(output);
                    outWriter.Write(se, writeVersion );
                    outWriter.Flush();
                }
                output.WriteLine("Validation failed on " + tmpFileName );
                sv.PrintProblems(output);
                return false;
            }

            // 5) Read the object again into memory
            try
            {
                se = AdkObjectParseHelper.ParseFile(fileName, parseVersion);
            }
            catch (AdkException adke)
            {
                // Parsing failed. However, since this unit test is a complete
                // test of all available objects, just emit the problem and allow
                // the test to continue (with a notification of false)
                output.WriteLine("Error parsing file " + fileName + ": "
                        + adke.Message );
                return false;
            }
            catch (Exception re)
            {
                output.Write("Error parsing file " + fileName + ": "
                        + re.Message + "\r\n");
                return false;
            }

            return validated;
        }
        private static ISessionFactory CreateEntityManagerFactory(SchemaFactoryModeEnum mode, CategoryPropertyItem configItem)
        {
            CategoryPropertyItem item = ConfigurationAccessHelper.GetCategoryPropertyByPath(configItem.PropertyItems, "DatabaseManager");

            if (item != null && !string.IsNullOrEmpty(item.EntryValue))
            {
                Type databaseManagerType = null;
                try
                {
                    databaseManagerType = TypeHelper.GetTypeFromString(item.EntryValue);
                }
                catch (Exception ex)
                {
                    throw new InvalidConfigurationValueException(ex.Message, ex);
                }

                if (databaseManagerType != null)
                {
                    using (IDatabaseManager manager = (IDatabaseManager)databaseManagerType.GetConstructor(Type.EmptyTypes).Invoke(null))
                    {
                        manager.Initialize(item);
                        Dictionary <string, string> settings = new Dictionary <string, string>();
                        foreach (CategoryPropertyItem pi in ConfigurationAccessHelper.GetCategoryPropertyByPath(configItem.PropertyItems, "NHibernateSettings"))
                        {
                            settings[pi.Id] = pi.EntryValue;
                        }
                        manager.EnsureDatabaseIntegrity(SYSTEM_ID, settings, mode);
                    }
                }
            }

            string hbm2ddl = "hbm2ddl.auto";

            NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
            cfg.Properties.Clear();

            foreach (CategoryPropertyItem pi in ConfigurationAccessHelper.GetCategoryPropertyByPath(configItem.PropertyItems, "NHibernateSettings"))
            {
                if (!hbm2ddl.Equals(pi.Id.ToLower()))
                {
                    cfg.Properties[pi.Id] = pi.EntryValue;
                }
            }

            if (mode == SchemaFactoryModeEnum.Create)
            {
                cfg.Properties[hbm2ddl] = "create";
            }
            else if (mode == SchemaFactoryModeEnum.Create_And_Drop)
            {
                cfg.Properties[hbm2ddl] = "create-drop";
            }

            HbmSerializer serializer = new HbmSerializer();

            serializer.HbmAssembly      = typeof(PersistentStorageItem).Assembly.GetName().FullName;
            serializer.HbmAutoImport    = true;
            serializer.Validate         = true;
            serializer.WriteDateComment = false;
            serializer.HbmDefaultAccess = "field";

            cfg.AddInputStream(serializer.Serialize(typeof(PersistentStorageItem).Assembly));
            //cfg.Configure();

            if (mode == SchemaFactoryModeEnum.Validate)
            {
                SchemaValidator schemaValidator = new SchemaValidator(cfg);
                schemaValidator.Validate(); // validate the database schema
            }
            else if (mode == SchemaFactoryModeEnum.Update)
            {
                SchemaUpdate schemaUpdater = new SchemaUpdate(cfg); // try to update schema
                schemaUpdater.Execute(false, true);
                if (schemaUpdater.Exceptions.Count > 0)
                {
                    throw new Exception("FAILED TO UPDATE SCHEMA");
                }
            }

            return(cfg.BuildSessionFactory());
        }
Beispiel #15
0
 public static XmlDocument IsValid(TextReader reader, bool warningsAsError)
 {
     Assert.IsNotNull(reader);
     SchemaValidator validator = new SchemaValidator(warningsAsError);
     return validator.Validate(IsWellFormed(reader));
 }
        public void DbHasExpectedType()
        {
            var validator = new SchemaValidator(cfg);

            validator.Validate();
        }
Beispiel #17
0
 public static XmlDocument IsValidXml(string xml, bool warningsAsError)
 {
     Assert.IsNotNull(xml);
     SchemaValidator validator = new SchemaValidator(warningsAsError);
     return validator.Validate(IsWellFormedXml(xml));
 }
        public void OnActionExecuting(ActionExecutingContext context)
        {
            NullGuard.NotNull(context, nameof(context));

            SchemaValidator.Validate(context.ModelState);
        }
Beispiel #19
0
        private void runSchemaValidatorTest(string reportFileName)
        {
            string testsDll = "mock-assembly.dll";
            TestSuiteBuilder builder = new TestSuiteBuilder();
            Test suite = builder.Build( new TestPackage( testsDll ) );

            TestResult result = suite.Run(NullListener.NULL, TestFilter.Empty);

            new XmlResultWriter(reportFileName).SaveTestResult(result);

            SchemaValidator validator = new SchemaValidator(reportFileName, schemaFile.Path);
            Assert.IsTrue(validator.Validate(), "validate failed");
        }
Beispiel #20
0
        static void Main(string[] args)
        {
            try
            {
                var nhConfig = new Configuration();
                nhConfig.Configure();
                var sessionFactory = nhConfig.BuildSessionFactory();
                Console.WriteLine("NHibernate Configured!");
                Console.ReadKey();


                using (var session = sessionFactory.OpenSession())
                {
                    using (var tx = session.BeginTransaction())
                    {
                        //Variant for 2 tables: human and gender

                        ICriteria criteria = session.CreateCriteria <human>();
                        criteria.CreateAlias("gender", "Gender", JoinType.LeftOuterJoin);  //или выставить lazy="false" в human.hbm.xml внутри <many-to-one> но это плохо
                        criteria.SetResultTransformer(new DistinctRootEntityResultTransformer());
                        IList <human> list = criteria.List <human>();
                        people = list.ToList();

                        foreach (var item in people)
                        {
                            Console.WriteLine(item.ToString());
                        }
                        Console.WriteLine("+++++++++++++");

                        //UPDATE
                        //var hmnUpdate = session.Get<human>(1);
                        //hmnUpdate.gender.gendername = "female";
                        //hmnUpdate.firstname = "Alisa";
                        //hmnUpdate.lastname = "Kovaleva";
                        //session.SaveOrUpdate(hmnUpdate);



                        //SAVE INTO DB
                        //save human when gender doesn't exist(so we add new into DB)
                        //human hmnSave = new human();
                        //hmnSave.lastname = "Orlov";
                        //hmnSave.firstname = "Oleg";
                        //hmnSave.DOB = "15th od March";
                        //hmnSave.SSN = 111111111;
                        //hmnSave.activeStatus = 1;
                        //hmnSave.gender = new gender { gendername = "not male,not female" };
                        //session.SaveOrUpdate(hmnSave);


                        //save human when gender exists
                        //gender fmlGender = session.Query<gender>()
                        //.Where(g => g.gendername == "female").FirstOrDefault();
                        //Console.WriteLine("id of female=" + fmlGender.GenderId.ToString());

                        //human hmnSave1 = new human();
                        //hmnSave1.lastname = "Titarenko";
                        //hmnSave1.firstname = "Oksana";
                        //hmnSave1.DOB = "9th od February";
                        //hmnSave1.SSN = 333333333;
                        //hmnSave1.gender = fmlGender;
                        //hmnSave1.activeStatus = 1;
                        //session.SaveOrUpdate(hmnSave1);


                        //save gender
                        //gender someGender= new gender { gendername = "smth" };
                        //session.SaveOrUpdate(someGender);


                        //DELETE
                        //Delete human
                        //var hmnDelete = session.Get<human>(1);
                        //session.Delete(hmnDelete);

                        //Delete gender(1.Try to delete 'female'.2.Instead 'male write 'animal')
                        //var hmnIsThereMale = session.Query<human>()
                        //.Where(h => h.gender.gendername == "female");
                        //Console.WriteLine(hmnIsThereMale);

                        //foreach (var item in hmnIsThereMale)
                        //{
                        //    Console.WriteLine(item.ToString());
                        //}
                        //Console.WriteLine("+++++++++++++");


                        //if (hmnIsThereMale.Count() > 0)
                        //{
                        //    Console.WriteLine("\nThe record can't be deleted.There are records with gender 'female'.");
                        //}
                        //else if (hmnIsThereMale.Count() == 0)
                        //{
                        //    var gndrDelete = session.Query<gender>()
                        //    .Where(g => g.gendername == "female").First();
                        //    session.Delete(gndrDelete);
                        //}
                        //Console.WriteLine("+++++++++++++");



                        //Using activeStatus instead of deleting
                        //var hmnChangeStatus = session.Query<human>()
                        //.Where(h => h.lastname == "Sokolova").First();
                        //hmnChangeStatus.activeStatus = 0;
                        //session.SaveOrUpdate(hmnChangeStatus);

                        //var hmnActiveStatus = session.Query<human>()
                        //.Where(h => h.activeStatus == 1);

                        //foreach (var item in hmnActiveStatus)
                        //{
                        //    Console.WriteLine(item.ToString());
                        //}
                        //Console.WriteLine("+++++++++++++");



                        var validator = new SchemaValidator(nhConfig);
                        validator.Validate();
                        list   = criteria.List <human>();
                        people = list.ToList();

                        foreach (var item in people)
                        {
                            Console.WriteLine(item.ToString());
                        }
                        Console.WriteLine("+++++++++++++");
                        tx.Commit();
                    }

                    session.Flush();
                    session.Clear();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error (" + ex.GetType().Name + "): " + ex.Message);
                Console.WriteLine("ListCount=" + people.Count.ToString());
            }
        }