Skip to content

Commit 815b154

Browse files
piotrzajacclaude
andauthored
fix: resolve CodeQL warnings across Core and test projects (#329)
* fix: resolve CodeQL warnings across Core and test projects - Combine nested if statements in IgnoreVirtualMembersSpecimenBuilder - Add ToString() override to AbstractTestClass in AutoDataAdapterAttributeTests - Use object instead of var to fix incomparable-types Equals in ValuesRequestTests - Remove redundant GetHashCode() call on int in ValuesRequestTests - Refactor CustomizeFixture foreach to use Select projection in AutoDataAdapterAttribute - Replace as+Assert.NotNull with Assert.IsType<T> in Assert section in CustomizeWithAttributeTests and AutoDataAttributeProviderTests Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: resolve incomparable-types Equals warning in ValuesRequestTests line 203 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore(coderabbit): disable docstrings pre-merge check * fix(test): No need for `as` cast --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 6aa4465 commit 815b154

8 files changed

Lines changed: 800 additions & 787 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
id: TASK-16
3+
title: Fix CodeQL warnings
4+
status: Done
5+
assignee:
6+
- piotrzajac
7+
- claude
8+
created_date: '2026-04-19 14:23'
9+
updated_date: '2026-04-19 15:13'
10+
labels: []
11+
dependencies: []
12+
priority: medium
13+
---
14+
15+
## Acceptance Criteria
16+
<!-- AC:BEGIN -->
17+
- [x] #1 Collapsible if statements combined (IgnoreVirtualMembersSpecimenBuilder)
18+
- [x] #2 Default ToString() override added (AbstractTestClass in AutoDataAdapterAttributeTests)
19+
- [x] #3 Change var to object to resolve incomparable-types Equals warning (ValuesRequestTests)
20+
- [x] #4 Useless call to GetHashCode() as value is its own hash (ValuesRequestTests)
21+
- [x] #5 AutoDataAdapterAttribute CustomizeFixture: foreach refactored to use Select projection.
22+
- [x] #6 CustomizeWithAttributeTests: as+Assert.NotNull replaced with Assert.IsType<T> in Assert section (lines 136, 157)
23+
- [x] #7 AutoDataAttributeProviderTests: same pattern applied (line 22)
24+
<!-- AC:END -->

.coderabbit.yaml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
# CodeRabbit configuration for AutoFixture.XUnit2.AutoMock
2-
# https://docs.coderabbit.ai/getting-started/configure-coderabbit
3-
#
4-
# One-time prerequisite: install the CodeRabbit GitHub App at the org/repo level.
5-
# https://github.com/apps/coderabbit-ai
6-
71
language: "en-US"
82

93
reviews:
@@ -16,6 +10,9 @@ reviews:
1610
auto_review:
1711
enabled: true
1812
drafts: false
19-
13+
pre_merge_checks:
14+
docstrings:
15+
mode: off
16+
2017
chat:
2118
auto_reply: true
Lines changed: 172 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -1,172 +1,172 @@
1-
namespace Objectivity.AutoFixture.XUnit2.Core.Tests.Attributes
2-
{
3-
using System;
4-
using System.Diagnostics.CodeAnalysis;
5-
using System.Linq;
6-
using System.Reflection;
7-
8-
using global::AutoFixture;
9-
using global::AutoFixture.Kernel;
10-
using global::AutoFixture.Xunit2;
11-
using Objectivity.AutoFixture.XUnit2.Core.Attributes;
12-
13-
using Xunit;
14-
15-
[Collection("AutoDataAdapterAttribute")]
16-
[Trait("Category", "DataAttribute")]
17-
[SuppressMessage("Design", "CA1034:Nested types should not be visible", Justification = "Test objects")]
18-
public class AutoDataAdapterAttributeTests
19-
{
20-
[AutoData]
21-
[Theory(DisplayName = "GIVEN fixture WHEN constructor is invoked THEN passed fixture is being adapted and inline values collection is empty")]
22-
public void GivenFixture_WhenConstructorIsInvoked_ThenPassedFixtureIsBeingAdaptedAndInlineValuesCollectionIsEmpty(Fixture fixture)
23-
{
24-
// Arrange
25-
// Act
26-
var attribute = new AutoDataAdapterAttribute(fixture, null);
27-
28-
// Assert
29-
Assert.Equal(fixture, attribute.AdaptedFixture);
30-
Assert.Empty(attribute.InlineValues);
31-
}
32-
33-
[Fact(DisplayName = "GIVEN uninitialized fixture WHEN constructor is invoked THEN exception is thrown")]
34-
public void GivenUninitializedFixture_WhenConstructorIsInvoked_ThenExceptionIsThrown()
35-
{
36-
// Arrange
37-
// Act
38-
static object Act() => new AutoDataAdapterAttribute(null);
39-
40-
// Assert
41-
var exception = Assert.Throws<ArgumentNullException>(Act);
42-
Assert.Equal("fixture", exception.ParamName);
43-
}
44-
45-
[AutoData]
46-
[Theory(DisplayName = "GIVEN uninitialized method info WHEN GetData is invoked THEN exception is thrown")]
47-
public void GivenUninitializedMethodInfo_WhenConstructorIsInvoked_ThenExceptionIsThrown(Fixture fixture)
48-
{
49-
// Arrange
50-
var attribute = new AutoDataAdapterAttribute(fixture);
51-
52-
// Act
53-
object Act() => attribute.GetData(null);
54-
55-
// Assert
56-
var exception = Assert.Throws<ArgumentNullException>(Act);
57-
Assert.Equal("testMethod", exception.ParamName);
58-
}
59-
60-
[Fact(DisplayName = "GIVEN test data with instance WHEN GetData called THEN auto data generation skipped")]
61-
public void GivenTestDataWithInstance_WhenGetDataCalled_ThenAutoDataGenerationSkipped()
62-
{
63-
// Arrange
64-
IFixture fixture = new Fixture();
65-
var attribute = new AutoDataAdapterAttribute(fixture, SpecificTestClass.Create());
66-
var methodInfo = typeof(AutoDataAdapterAttributeTests).GetMethod(nameof(this.TestMethodWithAbstractTestClass), BindingFlags.Instance | BindingFlags.NonPublic);
67-
var expectedNumberOfParameters = methodInfo.GetParameters().Length;
68-
69-
// Act
70-
var data = attribute.GetData(methodInfo).ToArray();
71-
72-
// Assert
73-
Assert.Single(data);
74-
Assert.Equal(expectedNumberOfParameters, data.First().Length);
75-
Assert.All(data.First(), Assert.NotNull);
76-
Assert.All(data.First().Skip(1), item => Assert.Equal(data.First().Last(), item));
77-
}
78-
79-
[Fact(DisplayName = "GIVEN empty test data WHEN GetData called THEN auto data generation throws exception")]
80-
public void GivenEmptyTestData_WhenGetDataCalled_ThenAutoDataGenerationSkipped()
81-
{
82-
// Arrange
83-
IFixture fixture = new Fixture();
84-
var attribute = new AutoDataAdapterAttribute(fixture);
85-
var methodInfo = typeof(AutoDataAdapterAttributeTests).GetMethod(nameof(this.TestMethodWithAbstractTestClass), BindingFlags.Instance | BindingFlags.NonPublic);
86-
87-
// Act
88-
void Act() => attribute.GetData(methodInfo);
89-
90-
// Assert
91-
Assert.ThrowsAny<Exception>(Act);
92-
}
93-
94-
[Fact(DisplayName = "GIVEN test method with Frozen customization after others WHEN GetData called THEN ensure parameter is frozen on the end")]
95-
public void GivenTestMethodWithFrozenCustomizationAfterOthers_WhenGetDataCalled_ThenEnsureParameterIsFrozenOnTheEnd()
96-
{
97-
// Arrange
98-
IFixture fixture = new Fixture();
99-
var attribute = new AutoDataAdapterAttribute(fixture, null);
100-
var methodInfo = typeof(AutoDataAdapterAttributeTests).GetMethod(nameof(this.TestMethodWithFrozenCustomizationBeforeOthers), BindingFlags.Instance | BindingFlags.NonPublic);
101-
var expectedNumberOfParameters = methodInfo.GetParameters().Length;
102-
103-
// Act
104-
var data = attribute.GetData(methodInfo).ToArray();
105-
106-
// Assert
107-
Assert.Single(data);
108-
Assert.Equal(expectedNumberOfParameters, data.First().Length);
109-
Assert.All(data.First(), Assert.NotNull);
110-
Assert.All(
111-
data.First().Skip(1),
112-
x =>
113-
{
114-
var parameters = data.First();
115-
Assert.Equal(parameters.Last(), x);
116-
Assert.NotEqual(parameters.First(), x);
117-
Assert.Contains(StopStringCustomization.Value, x as string);
118-
});
119-
}
120-
121-
protected string TestMethodWithAbstractTestClass(
122-
SpecificTestClass instance,
123-
[Frozen] string text,
124-
string message)
125-
{
126-
return $"{instance}: {text}, {message}";
127-
}
128-
129-
protected string TestMethodWithFrozenCustomizationBeforeOthers(
130-
string first,
131-
[Frozen][StopString] string second,
132-
string third)
133-
{
134-
return $"{first}: {second}, {third}";
135-
}
136-
137-
[SuppressMessage("Minor Code Smell", "S2094:Classes should not be empty", Justification = "Test class")]
138-
protected abstract class AbstractTestClass
139-
{
140-
}
141-
142-
protected sealed class SpecificTestClass : AbstractTestClass
143-
{
144-
private SpecificTestClass()
145-
{
146-
}
147-
148-
public static AbstractTestClass Create()
149-
{
150-
return new SpecificTestClass();
151-
}
152-
}
153-
154-
protected sealed class StopStringAttribute : CustomizeWithAttribute<StopStringCustomization>
155-
{
156-
}
157-
158-
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global", Justification = "This class is instantiated indirectly.")]
159-
protected class StopStringCustomization : ICustomization
160-
{
161-
public const string Value = "STOP";
162-
163-
public void Customize(IFixture fixture)
164-
{
165-
fixture.Customizations.Add(
166-
new FilteringSpecimenBuilder(
167-
new FixedBuilder(Value),
168-
new ExactTypeSpecification(Value.GetType())));
169-
}
170-
}
171-
}
172-
}
1+
namespace Objectivity.AutoFixture.XUnit2.Core.Tests.Attributes
2+
{
3+
using System;
4+
using System.Diagnostics.CodeAnalysis;
5+
using System.Linq;
6+
using System.Reflection;
7+
8+
using global::AutoFixture;
9+
using global::AutoFixture.Kernel;
10+
using global::AutoFixture.Xunit2;
11+
using Objectivity.AutoFixture.XUnit2.Core.Attributes;
12+
13+
using Xunit;
14+
15+
[Collection("AutoDataAdapterAttribute")]
16+
[Trait("Category", "DataAttribute")]
17+
[SuppressMessage("Design", "CA1034:Nested types should not be visible", Justification = "Test objects")]
18+
public class AutoDataAdapterAttributeTests
19+
{
20+
[AutoData]
21+
[Theory(DisplayName = "GIVEN fixture WHEN constructor is invoked THEN passed fixture is being adapted and inline values collection is empty")]
22+
public void GivenFixture_WhenConstructorIsInvoked_ThenPassedFixtureIsBeingAdaptedAndInlineValuesCollectionIsEmpty(Fixture fixture)
23+
{
24+
// Arrange
25+
// Act
26+
var attribute = new AutoDataAdapterAttribute(fixture, null);
27+
28+
// Assert
29+
Assert.Equal(fixture, attribute.AdaptedFixture);
30+
Assert.Empty(attribute.InlineValues);
31+
}
32+
33+
[Fact(DisplayName = "GIVEN uninitialized fixture WHEN constructor is invoked THEN exception is thrown")]
34+
public void GivenUninitializedFixture_WhenConstructorIsInvoked_ThenExceptionIsThrown()
35+
{
36+
// Arrange
37+
// Act
38+
static object Act() => new AutoDataAdapterAttribute(null);
39+
40+
// Assert
41+
var exception = Assert.Throws<ArgumentNullException>(Act);
42+
Assert.Equal("fixture", exception.ParamName);
43+
}
44+
45+
[AutoData]
46+
[Theory(DisplayName = "GIVEN uninitialized method info WHEN GetData is invoked THEN exception is thrown")]
47+
public void GivenUninitializedMethodInfo_WhenConstructorIsInvoked_ThenExceptionIsThrown(Fixture fixture)
48+
{
49+
// Arrange
50+
var attribute = new AutoDataAdapterAttribute(fixture);
51+
52+
// Act
53+
object Act() => attribute.GetData(null);
54+
55+
// Assert
56+
var exception = Assert.Throws<ArgumentNullException>(Act);
57+
Assert.Equal("testMethod", exception.ParamName);
58+
}
59+
60+
[Fact(DisplayName = "GIVEN test data with instance WHEN GetData called THEN auto data generation skipped")]
61+
public void GivenTestDataWithInstance_WhenGetDataCalled_ThenAutoDataGenerationSkipped()
62+
{
63+
// Arrange
64+
IFixture fixture = new Fixture();
65+
var attribute = new AutoDataAdapterAttribute(fixture, SpecificTestClass.Create());
66+
var methodInfo = typeof(AutoDataAdapterAttributeTests).GetMethod(nameof(this.TestMethodWithAbstractTestClass), BindingFlags.Instance | BindingFlags.NonPublic);
67+
var expectedNumberOfParameters = methodInfo.GetParameters().Length;
68+
69+
// Act
70+
var data = attribute.GetData(methodInfo).ToArray();
71+
72+
// Assert
73+
Assert.Single(data);
74+
Assert.Equal(expectedNumberOfParameters, data.First().Length);
75+
Assert.All(data.First(), Assert.NotNull);
76+
Assert.All(data.First().Skip(1), item => Assert.Equal(data.First().Last(), item));
77+
}
78+
79+
[Fact(DisplayName = "GIVEN empty test data WHEN GetData called THEN auto data generation throws exception")]
80+
public void GivenEmptyTestData_WhenGetDataCalled_ThenAutoDataGenerationSkipped()
81+
{
82+
// Arrange
83+
IFixture fixture = new Fixture();
84+
var attribute = new AutoDataAdapterAttribute(fixture);
85+
var methodInfo = typeof(AutoDataAdapterAttributeTests).GetMethod(nameof(this.TestMethodWithAbstractTestClass), BindingFlags.Instance | BindingFlags.NonPublic);
86+
87+
// Act
88+
void Act() => attribute.GetData(methodInfo);
89+
90+
// Assert
91+
Assert.ThrowsAny<Exception>(Act);
92+
}
93+
94+
[Fact(DisplayName = "GIVEN test method with Frozen customization after others WHEN GetData called THEN ensure parameter is frozen on the end")]
95+
public void GivenTestMethodWithFrozenCustomizationAfterOthers_WhenGetDataCalled_ThenEnsureParameterIsFrozenOnTheEnd()
96+
{
97+
// Arrange
98+
IFixture fixture = new Fixture();
99+
var attribute = new AutoDataAdapterAttribute(fixture, null);
100+
var methodInfo = typeof(AutoDataAdapterAttributeTests).GetMethod(nameof(this.TestMethodWithFrozenCustomizationBeforeOthers), BindingFlags.Instance | BindingFlags.NonPublic);
101+
var expectedNumberOfParameters = methodInfo.GetParameters().Length;
102+
103+
// Act
104+
var data = attribute.GetData(methodInfo).ToArray();
105+
106+
// Assert
107+
Assert.Single(data);
108+
Assert.Equal(expectedNumberOfParameters, data.First().Length);
109+
Assert.All(data.First(), Assert.NotNull);
110+
Assert.All(
111+
data.First().Skip(1),
112+
x =>
113+
{
114+
var parameters = data.First();
115+
Assert.Equal(parameters.Last(), x);
116+
Assert.NotEqual(parameters.First(), x);
117+
Assert.Contains(StopStringCustomization.Value, x as string);
118+
});
119+
}
120+
121+
protected string TestMethodWithAbstractTestClass(
122+
SpecificTestClass instance,
123+
[Frozen] string text,
124+
string message)
125+
{
126+
return $"{instance}: {text}, {message}";
127+
}
128+
129+
protected string TestMethodWithFrozenCustomizationBeforeOthers(
130+
string first,
131+
[Frozen][StopString] string second,
132+
string third)
133+
{
134+
return $"{first}: {second}, {third}";
135+
}
136+
137+
protected abstract class AbstractTestClass
138+
{
139+
public override string ToString() => this.GetType().Name;
140+
}
141+
142+
protected sealed class SpecificTestClass : AbstractTestClass
143+
{
144+
private SpecificTestClass()
145+
{
146+
}
147+
148+
public static AbstractTestClass Create()
149+
{
150+
return new SpecificTestClass();
151+
}
152+
}
153+
154+
protected sealed class StopStringAttribute : CustomizeWithAttribute<StopStringCustomization>
155+
{
156+
}
157+
158+
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global", Justification = "This class is instantiated indirectly.")]
159+
protected class StopStringCustomization : ICustomization
160+
{
161+
public const string Value = "STOP";
162+
163+
public void Customize(IFixture fixture)
164+
{
165+
fixture.Customizations.Add(
166+
new FilteringSpecimenBuilder(
167+
new FixedBuilder(Value),
168+
new ExactTypeSpecification(Value.GetType())));
169+
}
170+
}
171+
}
172+
}

0 commit comments

Comments
 (0)