Skip to content

Commit

Permalink
fix:[#484]read dic config error
Browse files Browse the repository at this point in the history
  • Loading branch information
RayWangQvQ committed Mar 7, 2023
1 parent 7cbd2cf commit 420a0bc
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,5 @@
- Feature #460 : publish single file when release
- Feature: use new scripts for gh actions's release
- Feature #473 : let user input when there is no target task in configs
## 1.0.2
- Fix #484 : fix read dic config error
2 changes: 1 addition & 1 deletion common.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<Authors>Ray</Authors>
<Version>1.0.1</Version>
<Version>1.0.2</Version>
<NoWarn>$(NoWarn);CS1591;CS0436</NoWarn>
</PropertyGroup>
</Project>
13 changes: 11 additions & 2 deletions src/Ray.BiliBiliTool.Config/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Ray.BiliBiliTool.Config
{
Expand Down Expand Up @@ -33,13 +35,16 @@ public static class OptionsNames
/// <returns></returns>
public static Dictionary<string, string> GetExpDic()
{
return new Dictionary<string, string>()
var dic = new Dictionary<string, string>()
{
{"每日登录", "5"},
{"每日观看视频", "5"},
{"每日分享视频", "5"},
{"每日投币", "10"}
};
return dic.Select(x =>
new KeyValuePair<string, string>($"{OptionsNames.ExpDictionaryName}:{x.Key}", x.Value))
.ToDictionary(k => k.Key, v => v.Value);
}

/// <summary>
Expand All @@ -49,7 +54,7 @@ public static Dictionary<string, string> GetExpDic()
/// <returns></returns>
public static Dictionary<string, string> GetDonateCoinCanContinueStatusDic()
{
return new Dictionary<string, string>()
var dic = new Dictionary<string, string>()
{
{"0", "成功"},
{"-400", "请求错误"},
Expand All @@ -59,6 +64,10 @@ public static Dictionary<string, string> GetDonateCoinCanContinueStatusDic()
{"34004", "投币间隔太短"},
{"34005", "超过投币上限"}
};
return dic.Select(x =>
new KeyValuePair<string, string>($"{OptionsNames.DonateCoinCanContinueStatusDictionaryName}:{x.Key}", x.Value))
.ToDictionary(k => k.Key, v => v.Value)
;
}

public static Dictionary<string, string> GetCommandLineMappingsDic()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public static IServiceCollection AddBiliBiliConfigs(this IServiceCollection serv
.Configure<SecurityOptions>(configuration.GetSection("Security"))
.Configure<ReceiveVipPrivilegeOptions>(configuration.GetSection("ReceiveVipPrivilegeConfig"))
.Configure<LiveFansMedalTaskOptions>(configuration.GetSection("LiveFansMedalTaskOptions"))
.Configure<Dictionary<string, int>>(Constants.OptionsNames.ExpDictionaryName, configuration.GetSection("Exp"))
.Configure<Dictionary<string, string>>(Constants.OptionsNames.DonateCoinCanContinueStatusDictionaryName, configuration.GetSection("DonateCoinCanContinueStatus"));
.Configure<Dictionary<string, int>>(Constants.OptionsNames.ExpDictionaryName, configuration.GetSection(Constants.OptionsNames.ExpDictionaryName))
.Configure<Dictionary<string, string>>(Constants.OptionsNames.DonateCoinCanContinueStatusDictionaryName, configuration.GetSection(Constants.OptionsNames.DonateCoinCanContinueStatusDictionaryName));

return services;
}
Expand Down
5 changes: 2 additions & 3 deletions test/ConfigTest/TestDonateCoinStatusConfig.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using System;
using System.Text.Json;
using System.Diagnostics;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Ray.BiliBiliTool.Config;
using Ray.BiliBiliTool.Config.Options;
using Ray.BiliBiliTool.Console;
using Xunit;
using Ray.BiliBiliTool.Infrastructure;
using Microsoft.Extensions.Hosting;
using System.Collections.Generic;

namespace ConfigTest
Expand All @@ -29,6 +26,8 @@ public void Test1()
var dic = options.Get(Constants.OptionsNames.DonateCoinCanContinueStatusDictionaryName);

Debug.WriteLine(dic.ToJson());

Assert.True(dic.Count > 0);
}
}
}
9 changes: 4 additions & 5 deletions test/ConfigTest/TestExpConfig.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using System;
using System.Text.Json;
using System.Diagnostics;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Ray.BiliBiliTool.Config;
using Ray.BiliBiliTool.Config.Options;
using Ray.BiliBiliTool.Console;
using Xunit;
using Ray.BiliBiliTool.Infrastructure;
using Microsoft.Extensions.Hosting;
using System.Collections.Generic;

namespace ConfigTest
Expand All @@ -25,10 +22,12 @@ public void Test1()
{
using var scope = Global.ServiceProviderRoot.CreateScope();

var options = scope.ServiceProvider.GetRequiredService<IOptionsMonitor<Dictionary<string, string>>>();
var dic = options.Get("exp");
var options = scope.ServiceProvider.GetRequiredService<IOptionsMonitor<Dictionary<string, int>>>();
var dic = options.Get(Constants.OptionsNames.ExpDictionaryName);

Debug.WriteLine(dic.ToJson());

Assert.True(dic.Count > 0);
}
}
}

0 comments on commit 420a0bc

Please sign in to comment.