-
Notifications
You must be signed in to change notification settings - Fork 801
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More column and common attribute tests
- Loading branch information
Showing
46 changed files
with
473 additions
and
3 deletions.
There are no files selected for viewing
File renamed without changes.
15 changes: 15 additions & 0 deletions
15
tests/Serenity.Net.Core.Tests/ComponentModel/Columns/ColumnSelectionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Serenity.Tests.ComponentModel; | ||
|
||
public class ColumnSelectionTests() | ||
{ | ||
[Fact] | ||
public void ColumnSelection_Values_AreCorrect() | ||
{ | ||
Assert.Equal(0, (int)ColumnSelection.List); | ||
Assert.Equal(1, (int)ColumnSelection.KeyOnly); | ||
Assert.Equal(2, (int)ColumnSelection.Details); | ||
Assert.Equal(3, (int)ColumnSelection.None); | ||
Assert.Equal(4, (int)ColumnSelection.IdOnly); | ||
Assert.Equal(5, (int)ColumnSelection.Lookup); | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
tests/Serenity.Net.Core.Tests/ComponentModel/Columns/EditLinkAttributeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
namespace Serenity.Tests.ComponentModel; | ||
|
||
public class EditLinkAttributeTests() | ||
{ | ||
[Fact] | ||
public void Value_IsTrue_ByDefault() | ||
{ | ||
var attribute = new EditLinkAttribute(); | ||
Assert.True(attribute.Value); | ||
} | ||
|
||
[Fact] | ||
public void Value_CanBeSet_ToFalse() | ||
{ | ||
var attribute = new EditLinkAttribute(false); | ||
Assert.False(attribute.Value); | ||
} | ||
|
||
[Fact] | ||
public void ItemType_CanBeSet() | ||
{ | ||
var attribute = new EditLinkAttribute() | ||
{ | ||
ItemType = "itemType" | ||
}; | ||
Assert.Equal("itemType", attribute.ItemType); | ||
} | ||
|
||
[Fact] | ||
public void ItemType_CanBe_SetTo_NullValue() | ||
{ | ||
var attribute = new EditLinkAttribute() | ||
{ | ||
ItemType = null | ||
}; | ||
Assert.Null(attribute.ItemType); | ||
} | ||
|
||
[Fact] | ||
public void ItemType_IsNull_ByDefault() | ||
{ | ||
var attribute = new EditLinkAttribute(); | ||
Assert.Null(attribute.ItemType); | ||
} | ||
|
||
[Fact] | ||
public void IdField_CanBeSet() | ||
{ | ||
var attribute = new EditLinkAttribute() | ||
{ | ||
IdField = "idField" | ||
}; | ||
Assert.Equal("idField", attribute.IdField); | ||
} | ||
|
||
[Fact] | ||
public void IdField_CanBe_SetTo_NullValue() | ||
{ | ||
var attribute = new EditLinkAttribute() | ||
{ | ||
IdField = null | ||
}; | ||
Assert.Null(attribute.IdField); | ||
} | ||
|
||
[Fact] | ||
public void IdField_IsNull_ByDefault() | ||
{ | ||
var attribute = new EditLinkAttribute(); | ||
Assert.Null(attribute.IdField); | ||
} | ||
|
||
[Fact] | ||
public void CssClass_CanBeSet() | ||
{ | ||
var attribute = new EditLinkAttribute() | ||
{ | ||
CssClass = "some-class" | ||
}; | ||
Assert.Equal("some-class", attribute.CssClass); | ||
} | ||
|
||
[Fact] | ||
public void CssClass_CanBe_SetTo_NullValue() | ||
{ | ||
var attribute = new EditLinkAttribute() | ||
{ | ||
CssClass = null | ||
}; | ||
Assert.Null(attribute.CssClass); | ||
} | ||
|
||
[Fact] | ||
public void CssClass_IsNullByDefault() | ||
{ | ||
var attribute = new EditLinkAttribute(); | ||
Assert.Null(attribute.CssClass); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
51 changes: 51 additions & 0 deletions
51
...Serenity.Net.Core.Tests/ComponentModel/Columns/Filtering/CustomFilteringAttributeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
namespace Serenity.Tests.ComponentModel; | ||
|
||
public class CustomFilteringAttributeTests | ||
{ | ||
class MyFilteringAttribute : CustomFilteringAttribute | ||
{ | ||
public MyFilteringAttribute() | ||
: base("text") | ||
{ | ||
} | ||
|
||
public string TestOption | ||
{ | ||
get => GetOption<string>("testOption"); | ||
set => SetOption("testOption", value); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void SetParams_ShouldThrow_ArgumentNullException_ForNull() | ||
{ | ||
var attribute = new MyFilteringAttribute(); | ||
Assert.Throws<ArgumentNullException>(() => attribute.SetParams(null)); | ||
} | ||
|
||
[Fact] | ||
public void SetParams_ShouldNotModify_FilteringParams_ForEmpty() | ||
{ | ||
var attr = new MyFilteringAttribute(); | ||
var dict = new Dictionary<string, object>(); | ||
attr.SetParams(dict); | ||
Assert.Empty(dict); | ||
} | ||
|
||
[Fact] | ||
public void SetParams_ShouldModify_FilteringParams_ForNonEmpty() | ||
{ | ||
var attr = new MyFilteringAttribute | ||
{ | ||
TestOption = "myvalue" | ||
}; | ||
var dict = new Dictionary<string, object>(); | ||
attr.SetParams(dict); | ||
var x = Assert.Single(dict); | ||
Assert.Equal("testOption", x.Key); | ||
Assert.Equal("myvalue", x.Value); | ||
} | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
48 changes: 48 additions & 0 deletions
48
...erenity.Net.Core.Tests/ComponentModel/Columns/Formatting/CustomFormatterAttributeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
namespace Serenity.Tests.ComponentModel; | ||
|
||
public class CustomFormatterAttributeTests | ||
{ | ||
class MyFormatter : CustomFormatterAttribute | ||
{ | ||
public MyFormatter() | ||
: base("test") | ||
{ | ||
} | ||
|
||
public string TestOption | ||
{ | ||
get => GetOption<string>("testOption"); | ||
set => SetOption("testOption", value); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void SetParams_ShouldThrowArgumentNullException_ForNull() | ||
{ | ||
var attribute = new MyFormatter(); | ||
Assert.Throws<ArgumentNullException>(() => attribute.SetParams(null)); | ||
} | ||
|
||
[Fact] | ||
public void SetParams_ShouldNotModify_FormatterParams_ForEmpty() | ||
{ | ||
var attr = new MyFormatter(); | ||
var dict = new Dictionary<string, object>(); | ||
attr.SetParams(dict); | ||
Assert.Empty(dict); | ||
} | ||
|
||
[Fact] | ||
public void SetParams_ShouldModify_FormatterParams_ForNonEmpty() | ||
{ | ||
var attr = new MyFormatter | ||
{ | ||
TestOption = "myvalue" | ||
}; | ||
var dict = new Dictionary<string, object>(); | ||
attr.SetParams(dict); | ||
var x = Assert.Single(dict); | ||
Assert.Equal("testOption", x.Key); | ||
Assert.Equal("myvalue", x.Value); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
.../Serenity.Net.Core.Tests/ComponentModel/Columns/Formatting/DisplayFormatAttributeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Serenity.Tests.ComponentModel; | ||
|
||
public class DisplayFormatAttributeTests | ||
{ | ||
[Fact] | ||
public void Value_CanBe_Set() | ||
{ | ||
var attribute = new DisplayFormatAttribute("expectedValue"); | ||
Assert.Equal("expectedValue", attribute.Value); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...erenity.Net.Core.Tests/ComponentModel/Columns/Formatting/FormatterOptionAttributeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
namespace Serenity.Tests.ComponentModel; | ||
|
||
public class FormatterOptionAttributeTests | ||
{ | ||
[Fact] | ||
public void Value_CanBePassed_AsString() | ||
{ | ||
var attribute = new FormatterOptionAttribute("someKey", "someStr"); | ||
Assert.Equal("someKey", attribute.Key); | ||
Assert.Equal("someStr", attribute.Value); | ||
} | ||
|
||
[Fact] | ||
public void Value_CanBePassed_AsNull() | ||
{ | ||
var attribute = new FormatterOptionAttribute("key", null); | ||
Assert.Equal("key",attribute.Key); | ||
Assert.Null(attribute.Value); | ||
} | ||
|
||
[Fact] | ||
public void Value_CanBePassed_AsBoolean() | ||
{ | ||
var attribute = new FormatterOptionAttribute("key", true); | ||
Assert.Equal("key", attribute.Key); | ||
Assert.Equal(true, attribute.Value); | ||
} | ||
|
||
[Fact] | ||
public void Value_CanBePassed_AsInt() | ||
{ | ||
var attribute = new FormatterOptionAttribute("key", 123); | ||
Assert.Equal("key", attribute.Key); | ||
Assert.Equal(123, attribute.Value); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
.../Serenity.Net.Core.Tests/ComponentModel/Columns/Formatting/FormatterTypeAttributeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Serenity.Tests.ComponentModel; | ||
|
||
public class FormatterTypeAttributeTests | ||
{ | ||
[Fact] | ||
public void FormatterType_CanBePassed_ViaConstructor() | ||
{ | ||
var attribute = new FormatterTypeAttribute("SomeFormatter"); | ||
Assert.Equal("SomeFormatter", attribute.FormatterType); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/Serenity.Net.Core.Tests/ComponentModel/Columns/SummaryTypeAttributeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Serenity.Tests.ComponentModel; | ||
|
||
public class SummaryTypeAttributeTests() | ||
{ | ||
[Fact] | ||
public void Value_CanBePassed_ViaConstructor() | ||
{ | ||
var attribute = new SummaryTypeAttribute(SummaryType.Max); | ||
Assert.Equal(SummaryType.Max, attribute.Value); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/Serenity.Net.Core.Tests/ComponentModel/Columns/SummaryTypeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Serenity.Tests.ComponentModel; | ||
|
||
public class SummaryTypeTests | ||
{ | ||
[Fact] | ||
public void SummaryType_Values_AreCorrect() | ||
{ | ||
Assert.Equal(-1, (int)SummaryType.Disabled); | ||
Assert.Equal(0, (int)SummaryType.None); | ||
Assert.Equal(1, (int)SummaryType.Sum); | ||
Assert.Equal(2, (int)SummaryType.Avg); | ||
Assert.Equal(3, (int)SummaryType.Min); | ||
Assert.Equal(4, (int)SummaryType.Max); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/Serenity.Net.Core.Tests/ComponentModel/Columns/WidthAttributeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace Serenity.Tests.ComponentModel; | ||
|
||
public class WidthAttributeTests() | ||
{ | ||
[Fact] | ||
public void Width_CanBePassed_ViaConstructor() | ||
{ | ||
var attribute = new WidthAttribute(73); | ||
Assert.Equal(73, attribute.Value); | ||
} | ||
|
||
[Fact] | ||
public void MinAndMaxProperties_CanBeSet() | ||
{ | ||
var attribute = new WidthAttribute(0) | ||
{ | ||
Min = 10, | ||
Max = 100 | ||
}; | ||
|
||
Assert.Equal(10, attribute.Min); | ||
Assert.Equal(100, attribute.Max); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
tests/Serenity.Net.Core.Tests/ComponentModel/Common/AllowHideAttributeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace Serenity.Tests.ComponentModel; | ||
|
||
public class AllowHideAttributeTests | ||
{ | ||
[Fact] | ||
public void Value_CanBeSet_ToFalse() | ||
{ | ||
var attribute = new AllowHideAttribute(false); | ||
Assert.False(attribute.Value); | ||
} | ||
|
||
[Fact] | ||
public void Value_CanBeSet_ToTrue() | ||
{ | ||
var attribute = new AllowHideAttribute(true); | ||
Assert.True(attribute.Value); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
tests/Serenity.Net.Core.Tests/ComponentModel/Common/HiddenAttributeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace Serenity.Tests.ComponentModel; | ||
|
||
public class HiddenAttributeTests | ||
{ | ||
[Fact] | ||
public void HiddenAttribute_ShouldInheritFromVisibleAttribute() | ||
{ | ||
var attribute = new HiddenAttribute(); | ||
Assert.IsAssignableFrom<VisibleAttribute>(attribute); | ||
} | ||
|
||
[Fact] | ||
public void Value_IsFalse_ByDefault() | ||
{ | ||
var attribute = new HiddenAttribute(); | ||
Assert.False(attribute.Value); | ||
} | ||
} |
Oops, something went wrong.