Пример #1
0
        public void GetTermTableUsingMinimalSchema()
        {
            StringBuilder fileContent = new StringBuilder();

            fileContent.Append("<?xml version=\"1.0\"?>\n");
            fileContent.Append("<xmldata>\n");
            fileContent.Append("  <PLCKTT>\n");
            fileContent.Append("    <Lang>\n");
            fileContent.Append("      <Term Term=\"countries\" Severity=\"2\" TermClass=\"Geopolitical\">\n");
            fileContent.Append("        <Comment>For detailed info see - http://relevant-url-here.com</Comment>\n");
            fileContent.Append("      </Term>\n");
            fileContent.Append("    </Lang>\n");
            fileContent.Append("  </PLCKTT>\n");
            fileContent.Append("</xmldata>\n");

            string fileName = Utilities.CreateTempTxtFile(fileContent.ToString());

            ITermTable table = Factory.GetTermTable(fileName);

            Assert.AreEqual(fileName, table.SourceFile, "SourceFile property is incorrect.");
            Assert.IsNotNull(table.Terms, "Terms property is null.");

            List <ISearchTerm> termList = Utilities.ListFromEnum(table.Terms);

            Assert.AreEqual(1, termList.Count, "Number of terms is incorrect.");
            Assert.AreEqual("countries", termList[0].Text, "Text property of term 0 is incorrect.");
            Assert.AreEqual("Geopolitical", termList[0].Class, "Class property of term 0 is incorrect.");
            Assert.AreEqual("For detailed info see - http://relevant-url-here.com", termList[0].Comment, "Comment property of term 0 is incorrect.");
            Assert.IsNull(termList[0].RecommendedTerm, "RecommendedTerm property of term 0 is incorrect.");

            List <IExclusion> term0exclusions = Utilities.ListFromEnum(termList[0].Exclusions);

            Assert.AreEqual(0, term0exclusions.Count, "Number of exclusions for term 0 is incorrect.");
        }
Пример #2
0
 public GroupBll()
 {
     Database = HttpContext.Current.Request.GetOwinContext().Get<ApplicationDbContext>();
     _groupTable = new GroupTable(Database);
     _userTable = new UserTable(Database);
     _permissionTable = new PermissionTable(Database);
     _termTable = new TermTable(Database);
 }
Пример #3
0
 public UserBll()
 {
     this.Database = (MySQLDatabase)OwinContextExtensions.Get<ApplicationDbContext>(HttpContextExtensions.GetOwinContext(HttpContext.Current.Request));
     this._userTable = (IUserTable)new UserTable(this.Database);
     this._groupTable = (IGroupTable)new GroupTable(this.Database);
     this._permissionTable = (IPermissionTable)new PermissionTable(this.Database);
     this._termTable = (ITermTable)new TermTable(this.Database);
 }
Пример #4
0
 public MockTerm(string text, int severity, string termClass, string comment, string recommended, ITermTable table)
 {
     _text        = text;
     _severity    = severity;
     _class       = termClass;
     _comment     = comment;
     _table       = table;
     _recommended = recommended;
 }
 protected SearchTerm(SerializationInfo info, StreamingContext context)
 {
     _text        = info.GetString(TextKey);
     _table       = (ITermTable)info.GetValue(TableKey, typeof(ITermTable));
     _class       = info.GetString(ClassKey);
     _severity    = info.GetInt32(SeverityKey);
     _comment     = info.GetString(CommentKey);
     _recommended = info.GetString(RecommendedKey);
     _exclusions  = (List <IExclusion>)info.GetValue(ExclusionsKey, typeof(List <IExclusion>));
 }
Пример #6
0
 protected SearchTerm(SerializationInfo info, StreamingContext context)
 {
     _text = info.GetString(TextKey);
     _table = (ITermTable)info.GetValue(TableKey, typeof(ITermTable));
     _class = info.GetString(ClassKey);
     _severity = info.GetInt32(SeverityKey);
     _comment = info.GetString(CommentKey);
     _recommended = info.GetString(RecommendedKey);
     _exclusions = (List<IExclusion>)info.GetValue(ExclusionsKey, typeof(List<IExclusion>));
 }
Пример #7
0
        /// <summary>
        /// Initializes the search term with the specified text.
        /// </summary>
        /// <param name="table">The table to which this term belongs.</param>
        /// <param name="text">The text to search for.</param>
        /// <param name="severity">The severity of the term, normally between 1 and 3 inclusive.</param>
        /// <param name="termClass">The class of the term, such as "Geopolitical".</param>
        /// <param name="comment">A descriptive comment for the term.</param>
        /// <param name="recommendedTerm">The recommended replacement; may be null.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if <c>text</c> is null.</exception>
        /// <exception cref="System.ArgumentException">Thrown if <c>text</c> is an empty string.</exception>
        public SearchTerm(ITermTable table, string text, int severity, string termClass, string comment, string recommendedTerm)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }
            if (text.Length == 0)
            {
                throw new ArgumentException("Empty string not allowed", "text");
            }

            _table       = table;
            _text        = text;
            _severity    = severity;
            _class       = termClass;
            _comment     = comment;
            _recommended = recommendedTerm;
        }
