Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
romankr committed Dec 9, 2023
1 parent 031a7a9 commit 06bb34e
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void Constructor_WithNullLogger_ThrowsException()
[Test]
public async Task Run_WithValidParameters_ReturnsEventResults()
{
IEnumerable<EventResult> expectedEventResults = [];
IEnumerable<EventResult> expectedEventResults = new List<EventResult>();

var loggerStub = Substitute.For<ILogger<EventResultsFunction>>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public async Task Run_WithServiceBusMessage_ReturnsEventPrediction()
.SetTimestamp(DateTime.Now)
.SetWinner("Manchester City").Instance;

ServiceBusReceivedMessage[] receivedmessages =
ServiceBusReceivedMessage[] receivedMessages =
[ServiceBusReceivedMessageFactory.CreateFromObject(upcomingEvent)];

var actionsMock = Substitute.For<ServiceBusMessageActions>();
Expand All @@ -88,12 +88,12 @@ public async Task Run_WithServiceBusMessage_ReturnsEventPrediction()

var token = new CancellationToken();

var prediction = await function.Run(receivedmessages, actionsMock, token).ConfigureAwait(false);
var prediction = await function.Run(receivedMessages, actionsMock, token).ConfigureAwait(false);

prediction.Should().NotBeNull().And.HaveCount(1);
prediction[0].Should().NotBeNull().And.Be(expectedPrediction);

await actionsMock.Received(Quantity.Exactly(1)).CompleteMessageAsync(receivedmessages[0], token);
await actionsMock.Received(Quantity.Exactly(1)).CompleteMessageAsync(receivedMessages[0], token);
}

[Test]
Expand Down Expand Up @@ -134,7 +134,7 @@ public async Task Run_WithInvalidItems_ReturnsSucessfuallyProcessedEventPredicti
.SetTimestamp(DateTime.Now)
.SetWinner("Manchester City").Instance;

