Exemplo n.º 1
0
        public void SequenceInfoNode_AppendAttribute_Works()
        {
            // setup
            var sequenceInfo = new SequenceInfo();

            sequenceInfo.AllowedAttributes.Should().HaveCount(3);
            sequenceInfo.Attributes.Should().BeEmpty();

            sequenceInfo
            .AddAttributes(
                new Fb2Attribute(AttributeNames.Name, "Test Sequence"),
                new Fb2Attribute(AttributeNames.Number, "1"))
            .AppendAttribute(AttributeNames.Language, "eng");

            sequenceInfo.Attributes.Should().HaveCount(3);

            // query
            sequenceInfo.TryGetAttribute(AttributeNames.Name, out var nameResult)
            .Should()
            .BeTrue();
            nameResult.Should().Be(new Fb2Attribute(AttributeNames.Name, "Test Sequence"));

            sequenceInfo.TryGetAttribute(AttributeNames.Number, out var numberResult)
            .Should()
            .BeTrue();
            numberResult.Should().Be(new Fb2Attribute(AttributeNames.Number, "1"));

            sequenceInfo.TryGetAttribute(AttributeNames.Language, out var langResult)
            .Should()
            .BeTrue();
            langResult.Should().Be(new Fb2Attribute(AttributeNames.Language, "eng"));
        }
Exemplo n.º 2
0
        public void Fb2Node_RemoveAttributes_ByPredicate()
        {
            // setup
            var sequenceInfo = new SequenceInfo();

            sequenceInfo.AllowedAttributes.Should().HaveCount(3);
            sequenceInfo.Attributes.Should().BeEmpty();

            sequenceInfo
            .AddAttributes(
                new Fb2Attribute(AttributeNames.Name, "Test Sequence"),
                new Fb2Attribute(AttributeNames.Number, "1"))
            .AddAttribute(() => new Fb2Attribute(AttributeNames.Language, "eng"));

            sequenceInfo.Attributes.Should().HaveCount(3);

            //Func<KeyValuePair<string, string>, bool> nameWrongCasePredicate = (kvp) => kvp.Key.Equals("nAMe");
            //Func<KeyValuePair<string, string>, bool> nameAttributePredicate = (kvp) => kvp.Key.Equals(AttributeNames.Name);

            Func <Fb2Attribute, bool> nameWrongCasePredicate = (kvp) => kvp.Key.Equals("nAMe");
            Func <Fb2Attribute, bool> nameAttributePredicate = (kvp) => kvp.Key.Equals(AttributeNames.Name);

            sequenceInfo.RemoveAttribute(nameWrongCasePredicate); // not removing anything, no matches
            sequenceInfo.Attributes.Should().HaveCount(3);

            sequenceInfo.RemoveAttribute(nameAttributePredicate);
            sequenceInfo.Attributes.Should().HaveCount(2).And.NotContain((attr) => attr.Key == AttributeNames.Name);
        }
Exemplo n.º 3
0
        public void Fb2Node_RemoveAttributes_ByAttributeName_CaseInSensitive()
        {
            // setup
            var sequenceInfo = new SequenceInfo();

            sequenceInfo.AllowedAttributes.Should().HaveCount(3);
            sequenceInfo.Attributes.Should().BeEmpty();

            sequenceInfo
            .AddAttributes(
                new Fb2Attribute(AttributeNames.Name, "Test Sequence"),
                new Fb2Attribute(AttributeNames.Number, "1"))
            .AddAttribute(() => new Fb2Attribute(AttributeNames.Language, "eng"));

            sequenceInfo.Attributes.Should().HaveCount(3);

            sequenceInfo.RemoveAttribute("NamE", true);
            //sequenceInfo.Attributes.Should().HaveCount(2).And.NotContainKey(AttributeNames.Name);
            sequenceInfo.Attributes.Should().HaveCount(2).And.NotContain((attr) => attr.Key == AttributeNames.Name);

            sequenceInfo.RemoveAttribute("NUmBeR", true);
            //sequenceInfo.Attributes.Should().HaveCount(1).And.NotContainKey(AttributeNames.Name, AttributeNames.Number);
            sequenceInfo.Attributes.Should().HaveCount(1).And.NotContain((attr) => attr.Key == AttributeNames.Name || attr.Key == AttributeNames.Number);

            sequenceInfo.RemoveAttribute("lAnG", true);
            sequenceInfo.Attributes.Should().BeEmpty();
        }