Пример #8
0
        /// <summary>
        /// Initializes the search term with the specified text.
        /// </summary>
        /// <param name="table">The table to which this term belongs.</param>
        /// <param name="text">The text to search for.</param>
        /// <param name="severity">The severity of the term, normally between 1 and 3 inclusive.</param>
        /// <param name="termClass">The class of the term, such as "Geopolitical".</param>
        /// <param name="comment">A descriptive comment for the term.</param>
        /// <param name="recommendedTerm">The recommended replacement; may be null.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if <c>text</c> is null.</exception>
        /// <exception cref="System.ArgumentException">Thrown if <c>text</c> is an empty string.</exception>
        public SearchTerm(ITermTable table, string text, int severity, string termClass, string comment, string recommendedTerm)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }
            if (text.Length == 0)
            {
                throw new ArgumentException("Empty string not allowed", "text");
            }

            _table = table;
            _text = text;
            _severity = severity;
            _class = termClass;
            _comment = comment;
            _recommended = recommendedTerm;
            _exclusions = new List<IExclusion>();
        }
Пример #9
0
        public void GetTermTableUsingFullSchema()
        {
            StringBuilder fileContent = new StringBuilder();

            fileContent.Append("<?xml version=\"1.0\"?>\n");
            fileContent.Append("<xmldata>\n");
            fileContent.Append("  <PLCKTT>\n");
            fileContent.Append("    <Lang>\n");
            fileContent.Append("      <Term Term=\"countries\" TermID=\"5\" Severity=\"2\" TermClass=\"Geopolitical\" CaseSensitive=\"0\" WholeWord=\"1\">\n");
            fileContent.Append("        <RecommendedTerm>countries/regions</RecommendedTerm>\n");
            fileContent.Append("        <Comment>For detailed info see - http://relevant-url-here.com</Comment>\n");
            fileContent.Append("        <Exclusion>and for other fareast countries</Exclusion>\n");
            fileContent.Append("        <Exclusion>\"countries\",</Exclusion>\n");
            fileContent.Append("        <ExclusionContext>hold true for other countries in the world</ExclusionContext>\n");
            fileContent.Append("        <ExclusionContext>lists the available countries in north america</ExclusionContext>\n");
            fileContent.Append("      </Term>\n");
            fileContent.Append("      <Term Term=\"shoot\" TermID=\"6\" Severity=\"3\" TermClass=\"Profanity\" CaseSensitive=\"1\" WholeWord=\"0\">\n");
            fileContent.Append("        <RecommendedTerm>darn</RecommendedTerm>\n");
            fileContent.Append("        <Comment>Watch that language!</Comment>\n");
            fileContent.Append("        <Exclusion>Did you shoot the sherrif?</Exclusion>\n");
            fileContent.Append("        <Exclusion>I did not shoot the deputy</Exclusion>\n");
            fileContent.Append("        <ExclusionContext>an old-fashioned shoot-em-up</ExclusionContext>\n");
            fileContent.Append("      </Term>\n");
            fileContent.Append("    </Lang>\n");
            fileContent.Append("  </PLCKTT>\n");
            fileContent.Append("</xmldata>\n");

            string fileName = Utilities.CreateTempTxtFile(fileContent.ToString());

            ITermTable table = Factory.GetTermTable(fileName);

            Assert.AreEqual(fileName, table.SourceFile, "SourceFile property is incorrect.");
            Assert.IsNotNull(table.Terms, "Terms property is null.");

            List <ISearchTerm> termList = Utilities.ListFromEnum(table.Terms);

            Assert.AreEqual(2, termList.Count, "Number of terms is incorrect.");
            Assert.AreEqual("countries", termList[0].Text, "Text property of term 0 is incorrect.");
            Assert.AreEqual("Geopolitical", termList[0].Class, "Class property of term 0 is incorrect.");
            Assert.AreEqual("For detailed info see - http://relevant-url-here.com", termList[0].Comment, "Comment property of term 0 is incorrect.");
            Assert.AreEqual("countries/regions", termList[0].RecommendedTerm, "RecommendedTerm property of term 0 is incorrect.");

            List <IExclusion> term0exclusions = Utilities.ListFromEnum(termList[0].Exclusions);

            Assert.AreEqual(4, term0exclusions.Count, "Number of exclusions for term 0 is incorrect.");
            Assert.AreEqual("and for other fareast countries", term0exclusions[0].Text, "Exclusion 0 of term 0 is incorrect.");
            Assert.AreEqual("\"countries\",", term0exclusions[1].Text, "Exclusion 1 of term 0 is incorrect.");
            Assert.AreEqual("hold true for other countries in the world", term0exclusions[2].Text, "Exclusion 2 of term 0 is incorrect.");
            Assert.AreEqual("lists the available countries in north america", term0exclusions[3].Text, "Exclusion 3 of term 0 is incorrect.");

            Assert.AreEqual("shoot", termList[1].Text, "Text property of term 1 is incorrect.");
            Assert.AreEqual("Profanity", termList[1].Class, "Class property of term 1 is incorrect.");
            Assert.AreEqual("Watch that language!", termList[1].Comment, "Comment property of term 1 is incorrect.");
            Assert.AreEqual("darn", termList[1].RecommendedTerm, "RecommendedTerm property of term 1 is incorrect.");

            List <IExclusion> term1exclusions = Utilities.ListFromEnum(termList[1].Exclusions);

            Assert.AreEqual(3, term1exclusions.Count, "Number of exclusions for term 1 is incorrect.");
            Assert.AreEqual("Did you shoot the sherrif?", term1exclusions[0].Text, "Exclusion 0 of term 1 is incorrect.");
            Assert.AreEqual("I did not shoot the deputy", term1exclusions[1].Text, "Exclusion 1 of term 1 is incorrect.");
            Assert.AreEqual("an old-fashioned shoot-em-up", term1exclusions[2].Text, "Exclusion 2 of term 1 is incorrect.");
        }