Skip to content

Commit

Permalink
[fix] analyzer warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
i4004 committed Jun 1, 2024
1 parent 4d09796 commit 250e954
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 46 deletions.
4 changes: 2 additions & 2 deletions src/SampleApps/SampleApp.Api/Setup/IocRegistrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ public static class IocRegistrations
{
private static IConfiguration Configuration { get; set; } = null!;

public static IDIContainerProvider RegisterAll(this IDIContainerProvider provider, IServiceCollection services)
public static IDIContainerProvider RegisterAll(this IDIContainerProvider provider)
{
provider.RegisterCustomConfiguration(config => Configuration = config)
.RegisterSimplifyWeb(Configuration);
.RegisterSimplifyWeb(Configuration);

return provider;
}
Expand Down
2 changes: 1 addition & 1 deletion src/SampleApps/SampleApp.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
DIContainer.Current = new SimpleInjectorDIProvider();

DIContainer.Current
.RegisterAll(builder.Services)
.RegisterAll()
.Verify();

var app = builder.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public override async Task<ControllerResponse> Invoke()
{
var claims = new List<Claim>
{
new Claim(ClaimTypes.Name, Model.UserName)
new(ClaimTypes.Name, Model.UserName)
};

var id = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private static ExpandoObject ToExpando(IDictionary<string, object> dictionary)
return expando;
}

private void TestDynamic(dynamic list, int numValues)
private static void TestDynamic(dynamic list, int numValues)
{
for (var i = 0; i < numValues; i++)
{
Expand All @@ -104,7 +104,7 @@ private void TestDynamic(dynamic list, int numValues)
}
}

private void TestDictionary(IDictionary<string, object> list, int numValues)
private static void TestDictionary(IDictionary<string, object> list, int numValues)
{
for (var i = 0; i < numValues; i++)
{
Expand All @@ -113,7 +113,7 @@ private void TestDictionary(IDictionary<string, object> list, int numValues)
}
}

private IDictionary<string, object> CreateAndFillExpando(int numValues)
private static IDictionary<string, object> CreateAndFillExpando(int numValues)
{
var expandoDict = (IDictionary<string, object>)new ExpandoObject();

Expand All @@ -123,7 +123,7 @@ private void TestDictionary(IDictionary<string, object> list, int numValues)
return expandoDict;
}

private IDictionary<string, object> CreateAndFillDictionary(int numValues)
private static Dictionary<string, object> CreateAndFillDictionary(int numValues)
{
var dictionary = new Dictionary<string, object>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Simplify.Web.Tests.Controllers.Execution;
[TestFixture]
public class PreviousPageUrlUpdaterTests
{
private readonly IReadOnlyList<IMatchedController> _controllers = new List<IMatchedController>();
private readonly IReadOnlyList<IMatchedController> _controllers = [];

private PreviousPageUrlUpdater _updater = null!;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public void Build()
Assert.That(result.Controllers[4].Controller.ExecParameters!.RunPriority, Is.EqualTo(5));
}

private IMatchedController CreateController(int priority) =>
private static IMatchedController CreateController(int priority) =>
Mock.Of<IMatchedController>(x => x.Controller.ExecParameters == new ControllerExecParameters(null, priority));
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public void IsViolated_AuthorizationRequiredWithGroupAuthorizedNoGroups_True()
{
// Arrange

var security = new ControllerSecurity(true, new List<string>
{
var security = new ControllerSecurity(true,
[
"Admin",
"User"
});
]);

var claims = new List<Claim>
{
Expand All @@ -48,10 +48,10 @@ public void IsViolated_AuthorizationRequiredWithGroupAuthorizedNotInGroup_True()
{
// Arrange

var security = new ControllerSecurity(true, new List<string>
{
var security = new ControllerSecurity(true,
[
"Admin"
});
]);

var claims = new List<Claim>
{
Expand All @@ -74,11 +74,11 @@ public void IsViolated_AuthorizationRequiredWithGroupAuthorizedInGroup_False()
{
// Arrange

var security = new ControllerSecurity(true, new List<string>
{
var security = new ControllerSecurity(true,
[
"Admin",
"User"
});
]);

var claims = new List<Claim>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
namespace Simplify.Web.Tests.Controllers.V2.Metadata.MetadataTests.TestTypes;

#pragma warning disable CA1822 // Mark members as static

public class BadReturnTypeController : Controller2
{
public object? Invoke() => null;
}
}

#pragma warning restore CA1822 // Mark members as static
4 changes: 2 additions & 2 deletions src/Simplify.Web.Tests/Responses/FileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void Initialize()
{
_context = new Mock<IWebContext>();
_responseWriter = new Mock<IResponseWriter>();
_headerDictionary = new HeaderDictionary();
_headerDictionary = [];

_context.SetupGet(x => x.Response.Headers).Returns(_headerDictionary);
_context.Setup(x => x.Response.Body.Write(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>()));
Expand All @@ -31,7 +31,7 @@ public async Task Process_NormalData_FileSent()
{
// Arrange

var data = new byte[] { 13 };
var data = "\r"u8.ToArray();
var file = new Mock<File>("Foo.txt", "application/example", data, 200) { CallBase = true };

file.SetupGet(x => x.Context).Returns(_context.Object);
Expand Down
16 changes: 8 additions & 8 deletions src/Simplify.Web/Model/Validation/Attributes/MaxAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ public override void Validate(object? value, PropertyInfo propertyInfo, IDIResol
$"Property '{propertyInfo.Name}' required maximum value is {MaxValue}, actual value: {value}");
}

private static IComparable ConvertToIComparable(object value)
{
if (value is not IComparable comparableValue)
throw new ArgumentException($"The type of object value must be inherited from {typeof(IComparable)}");

return comparableValue;
}

private void ValidateTypesMatching(object value)
{
if (value.GetType() != OperandType)
Expand All @@ -117,12 +125,4 @@ private IComparable ConvertToOperandComparableType(object value)

return ConvertToIComparable(convertedValue);
}

private IComparable ConvertToIComparable(object value)
{
if (value is not IComparable comparableValue)
throw new ArgumentException($"The type of object value must be inherited from {typeof(IComparable)}");

return comparableValue;
}
}
16 changes: 8 additions & 8 deletions src/Simplify.Web/Model/Validation/Attributes/MinAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ public override void Validate(object? value, PropertyInfo propertyInfo, IDIResol
$"Property '{propertyInfo.Name}' required minimum value is {MinValue}, actual value: {value}");
}

private static IComparable ConvertToIComparable(object value)
{
if (value is not IComparable comparableValue)
throw new ArgumentException($"The type of object value must be inherited from {typeof(IComparable)}");

return comparableValue;
}

private void ValidateTypesMatching(object value)
{
if (value.GetType() != OperandType)
Expand All @@ -117,12 +125,4 @@ private IComparable ConvertToOperandComparableType(object value)

return ConvertToIComparable(convertedValue);
}

private IComparable ConvertToIComparable(object value)
{
if (value is not IComparable comparableValue)
throw new ArgumentException($"The type of object value must be inherited from {typeof(IComparable)}");

return comparableValue;
}
}
16 changes: 8 additions & 8 deletions src/Simplify.Web/Model/Validation/Attributes/RangeAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ public override void Validate(object? value, PropertyInfo propertyInfo, IDIResol
$"The value is out of range. The range constraint - {MinValue} - {MaxValue}, actual value: {value}");
}

private static IComparable ConvertToIComparable(object value)
{
if (value is not IComparable comparableValue)
throw new ArgumentException($"The type of object value must be inherited from {typeof(IComparable)}");

return comparableValue;
}

private void ValidateTypesMatching(IComparable comparableValue)
{
if (comparableValue.GetType() != OperandType)
Expand All @@ -133,12 +141,4 @@ private IComparable ConvertToOperandComparableType(object value)

return ConvertToIComparable(convertedValue);
}

private IComparable ConvertToIComparable(object value)
{
if (value is not IComparable comparableValue)
throw new ArgumentException($"The type of object value must be inherited from {typeof(IComparable)}");

return comparableValue;
}
}

0 comments on commit 250e954

Please sign in to comment.