Exemplo n.º 4
0
        public void SequenceInfoNode_HasAttribute_Works()
        {
            // setup
            var sequenceInfo = new SequenceInfo();

            sequenceInfo.AllowedAttributes.Should().HaveCount(3);
            sequenceInfo.Attributes.Should().BeEmpty();

            sequenceInfo
            .AddAttributes(
                new Fb2Attribute(AttributeNames.Name, "Test Sequence"),
                new Fb2Attribute(AttributeNames.Number, "1"))
            .AddAttribute(() => new Fb2Attribute(AttributeNames.Language, "eng"));

            sequenceInfo.Attributes.Should().HaveCount(3);

            // query

            var hasNameAttribute = sequenceInfo.HasAttribute(AttributeNames.Name);

            hasNameAttribute.Should().BeTrue();

            var hasNameAttributeWrongCasing = sequenceInfo.HasAttribute("NaMe");

            hasNameAttributeWrongCasing.Should().BeFalse();

            var hasNameAttributeIgnoringCasing = sequenceInfo.HasAttribute("NaMe", true);

            hasNameAttributeIgnoringCasing.Should().BeTrue();

            var hasNameAttributeKeyWrongCasing = sequenceInfo.HasAttribute(new Fb2Attribute("NaMe", "Test Sequence"));

            hasNameAttributeKeyWrongCasing.Should().BeTrue(); // default key case-insensitive comparison

            var hasNameAttributeValueWrongCasing = sequenceInfo.HasAttribute(new Fb2Attribute(AttributeNames.Name, "TeSt SeQuEnCe"));

            hasNameAttributeValueWrongCasing.Should().BeFalse();

            //var hasNameAttributeKeyWrongCasingIgnore = sequenceInfo.HasAttribute("NaMe", "Test Sequence", true);
            //hasNameAttributeKeyWrongCasingIgnore.Should().BeTrue();

            //var hasNameAttributeValueWrongCasingIgnore = sequenceInfo.HasAttribute(AttributeNames.Name, "TeSt SeQuEnCe", true);
            //hasNameAttributeValueWrongCasingIgnore.Should().BeTrue();

            sequenceInfo.HasAttribute(new Fb2Attribute(AttributeNames.Name, "Test Sequence")).Should().BeTrue();
            sequenceInfo.HasAttribute(new Fb2Attribute(AttributeNames.Number, "1")).Should().BeTrue();
            sequenceInfo.HasAttribute(new Fb2Attribute(AttributeNames.Language, "eng")).Should().BeTrue();
        }
Exemplo n.º 5
0
        public void SequenceInfoNode_TryGetAttribute_Works()
        {
            // setup
            var sequenceInfo = new SequenceInfo();

            sequenceInfo.AllowedAttributes.Should().HaveCount(3);
            sequenceInfo.Attributes.Should().BeEmpty();

            sequenceInfo
            .AddAttributes(
                new Fb2Attribute(AttributeNames.Name, "Test Sequence"),
                new Fb2Attribute(AttributeNames.Number, "1"))
            .AddAttribute(() => new Fb2Attribute(AttributeNames.Language, "eng"));

            sequenceInfo.Attributes.Should().HaveCount(3);

            // query

            // case sensitive
            sequenceInfo.TryGetAttribute(AttributeNames.Name, out var nameResult)
            .Should()
            .BeTrue();
            nameResult.Should().Be(new Fb2Attribute(AttributeNames.Name, "Test Sequence"));

            sequenceInfo.TryGetAttribute(AttributeNames.Number, out var numberResult)
            .Should()
            .BeTrue();
            numberResult.Should().Be(new Fb2Attribute(AttributeNames.Number, "1"));

            sequenceInfo.TryGetAttribute(AttributeNames.Language, out var langResult)
            .Should()
            .BeTrue();
            langResult.Should().Be(new Fb2Attribute(AttributeNames.Language, "eng"));

            // case sensitive, wrong key casing
            sequenceInfo.TryGetAttribute("NaMe", out var nameResultInvalidCasing)
            .Should()
            .BeFalse();
            //nameResultInvalidCasing.Should().Be(default(KeyValuePair<string, string>));
            nameResultInvalidCasing.Should().Be(null);

            sequenceInfo.TryGetAttribute("NuMbEr", out var numberResultInvalidCasing)
            .Should()
            .BeFalse();
            //numberResultInvalidCasing.Should().Be(default(KeyValuePair<string, string>));
            numberResultInvalidCasing.Should().Be(null);

            sequenceInfo.TryGetAttribute("LaNg", out var langResultIvalidCasing)
            .Should()
            .BeFalse();
            //langResultIvalidCasing.Should().Be(default(KeyValuePair<string, string>));
            langResultIvalidCasing.Should().Be(null);

            // case in-sensitive, wrong key casing
            sequenceInfo.TryGetAttribute("NaMe", true, out var nameResultInvalidCasingIgnore)
            .Should()
            .BeTrue();
            nameResultInvalidCasingIgnore.Should().Be(new Fb2Attribute(AttributeNames.Name, "Test Sequence"));

            sequenceInfo.TryGetAttribute("NuMbEr", true, out var numberResultInvalidCasingIgnore)
            .Should()
            .BeTrue();
            numberResultInvalidCasingIgnore.Should().Be(new Fb2Attribute(AttributeNames.Number, "1"));

            sequenceInfo.TryGetAttribute("LaNg", true, out var langResultIvalidCasingIgnore)
            .Should()
            .BeTrue();
            langResultIvalidCasingIgnore.Should().Be(new Fb2Attribute(AttributeNames.Language, "eng"));
        }
