Beispiel #1
0
    public void AddChild(PropFilter filter)
    {
      if (children.Any(e => e.GetType() == typeof(IsNotDefinedFilter)))
        throw new InvalidFilterException("IsNotDefinedFilter cannot have siblings");

      children.Add(filter);
    }
Beispiel #2
0
    public void TestPropFilter()
    {
      var uut = new PropFilter("foo");
      var xmlDoc = new XmlDocument();
      uut.AddChild(new IsNotDefinedFilter());

      xmlDoc.LoadXml(AddNamespace(uut.ToXml()));

      Assert.AreEqual(1, xmlDoc.GetElementsByTagName("C:prop-filter").Count);
      var element = xmlDoc.GetElementsByTagName("C:prop-filter")[0];
      Assert.AreEqual("FOO", element.Attributes["name"].Value);
      Assert.AreEqual(1, element.ChildNodes.Count);

      try
      {
        uut.AddChild(new TimeRangeFilter());
        Assert.Fail();
      }
      catch (InvalidFilterException) { }
      try
      {
        uut.AddChild(new TextMatchFilter());
        Assert.Fail();
      }
      catch (InvalidFilterException) { }
      try
      {
        uut.AddChild(new ParamFilter("bar"));
        Assert.Fail();
      }
      catch (InvalidFilterException) { }

      uut = new PropFilter("foo");
      uut.AddChild(new TimeRangeFilter());
      try
      {
        uut.AddChild(new IsNotDefinedFilter());
        Assert.Fail();
      }
      catch (InvalidFilterException) { }
      try
      {
        uut.AddChild(new TextMatchFilter());
        Assert.Fail();
      }
      catch (InvalidFilterException) { }
      try
      {
        uut.AddChild(new TimeRangeFilter());
        Assert.Fail();
      }
      catch (InvalidFilterException) { }
      uut.AddChild(new ParamFilter("bar"));

      uut = new PropFilter("foo");
      uut.AddChild(new TextMatchFilter());
      try
      {
        uut.AddChild(new IsNotDefinedFilter());
        Assert.Fail();
      }
      catch (InvalidFilterException) { }
      try
      {
        uut.AddChild(new TextMatchFilter());
        Assert.Fail();
      }
      catch (InvalidFilterException) { }
      try
      {
        uut.AddChild(new TimeRangeFilter());
        Assert.Fail();
      }
      catch (InvalidFilterException) { }
      uut.AddChild(new ParamFilter("bar"));

      uut = new PropFilter("foo");
      uut.AddChild(new ParamFilter("bar"));
      try
      {
        uut.AddChild(new IsNotDefinedFilter());
        Assert.Fail();
      }
      catch (InvalidFilterException) { }
    }