Description
The DatabasePermission.Equals() method has a bug where it only compares the Permission property and ignores the State property. This causes incorrect equality comparisons when two instances have the same Permission but different State values.
Current Behavior
When comparing two DatabasePermission instances:
- Instance 1:
State = 'Deny', Permission = 'select'
- Instance 2:
State = 'Grant', Permission = 'select'
The comparison returns true (equal) when it should return false (not equal).
Expected Behavior
The Equals() method should compare both the State and Permission properties to determine equality.
Impact
- Tests currently assert the buggy behavior rather than the correct behavior
- Future developers may not realize this is incorrect behavior
- The bug becomes harder to track and fix over time
Affected Files
source/Classes/DatabasePermission.ps1 (or similar location for the class implementation)
tests/Unit/Classes/DatabasePermission.Tests.ps1 (lines 158-161)
Suggested Fix
- Update the
Equals() method to compare both State and Permission properties
- Ensure
GetHashCode() also covers both fields consistently
- Revert the test assertion to the correct expectation (
Should -BeFalse)
- Add/adjust unit tests to cover both equal and not-equal cases
References
Description
The
DatabasePermission.Equals()method has a bug where it only compares thePermissionproperty and ignores theStateproperty. This causes incorrect equality comparisons when two instances have the samePermissionbut differentStatevalues.Current Behavior
When comparing two
DatabasePermissioninstances:State = 'Deny', Permission = 'select'State = 'Grant', Permission = 'select'The comparison returns
true(equal) when it should returnfalse(not equal).Expected Behavior
The
Equals()method should compare both theStateandPermissionproperties to determine equality.Impact
Affected Files
source/Classes/DatabasePermission.ps1(or similar location for the class implementation)tests/Unit/Classes/DatabasePermission.Tests.ps1(lines 158-161)Suggested Fix
Equals()method to compare bothStateandPermissionpropertiesGetHashCode()also covers both fields consistentlyShould -BeFalse)References