Skip to content

Commit 84bb025

Browse files
author
Ruben Bisharyan
committed
Fix issue with faker config
1 parent 013b067 commit 84bb025

File tree

5 files changed

+117
-119
lines changed

5 files changed

+117
-119
lines changed

src/Communicator/Communicator.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
<PackageReadmeFile>Readme.md</PackageReadmeFile>
99
<Authors>Pandatech</Authors>
1010
<Copyright>MIT</Copyright>
11-
<Version>1.0.2</Version>
11+
<Version>1.0.3</Version>
1212
<PackageId>Pandatech.Communicator</PackageId>
1313
<Title>SMS and Email Communication helper</Title>
1414
<PackageTags>Pandatech, library, Sms, Email, Messages</PackageTags>
1515
<Description>A versatile .NET library for integrating SMS and email functionalities. Supports multiple SMS providers and easy configuration through appsettings.json or web builders, ideal for efficient and reliable messaging in any application..</Description>
1616
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-communicator</RepositoryUrl>
17+
<!--todo: to update this note-->
1718
<PackageReleaseNotes>InitialCommit - fake functionalities</PackageReleaseNotes>
1819
</PropertyGroup>
1920

src/Communicator/Helpers/CommunicatorConfigurator.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,14 @@ internal static class CommunicatorConfigurator
77
{
88
internal static CommunicatorOptions? ReadConfigurationOptions(IConfiguration configuration)
99
{
10-
try
11-
{
12-
var communicatorSection = configuration.GetSection("Communicator");
13-
14-
if (!communicatorSection.Exists()) return null;
15-
16-
var communicatorOptions = new CommunicatorOptions();
17-
18-
communicatorSection.Bind(communicatorOptions);
19-
20-
return communicatorOptions;
10+
var communicatorSection = configuration.GetSection("Communicator");
2111

22-
}
23-
catch (Exception exception)
24-
{
25-
throw new Exception(exception.Message);
26-
}
12+
if (!communicatorSection.Exists()) return null;
13+
14+
var communicatorOptions = new CommunicatorOptions();
15+
16+
communicatorSection.Bind(communicatorOptions);
17+
18+
return communicatorOptions;
2719
}
2820
}

src/Communicator/Helpers/OptionsValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal static void Validate(this CommunicatorOptions options)
2727

2828
var notSupportedChannels = emailConfigKeys?.Concat(smsConfigKeys ?? []).ToList();
2929

