public void ContainerNode_InvalidQueryChildren_Throws(Fb2Container node) { var invalidNodeName = "blahNameInvalid"; node.Invoking(n => n.GetDescendants(invalidNodeName)) .Should() .ThrowExactly <InvalidNodeException>() .And.Message.Should().Be("'blahNameInvalid' is not known Fb2 node name."); node.Invoking(n => n.GetFirstChild(invalidNodeName)) .Should() .ThrowExactly <InvalidNodeException>() .And.Message.Should().Be("'blahNameInvalid' is not known Fb2 node name."); node.Invoking(n => n.GetFirstDescendant(invalidNodeName)) .Should() .ThrowExactly <InvalidNodeException>() .And.Message.Should().Be("'blahNameInvalid' is not known Fb2 node name."); node.Invoking(n => n.TryGetFirstDescendant(invalidNodeName, out var result)) .Should() .ThrowExactly <InvalidNodeException>() .And.Message.Should().Be("'blahNameInvalid' is not known Fb2 node name."); //result.Should().BeNull(); node.Invoking(n => n.GetChildren(invalidNodeName)) .Should() .ThrowExactly <InvalidNodeException>() .And.Message.Should().Be("'blahNameInvalid' is not known Fb2 node name."); }
public void Container_RemoveContent_NullNode_Throws(Fb2Container node) { var firstAllowedNode = Fb2NodeFactory.GetNodeByName(node.AllowedElements.First()); node.Invoking(n => n.RemoveContent((Fb2Node)null)) // Fb2Node .Should() .ThrowExactly <ArgumentNullException>(); node.Invoking(n => n.RemoveContent((IEnumerable <Fb2Node>)null)) // IEnumerable<Fb2Node> .Should() .ThrowExactly <ArgumentNullException>(); node.Invoking(n => n.RemoveContent((Func <Fb2Node, bool>)null)) // Func<Fb2Node, bool> .Should() .ThrowExactly <ArgumentNullException>(); node.Invoking(n => n.RemoveContent(new List <Fb2Node> { null, null })) // IEnumerable<Fb2Node> .Should() .ThrowExactly <ArgumentNullException>(); node.Invoking(n => n.RemoveContent(new List <Fb2Node> { firstAllowedNode, null })) // IEnumerable<Fb2Node> .Should() .ThrowExactly <ArgumentNullException>(); }
public void GetFirstDescendant_NullParam_Throws(Fb2Container node) { node.Invoking(n => n.GetFirstDescendant((string)null)) .Should() .ThrowExactly <ArgumentNullException>(); node.Invoking(n => n.GetFirstDescendant("")) .Should() .ThrowExactly <ArgumentNullException>(); node.Invoking(n => n.GetFirstDescendant((Func <Fb2Node, bool>)null)) .Should() .ThrowExactly <ArgumentNullException>(); }
public void Container_AddContent_ByInvalidName_Throws(Fb2Container node) { node.Invoking(n => n.AddContent("impostorNodeName")) .Should() .ThrowExactly <InvalidNodeException>() .WithMessage("'impostorNodeName' is not known Fb2 node name."); }
public void Container_CantContainText_AddTextContent_Throws(Fb2Container node) { node.Should().NotBeNull(); if (node.CanContainText) { return; } node.Invoking(n => n.AddContent(new TextItem().AddContent("test text"))) .Should() .Throw <UnexpectedNodeException>() .WithMessage($"Node '{node.Name}' can not contain 'text'."); node.Invoking(n => n.AddTextContent("test text")) .Should() .Throw <UnexpectedNodeException>() .WithMessage($"Node '{node.Name}' can not contain 'text'."); }
public void Container_AddUnknownNode_Throws(Fb2Container node) { var impostor = new ImpostorNode(); node.Invoking(n => n.AddContent(impostor)) // Fb2Node .Should() .ThrowExactly <InvalidNodeException>() .WithMessage($"'Impostor' is not known Fb2 node name."); node.Invoking(n => n.AddContent(impostor.Name)) // name .Should() .ThrowExactly <InvalidNodeException>() .WithMessage($"'Impostor' is not known Fb2 node name."); var sneakyImpostor = new ImpostorNode(ElementNames.Paragraph); node.Invoking(n => n.AddContent(sneakyImpostor)) // Fb2Node .Should() .ThrowExactly <InvalidNodeException>() .WithMessage($"'{sneakyImpostor.Name}' is not known Fb2 node name."); }
public void Container_AddContent_NotAllowedElement_Throws(Fb2Container node) { node.Should().NotBeNull(); var dataCollection = new Fb2ContainerCollection(); var notAllowedElementName = dataCollection.AllElementsNames.Except(node.AllowedElements).Skip(5).First(); var notAllowedNode = Fb2NodeFactory.GetNodeByName(notAllowedElementName); node.Invoking(n => n.AddContent(notAllowedNode.Name)) // string nodeName .Should() .Throw <UnexpectedNodeException>() .WithMessage($"Node '{node.Name}' can not contain '{notAllowedNode.Name}'."); node.Invoking(n => n.AddContent(notAllowedNode)) // Fb2Node .Should() .Throw <UnexpectedNodeException>() .WithMessage($"Node '{node.Name}' can not contain '{notAllowedNode.Name}'."); // params Fb2Node[] nodes node.Invoking(n => n.AddContent(notAllowedNode, notAllowedNode)) // lol .Should() .Throw <UnexpectedNodeException>() .WithMessage($"Node '{node.Name}' can not contain '{notAllowedNode.Name}'."); node.Invoking(n => n.AddContent(() => notAllowedNode)) // Func<Fb2Node> .Should() .Throw <UnexpectedNodeException>() .WithMessage($"Node '{node.Name}' can not contain '{notAllowedNode.Name}'."); node.Invoking(n => n.AddContent(new List <Fb2Node> { notAllowedNode })) // IEnumerable<Fb2Node> .Should() .Throw <UnexpectedNodeException>() .WithMessage($"Node '{node.Name}' can not contain '{notAllowedNode.Name}'."); node.Invoking(async n => await n.AddContentAsync(async() => await Task.FromResult(notAllowedNode))) // async node provider .Should() .ThrowExactlyAsync <UnexpectedNodeException>() .WithMessage($"Node '{node.Name}' can not contain '{notAllowedNode.Name}'."); }
public void GetFirstChild_NullParam_Throws(Fb2Container node) { node.Invoking(n => n.GetFirstChild((Func <Fb2Node, bool>)null)) .Should() .ThrowExactly <ArgumentNullException>(); }
public void Container_AddContent_NullNode_Throws(Fb2Container node) { node.Should().NotBeNull(); var firstAllowedNode = Fb2NodeFactory.GetNodeByName(node.AllowedElements.First()); node.Invoking(n => n.AddContent((Fb2Node)null)) // Fb2Node .Should() .Throw <ArgumentNullException>(); //string nodeName node.Invoking(n => n.AddContent("")).Should().Throw <ArgumentNullException>(); //string nodeName node.Invoking(n => n.AddContent((string)null)).Should().Throw <ArgumentNullException>(); // params Fb2Node[] nodes node.Invoking(n => n.AddContent()).Should().Throw <ArgumentNullException>(); // params Fb2Node[] nodes node.Invoking(n => n.AddContent(null, null)) // lol .Should() .Throw <ArgumentNullException>(); node.Invoking(n => n.AddContent(() => null)) // Func<Fb2Node> .Should() .Throw <ArgumentNullException>(); node.Invoking(n => n.AddContent((Func <Fb2Node>)null)) // Func<Fb2Node> .Should() .Throw <ArgumentNullException>(); node.Invoking(n => n.AddContent((List <Fb2Node>)null)) // IEnumerable<Fb2Node> .Should() .Throw <ArgumentNullException>(); node.Invoking(n => n.AddContent(new List <Fb2Node> { null, null })) // IEnumerable<Fb2Node> .Should() .Throw <ArgumentNullException>(); node.Invoking(n => n.AddContent(new List <Fb2Node> { firstAllowedNode, null })) // IEnumerable<Fb2Node> .Should() .Throw <ArgumentNullException>(); node.Invoking(async n => await n.AddContentAsync( async() => await Task.FromResult <Fb2Node>(null))) // async node provider .Should() .ThrowExactlyAsync <ArgumentNullException>(); node.Invoking(async n => await n.AddContentAsync(null)) .Should() .ThrowExactlyAsync <ArgumentNullException>(); }