示例#1
0
        public void ShouldBulidEmptyClasses()
        {
            //arrange
            var shouldShow = false;

            //act
            var ClassToRender = new CssBuilder()
                                .AddClass("some-class", shouldShow)
                                .Build();

            //assert
            ClassToRender.Should().Be(string.Empty);
        }
示例#2
0
        public void ForceNullForWhitespace_BuildClassesFromAttributes()
        {
            {
                //arrange
                // Simulates Razor Components attribute splatting feature
                IReadOnlyDictionary <string, object> attributes = null;

                //act
                var ClassToRender = new CssBuilder()
                                    .AddClassFromAttributes(attributes)
                                    .NullIfEmpty();
                //assert
                ClassToRender.Should().BeNull();
            }
        }
示例#3
0
        public void ShouldNotThrowWhenNullFor_BuildClassesFromAttributes()
        {
            {
                //arrange
                // Simulates Razor Components attribute splatting feature
                IReadOnlyDictionary <string, object> attributes = null;

                //act
                var ClassToRender = new CssBuilder("item-one")
                                    .AddClassFromAttributes(attributes)
                                    .Build();
                //assert
                ClassToRender.Should().Be("item-one");
            }
        }
示例#4
0
        public void ShouldBuildClassesWithFunc()
        {
            {
                //arrange
                // Simulates Razor Components attribute splatting feature
                IReadOnlyDictionary <string, object> attributes = new Dictionary <string, object> {
                    { "class", "my-custom-class-1" }
                };

                //act
                var ClassToRender = new CssBuilder("item-one")
                                    .AddClass(() => attributes["class"].ToString(), when: attributes.ContainsKey("class"))
                                    .Build();
                //assert
                ClassToRender.Should().Be("item-one my-custom-class-1");
            }
        }
示例#5
0
        public void ShouldNotThrowNoKeyExceptionWithDictionary()
        {
            {
                //arrange
                // Simulates Razor Components attribute splatting feature
                IReadOnlyDictionary <string, object> attributes = new Dictionary <string, object> {
                    { "foo", "bar" }
                };

                //act
                var ClassToRender = new CssBuilder("item-one")
                                    .AddClass(() => attributes["string"].ToString(), when: attributes.ContainsKey("class"))
                                    .Build();
                //assert
                ClassToRender.Should().Be("item-one");
            }
        }
示例#6
0
        public void ShouldBuildClassesFromAttributes()
        {
            {
                //arrange
                // Simulates Razor Components attribute splatting feature
                IReadOnlyDictionary <string, object> attributes = new Dictionary <string, object> {
                    { "class", "my-custom-class-1" }
                };

                //act
                var ClassToRender = new CssBuilder("item-one")
                                    .AddClassFromAttributes(attributes)
                                    .Build();
                //assert
                ClassToRender.Should().Be("item-one my-custom-class-1");
            }
        }
示例#7
0
        public void ShouldBulidConditionalCssClasses()
        {
            //arrange
            var         hasTwo   = false;
            var         hasThree = true;
            Func <bool> hasFive  = () => false;

            //act
            var ClassToRender = new CssBuilder("item-one")
                                .AddClass("item-two", when: hasTwo)
                                .AddClass("item-three", when: hasThree)
                                .AddClass("item-four")
                                .AddClass("item-five", when: hasFive)
                                .Build();

            //assert
            ClassToRender.Should().Be("item-one item-three item-four");
        }
示例#8
0
        public void ShouldBulidConditionalCssClassesUsingMultiplePrefixes()
        {
            //arrange
            var         hasTwo   = true;
            var         hasThree = true;
            Func <bool> hasFive  = () => false;

            //act
            var ClassToRender = new CssBuilder("default")
                                .AddClass("no-prefix-two", when: hasTwo)
                                .SetPrefix("item-")
                                .AddClass("three", when: hasThree)
                                .SetPrefix("namespace-")
                                .AddClass("four")
                                .AddClass("five", when: hasFive)
                                .Build();

            //assert
            ClassToRender.Should().Be("default no-prefix-two item-three namespace-four");
        }