Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for permission and editor type attributes #7217

Merged
merged 2 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ public void AutoKeyFor_Returns_TypeName_When_ModuleAttribute_NotPresent()
public void AutoKeyFor_Handles_Namespace_With_SubNamespace()
{
var type = typeof(MyClassWithModule);
var expectedKey = "TestModule.MyClassWithModule";
var result = DataScriptAttribute.AutoKeyFor(type);
Assert.Equal(expectedKey, result);
Assert.Equal("TestModule.MyClassWithModule", result);
}

[Module("TestModule")]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Serenity.Tests.ComponentModel;

public class TypeSourceExtensionsTests
{
[Fact]
public void GetAssemblyAttributes_ThrowsArgumentNullException_ForNull()
{
ITypeSource typeSource = null;
Assert.Throws<ArgumentNullException>(() => TypeSourceExtensions.GetAssemblyAttributes<Attribute>(typeSource));
}

[Fact]
public void GetAssemblyAttributes_ReturnsAttributes_WhenTypeSourceIsValid()
{
var mockTypeSource = new MockTypeSource(new ObsoleteAttribute());
var result = TypeSourceExtensions.GetAssemblyAttributes<ObsoleteAttribute>(mockTypeSource);
Assert.Single(result);
Assert.IsType<ObsoleteAttribute>(result.First());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
namespace Serenity.Tests.ComponentModel;

public class DeletePermissionAttributeTests
{
[Fact]
public void Constructor_With_String()
{
var attribute = new DeletePermissionAttribute("a");
Assert.Equal("a", attribute.Permission);
}

[Fact]
public void Constructor_With_String_String()
{
var attribute = new DeletePermissionAttribute("a", "a");
Assert.Equal("a:a", attribute.Permission);
}

[Fact]
public void Constructor_With_String_String_String()
{
var attribute = new DeletePermissionAttribute("a", "b", "c");
Assert.Equal("a:b:c", attribute.Permission);
}

[Fact]
public void Constructor_With_Enum()
{
var attribute = new DeletePermissionAttribute(Serenity.IO.DeleteType.Delete);
Assert.Equal("Delete", attribute.Permission);
}

[Fact]
public void Constructor_With_Enum_Enum()
{
var attribute = new DeletePermissionAttribute(Serenity.IO.DeleteType.Delete, Serenity.IO.DeleteType.TryDelete);
Assert.Equal("Delete:TryDelete", attribute.Permission);
}

[Fact]
public void Constructor_With_Enum_Enum_Enum()
{
var attribute = new DeletePermissionAttribute(Serenity.IO.DeleteType.Delete, Serenity.IO.DeleteType.TryDelete, Serenity.IO.DeleteType.TryDeleteOrMark);
Assert.Equal("Delete:TryDelete:TryDeleteOrMark", attribute.Permission);
}

[Fact]
public void Constructor_With_Int()
{
var attribute = new DeletePermissionAttribute(1);
Assert.Equal("1", attribute.Permission);
}

[Fact]
public void Constructor_With_Int_Int()
{
var attribute = new DeletePermissionAttribute(1, 2);
Assert.Equal("1:2", attribute.Permission);
}

[Fact]
public void Constructor_With_Int_Int_Int()
{
var attribute = new DeletePermissionAttribute(1, 2, 3);
Assert.Equal("1:2:3", attribute.Permission);
}

[Fact]
public void Constructor_WithNull()
{
var attribute = new DeletePermissionAttribute(null);
Assert.Null(attribute.Permission);
}

[Fact]
public void Constructor_With_Null_Null()
{
var attribute = new DeletePermissionAttribute(null, null);
Assert.Equal(":", attribute.Permission);
}

[Fact]
public void Constructor_With_Null_Null_Null()
{
var attribute = new DeletePermissionAttribute(null, null, null);
Assert.Equal("::", attribute.Permission);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
namespace Serenity.Tests.ComponentModel;

public class FieldInsertPermissionAttributeTests
{
[Fact]
public void Constructor_With_String()
{
var attribute = new FieldInsertPermissionAttribute("a");
Assert.Equal("a", attribute.Permission);
}

[Fact]
public void Constructor_With_String_String()
{
var attribute = new FieldInsertPermissionAttribute("a", "a");
Assert.Equal("a:a", attribute.Permission);
}

[Fact]
public void Constructor_With_String_String_String()
{
var attribute = new FieldInsertPermissionAttribute("a", "b", "c");
Assert.Equal("a:b:c", attribute.Permission);
}

[Fact]
public void Constructor_With_Enum()
{
var attribute = new FieldInsertPermissionAttribute(Serenity.IO.DeleteType.Delete);
Assert.Equal("Delete", attribute.Permission);
}
[Fact]
public void Constructor_With_Enum_Enum()
{
var attribute = new FieldInsertPermissionAttribute(Serenity.IO.DeleteType.Delete, Serenity.IO.DeleteType.TryDelete);
Assert.Equal("Delete:TryDelete", attribute.Permission);
}

[Fact]
public void Constructor_With_Enum_Enum_Enum()
{
var attribute = new FieldInsertPermissionAttribute(Serenity.IO.DeleteType.Delete, Serenity.IO.DeleteType.TryDelete, Serenity.IO.DeleteType.TryDeleteOrMark);
Assert.Equal("Delete:TryDelete:TryDeleteOrMark", attribute.Permission);
}

[Fact]
public void Constructor_With_Int()
{
var attribute = new FieldInsertPermissionAttribute(1);
Assert.Equal("1", attribute.Permission);
}

[Fact]
public void Constructor_With_Int_Int()
{
var attribute = new FieldInsertPermissionAttribute(1, 2);
Assert.Equal("1:2", attribute.Permission);
}

[Fact]
public void Constructor_With_Int_Int_Int()
{
var attribute = new FieldInsertPermissionAttribute(1, 2, 3);
Assert.Equal("1:2:3", attribute.Permission);
}

[Fact]
public void Constructor_WithNull()
{
var attribute = new FieldInsertPermissionAttribute(null);
Assert.Null(attribute.Permission);
}

[Fact]
public void Constructor_With_Null_Null()
{
var attribute = new FieldInsertPermissionAttribute(null, null);
Assert.Equal(":", attribute.Permission);
}

[Fact]
public void Constructor_With_Null_Null_Null()
{
var attribute = new FieldInsertPermissionAttribute(null, null, null);
Assert.Equal("::", attribute.Permission);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
namespace Serenity.Tests.ComponentModel;

public class FieldModifyPermissionAttributeTests
{
[Fact]
public void Constructor_With_String()
{
var attribute = new FieldModifyPermissionAttribute("a");
Assert.Equal("a", attribute.Permission);
}

[Fact]
public void Constructor_With_String_String()
{
var attribute = new FieldModifyPermissionAttribute("a", "a");
Assert.Equal("a:a", attribute.Permission);
}

[Fact]
public void Constructor_With_String_String_String()
{
var attribute = new FieldModifyPermissionAttribute("a", "b", "c");
Assert.Equal("a:b:c", attribute.Permission);
}

[Fact]
public void Constructor_With_Enum()
{
var attribute = new FieldModifyPermissionAttribute(Serenity.IO.DeleteType.Delete);
Assert.Equal("Delete", attribute.Permission);
}

[Fact]
public void Constructor_With_Enum_Enum()
{
var attribute = new FieldModifyPermissionAttribute(Serenity.IO.DeleteType.Delete, Serenity.IO.DeleteType.TryDelete);
Assert.Equal("Delete:TryDelete", attribute.Permission);
}

[Fact]
public void Constructor_With_Enum_Enum_Enum()
{
var attribute = new FieldModifyPermissionAttribute(Serenity.IO.DeleteType.Delete, Serenity.IO.DeleteType.TryDelete, Serenity.IO.DeleteType.TryDeleteOrMark);
Assert.Equal("Delete:TryDelete:TryDeleteOrMark", attribute.Permission);
}

[Fact]
public void Constructor_With_Int()
{
var attribute = new FieldModifyPermissionAttribute(1);
Assert.Equal("1", attribute.Permission);
}

[Fact]
public void Constructor_With_Int_Int()
{
var attribute = new FieldModifyPermissionAttribute(1, 2);
Assert.Equal("1:2", attribute.Permission);
}

[Fact]
public void Constructor_With_Int_Int_Int()
{
var attribute = new FieldModifyPermissionAttribute(1, 2, 3);
Assert.Equal("1:2:3", attribute.Permission);
}

[Fact]
public void Constructor_With_Null()
{
var attribute = new FieldModifyPermissionAttribute(null);
Assert.Null(attribute.Permission);
}

[Fact]
public void Constructor_With_Null_Null()
{
var attribute = new FieldModifyPermissionAttribute(null, null);
Assert.Equal(":", attribute.Permission);
}

[Fact]
public void Constructor_With_Null_Null_Null()
{
var attribute = new FieldModifyPermissionAttribute(null, null, null);
Assert.Equal("::", attribute.Permission);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
namespace Serenity.Tests.ComponentModel;

public class FieldReadPermissionAttributeTests
{
[Fact]
public void Constructor_With_String()
{
var attribute = new FieldReadPermissionAttribute("a");
Assert.Equal("a", attribute.Permission);
}

[Fact]
public void Constructor_With_String_String()
{
var attribute = new FieldReadPermissionAttribute("a", "a");
Assert.Equal("a:a", attribute.Permission);
}

[Fact]
public void Constructor_With_String_String_String()
{
var attribute = new FieldReadPermissionAttribute("a", "b", "c");
Assert.Equal("a:b:c", attribute.Permission);
}

[Fact]
public void Constructor_With_Enum()
{
var attribute = new FieldReadPermissionAttribute(Serenity.IO.DeleteType.Delete);
Assert.Equal("Delete", attribute.Permission);
}

[Fact]
public void Constructor_With_Enum_Enum()
{
var attribute = new FieldReadPermissionAttribute(Serenity.IO.DeleteType.Delete, Serenity.IO.DeleteType.TryDelete);
Assert.Equal("Delete:TryDelete", attribute.Permission);
}

[Fact]
public void Constructor_With_Enum_Enum_Enum()
{
var attribute = new FieldReadPermissionAttribute(Serenity.IO.DeleteType.Delete, Serenity.IO.DeleteType.TryDelete, Serenity.IO.DeleteType.TryDeleteOrMark);
Assert.Equal("Delete:TryDelete:TryDeleteOrMark", attribute.Permission);
}

[Fact]
public void Constructor_With_Int()
{
var attribute = new FieldReadPermissionAttribute(1);
Assert.Equal("1", attribute.Permission);
}

[Fact]
public void Constructor_With_Int_Int()
{
var attribute = new FieldReadPermissionAttribute(1, 2);
Assert.Equal("1:2", attribute.Permission);
}

[Fact]
public void Constructor_With_Int_Int_Int()
{
var attribute = new FieldReadPermissionAttribute(1, 2, 3);
Assert.Equal("1:2:3", attribute.Permission);
}

[Fact]
public void Constructor_WithNull()
{
var attribute = new FieldReadPermissionAttribute(null);
Assert.Null(attribute.Permission);
}

[Fact]
public void Constructor_With_Null_Null()
{
var attribute = new FieldReadPermissionAttribute(null, null);
Assert.Equal(":", attribute.Permission);
}

[Fact]
public void Constructor_With_Null_Null_Null()
{
var attribute = new FieldReadPermissionAttribute(null, null, null);
Assert.Equal("::", attribute.Permission);
}
}
Loading
Loading