diff --git a/Structurizr.Core.Tests/View/ConfigurationTests.cs b/Structurizr.Core.Tests/View/ConfigurationTests.cs index 47af3a2..7406fd3 100644 --- a/Structurizr.Core.Tests/View/ConfigurationTests.cs +++ b/Structurizr.Core.Tests/View/ConfigurationTests.cs @@ -1,4 +1,5 @@ -using Xunit; +using System; +using Xunit; namespace Structurizr.Core.Tests { @@ -33,6 +34,47 @@ public void test_copyConfigurationFrom() ViewConfiguration destination = new ViewConfiguration(); destination.CopyConfigurationFrom(source); Assert.Equal("someKey", destination.LastSavedView); + } + + [Fact] + public void Test_SetTheme_WithAUrl() + { + ViewConfiguration configuration = new ViewConfiguration(); + configuration.Theme = "https://example.com/theme.json"; + Assert.Equal("https://example.com/theme.json", configuration.Theme); + } + + [Fact] + public void Test_SetTheme_WithAUrlThatHasATrailingSpaceCharacter() + { + ViewConfiguration configuration = new ViewConfiguration(); + configuration.Theme = "https://example.com/theme.json "; + Assert.Equal("https://example.com/theme.json", configuration.Theme); + } + + [Fact] + public void Test_SetTheme_ThrowsAnIllegalArgumentException_WhenAnInvalidUrlIsSpecified() + { + ViewConfiguration configuration = new ViewConfiguration(); + Assert.Throws(() => + configuration.Theme = "blah" + ); + } + + [Fact] + public void Test_SetTheme_DoesNothing_WhenANullUrlIsSpecified() + { + ViewConfiguration configuration = new ViewConfiguration(); + configuration.Theme = null; + Assert.Null(configuration.Theme); + } + + [Fact] + public void Test_SetTheme_DoesNothing_WhenAnEmptyUrlIsSpecified() + { + ViewConfiguration configuration = new ViewConfiguration(); + configuration.Theme = " "; + Assert.Null(configuration.Theme); } } diff --git a/Structurizr.Core/View/ViewConfiguration.cs b/Structurizr.Core/View/ViewConfiguration.cs index 44a58b8..0a0c8da 100644 --- a/Structurizr.Core/View/ViewConfiguration.cs +++ b/Structurizr.Core/View/ViewConfiguration.cs @@ -1,5 +1,7 @@ +using System; using System.Runtime.Serialization; using Structurizr.Core.View; +using Structurizr.Util; namespace Structurizr { @@ -21,6 +23,27 @@ internal ViewConfiguration() [DataMember(Name = "styles", EmitDefaultValue = false)] public Styles Styles { get; internal set; } + private String _theme; + + [DataMember(Name = "theme", EmitDefaultValue = false)] + public string Theme + { + get { return _theme; } + set + { + if (value != null && value.Trim().Length > 0) + { + if (Url.IsUrl(value)) + { + _theme = value.Trim(); + } + else { + throw new ArgumentException(value + " is not a valid URL."); + } + } + } + } + [DataMember(Name = "branding", EmitDefaultValue = false)] public Branding Branding { get; internal set; } diff --git a/docs/changelog.md b/docs/changelog.md index cfd51db..bae51be 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -3,6 +3,7 @@ ## 0.9.6 (unreleased) - Added A1 and A0 paper sizes. +- Adds support for themes. ## 0.9.5 (24th December 2019)