public void ShouldBulidEmptyClasses() { //arrange var shouldShow = false; //act var ClassToRender = new CssBuilder() .AddClass("some-class", shouldShow) .Build(); //assert ClassToRender.Should().Be(string.Empty); }
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(); } }
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"); } }
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"); } }
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"); } }
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"); } }
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"); }
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"); }