Skip to content

Commit

Permalink
feat: disable ReSharper attribute joining. (#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
joesdu authored Oct 16, 2024
2 parents a20d9ec + c908644 commit 810721d
Show file tree
Hide file tree
Showing 20 changed files with 546 additions and 289 deletions.
573 changes: 317 additions & 256 deletions Reshaper.DotSettings

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion sample/WebApi.Test.Unit/Controllers/GarnetController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace WebApi.Test.Unit.Controllers;

/// <inheritdoc />
[Route("api/[controller]"), ApiController, ApiGroup("GarnetTest", "v1", "Garnet的基本使用")]
[Route("api/[controller]")]
[ApiController]
[ApiGroup("GarnetTest", "v1", "Garnet的基本使用")]
public class GarnetController : ControllerBase
{
private readonly IDatabase _rdb;
Expand Down
4 changes: 3 additions & 1 deletion sample/WebApi.Test.Unit/Controllers/GridFSController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ namespace WebApi.Test.Unit.Controllers;
/// <summary>
/// GridFS控制器,当引入Extension后,请使用Extension版本的API
/// </summary>
[ApiController, Route("api/[controller]"), ApiGroup("MongoFS", "v1", "MongoDB GridFS")]
[ApiController]
[Route("api/[controller]")]
[ApiGroup("MongoFS", "v1", "MongoDB GridFS")]
public class GridFSController(GridFSBucket bucket) : ControllerBase
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ namespace WebApi.Test.Unit.Controllers;
/// <summary>
/// 测试HttpClient上传文件的问题复现
/// </summary>
[Route("api/[controller]"), ApiController, ApiGroup("GridFSTest", "v1", "HttpClientGridFSController")]
[Route("api/[controller]")]
[ApiController]
[ApiGroup("GridFSTest", "v1", "HttpClientGridFSController")]
public class HttpClientGridFSController : ControllerBase
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ namespace WebApi.Test.Unit.Controllers;
/// <summary>
/// KeyedServiceTest
/// </summary>
[Route("api/[controller]"), ApiController, ApiGroup("KeyedServiceTest", "v1", "KeyedServiceTestController")]
[Route("api/[controller]")]
[ApiController]
[ApiGroup("KeyedServiceTest", "v1", "KeyedServiceTestController")]
public class KeyedServiceTestController(IServiceProvider sp, IKeyedServiceTest kst2) : ControllerBase
{
/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion sample/WebApi.Test.Unit/Controllers/MongoArrayController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ namespace WebApi.Test.Unit.Controllers;
/// Mongo的数组对象操作
/// </summary>
/// <param name="db"></param>
[Route("api/[controller]"), ApiController, ApiGroup("MongoTest", "v1", "MongoDB一些测试")]
[Route("api/[controller]")]
[ApiController]
[ApiGroup("MongoTest", "v1", "MongoDB一些测试")]
public class MongoArrayController(DbContext db) : ControllerBase
{
private readonly FilterDefinitionBuilder<FamilyInfo> _bf = Builders<FamilyInfo>.Filter;
Expand Down
4 changes: 3 additions & 1 deletion sample/WebApi.Test.Unit/Controllers/MongoLockController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace WebApi.Test.Unit.Controllers;
/// <summary>
/// MongoDB分布式锁测试
/// </summary>
[Route("api/[controller]/[action]"), ApiController, ApiGroup("MongoLock", "v1", "基于MongoDB实现的分布式锁测试")]
[Route("api/[controller]/[action]")]
[ApiController]
[ApiGroup("MongoLock", "v1", "基于MongoDB实现的分布式锁测试")]
public class MongoLockController(IMongoLockFactory lockFactory, DbContext db) : ControllerBase
{
/// <summary>
Expand Down
7 changes: 5 additions & 2 deletions sample/WebApi.Test.Unit/Controllers/MongoTestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ namespace WebApi.Test.Unit.Controllers;
/// <summary>
/// 测试mongodb的一些功能
/// </summary>
[ApiController, Route("api/[controller]"), ApiGroup("MongoTest", "v1", "MongoDB一些测试")]
[ApiController]
[Route("api/[controller]")]
[ApiGroup("MongoTest", "v1", "MongoDB一些测试")]
public class MongoTestController(DbContext db) : ControllerBase
{
private readonly FilterDefinitionBuilder<MongoTest> bf = Builders<MongoTest>.Filter;
Expand Down Expand Up @@ -81,7 +83,8 @@ public Task MongoPost()
/// 测试从MongoDB中取出插入的数据,再返回到Swagger查看数据JSON转换是否正常
/// </summary>
/// <returns></returns>
[HttpGet("MongoGet"), OutputCache]
[HttpGet("MongoGet")]
[OutputCache]
public async Task<IEnumerable<MongoTest>> MongoGet() => await db.Test.Find(bf.Empty).ToListAsync();

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion sample/WebApi.Test.Unit/Controllers/PramsIgnoreController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace WebApi.Test.Unit.Controllers;
/// <summary>
/// 测试参数隐藏
/// </summary>
[Route("api/[controller]/[action]"), ApiController]
[Route("api/[controller]/[action]")]
[ApiController]
public class PramsIgnoreController : ControllerBase
{
/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion sample/WebApi.Test.Unit/Controllers/RabbitBusController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ namespace WebApi.Test.Unit.Controllers;
/// <summary>
/// 消息总线测试控制器
/// </summary>
[ApiController, Route("api/[controller]/[action]"), ApiGroup("RabbitBus", "v1", "RabbitBus Test")]
[ApiController]
[Route("api/[controller]/[action]")]
[ApiGroup("RabbitBus", "v1", "RabbitBus Test")]
public class RabbitBusController(IBus ibus) : ControllerBase
{
/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion sample/WebApi.Test.Unit/Controllers/ValuesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ namespace WebApi.Test.Unit.Controllers;
/// <summary>
/// 一些接口上的功能测试
/// </summary>
[Route("api/[controller]/[action]"), ApiController]
[Route("api/[controller]/[action]")]
[ApiController]
public class ValuesController : ControllerBase
{
/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion sample/WebApi.Test.Unit/Events/RabbitEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ namespace WebApi.Test.Unit.Events;
/// 测试HelloWorld模式消息类型
/// </summary>
//[Exchange(EModel.None, queue: "hello.world")]
[Exchange(EModel.Delayed, "delayed.hello", queue: "delayed.hello.world"), QueueArg("x-message-ttl", 5000)]
[Exchange(EModel.Delayed, "delayed.hello", queue: "delayed.hello.world")]
[QueueArg("x-message-ttl", 5000)]
public class HelloWorldEvent : IEvent
{
/// <summary>
Expand Down
6 changes: 0 additions & 6 deletions sample/WebApi.Test.Unit/ServiceModules/MongoModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using EasilyNET.AutoDependencyInjection.Modules;
using EasilyNET.Mongo.AspNetCore.Serializers;
using EasilyNET.Mongo.ConsoleDebug.Subscribers;
using MongoDB.Driver.Linq;

namespace WebApi.Test.Unit.ServiceModules;

Expand All @@ -26,8 +25,6 @@ public override void ConfigureServices(ConfigureServicesContext context)
//{
// Servers = new List<MongoServerAddress> { new("127.0.0.1", 27018) },
// Credential = MongoCredential.CreateCredential("admin", "guest", "guest"),
// // 新版驱动使用V3版本,有可能会出现一些Linq表达式客户端函数无法执行,需要调整代码,但是工作量太大了,所以可以先使用V2兼容.
// LinqProvider = LinqProvider.V3,
// // 对接 SkyAPM 的 MongoDB探针
// ClusterConfigurator = cb => cb.Subscribe(new DiagnosticsActivityEventSubscriber())
//}, c =>
Expand Down Expand Up @@ -64,7 +61,6 @@ public override void ConfigureServices(ConfigureServicesContext context)
// };
// c.ClientSettings = cs =>
// {
// cs.LinqProvider = LinqProvider.V2;
// cs.ClusterConfigurator = cb => cb.Subscribe(new ActivityEventSubscriber());
// };
//});
Expand All @@ -84,14 +80,12 @@ public override void ConfigureServices(ConfigureServicesContext context)
CaptureCommandText = true
}));
};
cs.LinqProvider = LinqProvider.V3;
// https://www.mongodb.com/docs/drivers/csharp/current/fundamentals/logging/#log-messages-by-category
//cs.LoggingSettings = new(LoggerFactory.Create(b =>
//{
// b.AddConfiguration(new ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string, string?>
// {
// //{ "LogLevel:Default", "Debug" },
// //{ "LogLevel:MongoDB.SDAM", "Debug" },
// { "LogLevel:MongoDB.COMMAND", "Debug" }
// //{ "LogLevel:MongoDB.CONNECTION", "Debug" },
// //{ "LogLevel:MongoDB.INTERNAL.*", "Debug" },
Expand Down
2 changes: 1 addition & 1 deletion sample/WebApi.Test.Unit/WebApi.Test.Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
<ProjectReference Include="..\..\src\EasilyNET.WebCore.Swagger\EasilyNET.WebCore.Swagger.csproj" />
</ItemGroup>

</Project>
</Project>
7 changes: 3 additions & 4 deletions test/EasilyNET.Test.Unit/DistributedLocks/LockTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
using FluentAssertions;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Linq;

namespace EasilyNET.Test.Unit.DistributedLocks;

/// <summary>
/// 测试
/// </summary>
[TestClass, Ignore]
[TestClass]
[Ignore]
public class LockTests
{
private readonly IMongoCollection<LockAcquire> _locks;
Expand All @@ -23,8 +23,7 @@ public LockTests()
var setting = new MongoClientSettings
{
Servers = [new("127.0.0.1", 27018)],
Credential = MongoCredential.CreateCredential("admin", "guest", "guest"),
LinqProvider = LinqProvider.V3
Credential = MongoCredential.CreateCredential("admin", "guest", "guest")
};
var client = new MongoClient(setting);
var db = client.GetDatabase("locks");
Expand Down
12 changes: 9 additions & 3 deletions test/EasilyNET.Test.Unit/Language/CustomIntEnumeratorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public class CustomIntEnumeratorTest
/// CustomIntEnumeratorExtension Test
/// </summary>
/// <param name="value"></param>
[TestMethod, DataRow(3), DataRow(5)]
[TestMethod]
[DataRow(3)]
[DataRow(5)]
public void TestCustomIntEnumeratorExtension(int value)
{
foreach (var i in ..value)
Expand All @@ -24,7 +26,9 @@ public void TestCustomIntEnumeratorExtension(int value)
/// CustomIntEnumeratorExtension Test
/// </summary>
/// <param name="value"></param>
[TestMethod, DataRow(3), DataRow(5)]
[TestMethod]
[DataRow(3)]
[DataRow(5)]
public void OneToValue(int value)
{
foreach (var i in 1..value)
Expand All @@ -37,7 +41,9 @@ public void OneToValue(int value)
/// CustomIntEnumeratorExtension Test
/// </summary>
/// <param name="value"></param>
[TestMethod, DataRow(3), DataRow(5)]
[TestMethod]
[DataRow(3)]
[DataRow(5)]
public void OnlyValue(int value)
{
foreach (var i in value)
Expand Down
6 changes: 4 additions & 2 deletions test/EasilyNET.Test.Unit/Misc/RmbCapitalizedTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public class RmbCapitalizedTest
/// <summary>
/// 较小值
/// </summary>
[TestMethod, DataRow(1594.6589)]
[TestMethod]
[DataRow(1594.6589)]
public void RmbCapitalizedMin(double value)
{
Console.WriteLine(value.ToRmb());
Expand All @@ -22,7 +23,8 @@ public void RmbCapitalizedMin(double value)
/// <summary>
/// 较大值
/// </summary>
[TestMethod, DataRow("1594278327421378518276358712.6589")]
[TestMethod]
[DataRow("1594278327421378518276358712.6589")]
public void RmbCapitalizedMax(string value)
{
Console.WriteLine(value.ToRmb());
Expand Down
9 changes: 4 additions & 5 deletions test/EasilyNET.Test.Unit/Randoms/RandomTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@ namespace EasilyNET.Test.Unit.Randoms;
[TestClass]
public class RandomTest
{
private readonly Random _random = new();

[TestMethod]
public void StrictNext_ShouldReturnValueWithinRange()
{
// Act
var result = _random.StrictNext();
var result = RandomExtensions.StrictNext();

// Assert
Assert.IsTrue(result is >= 0 and < int.MaxValue);
}

[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void StrictNext2_ShouldThrowArgumentOutOfRangeException_WhenStartIndexIsGreaterThanOrEqualToMaxValue()
{
// Act
_random.StrictNext(10, 5);
RandomExtensions.StrictNext(10, 5);
}
}
102 changes: 102 additions & 0 deletions test/EasilyNET.Test.Unit/System/SnowFlakeIdTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System.Diagnostics;
using EasilyNET.Core.System;
using FluentAssertions;

namespace EasilyNET.Test.Unit.System;

/// <summary>
/// 测试雪花ID,只支持long类型
/// </summary>
[TestClass]
public class SnowFlakeIdTest
{
/// <summary>
/// </summary>
[TestMethod]
public void TestDefaultNextId()
{
var id = SnowFlakeId.Default.NextId();
id.Should().BeGreaterThan(0);
}

/// <summary>
/// 检测ID是不是递增的
/// </summary>
[TestMethod]
public void TestGenerateIncreasing_Ids()
{
var lastId = 0L;
for (var i = 0; i < 100; i++)
{
var id = SnowFlakeId.Default.NextId();
id.Should().BeGreaterThan(lastId);
lastId = id;
}
}

/// <summary>
/// 生成唯一ID测试
/// </summary>
[TestMethod]
[Ignore]
public void GenerateOnlyUniqueIds()
{
var set = new HashSet<long>();
const int N = 2000000;
for (var i = 0; i < N; i++)
{
var id = SnowFlakeId.Default.NextId();
if (!set.Add(id))
{
Debug.WriteLine($"重复ID{id}");
}
}
set.Count.Should().Be(N);
}

/// <summary>
/// Task生成唯一ID测试
/// </summary>
[TestMethod]
[Ignore]
public void GenerateOnlyUniqueTaskIds()
{
var set = new HashSet<long>();
const int N = 2000000;
var lockObject = new Lock();
const int numberOfThreads = 10;
Parallel.For(0, numberOfThreads, _ =>
{
for (var j = 0; j < N; j++)
{
var id = SnowFlakeId.Default.NextId();
lock (lockObject)
{
if (!set.Add(id))
{
Debug.WriteLine($"重复ID{id}");
}
}
}
});
set.Count.Should().Be(N * numberOfThreads);
}

/// <summary>
/// </summary>
[TestMethod]
public void It_should_properly_mask_worker_id()
{
// Arrange
const int workerId = 123;
SnowFlakeId.SetDefaultSnowFlakeId(new(workerId));
const long expectedMaskedWorkerId = workerId & 0xFFF; // 0xFFF is the mask for 12 bits

// Act
var generatedId = SnowFlakeId.Default.NextId();
var maskedWorkerId = (generatedId >> 10) & 0xFFF; // Shift and mask to get workerId

// Assert
Assert.AreEqual(expectedMaskedWorkerId, maskedWorkerId);
}
}
Loading

0 comments on commit 810721d

Please sign in to comment.