Esempio n. 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);
        }
Esempio n. 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();
            }
        }
Esempio n. 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");
            }
        }
Esempio n. 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");
            }
        }
Esempio n. 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");
            }
        }
Esempio n. 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");
            }
        }
Esempio n. 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");
        }
Esempio n. 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");
        }