Skip to content

Commit 60aec79

Browse files
committed
fix: Fix unit test issues
1 parent 52aaa75 commit 60aec79

File tree

11 files changed

+31
-35
lines changed

11 files changed

+31
-35
lines changed

src/BuildingBlocks/Exception/Masa.BuildingBlocks.Exceptions.Tests/MasaArgumentExceptionTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public void TestThrowIfNull()
1919
}
2020
catch (MasaArgumentException ex)
2121
{
22-
Assert.AreEqual(Masa.BuildingBlocks.Data.Constants.ErrorCode.NULL_VALIDATOR, ex.ErrorCode);
23-
Assert.AreEqual("Value cannot be null. (Parameter '{0}')", ex.ErrorMessage);
22+
Assert.AreEqual(Data.Constants.ErrorCode.NOT_NULL_VALIDATOR, ex.ErrorCode);
23+
Assert.AreEqual("'{0}' must not be empty.", ex.ErrorMessage);
2424
}
2525
}
2626
}

src/Contrib/Caching/Distributed/Tests/Masa.Contrib.Caching.Distributed.StackExchangeRedis.Tests/DistributedCacheClientTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ public async Task TestHashIncrementAndValueLessThan1Async(string key, int value)
528528
{
529529
await _distributedCacheClient.RemoveAsync(key);
530530

531-
await Assert.ThrowsExceptionAsync<ArgumentOutOfRangeException>(async ()
531+
await Assert.ThrowsExceptionAsync<MasaArgumentException>(async ()
532532
=> await _distributedCacheClient.HashIncrementAsync(key, value));
533533
}
534534

@@ -555,7 +555,7 @@ public async Task TestHashDecrementAndValueLessThan1Async(string key, long value
555555
{
556556
await _distributedCacheClient.RemoveAsync(key);
557557

558-
await Assert.ThrowsExceptionAsync<ArgumentOutOfRangeException>(async ()
558+
await Assert.ThrowsExceptionAsync<MasaArgumentException>(async ()
559559
=> await _distributedCacheClient.HashDecrementAsync(key, value));
560560
}
561561

src/Contrib/Caching/Distributed/Tests/Masa.Contrib.Caching.Distributed.StackExchangeRedis.Tests/TestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ protected static RedisConfigurationOptions GetConfigurationOptions()
1313
{
1414
GlobalCacheOptions = new CacheOptions()
1515
{
16-
CacheKeyType = CacheKeyType.TypeName
16+
CacheKeyType = CacheKeyType.None
1717
}
1818
};
1919
redisConfigurationOptions.Servers.Add(new RedisServerOptions());

src/Contrib/Configuration/ConfigurationApi/Tests/Masa.Contrib.Configuration.ConfigurationApi.Dcc.Tests/DccTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ public void TestComplementAndCheckDccConfigurationOptionByCustomerDccOptions()
524524
public void TestComplementAndCheckDccConfigurationOptionByManageServiceAddressIsEmpty()
525525
{
526526
DccOptions dccOptions = new DccOptions();
527-
Assert.ThrowsException<ArgumentNullException>(() =>
527+
Assert.ThrowsException<MasaArgumentException>(() =>
528528
{
529529
MasaConfigurationExtensions.ComplementAndCheckDccConfigurationOption(_masaConfigurationBuilder.Object, dccOptions);
530530
});
@@ -537,7 +537,7 @@ public void TestComplementAndCheckDccConfigurationOptionByRedisServersIsEmpty()
537537
{
538538
ManageServiceAddress = nameof(DccOptions.ManageServiceAddress),
539539
};
540-
Assert.ThrowsException<ArgumentException>(() =>
540+
Assert.ThrowsException<MasaArgumentException>(() =>
541541
{
542542
MasaConfigurationExtensions.ComplementAndCheckDccConfigurationOption(_masaConfigurationBuilder.Object, dccOptions);
543543
});
@@ -599,7 +599,7 @@ public void TestComplementAndCheckDccConfigurationOptionByAppIdIsEmpty()
599599
}
600600
}
601601
};
602-
Assert.ThrowsException<ArgumentException>(() =>
602+
Assert.ThrowsException<MasaArgumentException>(() =>
603603
{
604604
MasaConfigurationExtensions.ComplementAndCheckDccConfigurationOption(_masaConfigurationBuilder.Object, dccOptions);
605605
});

src/Contrib/Configuration/Masa.Contrib.Configuration/Extensions/ServiceCollectionExtensions.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
33

44
// ReSharper disable once CheckNamespace
5+
56
namespace Microsoft.Extensions.DependencyInjection;
67

78
public static class ServiceCollectionExtensions
@@ -135,12 +136,7 @@ public static IServiceCollection AddMasaConfiguration(
135136
configurationBuilder.Sources.Clear();
136137
configurationBuilder.AddConfiguration(masaConfiguration);
137138

138-
if (sourceConfiguration == null)
139-
{
140-
var configurationManager = new ConfigurationManager();
141-
configurationBuilder.AddConfiguration(configurationBuilder.Build());
142-
services.AddSingleton<IConfiguration>(_ => configurationManager);
143-
}
139+
if (sourceConfiguration == null) services.AddSingleton<IConfiguration>(_ => configurationBuilder.Build());
144140

145141
return services;
146142
}

src/Contrib/Dispatcher/IntegrationEvents/Tests/Masa.Contrib.Dispatcher.IntegrationEvents.Dapr.Tests/IntegrationEventBusTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ public void TestDispatcherOption()
4444
var services = new ServiceCollection();
4545
DispatcherOptions options;
4646

47-
Assert.ThrowsException<ArgumentException>(() =>
47+
Assert.ThrowsException<MasaArgumentException>(() =>
4848
{
4949
options = new DispatcherOptions(services, null!);
5050
});
51-
Assert.ThrowsException<ArgumentException>(() =>
51+
Assert.ThrowsException<MasaArgumentException>(() =>
5252
{
5353
options = new DispatcherOptions(services, Array.Empty<Assembly>());
5454
});

src/Contrib/Dispatcher/IntegrationEvents/Tests/Masa.Contrib.Dispatcher.IntegrationEvents.Tests/DispatcherOptionTest.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void TestSetLocalRetryTimes()
2222
_options.LocalRetryTimes = 5;
2323
Assert.IsTrue(_options.LocalRetryTimes == 5);
2424

25-
Assert.ThrowsException<ArgumentException>(() => _options.LocalRetryTimes = 0);
25+
Assert.ThrowsException<MasaArgumentException>(() => _options.LocalRetryTimes = 0);
2626
}
2727

2828
[TestMethod]
@@ -32,7 +32,7 @@ public void TestSetMaxRetryTimes()
3232
_options.MaxRetryTimes = 5;
3333
Assert.IsTrue(_options.MaxRetryTimes == 5);
3434

35-
Assert.ThrowsException<ArgumentException>(() => _options.MaxRetryTimes = 0);
35+
Assert.ThrowsException<MasaArgumentException>(() => _options.MaxRetryTimes = 0);
3636
}
3737

3838
[TestMethod]
@@ -42,7 +42,7 @@ public void TestSetFailedRetryInterval()
4242
_options.FailedRetryInterval = 5;
4343
Assert.IsTrue(_options.FailedRetryInterval == 5);
4444

45-
Assert.ThrowsException<ArgumentException>(() => _options.FailedRetryInterval = 0);
45+
Assert.ThrowsException<MasaArgumentException>(() => _options.FailedRetryInterval = 0);
4646
}
4747

4848
[TestMethod]
@@ -52,7 +52,7 @@ public void TestSetMinimumRetryInterval()
5252
_options.MinimumRetryInterval = 5;
5353
Assert.IsTrue(_options.MinimumRetryInterval == 5);
5454

55-
Assert.ThrowsException<ArgumentException>(() => _options.MinimumRetryInterval = 0);
55+
Assert.ThrowsException<MasaArgumentException>(() => _options.MinimumRetryInterval = 0);
5656
}
5757

5858
[TestMethod]
@@ -62,7 +62,7 @@ public void TestSetLocalFailedRetryInterval()
6262
_options.LocalFailedRetryInterval = 5;
6363
Assert.IsTrue(_options.LocalFailedRetryInterval == 5);
6464

65-
Assert.ThrowsException<ArgumentException>(() => _options.LocalFailedRetryInterval = -1);
65+
Assert.ThrowsException<MasaArgumentException>(() => _options.LocalFailedRetryInterval = -1);
6666
}
6767

6868
[TestMethod]
@@ -72,7 +72,7 @@ public void TestSetRetryBatchSize()
7272
_options.RetryBatchSize = 5;
7373
Assert.IsTrue(_options.RetryBatchSize == 5);
7474

75-
Assert.ThrowsException<ArgumentException>(() => _options.RetryBatchSize = -1);
75+
Assert.ThrowsException<MasaArgumentException>(() => _options.RetryBatchSize = -1);
7676
}
7777

