예제 #1
0
    public void AddChild(TimeRangeFilter filter)
    {
      if (children.Any(e => e.GetType() == typeof(TimeRangeFilter)))
        throw new InvalidFilterException("Only one TimeRangeFilter is allowed");
      if (children.Any(e => e.GetType() == typeof(IsNotDefinedFilter)))
        throw new InvalidFilterException("IsNotDefinedFilter cannot have siblings");

      children.Add(filter);
    }
예제 #2
0
    public void AddChild(TimeRangeFilter filter)
    {
      if (children.Any(e => e.GetType() == typeof(IsNotDefinedFilter)))
        throw new InvalidFilterException("IsNotDefinedFilter cannot have siblings");
      if (children.Any(e => e.GetType() == typeof(TimeRangeFilter)))
        throw new InvalidFilterException("Children already contains TimeRangeFilter");
      if (children.Any(e => e.GetType() == typeof(TextMatchFilter)))
        throw new InvalidFilterException("Children already contains TextMatchFilter");

      children.Add(filter);
    }
예제 #3
0
    public void TestTimeRangeFilter()
    {
      var uut = new TimeRangeFilter();

      try
      {
        uut.ToXml();
        Assert.Fail();
      }
      catch (InvalidFilterException) { }

      uut.Start = new DateTime(2000, 1, 1, 20, 0, 0);

      var xmlDoc = new XmlDocument();
      xmlDoc.LoadXml(AddNamespace(uut.ToXml()));

      Assert.AreEqual(1, xmlDoc.GetElementsByTagName("C:time-range").Count);
      var element = xmlDoc.GetElementsByTagName("C:time-range")[0];
      Assert.AreEqual(uut.Start.Value.ToString("yyyyMMdd'T'HHmmss'Z'"), element.Attributes["start"].Value);
      Assert.IsNull(uut.End);

      uut.End = new DateTime(2000, 1, 1, 21, 0, 0);
      xmlDoc.LoadXml(AddNamespace(uut.ToXml()));
      element = xmlDoc.GetElementsByTagName("C:time-range")[0];

      Assert.AreEqual(uut.Start.Value.ToString("yyyyMMdd'T'HHmmss'Z'"), element.Attributes["start"].Value);
      Assert.AreEqual(uut.End.Value.ToString("yyyyMMdd'T'HHmmss'Z'"), element.Attributes["end"].Value);

      uut.Start = DateTime.Now.AddHours(1);
      uut.End = DateTime.Now;
      try
      {
        uut.ToXml();
        Assert.Fail();
      }
      catch (InvalidFilterException) { }
    }