public void EmptyNodes_EqualityNullTest(Fb2Node instance) { instance.Should().NotBe(null); var instanceTwo = Fb2NodeFactory.GetNodeByName(instance.Name); instanceTwo.Should().NotBe(null); instance.Should().Be(instanceTwo); }
public void AddAttribute_AllowedAttribute_EscapesAttributeValue_Works(Fb2Node instance) { instance.Should().NotBe(null); if (!instance.AllowedAttributes.Any()) { return; } var firstAlowedAttributeName = instance.AllowedAttributes.First(); instance.AddAttribute(new Fb2Attribute(firstAlowedAttributeName, "<testValue")); CheckAttributes(instance, 1, firstAlowedAttributeName, "<testValue"); instance.AddAttribute(new Fb2Attribute(firstAlowedAttributeName, "testValue>")); CheckAttributes(instance, 1, firstAlowedAttributeName, "testValue>"); instance.AddAttribute(new Fb2Attribute(firstAlowedAttributeName, @"""testValue")); CheckAttributes(instance, 1, firstAlowedAttributeName, ""testValue"); instance.AddAttribute(new Fb2Attribute(firstAlowedAttributeName, "testValue'tv")); CheckAttributes(instance, 1, firstAlowedAttributeName, "testValue'tv"); instance.AddAttribute(new Fb2Attribute(firstAlowedAttributeName, "testValue&tv")); CheckAttributes(instance, 1, firstAlowedAttributeName, "testValue&tv"); instance.AddAttribute(new Fb2Attribute(firstAlowedAttributeName, @"<""testValue&tv'2"">")); CheckAttributes(instance, 1, firstAlowedAttributeName, "<"testValue&tv'2">"); instance.AddAttribute(new Fb2Attribute(firstAlowedAttributeName, " test value with whitespace ")); CheckAttributes(instance, 1, firstAlowedAttributeName, " test value with whitespace "); }
public void AddAttribute_InvalidAttribute_Throws(Fb2Node instance) { instance.Should().NotBe(null); if (!instance.AllowedAttributes.Any()) { return; } //instance // .Invoking(i => i.AddAttribute(() => new Fb2Attribute("testK", ""))) // .Should() // .ThrowExactly<InvalidAttributeException>(); instance .Invoking(i => i.AddAttribute(() => new Fb2Attribute("", "testV"))) .Should() .ThrowExactly <InvalidAttributeException>(); //instance // .Invoking(i => i.AddAttribute(new Fb2Attribute("testK", ""))) // .Should() // .ThrowExactly<InvalidAttributeException>(); instance .Invoking(i => i.AddAttribute(new Fb2Attribute("", "testV"))) .Should() .ThrowExactly <InvalidAttributeException>(); //instance // .Invoking(i => i.AddAttribute(new Fb2Attribute("testK", ""))) // .Should() // .ThrowExactly<InvalidAttributeException>(); instance .Invoking(i => i.AddAttribute(new Fb2Attribute("", "testV"))) .Should() .ThrowExactly <InvalidAttributeException>(); instance .Invoking(i => i.AddAttributes(new Fb2Attribute("", ""), new Fb2Attribute("", ""))) .Should() .ThrowExactly <InvalidAttributeException>(); instance .Invoking(i => i.AddAttributes( new List <Fb2Attribute> { new Fb2Attribute("testKey", ""), new Fb2Attribute("", "testValue") } )) .Should() .ThrowExactly <InvalidAttributeException>(); }
private static void CheckAttributes( Fb2Node instance, int expectedCount, string expectedName, string expectedValue) { instance.Should().NotBeNull(); instance.Attributes.Should().HaveCount(expectedCount); instance.Attributes.Should().Contain((attr) => attr.Key == expectedName); //instance.Attributes[expectedName].Should().Be(expectedValue); instance.GetAttribute(expectedName).Value.Should().Be(expectedValue); }
public void AddAttribute_NoAttributesAllowed_Throws(Fb2Node instance) { instance.Should().NotBe(null); if (instance.AllowedAttributes.Any()) { return; } instance .Invoking(i => i.AddAttribute(new Fb2Attribute("testKey", "testValue"))) .Should() .ThrowExactly <NoAttributesAllowedException>() .WithMessage($"Node '{instance.Name}' has no allowed attributes."); instance .Invoking(i => i.AddAttribute(() => new Fb2Attribute("testKey", "testValue"))) .Should() .ThrowExactly <NoAttributesAllowedException>() .WithMessage($"Node '{instance.Name}' has no allowed attributes."); instance .Invoking(i => i.AddAttribute(new Fb2Attribute("testKey", "testValue"))) .Should() .ThrowExactly <NoAttributesAllowedException>() .WithMessage($"Node '{instance.Name}' has no allowed attributes."); instance .Invoking(i => i.AddAttributes( new Fb2Attribute("testKey", "testValue"), new Fb2Attribute("testKey2", "testValue2"))) .Should() .ThrowExactly <NoAttributesAllowedException>() .WithMessage($"Node '{instance.Name}' has no allowed attributes."); instance .Invoking(i => i.AddAttributes( new List <Fb2Attribute> { new Fb2Attribute("testKey", "testValue"), new Fb2Attribute("testKey2", "testValue2") })) .Should() .ThrowExactly <NoAttributesAllowedException>() .WithMessage($"Node '{instance.Name}' has no allowed attributes."); instance .Invoking(async i => await i.AddAttributeAsync(() => Task.FromResult(new Fb2Attribute("testKey", "testValue")))) .Should() .ThrowExactlyAsync <NoAttributesAllowedException>() .WithMessage($"Node '{instance.Name}' has no allowed attributes."); }
public void AddAttribute_NotAllowedAttribute_Throws(Fb2Node instance) { instance.Should().NotBe(null); if (!instance.AllowedAttributes.Any()) { return; } instance .Invoking(i => i.AddAttribute(new Fb2Attribute("NotExistingKey", "NotExistingValue"))) .Should() .ThrowExactly <UnexpectedAtrributeException>(); }
public void Clone_AddAttribute_NotEquals(Fb2Node instance) { if (instance.AllowedAttributes == null || !instance.AllowedAttributes.Any()) { return; } var instanceTwo = instance.Clone() as Fb2Node; instanceTwo.AddAttribute(new Fb2Attribute(instance.AllowedAttributes.First(), "testValue")); instance.Should().NotBe(instanceTwo); instance.Attributes.Should().BeEmpty(); instanceTwo.Attributes.Should().NotBeEmpty().And.HaveCount(1); }
public void AddAttribute_AllowedAttribute_Works(Fb2Node instance) { instance.Should().NotBe(null); if (!instance.AllowedAttributes.Any()) { return; } var firstAlowedAttributeName = instance.AllowedAttributes.First(); instance.AddAttribute(new Fb2Attribute(firstAlowedAttributeName, "testValue")); var attributes = instance.Attributes; //attributes.Should().HaveCount(1).And.ContainKey(firstAlowedAttributeName); //attributes[firstAlowedAttributeName].Should().Be("testValue"); attributes.Should().HaveCount(1).And.Contain((attr) => attr.Key == firstAlowedAttributeName); attributes[0].Value.Should().Be("testValue"); }
public void AddAttribute_Whitespaces_Throws(Fb2Node instance) { instance.Should().NotBe(null); if (!instance.AllowedAttributes.Any()) { return; } instance // whitespace .Invoking(i => i.AddAttribute(new Fb2Attribute(" NotExistingKey", "NotExistingValue"))) .Should() .ThrowExactly <UnexpectedAtrributeException>(); instance // whitespace .Invoking(i => i.AddAttribute(new Fb2Attribute(" NotExistingKey", "NotExistingValue"))) .Should() .ThrowExactly <UnexpectedAtrributeException>(); instance .Invoking(i => i.AddAttribute(new Fb2Attribute('\t' + "NotExistingKey", "NotExistingValue"))) .Should() .ThrowExactly <UnexpectedAtrributeException>(); instance .Invoking(i => i.AddAttribute(new Fb2Attribute(Environment.NewLine + "NotExistingKey", "NotExistingValue"))) .Should() .ThrowExactly <UnexpectedAtrributeException>(); instance .Invoking(i => i.AddAttribute(new Fb2Attribute('\n' + "NotExistingKey", "NotExistingValue"))) .Should() .ThrowExactly <UnexpectedAtrributeException>(); instance .Invoking(i => i.AddAttribute(new Fb2Attribute('\r' + "NotExistingKey", "NotExistingValue"))) .Should() .ThrowExactly <UnexpectedAtrributeException>(); }
public void AddAttribute_EmptyOrNull_Throws(Fb2Node instance) { instance.Should().NotBe(null); if (!instance.AllowedAttributes.Any()) { return; } instance .Invoking(i => i.AddAttribute((Fb2Attribute)null)) .Should() .ThrowExactly <ArgumentNullException>(); instance .Invoking(i => i.AddAttributeAsync(null)) .Should() .ThrowExactlyAsync <ArgumentNullException>(); instance .Invoking(i => i.AddAttributes()) .Should() .ThrowExactly <ArgumentNullException>(); instance .Invoking(i => i.AddAttributes(Array.Empty <Fb2Attribute>())) .Should() .ThrowExactly <ArgumentNullException>(); instance .Invoking(i => i.AddAttributes((List <Fb2Attribute>)null)) .Should() .ThrowExactly <ArgumentNullException>(); //instance // .Invoking(i => i.AddAttributes(new Dictionary<string, string>())) // .Should() // .ThrowExactly<ArgumentNullException>(); }
public void CloneNode_EqualityTest(Fb2Node instance) { var instanceTwo = Fb2NodeFactory.GetNodeByName(instance.Name); instance.Should().Be(instanceTwo); }