7878
[TestMethod]
@@ -82,7 +82,7 @@ public void TestSetCleaningLocalQueueExpireInterval()
8282
_options.CleaningLocalQueueExpireInterval = 5;
8383
Assert.IsTrue(_options.CleaningLocalQueueExpireInterval == 5);
8484

85-
Assert.ThrowsException<ArgumentException>(() => _options.CleaningLocalQueueExpireInterval = 0);
85+
Assert.ThrowsException<MasaArgumentException>(() => _options.CleaningLocalQueueExpireInterval = 0);
8686
}
8787

8888
[TestMethod]
@@ -92,7 +92,7 @@ public void TestSetCleaningExpireInterval()
9292
_options.CleaningExpireInterval = 5;
9393
Assert.IsTrue(_options.CleaningExpireInterval == 5);
9494

95-
Assert.ThrowsException<ArgumentException>(() => _options.CleaningExpireInterval = 0);
95+
Assert.ThrowsException<MasaArgumentException>(() => _options.CleaningExpireInterval = 0);
9696
}
9797

9898
[TestMethod]
@@ -102,7 +102,7 @@ public void TestSetPublishedExpireTime()
102102
_options.PublishedExpireTime = 24 * 3 * 3600;
103103
Assert.IsTrue(_options.PublishedExpireTime == 24 * 3 * 3600);
104104

