-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decompose AdjustedConsensusPredictionStrategy (#63)
- Loading branch information
Showing
35 changed files
with
553 additions
and
338 deletions.
There are no files selected for viewing
20 changes: 0 additions & 20 deletions
20
OddsCollector.Functions.Tests/Infrastructure/Data/EventPredictionBuilderExtensions.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
OddsCollector.Functions.Tests/Tests/Models/EventPredictionBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
namespace OddsCollector.Functions.Tests.Tests.Models; | ||
|
||
internal class EventPredictionBuilder | ||
{ | ||
[TestCase("", TestName = "SetId_WithEmptyString_ThrowsException")] | ||
[TestCase(null, TestName = "SetId_WithNullString_ThrowsException")] | ||
public void SetId_WithNullOrEmptyString_ThrowsException(string? id) | ||
{ | ||
var builder = new OddsCollector.Functions.Models.EventPredictionBuilder(); | ||
|
||
var action = () => builder.SetId(id); | ||
|
||
action.Should().Throw<ArgumentException>().WithParameterName(nameof(id)); | ||
} | ||
|
||
[TestCase("", TestName = "SetAwayTeam_WithEmptyString_ThrowsException")] | ||
[TestCase(null, TestName = "SetAwayTeam_WithNullString_ThrowsException")] | ||
public void SetAwayTeam_WithNullOrEmptyString_ThrowsException(string? awayTeam) | ||
{ | ||
var builder = new OddsCollector.Functions.Models.EventPredictionBuilder(); | ||
|
||
var action = () => builder.SetAwayTeam(awayTeam); | ||
|
||
action.Should().Throw<ArgumentException>().WithParameterName(nameof(awayTeam)); | ||
} | ||
|
||
[TestCase("", TestName = "SetHomeTeam_WithEmptyString_ThrowsException")] | ||
[TestCase(null, TestName = "SetHomeTeam_WithNullString_ThrowsException")] | ||
public void SetHomeTeam_WithNullOrEmptyString_ThrowsException(string? homeTeam) | ||
{ | ||
var builder = new OddsCollector.Functions.Models.EventPredictionBuilder(); | ||
|
||
var action = () => builder.SetHomeTeam(homeTeam); | ||
|
||
action.Should().Throw<ArgumentException>().WithParameterName(nameof(homeTeam)); | ||
} | ||
|
||
[TestCase("", TestName = "SetWinner_WithEmptyString_ThrowsException")] | ||
[TestCase(null, TestName = "SetWinner_WithNullString_ThrowsException")] | ||
public void SetWinner_WithNullOrEmptyString_ThrowsException(string? winner) | ||
{ | ||
var builder = new OddsCollector.Functions.Models.EventPredictionBuilder(); | ||
|
||
var action = () => builder.SetWinner(winner); | ||
|
||
action.Should().Throw<ArgumentException>().WithParameterName(nameof(winner)); | ||
} | ||
|
||
[Test] | ||
public void SetCommenceTime_WithNullDateTime_ThrowsException() | ||
{ | ||
var builder = new OddsCollector.Functions.Models.EventPredictionBuilder(); | ||
|
||
var action = () => builder.SetCommenceTime(null); | ||
|
||
action.Should().Throw<ArgumentException>().WithParameterName("commenceTime"); | ||
} | ||
|
||
[Test] | ||
public void SetTimestamp_WithNullDateTime_ThrowsException() | ||
{ | ||
var builder = new OddsCollector.Functions.Models.EventPredictionBuilder(); | ||
|
||
var action = () => builder.SetTimestamp(null); | ||
|
||
action.Should().Throw<ArgumentException>().WithParameterName("timestamp"); | ||
} | ||
|
||
[Test] | ||
public void SetTraceId_WithNullGuid_ThrowsException() | ||
{ | ||
var builder = new OddsCollector.Functions.Models.EventPredictionBuilder(); | ||
|
||
var action = () => builder.SetTraceId(null); | ||
|
||
action.Should().Throw<ArgumentException>().WithParameterName("traceId"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
OddsCollector.Functions.Tests/Tests/Predictions/Configuration/ServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using OddsCollector.Functions.Predictions; | ||
using OddsCollector.Functions.Predictions.Configuration; | ||
|
||
namespace OddsCollector.Functions.Tests.Tests.Predictions.Configuration; | ||
|
||
internal class ServiceCollectionExtensions | ||
{ | ||
[Test] | ||
public void AddPredictionStrategy_AddsPredictionStrategy() | ||
{ | ||
var services = new ServiceCollection(); | ||
|
||
services.AddPredictionStrategy(); | ||
|
||
var descriptor = | ||
services.FirstOrDefault( | ||
x => x.ServiceType == typeof(IPredictionStrategy) | ||
&& x.ImplementationType == typeof(OddsCollector.Functions.Predictions.PredictionStrategy) | ||
&& x.Lifetime == ServiceLifetime.Singleton); | ||
|
||
descriptor.Should().NotBeNull(); | ||
} | ||
|
||
[Test] | ||
public void AddPredictionStrategy_AddsWinnerFinder() | ||
{ | ||
var services = new ServiceCollection(); | ||
|
||
services.AddPredictionStrategy(); | ||
|
||
var strategyDescriptor = | ||
services.FirstOrDefault( | ||
x => x.ServiceType == typeof(IWinnerFinder) | ||
&& x.ImplementationType == typeof(OddsCollector.Functions.Predictions.WinnerFinder) | ||
&& x.Lifetime == ServiceLifetime.Singleton); | ||
|
||
strategyDescriptor.Should().NotBeNull(); | ||
} | ||
|
||
[Test] | ||
public void AddPredictionStrategy_AddsScoreCalculator() | ||
{ | ||
var services = new ServiceCollection(); | ||
|
||
services.AddPredictionStrategy(); | ||
|
||
var strategyDescriptor = | ||
services.FirstOrDefault( | ||
x => x.ServiceType == typeof(IScoreCalculator) | ||
&& x.ImplementationType == typeof(OddsCollector.Functions.Predictions.ScoreCalculator) | ||
&& x.Lifetime == ServiceLifetime.Singleton); | ||
|
||
strategyDescriptor.Should().NotBeNull(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
OddsCollector.Functions.Tests/Tests/Predictions/OutcomeScoreBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace OddsCollector.Functions.Tests.Tests.Predictions; | ||
|
||
internal class OutcomeScoreBuilder | ||
{ | ||
[TestCase("", TestName = "SetScore_WithEmptyString_ThrowsException")] | ||
[TestCase(null, TestName = "SetScore_WithNullString_ThrowsException")] | ||
public void SetScore_WithNullOrEmptyString_ThrowsException(string? outcome) | ||
{ | ||
var builder = new OddsCollector.Functions.Predictions.OutcomeScoreBuilder(); | ||
|
||
var action = () => builder.SetOutcome(outcome); | ||
|
||
action.Should().Throw<ArgumentException>().WithParameterName(nameof(outcome)); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
OddsCollector.Functions.Tests/Tests/Predictions/PredictionStrategy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using FluentAssertions.Execution; | ||
using OddsCollector.Functions.Models; | ||
using OddsCollector.Functions.Predictions; | ||
|
||
namespace OddsCollector.Functions.Tests.Tests.Predictions; | ||
|
||
internal class PredictionStrategy | ||
{ | ||
[Test] | ||
public void GetPrediction_WithUpcomingEvent_ReturnsPrediction() | ||
{ | ||
// Arrange | ||
var expectedDateTime = DateTime.UtcNow; | ||
var expectedAwayTeam = "Liverpool"; | ||
var expectedHomeTeam = "Manchester City"; | ||
var expectedCommenceTime = new DateTime(2023, 11, 25, 12, 30, 0); | ||
var expectedId = Guid.NewGuid().ToString(); | ||
var expectedTraceId = Guid.NewGuid(); | ||
|
||
var upcomingEvent = new UpcomingEvent() | ||
{ | ||
AwayTeam = expectedAwayTeam, | ||
CommenceTime = expectedCommenceTime, | ||
HomeTeam = expectedHomeTeam, | ||
Id = expectedId, | ||
TraceId = expectedTraceId | ||
}; | ||
|
||
var finderStub = Substitute.For<IWinnerFinder>(); | ||
finderStub.GetWinner(Arg.Any<ICollection<Odd>>()).Returns(expectedHomeTeam); | ||
|
||
var strategy = new OddsCollector.Functions.Predictions.PredictionStrategy(finderStub); | ||
|
||
// Act | ||
var prediction = strategy.GetPrediction(upcomingEvent, expectedDateTime); | ||
|
||
// Assert | ||
prediction.Should().NotBeNull(); | ||
|
||
using (var scope = new AssertionScope()) | ||
{ | ||
prediction.AwayTeam.Should().NotBeNullOrEmpty().And.Be(expectedAwayTeam); | ||
prediction.HomeTeam.Should().NotBeNullOrEmpty().And.Be(expectedHomeTeam); | ||
prediction.CommenceTime.Should().Be(expectedCommenceTime); | ||
prediction.Id.Should().NotBeNullOrEmpty().And.Be(expectedId); | ||
prediction.TraceId.Should().Be(expectedTraceId); | ||
prediction.Winner.Should().Be(expectedHomeTeam); | ||
prediction.Timestamp.Should().BeCloseTo(DateTime.UtcNow, new TimeSpan(0, 0, 5)); | ||
} | ||
} | ||
|
||
[Test] | ||
public void GetPrediction_WithNullUpcomingEvent_ThrowsException() | ||
{ | ||
var finderStub = Substitute.For<IWinnerFinder>(); | ||
|
||
var strategy = new OddsCollector.Functions.Predictions.PredictionStrategy(finderStub); | ||
|
||
var action = () => strategy.GetPrediction(null, DateTime.Now); | ||
|
||
action.Should().ThrowExactly<ArgumentNullException>().WithParameterName("upcomingEvent"); | ||
} | ||
|
||
[Test] | ||
public void GetPrediction_WithNullTimestamp_ThrowsException() | ||
{ | ||
var finderStub = Substitute.For<IWinnerFinder>(); | ||
|
||
var strategy = new OddsCollector.Functions.Predictions.PredictionStrategy(finderStub); | ||
|
||
var action = () => strategy.GetPrediction(new UpcomingEvent(), null); | ||
|
||
action.Should().ThrowExactly<ArgumentNullException>().WithParameterName("timestamp"); | ||
} | ||
} |
Oops, something went wrong.