Skip to content

Commit

Permalink
More column and common attribute tests
Browse files Browse the repository at this point in the history
  • Loading branch information
burcuq committed Jul 4, 2024
1 parent 2a75994 commit cb79299
Show file tree
Hide file tree
Showing 46 changed files with 473 additions and 3 deletions.
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);
}
}
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);
}
}
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);
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public void Value_IsTrue_ByDefault()
}

[Fact]
public void Value_CanBe_SetTo_False()
public void Value_CanBe_Set_ToFalse()
{
var attribute = new FilterOnlyAttribute(false);
Assert.False(attribute.Value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public void DisplayFormat_CanBeSet_ToNull()
DisplayFormat = null
};
Assert.Null(attribute.DisplayFormat);

}

[Fact]
Expand Down
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Loading

0 comments on commit cb79299

Please sign in to comment.