105-
Assert.ThrowsException<ArgumentException>(() => _options.PublishedExpireTime = 0);
105+
Assert.ThrowsException<MasaArgumentException>(() => _options.PublishedExpireTime = 0);
106106
}
107107

108108
[TestMethod]
@@ -112,7 +112,7 @@ public void TestSetDeleteBatchCount()
112112
_options.DeleteBatchCount = 100;
113113
Assert.IsTrue(_options.DeleteBatchCount == 100);
114114

115-
Assert.ThrowsException<ArgumentException>(() => _options.DeleteBatchCount = 0);
115+
Assert.ThrowsException<MasaArgumentException>(() => _options.DeleteBatchCount = 0);
116116
}
117117

118118
[TestMethod]

src/Contrib/Dispatcher/IntegrationEvents/Tests/Masa.Contrib.Dispatcher.IntegrationEvents.Tests/IntegrationEventBusTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ public void TestDispatcherOption()
4949
var services = new ServiceCollection();
5050
DispatcherOptions options;
5151

52-
Assert.ThrowsException<ArgumentException>(() =>
52+
Assert.ThrowsException<MasaArgumentException>(() =>
5353
{
5454
options = new DispatcherOptions(services, null!);
5555
});
56-
Assert.ThrowsException<ArgumentException>(() =>
56+
Assert.ThrowsException<MasaArgumentException>(() =>
5757
{
5858
options = new DispatcherOptions(services, Array.Empty<Assembly>());
5959
});

src/Contrib/Dispatcher/Tests/Masa.Contrib.Dispatcher.Events.Tests/AssemblyResolutionTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void TestAddNullAssembly()
2424
{
2525
var services = new ServiceCollection();
2626
services.AddLogging(loggingBuilder => loggingBuilder.AddConsole());
27-
Assert.ThrowsException<ArgumentException>(() =>
27+
Assert.ThrowsException<MasaArgumentException>(() =>
2828
{
2929
Assembly[] assemblies = null!;
3030
services.AddEventBus(assemblies!);
@@ -36,7 +36,7 @@ public void TestAddEmptyAssembly()
3636
{
3737
var services = new ServiceCollection();
3838
services.AddLogging(loggingBuilder => loggingBuilder.AddConsole());
39-
Assert.ThrowsException<ArgumentException>(() =>
39+
Assert.ThrowsException<MasaArgumentException>(() =>
4040
{
4141
services.AddEventBus(Array.Empty<Assembly>());
4242
});
@@ -47,7 +47,7 @@ public void TestEventBusByAddNullAssembly()
4747
{
4848
var services = new ServiceCollection();
4949
services.AddLogging(loggingBuilder => loggingBuilder.AddConsole());
50-
Assert.ThrowsException<ArgumentException>(() =>
50+
Assert.ThrowsException<MasaArgumentException>(() =>
5151
{
5252
services.AddTestEventBus(null!, ServiceLifetime.Scoped);
5353
});

src/Contrib/Storage/ObjectStorage/Tests/Masa.Contrib.Storage.ObjectStorage.Aliyun.Tests/StorageTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void TestAddAliyunStorageAndNotAddConfigurationReturnClientIsNotNull()
1919
public void TestAddAliyunStorageByEmptySectionReturnThrowArgumentException()
2020
{
2121
var services = new ServiceCollection();
22-
Assert.ThrowsException<ArgumentException>(() => services.AddAliyunStorage(string.Empty));
22+
Assert.ThrowsException<MasaArgumentException>(() => services.AddAliyunStorage(string.Empty));
2323
}
2424

2525
[TestMethod]
@@ -226,7 +226,7 @@ public void TestAddAliyunStorageAndNullALiYunStorageOptionsReturnThrowArgumentNu
226226
[TestMethod]
227227
public void TestAddAliyunStorageByEmptyAccessKeyIdReturnThrowArgumentNullException()
228228
{
229-
Assert.ThrowsException<ArgumentException>(() => new AliyunStorageOptions(null!, null!, null!));
229+
Assert.ThrowsException<MasaArgumentException>(() => new AliyunStorageOptions(null!, null!, null!));
230230
}
231231

232232
[TestMethod]

0 commit comments

Comments
 (0)