Skip to content

Commit

Permalink
Refactor code and update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
omgitsjan committed Jan 19, 2024
1 parent cc4401e commit 7adec9d
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions DiscordBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Program
{
/// <summary>
/// This is the Discord token from the bot
/// </summary>
/// </summary>
private string? _discordToken;

/// <summary>
Expand All @@ -46,7 +46,7 @@ public class Program
/// <summary>
/// Init Program
/// </summary>
public static Task Main(string[] args)
public static Task Main()
{
return new Program().MainAsync();
}
Expand Down
2 changes: 1 addition & 1 deletion DiscordBot/Services/SlashCommandsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWith
Program.Log("Message: " + message);

if (success) {
DiscordEmbedBuilder embedMessage = new DiscordEmbedBuilder
DiscordEmbedBuilder embedMessage = new()
{
Title = $"{symbol} - {physicalCurrency} | ${message}",
Description = $"Price of {symbol} - {physicalCurrency} is ${message}",
Expand Down
2 changes: 1 addition & 1 deletion DiscordBot/SlashCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task CryptoSlashCommand(InteractionContext ctx,
[Option("PhysicalCurrency", "The physical currency to compare against, e.g., USDT")]
string physicalCurrency = "USDT")
{
InteractionContextWrapper context = new InteractionContextWrapper(ctx);
InteractionContextWrapper context = new(ctx);
await slashCommandsService.CryptoSlashCommandAsync(context, symbol, physicalCurrency);
}
}
Expand Down
16 changes: 8 additions & 8 deletions DiscordBotTests/ServiceTests/CryptoServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public void Setup()
public async Task GetCurrentCryptoPriceAsync_ReturnsCurrentPrice()
{
// Arrange
string symbol = "BTC";
string physicalCurrency = "USDT";
const string symbol = "BTC";
const string physicalCurrency = "USDT";
const string jsonResponse = "{\"result\": [{\"last_price\": \"50000\"}]}";
const string expectedPrice = "50000";
_mockHttpService.Setup(x => x.GetResponseFromUrl(It.IsAny<string>(), It.IsAny<Method>(), It.IsAny<string>(),
Expand All @@ -51,8 +51,8 @@ public async Task GetCurrentCryptoPriceAsync_ReturnsCurrentPrice()
public async Task GetCurrentCryptoPriceAsync_ApiError_ReturnsErrorMessage()
{
// Arrange
string symbol = "BTC";
string physicalCurrency = "USDT";
const string symbol = "BTC";
const string physicalCurrency = "USDT";
const string expectedErrorMessage = "API Error";
_mockHttpService.Setup(x => x.GetResponseFromUrl(It.IsAny<string>(), It.IsAny<Method>(), It.IsAny<string>(),
It.IsAny<List<KeyValuePair<string, string>>>(), It.IsAny<object>()))
Expand All @@ -70,8 +70,8 @@ public async Task GetCurrentCryptoPriceAsync_ApiError_ReturnsErrorMessage()
public async Task GetCurrentCryptoPriceAsync_InvalidJson_ReturnsFallbackMessage()
{
// Arrange
string symbol = "BTC";
string physicalCurrency = "USDT";
const string symbol = "BTC";
const string physicalCurrency = "USDT";
const string invalidJsonResponse = "Invalid JSON";
_mockHttpService.Setup(x => x.GetResponseFromUrl(It.IsAny<string>(), It.IsAny<Method>(), It.IsAny<string>(),
It.IsAny<List<KeyValuePair<string, string>>>(), It.IsAny<object>()))
Expand All @@ -89,8 +89,8 @@ public async Task GetCurrentCryptoPriceAsync_InvalidJson_ReturnsFallbackMessage(
public async Task GetCurrentCryptoPriceAsync_MissingLastPrice_ReturnsFallbackMessage()
{
// Arrange
string symbol = "BTC";
string physicalCurrency = "USDT";
const string symbol = "BTC";
const string physicalCurrency = "USDT";
const string jsonResponseMissingLastPrice = "{\"result\": [{}]}";
_mockHttpService.Setup(x => x.GetResponseFromUrl(It.IsAny<string>(), It.IsAny<Method>(), It.IsAny<string>(),
It.IsAny<List<KeyValuePair<string, string>>>(), It.IsAny<object>()))
Expand Down
4 changes: 2 additions & 2 deletions DiscordBotTests/ServiceTests/HttpServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public void SetUp()
_httpService = new HttpService(_mockRestClient.Object);
}

private Mock<IRestClient> _mockRestClient;
private IHttpService _httpService;
private Mock<IRestClient> _mockRestClient = null!;
private IHttpService _httpService = null!;

[Test]
public async Task GetResponseFromURL_WithValidResponse_ReturnsSuccess()
Expand Down
4 changes: 2 additions & 2 deletions DiscordBotTests/ServiceTests/OpenAiServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public void Setup()
_openAiService = new OpenAiService(_mockHttpService.Object, configuration);
}

private Mock<IHttpService> _mockHttpService;
private OpenAiService? _openAiService;
private Mock<IHttpService> _mockHttpService = null!;
private OpenAiService? _openAiService = null!;

[Test]
public async Task ChatGpt_WithValidApiKeyAndMessage_ReturnsSuccessAndResponse()
Expand Down
4 changes: 2 additions & 2 deletions DiscordBotTests/ServiceTests/OpenWeatherMapServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public void Setup()
_openWeatherMapService = new OpenWeatherMapService(_mockHttpService.Object, configuration);
}

private Mock<IHttpService> _mockHttpService;
private OpenWeatherMapService _openWeatherMapService;
private Mock<IHttpService> _mockHttpService = null!;
private OpenWeatherMapService _openWeatherMapService = null!;

[Test]
public void GetWeatherAsync_WithValidApiKeyAndCity_ReturnsSuccessAndWeatherData()
Expand Down
14 changes: 7 additions & 7 deletions DiscordBotTests/ServiceTests/SlashCommandsServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ namespace DiscordBotTests.ServiceTests;
[Ignore("This test is not yet implemented. Currently, I don't know exactly how to properly mock the DiscordUser & DiscordChannel.")]
public class SlashCommandsServiceTests
{
private Mock<IInteractionContextWrapper> _ctxMock;
private Mock<IOpenAiService> _openAiServiceMock;
private Mock<IOpenWeatherMapService> _openWeatherMapServiceMock;
private SlashCommandsService _slashCommandsService;
private Mock<IWatch2GetherService> _watch2GetherServiceMock;
private Mock<ICryptoService> _cryptoServiceMock;

private Mock<IInteractionContextWrapper> _ctxMock = null!;
private Mock<IOpenAiService> _openAiServiceMock = null!;
private Mock<IOpenWeatherMapService> _openWeatherMapServiceMock = null!;
private SlashCommandsService _slashCommandsService = null!;
private Mock<IWatch2GetherService> _watch2GetherServiceMock = null!;
private Mock<ICryptoService> _cryptoServiceMock = null!;
[SetUp]
public void Setup()
{
Expand Down
4 changes: 2 additions & 2 deletions DiscordBotTests/ServiceTests/Watch2GetherServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public void Setup()
_watch2GetherService = new Watch2GetherService(_mockHttpService.Object, configuration);
}

private Watch2GetherService _watch2GetherService;
private Mock<IHttpService> _mockHttpService;
private Watch2GetherService _watch2GetherService = null!;
private Mock<IHttpService> _mockHttpService = null!;

[Test]
public async Task CreateRoom_SuccessfulRequest_ReturnsSuccessAndRoomUrl()
Expand Down

0 comments on commit 7adec9d

Please sign in to comment.