public void AddChild(ParamFilter filter) { if (children.Any(e => e.GetType() == typeof(IsNotDefinedFilter))) throw new InvalidFilterException("IsNotDefinedFilter cannot have siblings"); children.Add(filter); }
public void TestParamFilter() { var uut = new ParamFilter("bar"); var xmlDoc = new XmlDocument(); uut.AddChild(new IsNotDefinedFilter()); xmlDoc.LoadXml(AddNamespace(uut.ToXml())); Assert.AreEqual(1, xmlDoc.GetElementsByTagName("C:param-filter").Count); var element = xmlDoc.GetElementsByTagName("C:param-filter")[0]; Assert.AreEqual("BAR", element.Attributes["name"].Value); Assert.AreEqual(1, element.ChildNodes.Count); try { uut.AddChild(new IsNotDefinedFilter()); Assert.Fail(); } catch (InvalidFilterException) { } try { uut.AddChild(new TextMatchFilter()); Assert.Fail(); } catch (InvalidFilterException) { } uut = new ParamFilter("bar"); uut.AddChild(new TextMatchFilter()); try { uut.AddChild(new IsNotDefinedFilter()); Assert.Fail(); } catch (InvalidFilterException) { } try { uut.AddChild(new TextMatchFilter()); Assert.Fail(); } catch (InvalidFilterException) { } }