public static IGradientSource ToSource(this GradientBuilder builder) { return(new GradientCollection { Gradients = new GradientElements <Gradient>(builder.Build()) }); }
public void AddCssGradient_InvalidCss_InvalidOperationException(string css) { // Arrange var builder = new GradientBuilder().AddCssGradient(css); // Act Action action = () => builder.Build(); // Assert action.Should().Throw <InvalidOperationException>(); }
public Gradient[] ParseCss(string css) { var builder = new GradientBuilder(); if (string.IsNullOrWhiteSpace(css)) { return(builder.Build()); } var reader = new CssReader(css); while (reader.CanRead) { var token = reader.Read().Trim(); var definition = _definitions.FirstOrDefault(x => x.IsMatch(token)); definition?.Parse(reader, builder); reader.MoveNext(); } return(builder.Build().Reverse().ToArray()); }
public void AddOnlyStops_DefaultGradientWithStops() { // Arrange var builder = new GradientBuilder(); // Act builder.AddStop(Colors.White); builder.AddStop(Colors.Black); var gradients = builder.Build(); // Assert using (new AssertionScope()) { gradients.Should().HaveCount(1); gradients[0].Should().BeOfType <LinearGradient>(); gradients[0].GetStops().Should().HaveCount(2); } }
public void AddGradient_AndStops_SingleGradientWithStops(GradientBuilderTestCase testCase) { // Arrange var builder = new GradientBuilder(); // Act testCase.AddGradientTo(builder); builder.AddStop(Colors.White); builder.AddStop(Colors.Black); var gradients = builder.Build(); // Assert using (new AssertionScope()) { gradients.Should().HaveCount(1); gradients[0].GetStops().Should().HaveCount(2); } }
public void Parse_ValidGradientCss_ExpectedGradientReturned(string css, LinearGradient expectedGradient) { // Arrange var reader = new CssReader(css); var builder = new GradientBuilder(); var definition = new LinearGradientDefinition(); // Act definition.Parse(reader, builder); // Assert var result = builder.Build(); using (new AssertionScope()) { result.Should().HaveCount(1); var linearGradient = result[0] as LinearGradient; linearGradient.Should().NotBeNull(); linearGradient.Should().BeEquivalentTo(expectedGradient); } }
public void AddStops_AndGradient_AndStops_TwoGradientsWithStops(GradientBuilderTestCase testCase) { // Arrange var builder = new GradientBuilder(); // Act builder.AddStop(Color.Red); testCase.AddGradientTo(builder); builder.AddStop(Color.White); builder.AddStop(Color.Black); var gradients = builder.Build(); // Assert using (new AssertionScope()) { gradients.Should().HaveCount(2); gradients[0].Stops.Should().HaveCount(1); gradients[1].Stops.Should().HaveCount(2); } }
public void Parse_ValidColor_SingleStopWithColorAndOffset(string color, Color expectedColor, double expectedOffset) { // Arrange var reader = new CssReader(color); var builder = new GradientBuilder(); var definition = new ColorChannelDefinition(); // Act definition.Parse(reader, builder); // Assert var result = builder.Build(); using (new AssertionScope()) { var stops = result.SelectMany(x => x.Stops).ToArray(); stops.Should().HaveCount(1); stops[0].Color.Should().Be(expectedColor); stops[0].Offset.Value.Should().Be(expectedOffset); } }
public static IGradientSource BuildSource(this GradientBuilder builder) { return(new GenericGradientSource(builder.Build())); }