Ejemplo n.º 1
0
    public void TestCompFilter()
    {
      var uut = new CompFilter(ResourceType.VEVENT);
      var xmlDoc = new XmlDocument();

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

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

      uut.AddChild(new TimeRangeFilter() { Start = new DateTime(2000, 1, 1, 21, 0, 0) });
      xmlDoc.LoadXml(AddNamespace(uut.ToXml()));
      element = xmlDoc.GetElementsByTagName("C:comp-filter")[0];

      Assert.AreEqual(1, element.ChildNodes.Count);

      try
      {
        uut.AddChild(new TimeRangeFilter());
        Assert.Fail();
      }
      catch (InvalidFilterException) { }

      uut = new CompFilter(ResourceType.VCALENDAR);
      uut.AddChild(new IsNotDefinedFilter());
      try
      {
        uut.AddChild(new CompFilter(ResourceType.VEVENT));
        Assert.Fail();
      }
      catch (InvalidFilterException) { }
    }
Ejemplo n.º 2
0
    public void AddChild(CompFilter filter)
    {
      if (children.Any(e => e.GetType() == typeof(IsNotDefinedFilter)))
        throw new InvalidFilterException("IsNotDefinedFilter cannot have siblings");

      children.Add(filter);
    }
Ejemplo n.º 3
0
    public void TestGetEvents()
    {
      uut.MakeCalendar(user, calendar);

      var evt1 = new Event()
      {
        Summary = "evt1",
        Start = new iCalDateTime(2000, 1, 1, 20, 0, 0),
        End = new iCalDateTime(2000, 1, 1, 21, 0, 0),
      };
      var evt2 = new Event()
      {
        Summary = "evt2",
        Start = new iCalDateTime(2000, 2, 1, 20, 0, 0),
        End = new iCalDateTime(2000, 2, 1, 21, 0, 0),
      };
      var evt3 = new Event()
      {
        Summary = "evt3",
        Location = "adh",
        Start = new iCalDateTime(2000, 3, 1, 20, 0, 0),
        End = new iCalDateTime(2000, 3, 1, 21, 0, 0),
      };
      var todo = new Todo()
      {
        Summary = "todo"
      };

      uut.CreateResource(user, calendar, evt1);
      uut.CreateResource(user, calendar, evt2);
      uut.CreateResource(user, calendar, evt3);
      uut.CreateResource(user, calendar, todo);

      IICalendar events = uut.GetResources(user, calendar);
      Assert.AreEqual(4, events.UniqueComponents.Count());

      var filter = new CompFilter(ResourceType.VCALENDAR);
      Assert.AreEqual(0, uut.GetResources(user, calendar, filter).UniqueComponents.Count());

      var eventFilter = new CompFilter(ResourceType.VEVENT);
      Assert.AreEqual(3, uut.GetResources(user, calendar, eventFilter).UniqueComponents.Count());

      var todoFilter = new CompFilter(ResourceType.VTODO);
      Assert.AreEqual(1, uut.GetResources(user, calendar, todoFilter).UniqueComponents.Count());
    }