-
Hello! I am relatively new to Blazor and very new to using bUnit, so apologies if this isn't the proper way to test such a thing. I have a relatively simple component that shouldn't render itself for a user not with the admin role.
I have written a test like so, expecting the
How can I go about this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi there, bUnit doesn't look at the authorize attribute of a component. It simply renders it if you tell it to. Testing that Blazor respects the authorize attribute would be you testing the blazor runtime, which is probably not what you want. If you want to test that the var actual = Attribute.GetCustomAttribute(typeof(Admin), typeof(AuthorizeAttribute)) as AuthorizeAttribute;
Assert.NotNull(actual);
Assert.Equal("admin", actual.Roles); (completely untested code, but that should get you started). |
Beta Was this translation helpful? Give feedback.
Hi there,
bUnit doesn't look at the authorize attribute of a component. It simply renders it if you tell it to.
Testing that Blazor respects the authorize attribute would be you testing the blazor runtime, which is probably not what you want.
If you want to test that the
Admin
component has the authorize attribute set correctly. I would look for the attribute on the component and assert it is there with the correct/expected values, e.g.:(completely untested code, but that should get you started).
More here: https://docs.…