30-
if (notSupportedChannels?.Count != 0)
30+
if (notSupportedChannels is not null && notSupportedChannels.Count != 0)
3131
{
3232
throw new InvalidOperationException(
3333
$"There are unsupported Channels provided {string.Join(",", notSupportedChannels!)}.");

test/Communicator.Demo/Program.cs

Lines changed: 61 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -7,66 +7,67 @@
77

88
var builder = WebApplication.CreateBuilder(args);
99

10-
builder.AddCommunicator(options =>
11-
{
12-
options.SmsFake = false;
13-
options.SmsConfigurations = new Dictionary<string, SmsConfiguration>
14-
{
15-
{
16-
"GeneralSender", new SmsConfiguration
17-
{
18-
Provider = "Dexatel",
19-
From = "sender_name",
20-
Properties = new Dictionary<string, string>
21-
{
22-
{ "X-Dexatel-Key", "key" }
23-
},
24-
TimeoutMs = 10000
25-
}
26-
},
27-
{
28-
"TransactionalSender", new SmsConfiguration
29-
{
30-
Provider = "Twilio",
31-
From = "sender_number",
32-
Properties = new Dictionary<string, string>
33-
{
34-
{ "SID", "key" },
35-
{ "AUTH_TOKEN", "token" }
36-
},
37-
TimeoutMs = 10000
38-
}
39-
}
40-
};
41-
options.EmailFake = false;
42-
options.EmailConfigurations = new Dictionary<string, EmailConfiguration>
43-
{
44-
{
45-
"GeneralSender2", new EmailConfiguration
46-
{
47-
SmtpServer = "smtp.test.com",
48-
SmtpPort = 465, // 587
49-
SmtpUsername = "test",
50-
SmtpPassword = "test123",
51-
SenderEmail = "[email protected]",
52-
UseSsl = true, // false
53-
TimeoutMs = 10000
54-
}
55-
},
56-
{
57-
"TransactionalSender", new EmailConfiguration
58-
{
59-
SmtpServer = "smtp.gmail.com",
60-
SmtpPort = 465, // 587
61-
SmtpUsername = "vazgen",
62-
SmtpPassword = "vazgen123",
63-
SenderEmail = "[email protected]",
64-
UseSsl = true, // false
65-
TimeoutMs = 10000
66-
}
67-
}
68-
};
69-
});
10+
builder.AddCommunicator();
11+
// builder.AddCommunicator(options =>
12+
// {
13+
// options.SmsFake = false;
14+
// options.SmsConfigurations = new Dictionary<string, SmsConfiguration>
15+
// {
16+
// {
17+
// "GeneralSender", new SmsConfiguration
18+
// {
19+
// Provider = "Dexatel",
20+
// From = "sender_name",
21+
// Properties = new Dictionary<string, string>
22+
// {
23+
// { "X-Dexatel-Key", "key" }
24+
// },
25+
// TimeoutMs = 10000
26+
// }
27+
// },
28+
// {
29+
// "TransactionalSender", new SmsConfiguration
30+
// {
31+
// Provider = "Twilio",
32+
// From = "sender_number",
33+
// Properties = new Dictionary<string, string>
34+
// {
35+
// { "SID", "key" },
36+
// { "AUTH_TOKEN", "token" }
37+
// },
38+
// TimeoutMs = 10000
39+
// }
40+
// }
41+
// };
42+
// options.EmailFake = false;
43+
// options.EmailConfigurations = new Dictionary<string, EmailConfiguration>
44+
// {
45+
// {
46+
// "GeneralSender2", new EmailConfiguration
47+
// {
48+
// SmtpServer = "smtp.test.com",
49+
// SmtpPort = 465, // 587
50+
// SmtpUsername = "test",
51+
// SmtpPassword = "test123",
52+
// SenderEmail = "[email protected]",
53+
// UseSsl = true, // false
54+
// TimeoutMs = 10000
55+
// }
56+
// },
57+
// {
58+
// "TransactionalSender", new EmailConfiguration
59+
// {
60+
// SmtpServer = "smtp.gmail.com",
61+
// SmtpPort = 465, // 587
62+
// SmtpUsername = "vazgen",
63+
// SmtpPassword = "vazgen123",
64+
// SenderEmail = "[email protected]",
65+
// UseSsl = true, // false
66+
// TimeoutMs = 10000
67+
// }
68+
// }
69+
// };
70+
// });
7071

7172
builder.Services.AddEndpointsApiExplorer();
7273
builder.Services.AddSwaggerGen();

test/Communicator.Demo/appsettings.Development.json

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,50 @@
66
}
77
},
88
"Communicator": {
9-
"SmsFake": false,
10-
"SmsConfigurations": {
11-
"GeneralSender": {
12-
"Provider": "Dexatel",
13-
"From": "sender_name",
14-
"Properties": {
15-
"X-Dexatel-Key": "key"
16-
},
17-
"TimeoutMs": "10000"
18-
},
19-
"TransactionalSender": {
20-
"Provider": "Twilio",
21-
"From": "sender_number",
22-
"Properties": {
23-
"SID": "key",
24-
"AUTH_TOKEN": "token"
25-
},
26-
"TimeoutMs": "10000"
27-
}
28-
},
29-
"EmailFake": false,
30-
"EmailConfigurations": {
31-
"GeneralSender": {
32-
"SmtpServer": "smtp.gmail.com",
33-
"SmtpPort": 465, // 587
34-
"SmtpUsername": "vazgen",
35-
"SmtpPassword": "vazgen123",
36-
"SenderEmail": "[email protected]",
37-
"UseSsl": true, // false
38-
"TimeoutMs": "10000"
39-
},
40-
"TransactionalSender": {
41-
"SmtpServer": "smtp.gmail.com",
42-
"SmtpPort": 465, // 587
43-
"SmtpUsername": "vazgen",
44-
"SmtpPassword": "vazgen123",
45-
"SenderEmail": "[email protected]",
46-
"UseSsl": true, // false
47-
"TimeoutMs": "10000"
48-
}
49-
}
9+
"SmsFake": true,
10+
"EmailFake": true
5011
}
12+
// "Communicator": {
13+
// "SmsFake": false,
14+
// "SmsConfigurations": {
15+
// "GeneralSender": {
16+
// "Provider": "Dexatel",
17+
// "From": "sender_name",
18+
// "Properties": {
19+
// "X-Dexatel-Key": "key"
20+
// },
21+
// "TimeoutMs": "10000"
22+
// },
23+
// "TransactionalSender": {
24+
// "Provider": "Twilio",
25+
// "From": "sender_number",
26+
// "Properties": {
27+
// "SID": "key",
28+
// "AUTH_TOKEN": "token"
29+
// },
30+
// "TimeoutMs": "10000"
31+
// }
32+
// },
33+
// "EmailFake": false,
34+
// "EmailConfigurations": {
35+
// "GeneralSender": {
36+
// "SmtpServer": "smtp.gmail.com",
37+
// "SmtpPort": 465, // 587
38+
// "SmtpUsername": "vazgen",
39+
// "SmtpPassword": "vazgen123",
40+
// "SenderEmail": "[email protected]",
41+
// "UseSsl": true, // false
42+
// "TimeoutMs": "10000"
43+
// },
44+
// "TransactionalSender": {
45+
// "SmtpServer": "smtp.gmail.com",
46+
// "SmtpPort": 465, // 587
47+
// "SmtpUsername": "vazgen",
48+
// "SmtpPassword": "vazgen123",
49+
// "SenderEmail": "[email protected]",
50+
// "UseSsl": true, // false
51+
// "TimeoutMs": "10000"
52+
// }
53+
// }
54+
// }
5155
}

0 commit comments

Comments
 (0)