Exemplo n.º 6
0
        public void SequenceInfoNode_GetAttribute_Works()
        {
            // setup
            var sequenceInfo = new SequenceInfo();

            sequenceInfo.AllowedAttributes.Should().HaveCount(3);
            sequenceInfo.Attributes.Should().BeEmpty();

            sequenceInfo
            .AddAttributes(
                new Fb2Attribute(AttributeNames.Name, "Test Sequence"),
                new Fb2Attribute(AttributeNames.Number, "1"))
            .AddAttribute(() => new Fb2Attribute(AttributeNames.Language, "eng"));

            sequenceInfo.Attributes.Should().HaveCount(3);

            // query

            //sequenceInfo.GetAttribute(AttributeNames.Name)
            //    .Should()
            //    .Be(new KeyValuePair<string, string>(AttributeNames.Name, "Test Sequence"));

            var expectedAttr = new Fb2Attribute(AttributeNames.Name, "Test Sequence");

            sequenceInfo.GetAttribute(AttributeNames.Name)
            .Should()
            .Be(new Fb2Attribute(AttributeNames.Name, "Test Sequence"));
            //sequenceInfo.GetAttribute(AttributeNames.Number)
            //    .Should()
            //    .Be(new KeyValuePair<string, string>(AttributeNames.Number, "1"));
            sequenceInfo.GetAttribute(AttributeNames.Number)
            .Should()
            .Be(new Fb2Attribute(AttributeNames.Number, "1"));

            //sequenceInfo.GetAttribute(AttributeNames.Language)
            //    .Should()
            //    .Be(new KeyValuePair<string, string>(AttributeNames.Language, "eng"));
            sequenceInfo.GetAttribute(AttributeNames.Language)
            .Should()
            .Be(new Fb2Attribute(AttributeNames.Language, "eng"));

            //sequenceInfo.GetAttribute("NaMe").Should().Be(default(KeyValuePair<string, string>));
            //sequenceInfo.GetAttribute("NuMbEr").Should().Be(default(KeyValuePair<string, string>));
            //sequenceInfo.GetAttribute("LaNg").Should().Be(default(KeyValuePair<string, string>));

            sequenceInfo.GetAttribute("NaMe").Should().Be(null);
            sequenceInfo.GetAttribute("NuMbEr").Should().Be(null);
            sequenceInfo.GetAttribute("LaNg").Should().Be(null);

            sequenceInfo.GetAttribute("NaMe", true)
            .Should()
            .Be(new Fb2Attribute(AttributeNames.Name, "Test Sequence"));
            sequenceInfo.GetAttribute("NuMbEr", true)
            .Should()
            .Be(new Fb2Attribute(AttributeNames.Number, "1"));
            sequenceInfo.GetAttribute("LaNg", true)
            .Should()
            .Be(new Fb2Attribute(AttributeNames.Language, "eng"));

            //sequenceInfo.GetAttribute("NaMe", true)
            //    .Should()
            //    .Be(new KeyValuePair<string, string>(AttributeNames.Name, "Test Sequence"));
            //sequenceInfo.GetAttribute("NuMbEr", true)
            //    .Should()
            //    .Be(new KeyValuePair<string, string>(AttributeNames.Number, "1"));
            //sequenceInfo.GetAttribute("LaNg", true)
            //    .Should()
            //    .Be(new KeyValuePair<string, string>(AttributeNames.Language, "eng"));
        }