From f9e0a0fe1b6ea2967718eff5a3d36a945533fc24 Mon Sep 17 00:00:00 2001 From: burcuq Date: Fri, 26 Jul 2024 15:24:26 +0300 Subject: [PATCH] Add more tests for component model --- .../NavigationGroupAttributeTests.cs | 56 + .../NavigationItemAttributeTests.cs | 232 +++ .../Navigation/NavigationItemTests.cs | 222 ++ .../NavigationMenuAttributeTests.cs | 40 + .../NavigationSectionAttributeTests.cs | 40 + .../PropertyGrid/BasedOnRowAttributeTests.cs | 52 + .../PropertyGrid/CollapsibleAttributeTests.cs | 28 + .../PropertyGrid/CssClassAttributeTests.cs | 19 + .../PropertyGrid/GroupOrderAttributeTests.cs | 12 + .../HeaderCssClassAttributeTests.cs | 19 + .../HideOnInsertAttributeTests.cs | 26 + .../HideOnUpdateAttributeTests.cs | 26 + .../PropertyGrid/HintAttributeTests.cs | 18 + .../Layout/FullWidthAttributeTests.cs | 18 + .../Layout/HalfWidthAttributeTests.cs | 19 + .../Layout/HideLabelAttributeTests.cs | 22 + .../Layout/LabelWidthAttributeTests.cs | 65 + ...diumHalfLargeQuarterWidthAttributeTests.cs | 18 + ...MediumHalfLargeThirdWidthAttributeTests.cs | 19 + .../Layout/MediumHalfWidthAttributeTests.cs | 18 + .../MediumQuarterWidthAttributeTests.cs | 19 + ...iumThirdLargeQuarterWidthAttributeTests.cs | 19 + .../Layout/OneThirdWidthAttributeTests.cs | 19 + .../Layout/QuarterWidthAttributeTests.cs | 19 + .../Layout/ResetFormWidthAttributeTests.cs | 19 + .../Layout/ResetLabelWidthAttributeTests.cs | 18 + .../Layout/ThreeQuarterWidthAttributeTests.cs | 19 + .../Layout/TwoThirdWidthAttributeTests.cs | 19 + .../PropertyGrid/MaxLengthAttributeTests.cs | 12 + .../PropertyGrid/OneWayAttributeTests.cs | 12 + .../PropertyGrid/PlaceholderAttributeTests.cs | 18 + .../PropertyGrid/PropertyItemTests.cs | 1833 +++++++++++++++++ .../PropertyGrid/PropertyItemsDataTests.cs | 42 + .../PropertyGrid/RequiredAttributeTests.cs | 26 + .../PropertyGrid/ResizableAttributeTests.cs | 26 + .../PropertyGrid/SortOrderAttributeTests.cs | 32 + .../PropertyGrid/TabAttributeTests.cs | 19 + .../Upload/BaseUploadEditorAttributeTests.cs | 534 +++++ .../DefaultFilenameFormatSanitizerTests.cs | 116 ++ .../Upload/FileUploadEditorAttributeTests.cs | 45 + .../Upload/ImageUploadEditorAttributeTests.cs | 45 + .../MultipleFileUploadEditorAttributeTests.cs | 75 + ...MultipleImageUploadEditorAttributeTests.cs | 72 + .../Upload/UploadOptionsTests.cs | 535 +++++ .../Plugins/CssFileTests.cs | 27 + .../Plugins/NavigationEntryTests.cs | 248 +++ .../Plugins/PrecompiledViewsAttributeTests.cs | 14 + .../Plugins/ScriptFileTests.cs | 27 + 48 files changed, 4878 insertions(+) create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/Navigation/NavigationGroupAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/Navigation/NavigationItemAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/Navigation/NavigationItemTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/Navigation/NavigationMenuAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/Navigation/NavigationSectionAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/BasedOnRowAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/CollapsibleAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/CssClassAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/GroupOrderAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/HeaderCssClassAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/HideOnInsertAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/HideOnUpdateAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/HintAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/FullWidthAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/HalfWidthAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/HideLabelAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/LabelWidthAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/MediumHalfLargeQuarterWidthAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/MediumHalfLargeThirdWidthAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/MediumHalfWidthAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/MediumQuarterWidthAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/MediumThirdLargeQuarterWidthAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/OneThirdWidthAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/QuarterWidthAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/ResetFormWidthAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/ResetLabelWidthAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/ThreeQuarterWidthAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/TwoThirdWidthAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/MaxLengthAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/OneWayAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/PlaceholderAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/PropertyItemTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/PropertyItemsDataTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/RequiredAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/ResizableAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/SortOrderAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/TabAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/Upload/BaseUploadEditorAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/Upload/DefaultFilenameFormatSanitizerTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/Upload/FileUploadEditorAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/Upload/ImageUploadEditorAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/Upload/MultipleFileUploadEditorAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/Upload/MultipleImageUploadEditorAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/ComponentModel/Upload/UploadOptionsTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/Plugins/CssFileTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/Plugins/NavigationEntryTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/Plugins/PrecompiledViewsAttributeTests.cs create mode 100644 tests/Serenity.Net.Core.Tests/Plugins/ScriptFileTests.cs diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/Navigation/NavigationGroupAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/Navigation/NavigationGroupAttributeTests.cs new file mode 100644 index 0000000000..91a74a6f85 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/Navigation/NavigationGroupAttributeTests.cs @@ -0,0 +1,56 @@ +using Serenity.Navigation; + +namespace Serenity.Tests.ComponentModel; + +public class NavigationGroupAttributeTests +{ + [Fact] + public void Constructor_SetsPropertiesCorrectly_WithAllParameters() + { + int order = 1; + string title = "GroupTitle"; + string icon = "icon-class"; + var attribute = new NavigationGroupAttribute(order, title, icon); + Assert.Equal(order, attribute.Order); + Assert.Equal(title, attribute.Title); + Assert.Equal(icon, attribute.IconClass); + } + + [Fact] + public void Constructor_SetsPropertiesCorrectly_WithTitleAndIcon() + { + string title = "GroupTitle"; + string icon = "icon-class"; + var attribute = new NavigationGroupAttribute(title, icon); + Assert.Equal(int.MaxValue, attribute.Order); + Assert.Equal(title, attribute.Title); + Assert.Equal(icon, attribute.IconClass); + } + + [Fact] + public void Constructor_SetsPropertiesCorrectly_WithTitleOnly() + { + string title = "GroupTitle"; + var attribute = new NavigationGroupAttribute(title); + Assert.Equal(int.MaxValue, attribute.Order); + Assert.Equal(title, attribute.Title); + Assert.Null(attribute.IconClass); + } + + [Fact] + public void IncludeProperty_CanBeSetAndRetrieved() + { + var attribute = new NavigationGroupAttribute("Title"); + string[] includePaths = { "B/", "C/" }; + attribute.Include = includePaths; + Assert.Equal(includePaths, attribute.Include); + } + + [Fact] + public void DefaultProperty_CanBeSetAndRetrieved() + { + var attribute = new NavigationGroupAttribute("Title"); + attribute.Default = true; + Assert.True(attribute.Default); + } +} diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/Navigation/NavigationItemAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/Navigation/NavigationItemAttributeTests.cs new file mode 100644 index 0000000000..5bce79e516 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/Navigation/NavigationItemAttributeTests.cs @@ -0,0 +1,232 @@ +using Serenity.Navigation; + + +namespace Serenity.Tests.ComponentModel +{ + public class NavigationItemAttributeTests + { + public class MyNavigationItemAttribute(int order, string path, string url, object permission, string icon) + : NavigationItemAttribute(order, path, url, permission, icon) + { + } + + [Fact] + public void Constructor_InitializesPropertiesCorrectly_WithPathContainingSlash() + { + + int order = 1; + string path = "category/item"; + string url = "http://example.com"; + object permission = "read"; + string icon = "icon-class"; + var attribute = new MyNavigationItemAttribute(order, path, url, permission, icon); + Assert.Equal("category", attribute.Category); + Assert.Equal("item", attribute.Title); + Assert.Equal(order, attribute.Order); + Assert.Equal("read", attribute.Permission); + Assert.Equal("icon-class", attribute.IconClass); + Assert.Equal(url, attribute.Url); + } + + [Fact] + public void Constructor_InitializesPropertiesCorrectly_WithPathWithoutSlash() + { + + int order = 2; + string path = "item"; + string url = "http://example.com"; + object permission = "write"; + string icon = "icon-class"; + var attribute = new MyNavigationItemAttribute(order, path, url, permission, icon); + Assert.Null(attribute.Category); + Assert.Equal("item", attribute.Title); + Assert.Equal(order, attribute.Order); + Assert.Equal("write", attribute.Permission); + Assert.Equal("icon-class", attribute.IconClass); + Assert.Equal(url, attribute.Url); + } + + [Fact] + public void Constructor_InitializesPropertiesCorrectly_WithNullPath() + { + int order = 3; + string path = null; + string url = "http://example.com"; + object permission = null; + string icon = "icon-class"; + var attribute = new MyNavigationItemAttribute(order, path, url, permission, icon); + Assert.Null(attribute.Category); + Assert.Equal("", attribute.Title); + Assert.Equal(order, attribute.Order); + Assert.Null(attribute.Permission); + Assert.Equal("icon-class", attribute.IconClass); + Assert.Equal(url, attribute.Url); + } + + [Fact] + public void Constructor_InitializesPropertiesCorrectly_WithEmptyPath() + { + int order = 4; + string path = ""; + string url = "http://example.com"; + object permission = null; + string icon = "icon-class"; + var attribute = new MyNavigationItemAttribute(order, path, url, permission, icon); + Assert.Null(attribute.Category); + Assert.Equal("", attribute.Title); + Assert.Equal(order, attribute.Order); + Assert.Null(attribute.Permission); + Assert.Equal("icon-class", attribute.IconClass); + Assert.Equal(url, attribute.Url); + } + + [Fact] + public void Title_CanBeSet() + { + var attribute = new MyNavigationItemAttribute(1, "path", null, null, "icon") + { + Title = "sometext" + }; + Assert.Equal("sometext", attribute.Title); + } + + [Fact] + public void Title_CanBeSet_ToNull() + { + var attribute = new MyNavigationItemAttribute(1, "path", null, null, "icon") + { + Title = null + }; + Assert.Null(attribute.Title); + } + + [Fact] + public void FullPath_CanBeSet() + { + var attribute = new MyNavigationItemAttribute(1, "path", null, null, "icon") + { + FullPath = "sometext" + }; + Assert.Equal("sometext", attribute.FullPath); + } + + [Fact] + public void FullPath_CanBeSet_ToNull() + { + var attribute = new MyNavigationItemAttribute(1, "path", null, null, "icon") + { + FullPath = null + }; + Assert.Null(attribute.FullPath); + } + + [Fact] + public void Category_CanBeSet() + { + var attribute = new MyNavigationItemAttribute(1, "path", null, null, "icon") + { + Category = "sometext" + }; + Assert.Equal("sometext", attribute.Category); + } + + [Fact] + public void Category_CanBeSet_ToNull() + { + var attribute = new MyNavigationItemAttribute(1, "path", null, null, "icon") + { + Category = null + }; + Assert.Null(attribute.Category); + } + + [Fact] + public void IconClass_IsNull_ByDefault() + { + var attribute = new MyNavigationItemAttribute(1, "path", null, null, null); + Assert.Null(attribute.IconClass); + } + + [Fact] + public void IconClass_CanBeSet() + { + var attribute = new MyNavigationItemAttribute(1, "path", null, null, "icon") + { + IconClass = "sometext" + }; + Assert.Equal("sometext", attribute.IconClass); + } + + [Fact] + public void IconClass_CanBeSet_ToNull() + { + var attribute = new MyNavigationItemAttribute(1, "path", null, null, "icon") + { + IconClass = null + }; + Assert.Null(attribute.IconClass); + } + + [Fact] + public void ItemClass_CanBeSet() + { + var attribute = new MyNavigationItemAttribute(1, "path", null, null, "icon") + { + ItemClass = "sometext" + }; + Assert.Equal("sometext", attribute.ItemClass); + } + + [Fact] + public void ItemClass_CanBeSet_ToNull() + { + var attribute = new MyNavigationItemAttribute(1, "path", null, null, "icon") + { + ItemClass = null + }; + Assert.Null(attribute.ItemClass); + } + + + [Fact] + public void Url_CanBeSet() + { + var attribute = new MyNavigationItemAttribute(1, "path", null, null, "icon") + { + Url = "sometext" + }; + Assert.Equal("sometext", attribute.Url); + } + + [Fact] + public void Url_CanBeSet_ToNull() + { + var attribute = new MyNavigationItemAttribute(1, "path", null, null, "icon") + { + Url = null + }; + Assert.Null(attribute.Url); + } + + [Fact] + public void Target_CanBeSet() + { + var attribute = new MyNavigationItemAttribute(1, "path", null, null, "icon") + { + Target = "sometext" + }; + Assert.Equal("sometext", attribute.Target); + } + + [Fact] + public void Target_CanBeSet_ToNull() + { + var attribute = new MyNavigationItemAttribute(1, "path", null, null, "icon") + { + Target = null + }; + Assert.Null(attribute.Target); + } + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/Navigation/NavigationItemTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/Navigation/NavigationItemTests.cs new file mode 100644 index 0000000000..cbd9b59c34 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/Navigation/NavigationItemTests.cs @@ -0,0 +1,222 @@ +using Serenity.Navigation; + +namespace Serenity.Tests.ComponentModel; + +public class NavigationItemTests +{ + [Fact] + public void Title_IsNull_ByDefault() + { + var attribute = new NavigationItem(); + Assert.Null(attribute.Title); + } + + [Fact] + public void Title_CanBeSet() + { + var attribute = new NavigationItem() + { + Title = "sometext" + }; + Assert.Equal("sometext", attribute.Title); + } + + [Fact] + public void Title_CanBeSet_ToNull() + { + var attribute = new NavigationItem() + { + Title = null + }; + Assert.Null(attribute.Title); + } + + [Fact] + public void FullPath_IsNull_ByDefault() + { + var attribute = new NavigationItem(); + Assert.Null(attribute.FullPath); + } + + [Fact] + public void FullPath_CanBeSet() + { + var attribute = new NavigationItem() + { + FullPath = "sometext" + }; + Assert.Equal("sometext", attribute.FullPath); + } + + [Fact] + public void FullPath_CanBeSet_ToNull() + { + var attribute = new NavigationItem() + { + FullPath = null + }; + Assert.Null(attribute.FullPath); + } + + [Fact] + public void IconClass_IsNull_ByDefault() + { + var attribute = new NavigationItem(); + Assert.Null(attribute.IconClass); + } + + [Fact] + public void IconClass_CanBeSet() + { + var attribute = new NavigationItem() + { + IconClass = "sometext" + }; + Assert.Equal("sometext", attribute.IconClass); + } + + [Fact] + public void IconClass_CanBeSet_ToNull() + { + var attribute = new NavigationItem() + { + IconClass = null + }; + Assert.Null(attribute.IconClass); + } + + [Fact] + public void ItemClass_IsNull_ByDefault() + { + var attribute = new NavigationItem(); + Assert.Null(attribute.Title); + } + + [Fact] + public void ItemClass_CanBeSet() + { + var attribute = new NavigationItem() + { + ItemClass = "sometext" + }; + Assert.Equal("sometext", attribute.ItemClass); + } + + [Fact] + public void ItemClass_CanBeSet_ToNull() + { + var attribute = new NavigationItem() + { + ItemClass = null + }; + Assert.Null(attribute.ItemClass); + } + + [Fact] + public void Url_IsNull_ByDefault() + { + var attribute = new NavigationItem(); + Assert.Null(attribute.Title); + } + + [Fact] + public void Url_CanBeSet() + { + var attribute = new NavigationItem() + { + Url = "sometext" + }; + Assert.Equal("sometext", attribute.Url); + } + + [Fact] + public void Url_CanBeSet_ToNull() + { + var attribute = new NavigationItem() + { + Url = null + }; + Assert.Null(attribute.Url); + } + + [Fact] + public void Target_IsNull_ByDefault() + { + var attribute = new NavigationItem(); + Assert.Null(attribute.Title); + } + + [Fact] + public void Target_CanBeSet() + { + var attribute = new NavigationItem() + { + Target = "sometext" + }; + Assert.Equal("sometext", attribute.Target); + } + + [Fact] + public void Target_CanBeSet_ToNull() + { + var attribute = new NavigationItem() + { + Target = null + }; + Assert.Null(attribute.Target); + } + + [Fact] + public void Parent_CanBeSet_ToNull() + { + var attribute = new NavigationItem() + { + Parent = null + }; + Assert.Null(attribute.Target); + } + + [Fact] + public void Parent_IsNull_ByDefault() + { + var attribute = new NavigationItem(); + Assert.Null(attribute.Parent); + } + + [Fact] + public void Children_CanAddItems() + { + var testObject = new NavigationItem(); + var item = new NavigationItem(); + testObject.Children.Add(item); + Assert.Contains(item, testObject.Children); + } + + [Fact] + public void Children_IsInitialized_AsEmptyList() + { + var testObject = new NavigationItem(); + Assert.NotNull(testObject.Children); + Assert.Empty(testObject.Children); + } + + [Fact] + public void IsSection_CanBeSet_ToTrue() + { + var attribute = new NavigationItem() + { + IsSection = true + }; + Assert.True(attribute.IsSection); + } + + [Fact] + public void IsSection_CanBeSet_ToFalse() + { + var attribute = new NavigationItem() + { + IsSection = false + }; + Assert.False(attribute.IsSection); + } +} \ No newline at end of file diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/Navigation/NavigationMenuAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/Navigation/NavigationMenuAttributeTests.cs new file mode 100644 index 0000000000..b3cd0ada5c --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/Navigation/NavigationMenuAttributeTests.cs @@ -0,0 +1,40 @@ +using Serenity.Navigation; + +namespace Serenity.Tests.ComponentModel; + +public class NavigationMenuAttributeTests +{ + [Fact] + public void Constructor_SetsPropertiesCorrectly_WithAllParameters() + { + int order = 1; + string title = "MenuTitle"; + string icon = "icon-class"; + var attribute = new NavigationMenuAttribute(order, title, icon); + Assert.Equal(order, attribute.Order); + Assert.Equal(title, attribute.Title); + Assert.Equal(icon, attribute.IconClass); + } + + [Fact] + public void Constructor_SetsPropertiesCorrectly_WithTitleAndIcon() + { + string title = "MenuTitle"; + string icon = "icon-class"; + var attribute = new NavigationMenuAttribute(title, icon); + Assert.Equal(int.MaxValue, attribute.Order); + Assert.Equal(title, attribute.Title); + Assert.Equal(icon, attribute.IconClass); + } + + [Fact] + public void Constructor_SetsPropertiesCorrectly_WithTitleOnly() + { + string title = "MenuTitle"; + var attribute = new NavigationMenuAttribute(title); + Assert.Equal(int.MaxValue, attribute.Order); + Assert.Equal(title, attribute.Title); + Assert.Null(attribute.IconClass); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/Navigation/NavigationSectionAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/Navigation/NavigationSectionAttributeTests.cs new file mode 100644 index 0000000000..ec5e62a361 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/Navigation/NavigationSectionAttributeTests.cs @@ -0,0 +1,40 @@ +using Serenity.Navigation; + +namespace Serenity.Tests.ComponentModel; + +public class NavigationSectionAttributeTests +{ + [Fact] + public void Constructor_SetsPropertiesCorrectly_WithAllParameters() + { + int order = 1; + string title = "SectionTitle"; + string icon = "icon-class"; + var attribute = new NavigationSectionAttribute(order, title, icon); + Assert.Equal(order, attribute.Order); + Assert.Equal(title, attribute.Title); + Assert.Equal(icon, attribute.IconClass); + } + + [Fact] + public void Constructor_SetsPropertiesCorrectly_WithTitleAndIcon() + { + string title = "SectionTitle"; + string icon = "icon-class"; + var attribute = new NavigationSectionAttribute(title, icon); + Assert.Equal(int.MaxValue, attribute.Order); + Assert.Equal(title, attribute.Title); + Assert.Equal(icon, attribute.IconClass); + } + + [Fact] + public void Constructor_SetsPropertiesCorrectly_WithTitleOnly() + { + string title = "SectionTitle"; + var attribute = new NavigationSectionAttribute(title); + Assert.Equal(int.MaxValue, attribute.Order); + Assert.Equal(title, attribute.Title); + Assert.Null(attribute.IconClass); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/BasedOnRowAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/BasedOnRowAttributeTests.cs new file mode 100644 index 0000000000..ebee48ee76 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/BasedOnRowAttributeTests.cs @@ -0,0 +1,52 @@ +namespace Serenity.Tests.ComponentModel; + +public class BasedOnRowAttributeTests +{ + [Fact] + public void RowType_CanBePassed_AsTypeOfBool() + { + var attribute = new BasedOnRowAttribute(typeof(bool)); + Assert.Equal(typeof(bool), attribute.RowType); + } + + [Fact] + public void RowType_CanBePassed_AsTypeOfInt() + { + var attribute = new BasedOnRowAttribute(typeof(int)); + Assert.Equal(typeof(int), attribute.RowType); + } + + [Fact] + public void RowType_CanBePassed_AsTypeOfEnum() + { + var attribute = new BasedOnRowAttribute(typeof(Enum)); + Assert.Equal(typeof(Enum), attribute.RowType); + } + + [Fact] + public void RowType_CanBePassed_AsTypeOfString() + { + var attribute = new BasedOnRowAttribute(typeof(string)); + Assert.Equal(typeof(string), attribute.RowType); + } + + [Fact] + public void CheckNames_CanBeSet_ToTrue() + { + var attribute = new BasedOnRowAttribute(typeof(bool)) + { + CheckNames = true + }; + Assert.True(attribute.CheckNames); + } + + [Fact] + public void CheckNames_CanBeSet_ToFalse() + { + var attribute = new BasedOnRowAttribute(typeof(bool)) + { + CheckNames = false + }; + Assert.False(attribute.CheckNames); + } +} diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/CollapsibleAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/CollapsibleAttributeTests.cs new file mode 100644 index 0000000000..3a591dcd3f --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/CollapsibleAttributeTests.cs @@ -0,0 +1,28 @@ +namespace Serenity.Tests.ComponentModel; + +public class CollapsibleAttributeTests +{ + [Fact] + public void Value_ShouldBeTrue_ByDefault() + { + var attribute = new CollapsibleAttribute(); + Assert.True(attribute.Value); + } + + [Fact] + public void Collapsed_ShouldBeFalse_ByDefault() + { + var attribute = new CollapsibleAttribute(); + Assert.False(attribute.Collapsed); + } + + [Fact] + public void Collapsed_CanBeSet_ToTrue() + { + var attribute = new CollapsibleAttribute() + { + Collapsed = true + }; + Assert.True(attribute.Collapsed); + } +} diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/CssClassAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/CssClassAttributeTests.cs new file mode 100644 index 0000000000..ee6f7e402b --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/CssClassAttributeTests.cs @@ -0,0 +1,19 @@ +namespace Serenity.Tests.ComponentModel; + +public class CssClassAttributeTests +{ + [Fact] + public void CssClass_CanBePassed_AsString() + { + var attribute = new CssClassAttribute("cssClass"); + Assert.Equal("cssClass", attribute.CssClass); + } + + [Fact] + public void CssClass_CanBePassed_AsNull() + { + var attribute = new CssClassAttribute(null); + Assert.Null(attribute.CssClass); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/GroupOrderAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/GroupOrderAttributeTests.cs new file mode 100644 index 0000000000..e4d840790b --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/GroupOrderAttributeTests.cs @@ -0,0 +1,12 @@ +namespace Serenity.Tests.ComponentModel; + +public class GroupOrderAttributeTests +{ + [Fact] + public void GroupOrder_CanBePassed_AsInt() + { + var attribute = new GroupOrderAttribute(2); + Assert.Equal(2, attribute.GroupOrder); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/HeaderCssClassAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/HeaderCssClassAttributeTests.cs new file mode 100644 index 0000000000..3b7e1f1a63 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/HeaderCssClassAttributeTests.cs @@ -0,0 +1,19 @@ +namespace Serenity.Tests.ComponentModel; + +public class HeaderCssClassAttributeTests +{ + [Fact] + public void Value_CanBePassed_AsString() + { + var attribute = new HeaderCssClassAttribute("value"); + Assert.Equal("value", attribute.Value); + } + + [Fact] + public void Value_CanBePassed_AsNull() + { + var attribute = new HeaderCssClassAttribute(null); + Assert.Null(attribute.Value); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/HideOnInsertAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/HideOnInsertAttributeTests.cs new file mode 100644 index 0000000000..d0d280ffd9 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/HideOnInsertAttributeTests.cs @@ -0,0 +1,26 @@ +namespace Serenity.Tests.ComponentModel; + +public class HideOnInsertAttributeTests +{ + [Fact] + public void Value_ShouldBeTrue_ByDefault() + { + var attribute = new HideOnInsertAttribute(); + Assert.True(attribute.Value); + } + + [Fact] + public void Value_CanBePassed_AsFalse() + { + var attribute = new HideOnInsertAttribute(false); + Assert.False(attribute.Value); + } + + [Fact] + public void Value_CanBePassed_AsTrue() + { + var attribute = new HideOnInsertAttribute(true); + Assert.True(attribute.Value); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/HideOnUpdateAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/HideOnUpdateAttributeTests.cs new file mode 100644 index 0000000000..1c2f034ab4 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/HideOnUpdateAttributeTests.cs @@ -0,0 +1,26 @@ +namespace Serenity.Tests.ComponentModel; + +public class HideOnUpdateAttributeTests +{ + [Fact] + public void Value_ShouldBeTrue_ByDefault() + { + var attribute = new HideOnUpdateAttribute(); + Assert.True(attribute.Value); + } + + [Fact] + public void Value_CanBePassed_AsFalse() + { + var attribute = new HideOnUpdateAttribute(false); + Assert.False(attribute.Value); + } + + [Fact] + public void Value_CanBePassed_AsTrue() + { + var attribute = new HideOnUpdateAttribute(true); + Assert.True(attribute.Value); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/HintAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/HintAttributeTests.cs new file mode 100644 index 0000000000..31db685d4c --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/HintAttributeTests.cs @@ -0,0 +1,18 @@ +namespace Serenity.Tests.ComponentModel; + +public class HintAttributeTests +{ + [Fact] + public void Hint_CanBePassed_AsString() + { + var attribute = new HintAttribute("hint"); + Assert.Equal("hint", attribute.Hint); + } + + [Fact] + public void Hint_CanBePassed_AsNull() + { + var attribute = new HintAttribute(null); + Assert.Null(attribute.Hint); + } +} diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/FullWidthAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/FullWidthAttributeTests.cs new file mode 100644 index 0000000000..13c66aebc4 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/FullWidthAttributeTests.cs @@ -0,0 +1,18 @@ +namespace Serenity.Tests.ComponentModel; + +public class FullWidthAttributeTests +{ + [Fact] + public void IsSubClassOf_FormWidthAttribute() + { + var attribute = new FullWidthAttribute(); + Assert.IsAssignableFrom(attribute); + } + + [Fact] + public void Value_Is_Null() + { + var attribute = new FullWidthAttribute(); + Assert.Null(attribute.Value); + } +} diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/HalfWidthAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/HalfWidthAttributeTests.cs new file mode 100644 index 0000000000..a541dca9ad --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/HalfWidthAttributeTests.cs @@ -0,0 +1,19 @@ +namespace Serenity.Tests.ComponentModel; + +public class HalfWidthAttributeTests +{ + [Fact] + public void IsSubClassOf_FormWidthAttribute() + { + var attribute = new HalfWidthAttribute(); + Assert.IsAssignableFrom(attribute); + } + + [Fact] + public void Value_Is_ColSm6() + { + var attribute = new HalfWidthAttribute(); + Assert.Equal("col-sm-6", attribute.Value); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/HideLabelAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/HideLabelAttributeTests.cs new file mode 100644 index 0000000000..d1001c49d2 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/HideLabelAttributeTests.cs @@ -0,0 +1,22 @@ +namespace Serenity.Tests.ComponentModel; + +public class HideLabelAttributeTests +{ + [Fact] + public void IsSubClassOf_LabelWidthAttribute() + { + var attribute = new HideLabelAttribute(); + Assert.IsAssignableFrom(attribute); + } + + [Fact] + public void JustThis_IsTrue() + { + var attribute = new HideLabelAttribute() + { + JustThis = true + }; + Assert.True(attribute.JustThis); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/LabelWidthAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/LabelWidthAttributeTests.cs new file mode 100644 index 0000000000..0313a7e5b1 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/LabelWidthAttributeTests.cs @@ -0,0 +1,65 @@ +namespace Serenity.Tests.ComponentModel; + +public class LabelWidthAttributeTests +{ + [Fact] + public void Value_ShouldIncludePxSuffix() + { + var attribute = new LabelWidthAttribute(2); + Assert.Equal(2 + "px", attribute.Value); + } + + [Fact] + public void Value_CanBePassed_AsNull() + { + var attribute = new LabelWidthAttribute(null); + Assert.Null(attribute.Value); + } + + [Fact] + public void Value_CanBePassed_AsString() + { + var attribute = new LabelWidthAttribute("value"); + Assert.Equal("value", attribute.Value); + } + + [Fact] + public void UntilNext_CanBeSet_ToTrue() + { + var attribute = new LabelWidthAttribute(1) + { + UntilNext = true + }; + Assert.True(attribute.UntilNext); + } + + [Fact] + public void UntilNext_CanBeSet_ToFalse() + { + var attribute = new LabelWidthAttribute(1) + { + UntilNext = false + }; + Assert.False(attribute.UntilNext); + } + + [Fact] + public void JustThis_CanBeSet_ToTrue() + { + var attribute = new LabelWidthAttribute(2) + { + JustThis = true + }; + Assert.True(attribute.JustThis); + } + + [Fact] + public void JustThis_CanBeSet_ToFalse() + { + var attribute = new LabelWidthAttribute(2) + { + JustThis = false + }; + Assert.False(attribute.JustThis); + } +} diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/MediumHalfLargeQuarterWidthAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/MediumHalfLargeQuarterWidthAttributeTests.cs new file mode 100644 index 0000000000..45f283a670 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/MediumHalfLargeQuarterWidthAttributeTests.cs @@ -0,0 +1,18 @@ +namespace Serenity.Tests.ComponentModel; + +public class MediumHalfLargeQuarterWidthAttributeTests +{ + [Fact] + public void IsSubClassOf_FormWidthAttribute() + { + var attribute = new MediumHalfLargeQuarterWidthAttribute(); + Assert.IsAssignableFrom(attribute); + } + + [Fact] + public void Value_Is_ColMd6_ColLg3() + { + var attribute = new MediumHalfLargeQuarterWidthAttribute(); + Assert.Equal("col-md-6 col-lg-3", attribute.Value); + } +} diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/MediumHalfLargeThirdWidthAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/MediumHalfLargeThirdWidthAttributeTests.cs new file mode 100644 index 0000000000..e7ea626400 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/MediumHalfLargeThirdWidthAttributeTests.cs @@ -0,0 +1,19 @@ +namespace Serenity.Tests.ComponentModel; + +public class MediumHalfLargeThirdWidthAttributeTests +{ + [Fact] + public void IsSubClassOf_FormWidthAttribute() + { + var attribute = new MediumHalfLargeThirdWidthAttribute(); + Assert.IsAssignableFrom(attribute); + } + + [Fact] + public void Value_Is_ColMd6_ColLg4() + { + var attribute = new MediumHalfLargeThirdWidthAttribute(); + Assert.Equal("col-md-6 col-lg-4", attribute.Value); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/MediumHalfWidthAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/MediumHalfWidthAttributeTests.cs new file mode 100644 index 0000000000..54765c45d3 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/MediumHalfWidthAttributeTests.cs @@ -0,0 +1,18 @@ +namespace Serenity.Tests.ComponentModel; + +public class MediumHalfWidthAttributeTests +{ + [Fact] + public void IsSubClassOf_FormWidthAttribute() + { + var attribute = new MediumHalfWidthAttribute(); + Assert.IsAssignableFrom(attribute); + } + [Fact] + public void Value_Is_ColMd6() + { + var attribute = new MediumHalfWidthAttribute(); + Assert.Equal("col-md-6", attribute.Value); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/MediumQuarterWidthAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/MediumQuarterWidthAttributeTests.cs new file mode 100644 index 0000000000..85b7322162 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/MediumQuarterWidthAttributeTests.cs @@ -0,0 +1,19 @@ +namespace Serenity.Tests.ComponentModel; + +public class MediumQuarterWidthAttributeTests +{ + [Fact] + public void IsSubClassOf_FormWidthAttribute() + { + var attribute = new MediumQuarterWidthAttribute(); + Assert.IsAssignableFrom(attribute); + } + + [Fact] + public void Value_Is_ColMd3() + { + var attribute = new MediumQuarterWidthAttribute(); + Assert.Equal("col-md-3", attribute.Value); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/MediumThirdLargeQuarterWidthAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/MediumThirdLargeQuarterWidthAttributeTests.cs new file mode 100644 index 0000000000..0e4818b7bb --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/MediumThirdLargeQuarterWidthAttributeTests.cs @@ -0,0 +1,19 @@ +namespace Serenity.Tests.ComponentModel; + +public class MediumThirdLargeQuarterWidthAttributeTests +{ + [Fact] + public void IsSubClassOf_FormWidthAttribute() + { + var attribute = new MediumThirdLargeQuarterWidthAttribute(); + Assert.IsAssignableFrom(attribute); + } + + [Fact] + public void Value_Is_ColMd4_ColLg3() + { + var attribute = new MediumThirdLargeQuarterWidthAttribute(); + Assert.Equal("col-md-4 col-lg-3", attribute.Value); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/OneThirdWidthAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/OneThirdWidthAttributeTests.cs new file mode 100644 index 0000000000..7d01bd6404 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/OneThirdWidthAttributeTests.cs @@ -0,0 +1,19 @@ +namespace Serenity.Tests.ComponentModel; + +public class OneThirdWidthAttributeTests +{ + [Fact] + public void IsSubClassOf_FormWidthAttribute() + { + var attribute = new OneThirdWidthAttribute(); + Assert.IsAssignableFrom(attribute); + } + + [Fact] + public void Value_Is_ColMd4() + { + var attribute = new OneThirdWidthAttribute(); + Assert.Equal("col-md-4", attribute.Value); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/QuarterWidthAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/QuarterWidthAttributeTests.cs new file mode 100644 index 0000000000..d95f832d60 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/QuarterWidthAttributeTests.cs @@ -0,0 +1,19 @@ +namespace Serenity.Tests.ComponentModel; + +public class QuarterWidthAttributeTests +{ + [Fact] + public void IsSubClassOf_FormWidthAttribute() + { + var attribute = new QuarterWidthAttribute(); + Assert.IsAssignableFrom(attribute); + } + + [Fact] + public void Value_Is_ColLg3_ColSm6() + { + var attribute = new QuarterWidthAttribute(); + Assert.Equal("col-lg-3 col-sm-6", attribute.Value); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/ResetFormWidthAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/ResetFormWidthAttributeTests.cs new file mode 100644 index 0000000000..cdae4aa13b --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/ResetFormWidthAttributeTests.cs @@ -0,0 +1,19 @@ +namespace Serenity.Tests.ComponentModel; + +public class ResetFormWidthAttributeTests +{ + [Fact] + public void IsSubClassOf_FormWidthAttribute() + { + var attribute = new ResetFormWidthAttribute(); + Assert.IsAssignableFrom(attribute); + } + + [Fact] + public void Value_Is_Null() + { + var attribute = new ResetFormWidthAttribute(); + Assert.Null(attribute.Value); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/ResetLabelWidthAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/ResetLabelWidthAttributeTests.cs new file mode 100644 index 0000000000..94e202e635 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/ResetLabelWidthAttributeTests.cs @@ -0,0 +1,18 @@ +namespace Serenity.Tests.ComponentModel; + +public class ResetLabelWidthAttributeTests +{ + [Fact] + public void IsSubClassOf_LabelWidthAttribute() + { + var attribute = new ResetLabelWidthAttribute(); + Assert.IsAssignableFrom(attribute); + } + + [Fact] + public void Value_Is_Null() + { + var attribute = new ResetLabelWidthAttribute(); + Assert.Null(attribute.Value); + } +} diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/ThreeQuarterWidthAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/ThreeQuarterWidthAttributeTests.cs new file mode 100644 index 0000000000..13533bc2f5 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/ThreeQuarterWidthAttributeTests.cs @@ -0,0 +1,19 @@ +namespace Serenity.Tests.ComponentModel; + +public class ThreeQuarterWidthAttributeTests +{ + [Fact] + public void IsSubClassOf_FormWidthAttribute() + { + var attribute = new ThreeQuarterWidthAttribute(); + Assert.IsAssignableFrom(attribute); + } + + [Fact] + public void Value_Is_ColLg9() + { + var attribute = new ThreeQuarterWidthAttribute(); + Assert.Equal("col-lg-9", attribute.Value); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/TwoThirdWidthAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/TwoThirdWidthAttributeTests.cs new file mode 100644 index 0000000000..b82881450b --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/Layout/TwoThirdWidthAttributeTests.cs @@ -0,0 +1,19 @@ +namespace Serenity.Tests.ComponentModel; + +public class TwoThirdWidthAttributeTests +{ + [Fact] + public void IsSubClassOf_FormWidthAttribute() + { + var attribute = new TwoThirdWidthAttribute(); + Assert.IsAssignableFrom(attribute); + } + + [Fact] + public void Value_Is_ColMd8() + { + var attribute = new TwoThirdWidthAttribute(); + Assert.Equal("col-md-8",attribute.Value); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/MaxLengthAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/MaxLengthAttributeTests.cs new file mode 100644 index 0000000000..3c3dbe191b --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/MaxLengthAttributeTests.cs @@ -0,0 +1,12 @@ +namespace Serenity.Tests.ComponentModel; + +public class MaxLengthAttributeTests +{ + [Fact] + public void MaxLength_CanBePassed_AsInt() + { + var attribute = new MaxLengthAttribute(2); + Assert.Equal(2, attribute.MaxLength); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/OneWayAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/OneWayAttributeTests.cs new file mode 100644 index 0000000000..b7a8175b33 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/OneWayAttributeTests.cs @@ -0,0 +1,12 @@ +namespace Serenity.Tests.ComponentModel; + +public class OneWayAttributeTests +{ + [Fact] + public void IsSubClassOf_Attribute() + { + var attribute = new OneWayAttribute(); + Assert.IsAssignableFrom(attribute); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/PlaceholderAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/PlaceholderAttributeTests.cs new file mode 100644 index 0000000000..c2943c50b8 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/PlaceholderAttributeTests.cs @@ -0,0 +1,18 @@ +namespace Serenity.Tests.ComponentModel; + +public class PlaceholderAttributeTests +{ + [Fact] + public void Value_CanBePassed_AsString() + { + var attribute = new PlaceholderAttribute("value"); + Assert.Equal("value", attribute.Value); + } + + [Fact] + public void Value_CanBePassed_AsNull() + { + var attribute = new PlaceholderAttribute(null); + Assert.Null(attribute.Value); + } +} diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/PropertyItemTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/PropertyItemTests.cs new file mode 100644 index 0000000000..0a2f17005b --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/PropertyItemTests.cs @@ -0,0 +1,1833 @@ +namespace Serenity.Tests.ComponentModel; + +public class PropertyItemTests +{ + [Fact] + public void Name_CanBeSet() + { + var attribute = new PropertyItem() + { + Name = "name" + }; + Assert.Equal("name", attribute.Name); + } + + [Fact] + public void Name_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.Name); + } + + [Fact] + public void Name_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + Name = null + }; + Assert.Null(attribute.Name); + } + + [Fact] + public void Title_CanBeSet() + { + var attribute = new PropertyItem() + { + Title = "title" + }; + Assert.Equal("title", attribute.Title); + } + + [Fact] + public void Title_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.Title); + } + + [Fact] + public void Title_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + Title = null + }; + Assert.Null(attribute.Title); + } + + [Fact] + public void Hint_CanBeSet() + { + var attribute = new PropertyItem() + { + Hint = "hint" + }; + Assert.Equal("hint", attribute.Hint); + } + + [Fact] + public void Hint_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.Hint); + } + + [Fact] + public void Hint_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + Hint = null + }; + Assert.Null(attribute.Hint); + } + + [Fact] + public void Placeholder_CanBeSet() + { + var attribute = new PropertyItem() + { + Placeholder = "text" + }; + Assert.Equal("text", attribute.Placeholder); + } + + [Fact] + public void Placeholder_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.Placeholder); + } + + [Fact] + public void Placeholder_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + Placeholder = null + }; + Assert.Null(attribute.Placeholder); + } + + [Fact] + public void EditorType_CanBeSet() + { + var attribute = new PropertyItem() + { + EditorType = "editorType" + }; + Assert.Equal("editorType", attribute.EditorType); + } + + [Fact] + public void EditorType_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.EditorType); + } + + [Fact] + public void EditorType_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + EditorType = null + }; + Assert.Null(attribute.EditorType); + } + [Fact] + public void EditorAddons_ShouldBeInitializedCorrectly() + { + var editorAddons = new List + { + new EditorAddonItem { }, + new EditorAddonItem { } + }; + var data = new PropertyItem + { + EditorAddons = editorAddons + }; + + Assert.Equal(editorAddons, data.EditorAddons); + } + + [Fact] + public void EditorAddons_IsNull_ByDefault() + { + var data = new PropertyItem(); + Assert.Null(data.EditorAddons); + } + + [Fact] + public void EditorCssClass_CanBeSet() + { + var attribute = new PropertyItem() + { + EditorCssClass = "sometext" + }; + Assert.Equal("sometext", attribute.EditorCssClass); + } + + [Fact] + public void EditorCssClass_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.EditorCssClass); + } + + [Fact] + public void EditorCssClass_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + EditorCssClass = null + }; + Assert.Null(attribute.EditorCssClass); + } + + [Fact] + public void Category_CanBeSet() + { + var attribute = new PropertyItem() + { + Category = "sometext" + }; + Assert.Equal("sometext", attribute.Category); + } + + [Fact] + public void Category_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.Category); + } + + [Fact] + public void Category_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + Category = null + }; + Assert.Null(attribute.Category); + } + + [Fact] + public void Collapsible_IsNull_ByDefault() + { + var attribute = new PropertyItem() + { + Collapsible = null + }; + Assert.Null(attribute.Collapsible); + } + + [Fact] + public void Collapsible_CanBeSet_ToTrue() + { + var attribute = new PropertyItem() + { + Collapsible = true + }; + Assert.True(attribute.Collapsible); + } + + [Fact] + public void Collapsible_CanBeSet_ToFalse() + { + var attribute = new PropertyItem() + { + Collapsed = false + }; + Assert.False(attribute.Collapsed); + } + + [Fact] + public void Tab_CanBeSet() + { + var attribute = new PropertyItem() + { + Tab = "tab" + }; + Assert.Equal("tab", attribute.Tab); + } + + [Fact] + public void Tab_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + Tab = null + }; + Assert.Null(attribute.Tab); + } + + [Fact] + public void Tab_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.Tab); + } + + [Fact] + public void CssClass_CanBeSet() + { + var attribute = new PropertyItem() + { + CssClass = "sometext" + }; + Assert.Equal("sometext", attribute.CssClass); + } + + [Fact] + public void CssClass_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + CssClass = null + }; + Assert.Null(attribute.CssClass); + } + + [Fact] + public void CssClass_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.CssClass); + } + + [Fact] + public void HeaderCssClass_CanBeSet() + { + var attribute = new PropertyItem() + { + HeaderCssClass = "sometext" + }; + Assert.Equal("sometext", attribute.HeaderCssClass); + } + + [Fact] + public void HeaderCssClass_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + HeaderCssClass = null + }; + Assert.Null(attribute.HeaderCssClass); + } + + [Fact] + public void HeaderCssClass_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.HeaderCssClass); + } + + [Fact] + public void FormCssClass_CanBeSet() + { + var attribute = new PropertyItem() + { + FormCssClass = "sometext" + }; + Assert.Equal("sometext", attribute.FormCssClass); + } + + [Fact] + public void FormCssClass_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + FormCssClass = null + }; + Assert.Null(attribute.FormCssClass); + } + + [Fact] + public void FormCssClass_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.FormCssClass); + } + + [Fact] + public void MaxLenght_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.MaxLength); + } + + [Fact] + public void MaxLenght_CanBeSet_ToInt() + { + var attribute = new PropertyItem() + { + MaxLength = 100 + }; + Assert.Equal(100, attribute.MaxLength); + } + + [Fact] + public void MaxLenght_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + MaxLength = null + }; + Assert.Null(attribute.MaxLength); + } + + [Fact] + public void Required_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.Required); + } + + [Fact] + public void Required_CanBeSet_ToTrue() + { + var attribute = new PropertyItem() + { + Required = true + }; + Assert.True(attribute.Required); + } + + [Fact] + public void Required_CanBeSet_ToFalse() + { + var attribute = new PropertyItem() + { + Required = false + }; + Assert.False(attribute.Required); + } + + [Fact] + public void ReadOnly_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.ReadOnly); + } + + [Fact] + public void ReadOnly_CanBeSet_ToTrue() + { + var attribute = new PropertyItem() + { + ReadOnly = true + }; + Assert.True(attribute.ReadOnly); + } + + [Fact] + public void ReadOnly_CanBeSet_ToFalse() + { + var attribute = new PropertyItem() + { + ReadOnly = false + }; + Assert.False(attribute.ReadOnly); + } + + [Fact] + public void ReadPermission_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.ReadPermission); + } + + [Fact] + public void ReadPermission_CanBeSet() + { + var attribute = new PropertyItem() + { + ReadPermission = "text" + }; + Assert.Equal("text", attribute.ReadPermission); + } + + [Fact] + public void ReadPermission_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + ReadPermission = null + }; + Assert.Null(attribute.ReadPermission); + } + + [Fact] + public void Insertable_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.Insertable); + } + + [Fact] + public void Insertable_CanBeSet_ToTrue() + { + var attribute = new PropertyItem() + { + Insertable = true + }; + Assert.True(attribute.Insertable); + } + + [Fact] + public void Insertable_CanBeSet_ToFalse() + { + var attribute = new PropertyItem() + { + Insertable = false + }; + Assert.False(attribute.Insertable); + } + + [Fact] + public void Insertable_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + Insertable = null + }; + Assert.Null(attribute.Insertable); + } + + [Fact] + public void InsertPermission_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.InsertPermission); + } + + [Fact] + public void InsertPermission_CanBeSet() + { + var attribute = new PropertyItem() + { + InsertPermission = "text" + }; + Assert.Equal("text", attribute.InsertPermission); + } + + [Fact] + public void InsertPermission_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + InsertPermission = null + }; + Assert.Null(attribute.InsertPermission); + } + [Fact] + public void HideOnInsert_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.HideOnInsert); + } + + [Fact] + public void HideOnInsert_CanBeSet_ToTrue() + { + var attribute = new PropertyItem() + { + HideOnInsert = true + }; + Assert.True(attribute.HideOnInsert); + } + + [Fact] + public void HideOnInsert_CanBeSet_ToFalse() + { + var attribute = new PropertyItem() + { + HideOnInsert = false + }; + Assert.False(attribute.HideOnInsert); + } + + [Fact] + public void HideOnInsert_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + HideOnInsert = null + }; + Assert.Null(attribute.HideOnInsert); + } + + [Fact] + public void Updatable_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.Updatable); + } + + [Fact] + public void Updatable_CanBeSet_ToTrue() + { + var attribute = new PropertyItem() + { + Updatable = true + }; + Assert.True(attribute.Updatable); + } + + [Fact] + public void Updatable_CanBeSet_ToFalse() + { + var attribute = new PropertyItem() + { + Updatable = false + }; + Assert.False(attribute.Updatable); + } + + [Fact] + public void Updatable_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + Updatable = null + }; + Assert.Null(attribute.Updatable); + } + + [Fact] + public void UpdatePermission_IsNull_ByDefault() + { + var attribute = new PropertyItem() + { + UpdatePermission = null + }; + Assert.Null(attribute.UpdatePermission); + } + + [Fact] + public void UpdatePermission_CanBeSet() + { + var attribute = new PropertyItem() + { + UpdatePermission = "text" + }; + Assert.Equal("text", attribute.UpdatePermission); + } + + [Fact] + public void UpdatePermission_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + UpdatePermission = null + }; + Assert.Null(attribute.UpdatePermission); + } + + [Fact] + public void HideOnUpdate_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.HideOnUpdate); + } + + [Fact] + public void HideOnUpdate_CanBeSet_ToTrue() + { + var attribute = new PropertyItem() + { + HideOnUpdate = true + }; + Assert.True(attribute.HideOnUpdate); + } + + [Fact] + public void HideOnUpdate_CanBeSet_ToFalse() + { + var attribute = new PropertyItem() + { + HideOnUpdate = false + }; + Assert.False(attribute.HideOnUpdate); + } + + [Fact] + public void HideOnUpdate_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + HideOnUpdate = null + }; + Assert.Null(attribute.HideOnUpdate); + } + + [Fact] + public void OneWay_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.OneWay); + } + + [Fact] + public void OneWay_CanBeSet_ToTrue() + { + var attribute = new PropertyItem() + { + OneWay = true + }; + Assert.True(attribute.OneWay); + } + + [Fact] + public void Oneway_CanBeSet_ToFalse() + { + var attribute = new PropertyItem() + { + OneWay = false + }; + Assert.False(attribute.OneWay); + } + + [Fact] + public void Oneway_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + OneWay = null + }; + Assert.Null(attribute.OneWay); + } + + [Fact] + public void DefaultValue_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.DefaultValue); + } + + [Fact] + public void DefaultValue_CanBeSet_ToTrue() + { + var attribute = new PropertyItem() + { + DefaultValue = true + }; + Assert.True((bool)attribute.DefaultValue); + } + + [Fact] + public void DefaultValue_CanBeSet_ToFalse() + { + var attribute = new PropertyItem() + { + DefaultValue = false + }; + Assert.False((bool)attribute.DefaultValue); + } + + [Fact] + public void DefaultValue_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + DefaultValue = null + }; + Assert.Null(attribute.DefaultValue); + } + + [Fact] + public void DefaultValue_CanBeSet() + { + var attribute = new PropertyItem() + { + DefaultValue = "text" + }; + Assert.Equal("text", attribute.DefaultValue); + } + + [Fact] + public void DefaultValue_CanBeSet_ToInt() + { + var attribute = new PropertyItem() + { + DefaultValue = 2 + }; + Assert.Equal(2, attribute.DefaultValue); + } + + [Fact] + public void DefaultValue_CanBeSet_ToEnum() + { + var attribute = new PropertyItem() + { + DefaultValue = Serenity.IO.DeleteType.Delete + }; + Assert.Equal(Serenity.IO.DeleteType.Delete, attribute.DefaultValue); + } + + [Fact] + public void Localizable_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.Localizable); + } + + [Fact] + public void Localizable_CanBeSet_ToTrue() + { + var attribute = new PropertyItem() + { + Localizable = true + }; + Assert.True((bool)attribute.Localizable); + } + + [Fact] + public void Localizable_CanBeSet_ToFalse() + { + var attribute = new PropertyItem() + { + Localizable = false + }; + Assert.False((bool)attribute.Localizable); + } + + [Fact] + public void Localizable_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + Localizable = null + }; + Assert.Null(attribute.Localizable); + } + + [Fact] + public void Visible_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.Visible); + } + + [Fact] + public void Visible_CanBeSet_ToTrue() + { + var attribute = new PropertyItem() + { + Visible = true + }; + Assert.True((bool)attribute.Visible); + } + + [Fact] + public void Visible_CanBeSet_ToFalse() + { + var attribute = new PropertyItem() + { + Visible = false + }; + Assert.False((bool)attribute.Visible); + } + + [Fact] + public void Visible_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + Visible = null + }; + Assert.Null(attribute.Visible); + } + + [Fact] + public void AllowHide_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.AllowHide); + } + + [Fact] + public void AllowHide_CanBeSet_ToTrue() + { + var attribute = new PropertyItem() + { + AllowHide = true + }; + Assert.True((bool)attribute.AllowHide); + } + + [Fact] + public void AllowHide_CanBeSet_ToFalse() + { + var attribute = new PropertyItem() + { + AllowHide = false + }; + Assert.False((bool)attribute.AllowHide); + } + + [Fact] + public void AllowHide_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + AllowHide = null + }; + Assert.Null(attribute.AllowHide); + } + + [Fact] + public void FormatterType_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.FormatterType); + } + + [Fact] + public void FormatterType_CanBeSet() + { + var attribute = new PropertyItem() + { + FormatterType = "sometext" + }; + Assert.Equal("sometext", attribute.FormatterType); + } + + [Fact] + public void FormatterType_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + FormatterType = null + }; + Assert.Null(attribute.FormatterType); + } + + [Fact] + public void DisplayFormat_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.DisplayFormat); + } + + [Fact] + public void DisplayFormat_CanBeSet() + { + var attribute = new PropertyItem() + { + DisplayFormat = "sometext" + }; + Assert.Equal("sometext", attribute.DisplayFormat); + } + + [Fact] + public void DisplayFormat_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + DisplayFormat = null + }; + Assert.Null(attribute.DisplayFormat); + } + + [Fact] + public void Alignment_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.Alignment); + } + + [Fact] + public void Alignment_CanBeSet() + { + var attribute = new PropertyItem() + { + Alignment = "sometext" + }; + Assert.Equal("sometext", attribute.Alignment); + } + + [Fact] + public void Aligment_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + Alignment = null + }; + Assert.Null(attribute.Alignment); + } + + [Fact] + public void Width_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.Width); + } + + [Fact] + public void Width_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + Width = null + }; + Assert.Null(attribute.Width); + } + + [Fact] + public void Width_CanBeSet_ToInt() + { + var attribute = new PropertyItem() + { + Width = 1 + }; + Assert.Equal(1, attribute.Width); + } + + [Fact] + public void WidthSet_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.WidthSet); + } + + [Fact] + public void WidthSet_CanBeSet_ToTrue() + { + var attribute = new PropertyItem() + { + WidthSet = true + }; + Assert.True((bool)attribute.WidthSet); + } + + [Fact] + public void WidthSet_CanBeSet_ToFalse() + { + var attribute = new PropertyItem() + { + WidthSet = false + }; + Assert.False((bool)attribute.WidthSet); + } + + [Fact] + public void WidthSet_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + WidthSet = null + }; + Assert.Null(attribute.WidthSet); + } + + [Fact] + public void MinWidth_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.MinWidth); + } + + [Fact] + public void MinWidth_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + MinWidth = null + }; + Assert.Null(attribute.MinWidth); + } + + [Fact] + public void MinWidth_CanBeSet_ToInt() + { + var attribute = new PropertyItem() + { + MinWidth = 1 + }; + Assert.Equal(1, attribute.MinWidth); + } + + [Fact] + public void MaxWidth_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.MaxWidth); + } + + [Fact] + public void MaxWidth_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + MaxWidth = null + }; + Assert.Null(attribute.MaxWidth); + } + + [Fact] + public void MaxWidth_CanBeSet_ToInt() + { + var attribute = new PropertyItem() + { + MaxWidth = 1 + }; + Assert.Equal(1, attribute.MaxWidth); + } + + [Fact] + public void LabelWidth_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.LabelWidth); + } + + [Fact] + public void LabelWidth_CanBeSet() + { + var attribute = new PropertyItem() + { + LabelWidth = "sometext" + }; + Assert.Equal("sometext", attribute.LabelWidth); + } + + [Fact] + public void LabelWidth_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + LabelWidth = null + }; + Assert.Null(attribute.LabelWidth); + } + + [Fact] + public void Resizable_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.Resizable); + } + + [Fact] + public void Resizable_CanBeSet_ToTrue() + { + var attribute = new PropertyItem() + { + Resizable = true + }; + Assert.True((bool)attribute.Resizable); + } + + [Fact] + public void Resizable_CanBeSet_ToFalse() + { + var attribute = new PropertyItem() + { + Resizable = false + }; + Assert.False((bool)attribute.Resizable); + } + + [Fact] + public void Resizable_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + Resizable = null + }; + Assert.Null(attribute.Resizable); + } + + [Fact] + public void Sortable_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.Sortable); + } + + [Fact] + public void Sortable_CanBeSet_ToTrue() + { + var attribute = new PropertyItem() + { + Sortable = true + }; + Assert.True((bool)attribute.Sortable); + } + + [Fact] + public void Sortable_CanBeSet_ToFalse() + { + var attribute = new PropertyItem() + { + Sortable = false + }; + Assert.False((bool)attribute.Sortable); + } + + [Fact] + public void Sortable_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + Sortable = null + }; + Assert.Null(attribute.Sortable); + } + + [Fact] + public void SortOrder_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.SortOrder); + } + + [Fact] + public void SortOrder_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + SortOrder = null + }; + Assert.Null(attribute.SortOrder); + } + + [Fact] + public void SortOrder_CanBeSet_ToInt() + { + var attribute = new PropertyItem() + { + SortOrder = 1 + }; + Assert.Equal(1, attribute.SortOrder); + } + + [Fact] + public void GroupOrder_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.GroupOrder); + } + + [Fact] + public void GroupOrder_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + GroupOrder = null + }; + Assert.Null(attribute.GroupOrder); + } + + [Fact] + public void GroupOrder_CanBeSet_ToInt() + { + var attribute = new PropertyItem() + { + GroupOrder = 1 + }; + Assert.Equal(1, attribute.GroupOrder); + } + + [Fact] + public void SummaryType_CanBeSet_ToEnum() + { + var attribute = new PropertyItem() + { + SummaryType = Serenity.SummaryType.None + }; + Assert.Equal(Serenity.SummaryType.None, attribute.SummaryType); + } + + [Fact] + public void SummaryType_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + SummaryType = null + }; + Assert.Null(attribute.SummaryType); + } + + [Fact] + public void SummaryType_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.EditLink); + } + + [Fact] + public void EditLink_CanBeSet_ToTrue() + { + var attribute = new PropertyItem() + { + EditLink = true + }; + Assert.True((bool)attribute.EditLink); + } + + [Fact] + public void EditLink_CanBeSet_ToFalse() + { + var attribute = new PropertyItem() + { + EditLink = false + }; + Assert.False((bool)attribute.EditLink); + } + + [Fact] + public void EditLink_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.EditLink); + } + + [Fact] + public void EditLink_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + EditLink = null + }; + Assert.Null(attribute.EditLink); + } + + [Fact] + public void EditLinkItemType_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.EditLinkItemType); + } + + [Fact] + public void EditLinkItemType_CanBeSet() + { + var attribute = new PropertyItem() + { + EditLinkItemType = "sometext" + }; + Assert.Equal("sometext", attribute.EditLinkItemType); + } + + [Fact] + public void EditLinkItemType_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + EditLinkItemType = null + }; + Assert.Null(attribute.EditLinkItemType); + } + + [Fact] + public void EditLinkIdField_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.EditLinkIdField); + } + + [Fact] + public void EditLinkIdField_CanBeSet() + { + var attribute = new PropertyItem() + { + EditLinkIdField = "sometext" + }; + Assert.Equal("sometext", attribute.EditLinkIdField); + } + + [Fact] + public void EditLinkIdField_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + EditLinkIdField = null + }; + Assert.Null(attribute.EditLinkIdField); + } + + [Fact] + public void EditLinkCssClass_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.EditLinkCssClass); + } + + [Fact] + public void EditLinkCssClass_CanBeSet() + { + var attribute = new PropertyItem() + { + EditLinkCssClass = "sometext" + }; + Assert.Equal("sometext", attribute.EditLinkCssClass); + } + + [Fact] + public void EditLinkCssClass_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + FilteringType = null + }; + Assert.Null(attribute.FilteringType); + } + + [Fact] + public void FilteringType_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.FilteringType); + } + + [Fact] + public void FilteringType_CanBeSet() + { + var attribute = new PropertyItem() + { + FilteringType = "sometext" + }; + Assert.Equal("sometext", attribute.FilteringType); + } + + [Fact] + public void FilteringType_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + FilteringType = null + }; + Assert.Null(attribute.FilteringType); + } + + [Fact] + public void FilteringIdField_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.FilteringIdField); + } + + [Fact] + public void FilteringIdField_CanBeSet() + { + var attribute = new PropertyItem() + { + FilteringIdField = "sometext" + }; + Assert.Equal("sometext", attribute.FilteringIdField); + } + + [Fact] + public void FilteringIdField_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + FilteringIdField = null + }; + Assert.Null(attribute.FilteringIdField); + } + + [Fact] + public void FilterOnly_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.FilterOnly); + } + + [Fact] + public void FilterOnly_CanBeSet_ToTrue() + { + var attribute = new PropertyItem() + { + FilterOnly = true + }; + Assert.True((bool)attribute.FilterOnly); + } + + [Fact] + public void FilterOnly_CanBeSet_ToFalse() + { + var attribute = new PropertyItem() + { + FilterOnly = false + }; + Assert.False((bool)attribute.FilterOnly); + } + + [Fact] + public void FilterOnly_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + FilterOnly = null + }; + Assert.Null(attribute.FilterOnly); + } + + [Fact] + public void NotFilterable_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.NotFilterable); + } + + [Fact] + public void NotFilterable_CanBeSet_ToTrue() + { + var attribute = new PropertyItem() + { + NotFilterable = true + }; + Assert.True((bool)attribute.NotFilterable); + } + + [Fact] + public void NotFilterable_CanBeSet_ToFalse() + { + var attribute = new PropertyItem() + { + NotFilterable = false + }; + Assert.False((bool)attribute.NotFilterable); + } + + [Fact] + public void NotFilterable_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + NotFilterable = null + }; + Assert.Null(attribute.NotFilterable); + } + + [Fact] + public void QuickFilter_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.QuickFilter); + } + + [Fact] + public void QuickFilter_CanBeSet_ToTrue() + { + var attribute = new PropertyItem() + { + QuickFilter = true + }; + Assert.True((bool)attribute.QuickFilter); + } + + [Fact] + public void QuickFilter_CanBeSet_ToFalse() + { + var attribute = new PropertyItem() + { + QuickFilter = false + }; + Assert.False((bool)attribute.QuickFilter); + } + + [Fact] + public void QuickFilter_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + QuickFilter = null + }; + Assert.Null(attribute.QuickFilter); + } + + [Fact] + public void QuickFilterSeparator_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.QuickFilterSeparator); + } + + [Fact] + public void QuickFilterSeparator_CanBeSet_ToTrue() + { + var attribute = new PropertyItem() + { + QuickFilterSeparator = true + }; + Assert.True((bool)attribute.QuickFilterSeparator); + } + + [Fact] + public void QuickFilterSeparator_CanBeSet_ToFalse() + { + var attribute = new PropertyItem() + { + QuickFilterSeparator = false + }; + Assert.False((bool)attribute.QuickFilterSeparator); + } + + [Fact] + public void QuickFilterSeparator_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + QuickFilterSeparator = null + }; + Assert.Null(attribute.QuickFilterSeparator); + } + + [Fact] + public void QuickFilterCssClass_IsNull_ByDefault() + { + var attribute = new PropertyItem(); + Assert.Null(attribute.QuickFilterCssClass); + } + + [Fact] + public void QuickFilterCssClass_CanBeSet() + { + var attribute = new PropertyItem() + { + QuickFilterCssClass = "sometext" + }; + Assert.Equal("sometext", attribute.QuickFilterCssClass); + } + + [Fact] + public void QuickFilterCssClass_CanBeSet_ToNull() + { + var attribute = new PropertyItem() + { + QuickFilterCssClass = null + }; + Assert.Null(attribute.QuickFilterCssClass); + } + + [Fact] + public void EditorType_NotNullAndNotString_ReturnsTrue() + { + var attribute = new PropertyItem + { + EditorType = "EditorType" + }; + + bool result = attribute.ShouldSerializeEditorType(); + Assert.True(result); + } + + [Fact] + public void EditorType_Null_ReturnsFalse() + { + var attribute = new PropertyItem + { + EditorType = null + }; + + bool result = attribute.ShouldSerializeEditorType(); + Assert.False(result); + } + + [Fact] + public void EditorType_String_ReturnsFalse() + { + var attribute = new PropertyItem + { + EditorType = "String" + }; + + bool result = attribute.ShouldSerializeEditorType(); + Assert.False(result); + } + + [Fact] + public void FilteringType_NotNullAndNotString_ReturnsTrue() + { + var attribute = new PropertyItem() + { + FilteringType = "FilteringType" + }; + bool result = attribute.ShouldSerializeFilteringType(); + Assert.True(result); + } + + [Fact] + public void FilteringType_IsNull_Return_False() + { + var attribute = new PropertyItem() + { + FilteringType = null + }; + bool result = attribute.ShouldSerializeFilteringType(); + Assert.False(result); + } + + [Fact] + public void FilteringType_String_ReturnFalse() + { + var attribute = new PropertyItem() + { + FilteringType = "String" + }; + bool result = attribute.ShouldSerializeFilteringType(); + Assert.False(result); + } + + [Fact] + public void ShouldSerializeEditorParams_WithNonEmptyDictionary_ReturnsTrue() + { + var attribute = new PropertyItem + { + EditorParams = new Dictionary + { + { "key", "value" } + } + }; + + bool result = attribute.ShouldSerializeEditorParams(); + Assert.True(result); + } + + [Fact] + public void ShouldSerializeEditorParams_WithNullDictionary_ReturnsFalse() + { + var attribute = new PropertyItem + { + EditorParams = null + }; + + bool result = attribute.ShouldSerializeEditorParams(); + Assert.False(result); + } + + [Fact] + public void ShouldSerializeEditorParams_WithEmptyDictionary_ReturnsFalse() + { + var attribute = new PropertyItem + { + EditorParams = new Dictionary() + }; + + bool result = attribute.ShouldSerializeEditorParams(); + Assert.False(result); + } + + [Fact] + public void FormatterParams_WithNonEmptyDictionary_ReturnsTrue() + { + var attribute = new PropertyItem + { + FormatterParams = new Dictionary + { + { "key", "value" } + } + }; + + bool result = attribute.ShouldSerializeFormatterParams(); + Assert.True(result); + } + + [Fact] + public void FormatterParams_WithNullDictionary_ReturnsFalse() + { + var attribute = new PropertyItem + { + FormatterParams = null + }; + + bool result = attribute.ShouldSerializeFormatterParams(); + Assert.False(result); + } + + [Fact] + public void FormatterParams_WithEmptyDictionary_ReturnsFalse() + { + var attribute = new PropertyItem + { + FormatterParams = new Dictionary() + }; + + bool result = attribute.ShouldSerializeFormatterParams(); + Assert.False(result); + } + + [Fact] + public void FilteringParams_WithNonEmptyDictionary_ReturnsTrue() + { + var attribute = new PropertyItem + { + FilteringParams = new Dictionary + { + { "key", "value" } + } + }; + + bool result = attribute.ShouldSerializeFilteringParams(); + Assert.True(result); + } + + [Fact] + public void FilteringParams_WithNullDictionary_ReturnsFalse() + { + var attribute = new PropertyItem + { + FilteringParams = null + }; + + bool result = attribute.ShouldSerializeFilteringParams(); + Assert.False(result); + } + + [Fact] + public void FilteringParams_WithEmptyDictionary_ReturnsFalse() + { + var attribute = new PropertyItem + { + FilteringParams = new Dictionary() + }; + + bool result = attribute.ShouldSerializeFilteringParams(); + Assert.False(result); + } + + [Fact] + public void QuickFilterParams_WithNonEmptyDictionary_ReturnsTrue() + { + var attribute = new PropertyItem + { + QuickFilterParams = new Dictionary + { + { "key", "value" } + } + }; + + bool result = attribute.ShouldSerializeQuickFilterParams(); + Assert.True(result); + } + + [Fact] + public void QuickFilterParams_WithNullDictionary_ReturnsFalse() + { + var attribute = new PropertyItem + { + QuickFilterParams = null + }; + + bool result = attribute.ShouldSerializeQuickFilterParams(); + Assert.False(result); + } + + [Fact] + public void QuickFilterParams_WithEmptyDictionary_ReturnsFalse() + { + var attribute = new PropertyItem + { + QuickFilterParams = new Dictionary() + }; + + bool result = attribute.ShouldSerializeQuickFilterParams(); + Assert.False(result); + } +} \ No newline at end of file diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/PropertyItemsDataTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/PropertyItemsDataTests.cs new file mode 100644 index 0000000000..084ff5d77f --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/PropertyItemsDataTests.cs @@ -0,0 +1,42 @@ +namespace Serenity.Tests.ComponentModel; + +public class PropertyItemsDataTests +{ + + [Fact] + public void Items_ShouldBeInitializedCorrectly() + { + var items = new List { new PropertyItem(), new PropertyItem() }; + var data = new PropertyItemsData + { + Items = items + }; + Assert.Equal(items, data.Items); + } + + [Fact] + public void AdditionalItems_ShouldBeInitializedCorrectly() + { + var additionalItems = new List { new PropertyItem(), new PropertyItem() }; + var data = new PropertyItemsData + { + AdditionalItems = additionalItems + }; + Assert.Equal(additionalItems, data.AdditionalItems); + } + + [Fact] + public void Items_IsNull_ByDefault() + { + var data = new PropertyItemsData(); + Assert.Null(data.Items); + } + + [Fact] + public void AdditionalItems_IsNull_ByDefault() + { + var data = new PropertyItemsData(); + Assert.Null(data.AdditionalItems); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/RequiredAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/RequiredAttributeTests.cs new file mode 100644 index 0000000000..bc0aecf162 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/RequiredAttributeTests.cs @@ -0,0 +1,26 @@ +namespace Serenity.Tests.ComponentModel; + +public class RequiredAttributeTests +{ + [Fact] + public void IsRequired_ShouldBeTrue_ByDefault() + { + var attribute = new RequiredAttribute(); + Assert.True(attribute.IsRequired); + } + + [Fact] + public void RequiredAttribute_CanBePassed_AsFalse() + { + var attribute = new RequiredAttribute(false); + Assert.False(attribute.IsRequired); + } + + [Fact] + public void RequiredAttribute_CanBePassed_AsTrue() + { + var attribute = new RequiredAttribute(true); + Assert.True(attribute.IsRequired); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/ResizableAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/ResizableAttributeTests.cs new file mode 100644 index 0000000000..d866374ae5 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/ResizableAttributeTests.cs @@ -0,0 +1,26 @@ +namespace Serenity.Tests.ComponentModel; + +public class ResizableAttributeTests +{ + [Fact] + public void Value_ShouldBeTrue_ByDefault() + { + var attribute = new ResizableAttribute(); + Assert.True(attribute.Value); + } + + [Fact] + public void Value_CanBePassed_AsFalse() + { + var attribute = new ResizableAttribute(false); + Assert.False(attribute.Value); + } + + [Fact] + public void Value_CanBePassed_AsTrue() + { + var attribute = new ResizableAttribute(true); + Assert.True(attribute.Value); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/SortOrderAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/SortOrderAttributeTests.cs new file mode 100644 index 0000000000..3847513d1d --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/SortOrderAttributeTests.cs @@ -0,0 +1,32 @@ +namespace Serenity.Tests.ComponentModel; + +public class SortOrderAttributeTests +{ + [Fact] + public void SortOrder_ShouldBeNegative_WhenDescendingIsTrue() + { + var attribute = new SortOrderAttribute(1, true); + Assert.Equal(-1, attribute.SortOrder); + } + + [Fact] + public void SortOder_ShouldBePositive_WhenDescendingIsFalse() + { + var attribute = new SortOrderAttribute(2, false); + Assert.Equal(2, attribute.SortOrder); + } + + [Fact] + public void SortOrderAttribute_NegativeSortOrder_ReturnsDescendingTrue() + { + var attribute = new SortOrderAttribute(-1); + Assert.True(attribute.Descending); + } + + [Fact] + public void SortOrderAttribute_PositiveSortOrder_ReturnsDescendingFalse() + { + var attribute = new SortOrderAttribute(1); + Assert.False(attribute.Descending); + } +} diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/TabAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/TabAttributeTests.cs new file mode 100644 index 0000000000..c380152265 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/PropertyGrid/TabAttributeTests.cs @@ -0,0 +1,19 @@ +namespace Serenity.Tests.ComponentModel; + +public class TabAttributeTests +{ + [Fact] + public void Value_CanBePassed_AsString() + { + var attribute = new TabAttribute("value"); + Assert.Equal("value", attribute.Value); + } + + [Fact] + public void Value_CanBePassed_AsNull() + { + var attribute = new TabAttribute(null); + Assert.Null(attribute.Value); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/Upload/BaseUploadEditorAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/Upload/BaseUploadEditorAttributeTests.cs new file mode 100644 index 0000000000..70707d275a --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/Upload/BaseUploadEditorAttributeTests.cs @@ -0,0 +1,534 @@ +namespace Serenity.Tests.ComponentModel; + +public class BaseUploadEditorAttributeTests +{ + private class MyBaseUploadEditorAttribute : BaseUploadEditorAttribute + { + public MyBaseUploadEditorAttribute(string editorType, bool isMultiple) : base(editorType) + { + _isMultiple = isMultiple; + } + + private readonly bool _isMultiple; + public override bool IsMultiple => _isMultiple; + } + + [Fact] + public void DisableDefaultBehavior_CanBeSet_ToTrue() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + DisableDefaultBehavior = true + }; + Assert.True(attribute.DisableDefaultBehavior); + + } + + [Fact] + public void DisableDefaultBehavior_CanBeSet_ToFalse() + { + var attribute = new MyBaseUploadEditorAttribute("text", false) + { + DisableDefaultBehavior = false + }; + Assert.False(attribute.DisableDefaultBehavior); + } + + [Fact] + public void IsMultiple_CanBeSet_ToTrue() + { + var attribute = new MyBaseUploadEditorAttribute("text", true); + Assert.True(attribute.IsMultiple); + } + + [Fact] + public void IsMultiple_CanBeSet_ToFalse() + { + var attribute = new MyBaseUploadEditorAttribute("text", false); + Assert.False(attribute.IsMultiple); + } + + [Fact] + public void UploadIntent_CanBeSet() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + UploadIntent = "sometext" + }; + Assert.Equal("sometext", attribute.UploadIntent); + } + + [Fact] + public void UploadIntent_CanBeSet_ToNull() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + UploadIntent = null + }; + Assert.Null(attribute.UploadIntent); + } + + [Fact] + public void AllowNonImage_CanBeSet_ToTrue() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + AllowNonImage = true + }; + Assert.True(attribute.AllowNonImage); + } + + [Fact] + public void AllowNonImage_CanBeSet_ToFalse() + { + var attribute = new MyBaseUploadEditorAttribute("text", false) + { + AllowNonImage = false + }; + Assert.False(attribute.AllowNonImage); + } + + [Fact] + public void MaxSize_CanBeSet_ToInt() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + MaxSize = 100 + }; + Assert.Equal(100, attribute.MaxSize); + } + + [Fact] + public void MinSize_CanBeSet_ToInt() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + MinSize = 1 + }; + Assert.Equal(1, attribute.MinSize); + } + + [Fact] + public void MaxHeight_CanBeSet_ToInt() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + MaxHeight = 100 + }; + Assert.Equal(100, attribute.MaxHeight); + } + + [Fact] + public void MaxWidth_CanBeSet_ToInt() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + MaxWidth = 100 + }; + Assert.Equal(100, attribute.MaxWidth); + } + + [Fact] + public void MinHeight_CanBeSet_ToInt() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + MinHeight = 100 + }; + Assert.Equal(100, attribute.MinHeight); + } + + [Fact] + public void MinWidth_CanBeSet_ToInt() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + MinWidth = 100 + }; + Assert.Equal(100, attribute.MinWidth); + } + + [Fact] + public void ScaleQuality_CanBeSet_ToInt() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + ScaleQuality = 80 + }; + Assert.Equal(80, attribute.ScaleQuality); + } + + [Fact] + public void ScaleWidth_CanBeSet_ToInt() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + ScaleWidth = 100 + }; + Assert.Equal(100, attribute.ScaleWidth); + } + + [Fact] + public void ScaleHeight_CanBeSet_ToInt() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + ScaleHeight = 100 + }; + Assert.Equal(100, attribute.ScaleHeight); + } + + [Fact] + public void ScaleSmaller_CanBeSet_ToTrue() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + ScaleSmaller = true + }; + Assert.True(attribute.ScaleSmaller); + } + + [Fact] + public void ScaleSmaller_CanBeSet_ToFalse() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + ScaleSmaller = false + }; + Assert.False(attribute.ScaleSmaller); + } + + [Fact] + public void ScaleMode_CanBeSet_ToEnum() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + ScaleMode = Serenity.Web.ImageScaleMode.StretchToFit + }; + Assert.Equal(Serenity.Web.ImageScaleMode.StretchToFit, attribute.ScaleMode); + } + + [Fact] + public void ScaleMode_CanBeSet_ToDefaultScaleMode() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + ScaleMode = UploadOptions.DefaultScaleMode + }; + Assert.Equal(UploadOptions.DefaultScaleMode, attribute.ScaleMode); + } + + [Fact] + public void ScaleBackColor_CanBeSet() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + ScaleBackColor = "sometext" + }; + Assert.Equal("sometext", attribute.ScaleBackColor); + } + + [Fact] + public void ScaleBackColor_CanBeSet_ToNull() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + ScaleBackColor = null + }; + Assert.Null(attribute.ScaleBackColor); + } + + [Fact] + public void ThumbHeight_CanBeSet_ToInt() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + ThumbHeight = 1 + }; + Assert.Equal(1, attribute.ThumbHeight); + } + + [Fact] + public void ThumbWidth_CanBeSet_ToInt() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + ThumbWidth = 1 + }; + Assert.Equal(1, attribute.ThumbWidth); + } + + [Fact] + public void ThumbSizes_CanBeSet() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + ThumbSizes = "sometext" + }; + Assert.Equal("sometext", attribute.ThumbSizes); + } + + [Fact] + public void ThumbSizes_CanBeSet_ToNull() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + ThumbSizes = null + }; + Assert.Null(attribute.ThumbSizes); + } + + [Fact] + public void ThumbMode_CanBeSet_ToEnum() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + ThumbMode = ImageScaleMode.CropSourceImage + }; + Assert.Equal(ImageScaleMode.CropSourceImage, attribute.ThumbMode); + } + + [Fact] + public void ThumbMode_CanBeSet_ToDefaultThumbMode() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + ThumbMode = UploadOptions.DefaultThumbMode + }; + Assert.Equal(UploadOptions.DefaultThumbMode, attribute.ThumbMode); + } + + [Fact] + public void ThumbQuality_CanBeSet_ToDefaultThumbQuality() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + ThumbQuality = UploadOptions.DefaultThumbQuality + }; + Assert.Equal(UploadOptions.DefaultThumbQuality, attribute.ThumbQuality); + } + + [Fact] + public void ThumbBackColor_CanBeSet() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + ThumbBackColor = "sometext" + }; + Assert.Equal("sometext", attribute.ThumbBackColor); + } + + [Fact] + public void ThumbBackColor_CanBeSet_ToNull() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + ThumbBackColor = null + }; + Assert.Null(attribute.ThumbBackColor); + } + + [Fact] + public void JsonEncodeValue_CanBeSet_ToTrue() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + JsonEncodeValue = true + }; + Assert.True(attribute.JsonEncodeValue); + } + + [Fact] + public void JsonEncodeValue_CanBeSet_ToFalse() + { + var attribute = new MyBaseUploadEditorAttribute("text", false) + { + JsonEncodeValue = false + }; + Assert.False(attribute.JsonEncodeValue); + } + + [Fact] + public void OriginalNameProperty_CanBeSet() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + OriginalNameProperty = "sometext" + }; + Assert.Equal("sometext", attribute.OriginalNameProperty); + } + + [Fact] + public void OriginalNameProperty_CanBeSetToNull() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + OriginalNameProperty = null + }; + Assert.Null(attribute.OriginalNameProperty); + } + + [Fact] + public void DisplayFileName_CanBeSet_ToTrue() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + DisplayFileName = true + }; + Assert.True(attribute.DisplayFileName); + } + [Fact] + public void CopyToHistory_CanBeSet_ToTrue() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + CopyToHistory = true + }; + Assert.True(attribute.CopyToHistory); + } + + [Fact] + public void CopyToHistory_CanBeSet_ToFalse() + { + var attribute = new MyBaseUploadEditorAttribute("text", false) + { + CopyToHistory = false + }; + Assert.False(attribute.CopyToHistory); + } + + [Fact] + public void FilenameFormat_CanBeSet() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + FilenameFormat = "sometext" + }; + Assert.Equal("sometext", attribute.FilenameFormat); + } + + [Fact] + public void FilenameFormat_CanBeSet_ToNull() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + FilenameFormat = null + }; + Assert.Null(attribute.FilenameFormat); + } + + [Fact] + public void AllowedExtensions_CanBeSet() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + AllowedExtensions = "sometext" + }; + Assert.Equal("sometext", attribute.AllowedExtensions); + } + + [Fact] + public void AllowedExtensions_CanBeSet_ToNull() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + AllowedExtensions = null + }; + Assert.Null(attribute.AllowedExtensions); + } + + [Fact] + public void ImageExtensions_CanBeSet() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + ImageExtensions = "sometext" + }; + Assert.Equal("sometext", attribute.ImageExtensions); + } + + [Fact] + public void ImageExtensions_CanBeSet_ToNull() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + ImageExtensions = null + }; + Assert.Null(attribute.ImageExtensions); + } + + [Fact] + public void ImageExtensions_CanBeSet_ToDefaultImageExtension() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + ImageExtensions = UploadOptions.DefaultImageExtensions + }; + Assert.Equal(UploadOptions.DefaultImageExtensions, attribute.ImageExtensions); + } + + [Fact] + public void IgnoreExtensionMismatch_CanBeSet_ToTrue() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + IgnoreExtensionMismatch = true + }; + Assert.True(attribute.IgnoreExtensionMismatch); + } + + [Fact] + public void IgnoreExtensionMismatch_CanBeSet_ToFalse() + { + var attribute = new MyBaseUploadEditorAttribute("text", false) + { + IgnoreExtensionMismatch = false + }; + Assert.False(attribute.IgnoreExtensionMismatch); + } + + [Fact] + public void IgnoreEmptyImage_CanBeSet_ToTrue() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + IgnoreEmptyImage = true + }; + Assert.True(attribute.IgnoreEmptyImage); + } + + [Fact] + public void IgnoreEmptyImage_CanBeSet_ToFalse() + { + var attribute = new MyBaseUploadEditorAttribute("text", false) + { + IgnoreEmptyImage = false + }; + Assert.False(attribute.IgnoreEmptyImage); + } + + [Fact] + public void IgnoreInvalidImage_CanBeSet_ToTrue() + { + var attribute = new MyBaseUploadEditorAttribute("text", true) + { + IgnoreInvalidImage = true + }; + Assert.True(attribute.IgnoreInvalidImage); + } + + [Fact] + public void IgnoreInvalidImage_CanBeSet_ToFalse() + { + var attribute = new MyBaseUploadEditorAttribute("text", false) + { + IgnoreInvalidImage = false + }; + Assert.False(attribute.IgnoreInvalidImage); + } +} + + + + + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/Upload/DefaultFilenameFormatSanitizerTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/Upload/DefaultFilenameFormatSanitizerTests.cs new file mode 100644 index 0000000000..484fd23928 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/Upload/DefaultFilenameFormatSanitizerTests.cs @@ -0,0 +1,116 @@ +namespace Serenity.Tests.ComponentModel; + +public class DefaultFilenameFormatSanitizerTests +{ + [Fact] + public void Instance_ReturnsNonNullSingleton() + { + var instance = DefaultFilenameFormatSanitizer.Instance; + Assert.NotNull(instance); + Assert.IsType(instance); + } + + [Fact] + public void SanitizePlaceholder_ReplacesBackslashesAndDiacritics() + { + var attribute = new DefaultFilenameFormatSanitizer(); + string result = attribute.SanitizePlaceholder("", @"filen\ame..txt"); + Assert.Equal("filen_ame_txt", result); + } + + [Fact] + public void SanitizePlaceholder_ReplacesMultipleDots() + { + var attribute = new DefaultFilenameFormatSanitizer(); + string result = attribute.SanitizePlaceholder("", "file..name"); + Assert.Equal("file_name", result); + } + + [Fact] + public void SanitizePlaceholder_HandlesEmptyOrWhitespace() + { + var attribute = new DefaultFilenameFormatSanitizer(); + string result = attribute.SanitizePlaceholder("", " "); + Assert.Equal("_", result); + } + + [Fact] + public void SanitizePlaceholder_TrimsTrailingDots() + { + var attribute = new DefaultFilenameFormatSanitizer(); + string result = attribute.SanitizePlaceholder("", "filename."); + Assert.Equal("filename_", result); + } + + [Fact] + public void SanitizePlaceholder_ReturnsUnderscore_ForNullValue() + { + var attribute = new DefaultFilenameFormatSanitizer(); + string result = attribute.SanitizePlaceholder("", null); + Assert.Equal("_", result); + } + + [Fact] + public void SanitizePlaceholder_ReturnsUnderscore_ForEmptyValue() + { + var attribute = new DefaultFilenameFormatSanitizer(); + string result = attribute.SanitizePlaceholder("", ""); + Assert.Equal("_", result); + } + + [Fact] + public void SanitizePlaceholder_ReturnsUnderscore_ForWhitespaceValue() + { + var attribute = new DefaultFilenameFormatSanitizer(); + string result = attribute.SanitizePlaceholder("", " "); + Assert.Equal("_", result); + } + + [Fact] + public void SanitizeResult_ReturnsUnderscoreAsIs() + { + var attribute = new DefaultFilenameFormatSanitizer(); + string result = attribute.SanitizeResult("_"); + Assert.Equal("_", result); + } + + [Fact] + public void SanitizeResult_ReturnsEmptyStringAsIs() + { + var attribute = new DefaultFilenameFormatSanitizer(); + string result = attribute.SanitizeResult(""); + Assert.Equal("", result); + } + + [Fact] + public void SanitizeResult_ReturnsNullAsIs() + { + var attribute = new DefaultFilenameFormatSanitizer(); + string result = attribute.SanitizeResult(null); + Assert.Null(result); + } + + [Fact] + public void SanitizeResult_ReplacesBackslashes_WithSlashes() + { + var attribute = new DefaultFilenameFormatSanitizer(); + string result = attribute.SanitizeResult("path\\to\\file"); + Assert.Equal("path/to/file", result); + } + + [Fact] + public void SanitizeResult_ReplacesDoubleSlashes_WithSlashUnderscoreSlash() + { + var attribute = new DefaultFilenameFormatSanitizer(); + string result = attribute.SanitizeResult("path//to//file"); + Assert.Equal("path/_/to/_/file", result); + } + + [Fact] + public void SanitizeResult_HandlesComplexPath() + { + var attribute = new DefaultFilenameFormatSanitizer(); + string result = attribute.SanitizeResult("path\\to//some\\file"); + Assert.Equal("path/to/_/some/file", result); + } +} \ No newline at end of file diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/Upload/FileUploadEditorAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/Upload/FileUploadEditorAttributeTests.cs new file mode 100644 index 0000000000..c5ffef6df0 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/Upload/FileUploadEditorAttributeTests.cs @@ -0,0 +1,45 @@ +namespace Serenity.Tests.ComponentModel; + +public class FileUploadEditorAttributeTests +{ + [Fact] + public void EditorType_ShouldBe_ImageUpload() + { + var attribute = new FileUploadEditorAttribute(); + Assert.Equal("ImageUpload", attribute.EditorType); + } + + [Fact] + public void AllowNonImage_CanBeSet_ToTrue() + { + var attribute = new FileUploadEditorAttribute() + { + AllowNonImage = true + }; + Assert.True(attribute.AllowNonImage); + } + + [Fact] + public void AllowNonImage_IsTrue_ByDefault() + { + var attribute = new FileUploadEditorAttribute(); + Assert.True(attribute.AllowNonImage); + } + + [Fact] + public void AllowNonImage_CanBeSet_ToFalse() + { + var attribute = new FileUploadEditorAttribute() + { + AllowNonImage = false + }; + Assert.False(attribute.AllowNonImage); + } + + [Fact] + public void IsMultiple_Isfalse_ByDefault() + { + var attribute = new FileUploadEditorAttribute(); + Assert.False(attribute.IsMultiple); + } +} diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/Upload/ImageUploadEditorAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/Upload/ImageUploadEditorAttributeTests.cs new file mode 100644 index 0000000000..b4e2dc8a17 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/Upload/ImageUploadEditorAttributeTests.cs @@ -0,0 +1,45 @@ +namespace Serenity.Tests.ComponentModel; + +public class ImageUploadEditorAttributeTests +{ + [Fact] + public void EditorType_ShouldBe_ImageUpload() + { + var attribute = new ImageUploadEditorAttribute(); + Assert.Equal("ImageUpload", attribute.EditorType); + } + + [Fact] + public void AllowNonImage_CanBeSet_ToTrue() + { + var attribute = new ImageUploadEditorAttribute() + { + AllowNonImage = true + }; + Assert.True(attribute.AllowNonImage); + } + + [Fact] + public void AllowNonImage_IsFalse_ByDefault() + { + var attribute = new ImageUploadEditorAttribute(); + Assert.False(attribute.AllowNonImage); + } + + [Fact] + public void AllowNonImage_CanBeSet_ToFalse() + { + var attribute = new ImageUploadEditorAttribute() + { + AllowNonImage = false + }; + Assert.False(attribute.AllowNonImage); + } + + [Fact] + public void IsMultiple_Isfalse_ByDefault() + { + var attribute = new ImageUploadEditorAttribute(); + Assert.False(attribute.IsMultiple); + } +} diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/Upload/MultipleFileUploadEditorAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/Upload/MultipleFileUploadEditorAttributeTests.cs new file mode 100644 index 0000000000..4484963334 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/Upload/MultipleFileUploadEditorAttributeTests.cs @@ -0,0 +1,75 @@ +namespace Serenity.Tests.ComponentModel; + +public class MultipleFileUploadEditorAttributeTests +{ + [Fact] + public void EditorType_ShouldBe_MultipleImageUpload() + { + var attribute = new MultipleFileUploadEditorAttribute(); + Assert.Equal("MultipleImageUpload", attribute.EditorType); + } + + [Fact] + public void AllowNonImage_CanBeSet_ToTrue() + { + var attribute = new MultipleFileUploadEditorAttribute() + { + AllowNonImage = true + }; + Assert.True(attribute.AllowNonImage); + } + + [Fact] + public void AllowNonImage_IsTrue_ByDefault() + { + var attribute = new MultipleFileUploadEditorAttribute(); + Assert.True(attribute.AllowNonImage); + } + + [Fact] + public void AllowNonImage_CanBeSet_ToFalse() + { + var attribute = new MultipleFileUploadEditorAttribute() + { + AllowNonImage = false + }; + Assert.False(attribute.AllowNonImage); + } + + [Fact] + public void JsonEncodeValue_CanBeSet_ToTrue() + { + var attribute = new MultipleFileUploadEditorAttribute() + { + JsonEncodeValue = true + }; + Assert.True(attribute.JsonEncodeValue); + } + + [Fact] + public void JsonEncodeValue_IsTrue_ByDefault() + { + var attribute = new MultipleFileUploadEditorAttribute(); + Assert.True(attribute.JsonEncodeValue); + } + + [Fact] + public void JsonEncodeValue_CanBeSet_ToFalse() + { + var attribute = new MultipleFileUploadEditorAttribute() + { + JsonEncodeValue = false + }; + Assert.False(attribute.JsonEncodeValue); + } + + [Fact] + public void IsMultiple_IsTrue_ByDefault() + { + var attribute = new MultipleFileUploadEditorAttribute(); + Assert.True(attribute.IsMultiple); + } +} + + + diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/Upload/MultipleImageUploadEditorAttributeTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/Upload/MultipleImageUploadEditorAttributeTests.cs new file mode 100644 index 0000000000..d35b57aca1 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/Upload/MultipleImageUploadEditorAttributeTests.cs @@ -0,0 +1,72 @@ +namespace Serenity.Tests.ComponentModel; + +public class MultipleImageUploadEditorAttributeTests +{ + [Fact] + public void EditorType_ShouldBe_ImageUpload() + { + var attribute = new MultipleImageUploadEditorAttribute(); + Assert.Equal("MultipleImageUpload", attribute.EditorType); + } + + [Fact] + public void AllowNonImage_CanBeSet_ToTrue() + { + var attribute = new MultipleImageUploadEditorAttribute() + { + AllowNonImage = true + }; + Assert.True(attribute.AllowNonImage); + } + + [Fact] + public void AllowNonImage_IsFalse_ByDefault() + { + var attribute = new MultipleImageUploadEditorAttribute(); + Assert.False(attribute.AllowNonImage); + } + + [Fact] + public void AllowNonImage_CanBeSet_ToFalse() + { + var attribute = new MultipleImageUploadEditorAttribute() + { + AllowNonImage = false + }; + Assert.False(attribute.AllowNonImage); + } + + [Fact] + public void JsonEncodeValue_CanBeSet_ToTrue() + { + var attribute = new MultipleImageUploadEditorAttribute() + { + JsonEncodeValue = true + }; + Assert.True(attribute.JsonEncodeValue); + } + + [Fact] + public void JsonEncodeValue_IsTrue_ByDefault() + { + var attribute = new MultipleImageUploadEditorAttribute(); + Assert.True(attribute.JsonEncodeValue); + } + + [Fact] + public void JsonEncodeValue_CanBeSet_ToFalse() + { + var attribute = new MultipleImageUploadEditorAttribute() + { + JsonEncodeValue = false + }; + Assert.False(attribute.JsonEncodeValue); + } + + [Fact] + public void IsMultiple_IsTrue_ByDefault() + { + var attribute = new MultipleImageUploadEditorAttribute(); + Assert.True(attribute.IsMultiple); + } +} diff --git a/tests/Serenity.Net.Core.Tests/ComponentModel/Upload/UploadOptionsTests.cs b/tests/Serenity.Net.Core.Tests/ComponentModel/Upload/UploadOptionsTests.cs new file mode 100644 index 0000000000..140477057a --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/ComponentModel/Upload/UploadOptionsTests.cs @@ -0,0 +1,535 @@ +namespace Serenity.Tests.ComponentModel; + +public class UploadOptionsTests +{ + [Fact] + public void AllowNonImage_IsTrue_ByDefault() + { + var attribute = new UploadOptions(); + Assert.True(attribute.AllowNonImage); + } + + [Fact] + public void AllowNonImage_CanBeSet_ToTrue() + { + var attribute = new UploadOptions() + { + AllowNonImage = true + }; + Assert.True(attribute.AllowNonImage); + } + + [Fact] + public void AllowNonImage_CanBeSet_ToFalse() + { + var attribute = new UploadOptions() + { + AllowNonImage = false + }; + Assert.False(attribute.AllowNonImage); + } + + [Fact] + public void MaxSize_CanBeSet_ToInt() + { + var attribute = new UploadOptions() + { + MaxSize = 100 + }; + Assert.Equal(100, attribute.MaxSize); + } + + [Fact] + public void MaxSize_IsZero_ByDefault() + { + var attribute = new UploadOptions(); + Assert.Equal(0, attribute.MaxSize); + } + + [Fact] + public void MinSize_CanBeSet_ToInt() + { + var attribute = new UploadOptions() + { + MinSize = 1 + }; + Assert.Equal(1, attribute.MinSize); + } + + [Fact] + public void MinSize_IsZero_ByDefault() + { + var attribute = new UploadOptions(); + Assert.Equal(0, attribute.MinSize); + } + + [Fact] + public void MaxHeight_CanBeSet_ToInt() + { + var attribute = new UploadOptions() + { + MaxHeight = 1 + }; + Assert.Equal(1, attribute.MaxHeight); + } + + [Fact] + public void MaxHeight_IsZero_ByDefault() + { + var attribute = new UploadOptions(); + Assert.Equal(0, attribute.MaxHeight); + } + + [Fact] + public void MaxWidth_CanBeSet_ToInt() + { + var attribute = new UploadOptions() + { + MaxWidth = 1 + }; + Assert.Equal(1, attribute.MaxWidth); + } + + [Fact] + public void MaxWidth_IsZero_ByDefault() + { + var attribute = new UploadOptions(); + Assert.Equal(0, attribute.MaxWidth); + } + + [Fact] + public void MinHeight_CanBeSet_ToInt() + { + var attribute = new UploadOptions() + { + MinHeight = 1 + }; + Assert.Equal(1, attribute.MinHeight); + } + + [Fact] + public void MinHeight_IsZero_ByDefault() + { + var attribute = new UploadOptions(); + Assert.Equal(0, attribute.MinHeight); + } + + [Fact] + public void MinWidth_CanBeSet_ToInt() + { + var attribute = new UploadOptions() + { + MinWidth = 1 + }; + Assert.Equal(1, attribute.MinWidth); + } + + [Fact] + public void MinWidth_IsZero_ByDefault() + { + var attribute = new UploadOptions(); + Assert.Equal(0, attribute.MinWidth); + } + + [Fact] + public void ScaleQuality_CanBeSet_ToInt() + { + var attribute = new UploadOptions() + { + ScaleQuality = 1 + }; + Assert.Equal(1, attribute.ScaleQuality); + } + + [Fact] + public void ScaleQuality_Is_ByDefault() + { + var attribute = new UploadOptions(); + Assert.Equal(80, attribute.ScaleQuality); + } + + [Fact] + public void ScaleWidth_CanBeSet_ToInt() + { + var attribute = new UploadOptions() + { + ScaleWidth = 1 + }; + Assert.Equal(1, attribute.ScaleWidth); + } + + [Fact] + public void ScaleWidth_Is_ByDefault() + { + var attribute = new UploadOptions(); + Assert.Equal(0, attribute.ScaleWidth); + } + + [Fact] + public void ScaleHeight_CanBeSet_ToInt() + { + var attribute = new UploadOptions() + { + ScaleHeight = 1 + }; + Assert.Equal(1, attribute.ScaleHeight); + } + + [Fact] + public void ScaleHeight_Is_ByDefault() + { + var attribute = new UploadOptions(); + Assert.Equal(0, attribute.ScaleHeight); + } + + [Fact] + public void ScaleSmaller_CanBeSet_ToTrue() + { + var attribute = new UploadOptions() + { + ScaleSmaller = true + }; + Assert.True(attribute.ScaleSmaller); + } + + [Fact] + public void ScaleSmaller_CanBeSet_ToFalse() + { + var attribute = new UploadOptions() + { + ScaleSmaller = false + }; + Assert.False(attribute.ScaleSmaller); + } + + [Fact] + public void ImageScaleMode_CanBeSet_ToPreserveRatioNoFill() + { + var attribute = new UploadOptions() + { + ScaleMode = ImageScaleMode.PreserveRatioNoFill + }; + Assert.Equal(ImageScaleMode.PreserveRatioNoFill, attribute.ScaleMode); + } + + [Fact] + public void ImageScaleMode_CanBeSet_ToDefaultScaleMode() + { + var attribute = new UploadOptions() + { + ScaleMode = UploadOptions.DefaultScaleMode + }; + Assert.Equal(UploadOptions.DefaultScaleMode, attribute.ScaleMode); + } + + [Fact] + public void ScaleBackColor_CanBeSet() + { + var attribute = new UploadOptions() + { + ScaleBackColor = "sometext" + }; + Assert.Equal("sometext", attribute.ScaleBackColor); + } + + [Fact] + public void ScaleBackColor_CanBeSet_ToNull() + { + var attribute = new UploadOptions() + { + ScaleBackColor = null + }; + Assert.Null(attribute.ScaleBackColor); + } + + [Fact] + public void ThumbHeight_CanBeSet_ToInt() + { + var attribute = new UploadOptions() + { + ThumbHeight = 1 + }; + Assert.Equal(1, attribute.ThumbHeight); + } + + [Fact] + public void ThumbWidth_CanBeSet_ToInt() + { + var attribute = new UploadOptions() + { + ThumbWidth = 1 + }; + Assert.Equal(1, attribute.ThumbWidth); + } + + [Fact] + public void ThumbSizes_CanBeSet() + { + var attribute = new UploadOptions() + { + ThumbSizes = "sometext" + }; + Assert.Equal("sometext", attribute.ThumbSizes); + } + + [Fact] + public void ThumbSizes_CanBeSet_ToNull() + { + var attribute = new UploadOptions() + { + ThumbSizes = null + }; + Assert.Null(attribute.ThumbSizes); + } + + [Fact] + public void ThumbMode_CanBeSet_ToEnum() + { + var attribute = new UploadOptions() + { + ThumbMode = ImageScaleMode.CropSourceImage + }; + Assert.Equal(ImageScaleMode.CropSourceImage, attribute.ThumbMode); + } + + [Fact] + public void ThumbMode_CanBeSet_ToDefaultThumbMode() + { + var attribute = new UploadOptions() + { + ThumbMode = UploadOptions.DefaultThumbMode + }; + Assert.Equal(UploadOptions.DefaultThumbMode, attribute.ThumbMode); + } + + [Fact] + public void ThumbQuality_CanBeSet_ToDefaultThumbQuality() + { + var attribute = new UploadOptions() + { + ThumbQuality = UploadOptions.DefaultThumbQuality + }; + Assert.Equal(UploadOptions.DefaultThumbQuality, attribute.ThumbQuality); + } + + [Fact] + public void ThumbBackColor_CanBeSet() + { + var attribute = new UploadOptions() + { + ThumbBackColor = "sometext" + }; + Assert.Equal("sometext", attribute.ThumbBackColor); + } + + [Fact] + public void ThumbBackColor_CanBeSet_ToNull() + { + var attribute = new UploadOptions() + { + ThumbBackColor = null + }; + Assert.Null(attribute.ThumbBackColor); + } + + [Fact] + public void JsonEncodeValue_CanBeSet_ToTrue() + { + var attribute = new UploadOptions() + { + JsonEncodeValue = true + }; + Assert.True(attribute.JsonEncodeValue); + } + + [Fact] + public void JsonEncodeValue_CanBeSet_ToFalse() + { + var attribute = new UploadOptions() + { + JsonEncodeValue = false + }; + Assert.False(attribute.JsonEncodeValue); + } + + [Fact] + public void OriginalNameProperty_CanBeSet() + { + var attribute = new UploadOptions() + { + OriginalNameProperty = "sometext" + }; + Assert.Equal("sometext", attribute.OriginalNameProperty); + } + + [Fact] + public void OriginalNameProperty_CanBeSetToNull() + { + var attribute = new UploadOptions() + { + OriginalNameProperty = null + }; + Assert.Null(attribute.OriginalNameProperty); + } + + [Fact] + public void DisplayFileName_CanBeSet_ToTrue() + { + var attribute = new UploadOptions() + { + DisplayFileName = true + }; + Assert.True(attribute.DisplayFileName); + } + + [Fact] + public void CopyToHistory_CanBeSet_ToTrue() + { + var attribute = new UploadOptions() + { + CopyToHistory = true + }; + Assert.True(attribute.CopyToHistory); + } + + [Fact] + public void CopyToHistory_CanBeSet_ToFalse() + { + var attribute = new UploadOptions() + { + CopyToHistory = false + }; + Assert.False(attribute.CopyToHistory); + } + + [Fact] + public void FilenameFormat_CanBeSet() + { + var attribute = new UploadOptions() + { + FilenameFormat = "sometext" + }; + Assert.Equal("sometext", attribute.FilenameFormat); + } + + [Fact] + public void FilenameFormat_CanBeSet_ToNull() + { + var attribute = new UploadOptions() + { + FilenameFormat = null + }; + Assert.Null(attribute.FilenameFormat); + } + + [Fact] + public void AllowedExtensions_CanBeSet() + { + var attribute = new UploadOptions() + { + AllowedExtensions = "sometext" + }; + Assert.Equal("sometext", attribute.AllowedExtensions); + } + + [Fact] + public void AllowedExtensions_CanBeSet_ToNull() + { + var attribute = new UploadOptions() + { + AllowedExtensions = null + }; + Assert.Null(attribute.AllowedExtensions); + } + + [Fact] + public void ImageExtensions_CanBeSet() + { + var attribute = new UploadOptions() + { + ImageExtensions = "sometext" + }; + Assert.Equal("sometext", attribute.ImageExtensions); + } + + [Fact] + public void ImageExtensions_CanBeSet_ToNull() + { + var attribute = new UploadOptions() + { + ImageExtensions = null + }; + Assert.Null(attribute.ImageExtensions); + } + + [Fact] + public void ImageExtensions_CanBeSet_ToDefaultImageExtension() + { + var attribute = new UploadOptions() + { + ImageExtensions = UploadOptions.DefaultImageExtensions + }; + Assert.Equal(UploadOptions.DefaultImageExtensions, attribute.ImageExtensions); + } + + [Fact] + public void IgnoreExtensionMismatch_CanBeSet_ToTrue() + { + var attribute = new UploadOptions() + { + IgnoreExtensionMismatch = true + }; + Assert.True(attribute.IgnoreExtensionMismatch); + } + + [Fact] + public void IgnoreExtensionMismatch_CanBeSet_ToFalse() + { + var attribute = new UploadOptions() + { + IgnoreExtensionMismatch = false + }; + Assert.False(attribute.IgnoreExtensionMismatch); + } + + [Fact] + public void IgnoreEmptyImage_CanBeSet_ToTrue() + { + var attribute = new UploadOptions() + { + IgnoreEmptyImage = true + }; + Assert.True(attribute.IgnoreEmptyImage); + } + + [Fact] + public void IgnoreEmptyImage_CanBeSet_ToFalse() + { + var attribute = new UploadOptions() + { + IgnoreEmptyImage = false + }; + Assert.False(attribute.IgnoreEmptyImage); + } + + [Fact] + public void IgnoreInvalidImage_CanBeSet_ToTrue() + { + var attribute = new UploadOptions() + { + IgnoreInvalidImage = true + }; + Assert.True(attribute.IgnoreInvalidImage); + } + + [Fact] + public void IgnoreInvalidImage_CanBeSet_ToFalse() + { + var attribute = new UploadOptions() + { + IgnoreInvalidImage = false + }; + Assert.False(attribute.IgnoreInvalidImage); + } +} + diff --git a/tests/Serenity.Net.Core.Tests/Plugins/CssFileTests.cs b/tests/Serenity.Net.Core.Tests/Plugins/CssFileTests.cs new file mode 100644 index 0000000000..e76a651c92 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/Plugins/CssFileTests.cs @@ -0,0 +1,27 @@ +using Serenity.Plugins; + +namespace Serenity.Tests.Plugins +{ + public class CssFileTests + { + [Fact] + public void Path_CanBeSet() + { + var cssFile = new CssFile() + { + Path = "path" + }; + Assert.Equal("path", cssFile.Path); + } + + [Fact] + public void Path_CanBeSet_ToNull() + { + var cssFile = new CssFile() + { + Path = null + }; + Assert.Null(cssFile.Path); + } + } +} diff --git a/tests/Serenity.Net.Core.Tests/Plugins/NavigationEntryTests.cs b/tests/Serenity.Net.Core.Tests/Plugins/NavigationEntryTests.cs new file mode 100644 index 0000000000..ebf8e8e8f0 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/Plugins/NavigationEntryTests.cs @@ -0,0 +1,248 @@ +using Serenity.Plugins; + +namespace Serenity.Tests.Plugins +{ + public class NavigationEntryTests + { + [Fact] + public void Order_CanBeSet_ToInt() + { + var entry = new NavigationEntry() + { + Order = 2 + }; + Assert.Equal(2, entry.Order); + } + + [Fact] + public void Action_CanBeSet() + { + var entry = new NavigationEntry() + { + Action = "text" + }; + Assert.Equal("text", entry.Action); + } + + [Fact] + public void Action_CanBeSet_ToNull() + { + var entry = new NavigationEntry() + { + Action = null + }; + Assert.Null(entry.Action); + } + + [Fact] + public void Controller_CanBeSet_ToNull() + { + var entry = new NavigationEntry() + { + Controller = null + }; + Assert.Null(entry.Controller); + } + + [Fact] + public void Controller_CanBeSet_ToTypeOfString() + { + var entry = new NavigationEntry() + { + + Controller = typeof(string) + }; + Assert.Equal(typeof(string), entry.Controller); + } + + [Fact] + public void Controller_CanBeSet_ToTypeOfInt() + { + var entry = new NavigationEntry() + { + Controller = typeof(int) + }; + Assert.Equal(typeof(int), entry.Controller); + } + + [Fact] + public void Controller_CanBeSet_ToTypeOfObject() + { + var entry = new NavigationEntry() + { + Controller = typeof(object) + }; + Assert.Equal(typeof(object), entry.Controller); + } + + [Fact] + public void Controller_CanBeSet_ToTypeOfDateTime() + { + var entry = new NavigationEntry() + { + Controller = typeof(DateTime) + }; + Assert.Equal(typeof(DateTime), entry.Controller); + } + + [Fact] + public void Url_CanBeSet() + { + var entry = new NavigationEntry() + { + Url = "text" + }; + Assert.Equal("text", entry.Url); + } + + [Fact] + public void Url_CanBeSet_ToNull() + { + var entry = new NavigationEntry() + { + Url = null + }; + Assert.Null(entry.Url); + } + + [Fact] + public void FullPath_CanBeSet() + { + var entry = new NavigationEntry() + { + FullPath = "text" + }; + Assert.Equal("text", entry.FullPath); + } + + [Fact] + public void FullPath_CanBeSet_ToNull() + { + var entry = new NavigationEntry() + { + FullPath = null + }; + Assert.Null(entry.FullPath); + } + + [Fact] + public void Category_CanBeSet() + { + var entry = new NavigationEntry() + { + Category = "text" + }; + Assert.Equal("text", entry.Category); + } + + [Fact] + public void Category_CanBeSet_ToNull() + { + var entry = new NavigationEntry() + { + Category = null + }; + Assert.Null(entry.Category); + } + + [Fact] + public void Title_CanBeSet() + { + var entry = new NavigationEntry() + { + Title = "text" + }; + Assert.Equal("text", entry.Title); + } + + [Fact] + public void Title_CanBeSet_ToNull() + { + var entry = new NavigationEntry() + { + Title = null + }; + Assert.Null(entry.Title); + } + + [Fact] + public void IconClass_CanBeSet() + { + var entry = new NavigationEntry() + { + IconClass = "text" + }; + Assert.Equal("text", entry.IconClass); + } + + [Fact] + public void IconClass_CanBeSet_ToNull() + { + var entry = new NavigationEntry() + { + IconClass = null + }; + Assert.Null(entry.IconClass); + } + + [Fact] + public void ItemClass_CanBeSet() + { + var entry = new NavigationEntry() + { + ItemClass = "text" + }; + Assert.Equal("text", entry.ItemClass); + } + + [Fact] + public void ItemClass_CanBeSet_ToNull() + { + var entry = new NavigationEntry() + { + ItemClass = null + }; + Assert.Null(entry.ItemClass); + } + + [Fact] + public void Permission_CanBeSet() + { + var entry = new NavigationEntry() + { + Permission = "text" + }; + Assert.Equal("text", entry.Permission); + } + + [Fact] + public void Permission_CanBeSet_ToNull() + { + var entry = new NavigationEntry() + { + Permission = null + }; + Assert.Null(entry.Permission); + } + + [Fact] + public void Target_CanBeSet() + { + var entry = new NavigationEntry() + { + Target = "text" + }; + Assert.Equal("text", entry.Target); + } + + [Fact] + public void Target_CanBeSet_ToNull() + { + var entry = new NavigationEntry() + { + Target = null + }; + Assert.Null(entry.Target); + } + } +} diff --git a/tests/Serenity.Net.Core.Tests/Plugins/PrecompiledViewsAttributeTests.cs b/tests/Serenity.Net.Core.Tests/Plugins/PrecompiledViewsAttributeTests.cs new file mode 100644 index 0000000000..050b4a4771 --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/Plugins/PrecompiledViewsAttributeTests.cs @@ -0,0 +1,14 @@ +using Serenity.Plugins; + +namespace Serenity.Tests.Plugins +{ + public class PrecompiledViewsAttributeTests + { + [Fact] + public void IsSubClassOf_Attribute() + { + var attribute = new PrecompiledViewsAttribute(); + Assert.IsAssignableFrom(attribute); + } + } +} diff --git a/tests/Serenity.Net.Core.Tests/Plugins/ScriptFileTests.cs b/tests/Serenity.Net.Core.Tests/Plugins/ScriptFileTests.cs new file mode 100644 index 0000000000..9d0445e3cc --- /dev/null +++ b/tests/Serenity.Net.Core.Tests/Plugins/ScriptFileTests.cs @@ -0,0 +1,27 @@ +using Serenity.Plugins; + +namespace Serenity.Tests.Plugins +{ + public class ScriptFileTests + { + [Fact] + public void Path_CanBeSet() + { + var script = new ScriptFile() + { + Path = "text" + }; + Assert.Equal("text", script.Path); + } + + [Fact] + public void Path_CanBeSet_Null() + { + var script = new ScriptFile() + { + Path = null + }; + Assert.Null(script.Path); + } + } +} \ No newline at end of file