ServiceBusReceivedMessage[] receivedmessages =
ServiceBusReceivedMessage[] receivedMessages =
[
ServiceBusReceivedMessageFactory.CreateFromObject(badUpcomingEvent),
ServiceBusReceivedMessageFactory.CreateFromObject(goodUpcomingEvent)
Expand All @@ -146,18 +146,18 @@ public async Task Run_WithInvalidItems_ReturnsSucessfuallyProcessedEventPredicti

var strategyStub = Substitute.For<IPredictionStrategy>();
strategyStub.GetPrediction(Arg.Any<UpcomingEvent>(), Arg.Any<DateTime>())
.Returns(x => { throw exception; }, x => expectedPrediction);
.Returns(x => throw exception, x => expectedPrediction);

var function = new PredictionFunction(loggerMock, strategyStub);

var token = new CancellationToken();

var prediction = await function.Run(receivedmessages, actionsMock, token).ConfigureAwait(false);
var prediction = await function.Run(receivedMessages, actionsMock, token).ConfigureAwait(false);

prediction.Should().NotBeNull().And.HaveCount(1);
prediction[0].Should().NotBeNull().And.Be(expectedPrediction);

await actionsMock.Received(Quantity.Exactly(1)).CompleteMessageAsync(receivedmessages[1], token);
await actionsMock.Received(Quantity.Exactly(1)).CompleteMessageAsync(receivedMessages[1], token);

var receivedCalls = loggerMock.ReceivedCalls().ToList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void Constructor_WithNullOddsClient_ThrowsException()
[Test]
public async Task Run_WithValidParameters_ReturnsEventResults()
{
IEnumerable<UpcomingEvent> expectedEventResults = [];
IEnumerable<UpcomingEvent> expectedEventResults = new List<UpcomingEvent>();

var loggerStub = Substitute.For<ILogger<UpcomingEventsFunction>>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal sealed class OddsApiOptionsTests
[Test]
public void SetLeagues_WithValidLeague_ReturnsThisLeague()
{
string league = nameof(league);
const string league = nameof(league);

var options = new OddsApiClientOptions();
options.AddLeagues(league);
Expand All @@ -20,7 +20,7 @@ public void SetLeagues_WithValidLeague_ReturnsThisLeague()
[Test]
public void SetLeagues_WithValidLeagues_ReturnsTheseLeagues()
{
var leagues = "league1;league2";
const string leagues = "league1;league2";

var options = new OddsApiClientOptions();
options.AddLeagues(leagues);
Expand All @@ -33,7 +33,7 @@ public void SetLeagues_WithValidLeagues_ReturnsTheseLeagues()
[Test]
public void SetLeagues_WithOneEmptyLeague_ReturnsNonEmptyLeagues()
{
var leagues = "league1;;league2";
const string leagues = "league1;;league2";

var options = new OddsApiClientOptions();
options.AddLeagues(leagues);
Expand All @@ -46,7 +46,7 @@ public void SetLeagues_WithOneEmptyLeague_ReturnsNonEmptyLeagues()
[Test]
public void SetLeagues_WithDuplicatedLeagues_ReturnsNewInstance()
{
var leagues = "league1;league1";
const string leagues = "league1;league1";

var options = new OddsApiClientOptions();
options.AddLeagues(leagues);
Expand All @@ -71,7 +71,7 @@ public void SetLeagues_WithNullOrEmptyLeagues_ThrowsException(string? leaguesStr
[Test]
public void SetApiKey_WithValidKey_ReturnsThisKey()
{
string key = nameof(key);
const string key = nameof(key);

var options = new OddsApiClientOptions();
options.SetApiKey(key);
Expand Down
3 changes: 2 additions & 1 deletion OddsCollector.Functions/Functions/EventResultsFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ internal class EventResultsFunction(ILogger<EventResultsFunction>? logger, IOdds
[Function(nameof(EventResultsFunction))]
[CosmosDBOutput("%CosmosDb:Database%", "%CosmosDb:EventResultsContainer%", Connection = "CosmosDb:Connection")]
public async Task<EventResult[]> Run(
[TimerTrigger("%EventResultsFunction:TimerInterval%")] CancellationToken cancellationToken)
[TimerTrigger("%EventResultsFunction:TimerInterval%")]
CancellationToken cancellationToken)
{
try
{
Expand Down
10 changes: 5 additions & 5 deletions OddsCollector.Functions/Functions/PredictionFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ internal class PredictionFunction(ILogger<PredictionFunction>? logger, IPredicti
[CosmosDBOutput("%CosmosDb:Database%", "%CosmosDb:EventPredictionsContainer%", Connection = "CosmosDb:Connection")]
public async Task<EventPrediction[]> Run(
[ServiceBusTrigger("%ServiceBus:Queue%", Connection = "ServiceBus:Connection", IsBatched = true)]
ServiceBusReceivedMessage[] messages, ServiceBusMessageActions messageActions,
IEnumerable<ServiceBusReceivedMessage> messages, ServiceBusMessageActions messageActions,
CancellationToken cancellationToken)
{
List<EventPrediction> predictions = [];

for (var i = 0; i < messages.Length; i++)
foreach (var message in messages)
{
try
{
var upcomingEvent = messages[i].Body.ToObjectFromJson<UpcomingEvent>();
var upcomingEvent = message.Body.ToObjectFromJson<UpcomingEvent>();

predictions.Add(_strategy.GetPrediction(upcomingEvent, DateTime.UtcNow));

await messageActions.CompleteMessageAsync(messages[i], cancellationToken).ConfigureAwait(false);
await messageActions.CompleteMessageAsync(message, cancellationToken).ConfigureAwait(false);
}
catch (Exception exception)
{
_logger.LogError(exception, "Failed to convert message with id {Id}", messages[i].MessageId);
_logger.LogError(exception, "Failed to convert message with id {Id}", message.MessageId);
}
}

Expand Down
8 changes: 4 additions & 4 deletions OddsCollector.Functions/Functions/PredictionsHttpFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace OddsCollector.Functions.Functions;

internal class PredictionsHttpFunction(ILogger<PredictionsHttpFunction> logger)
{
private static readonly JsonSerializerOptions _serializerOptions = new() { WriteIndented = true };
private static readonly JsonSerializerOptions SerializerOptions = new() { WriteIndented = true };

private readonly ILogger<PredictionsHttpFunction> _logger =
logger ?? throw new ArgumentNullException(nameof(logger));
Expand All @@ -26,7 +26,7 @@ public HttpResponseData Run(
Id = "id",
PartitionKey = "id",
SqlQuery = "SELECT * FROM EventPredictions p WHERE p.CommenceTime > GetCurrentDateTime()")]
EventPrediction[] predictions, CosmosClient client, Database database, Container container)
IEnumerable<EventPrediction> predictions, CosmosClient client, Database database, Container container)
{
try
{
Expand All @@ -35,7 +35,7 @@ public HttpResponseData Run(
var grouped = predictions.GroupBy(p => p.Id)
.Select(group => group.OrderByDescending(p => p.Timestamp).First()).ToList();

var serialized = JsonSerializer.Serialize(grouped, _serializerOptions);
var serialized = JsonSerializer.Serialize(grouped, SerializerOptions);

var response = request.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
Expand All @@ -45,7 +45,7 @@ public HttpResponseData Run(
}
catch (Exception exception)
{
var message = "Failed to return predictions";
const string message = "Failed to return predictions";

_logger.LogError(exception, message);

Expand Down
3 changes: 2 additions & 1 deletion OddsCollector.Functions/Functions/UpcomingEventsFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ private readonly ILogger<UpcomingEventsFunction>
[Function(nameof(UpcomingEventsFunction))]
[ServiceBusOutput("%ServiceBus:Queue%", Connection = "ServiceBus:Connection")]
public async Task<UpcomingEvent[]> Run(
[TimerTrigger("%UpcomingEventsFunction:TimerInterval%")] CancellationToken cancellationToken)
[TimerTrigger("%UpcomingEventsFunction:TimerInterval%")]
CancellationToken cancellationToken)
{
try
{
Expand Down

0 comments on commit 06bb34e

Please sign in to comment.