Skip to content

Commit

Permalink
next batch of unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
romankr committed Nov 26, 2023
1 parent 47d194c commit cb091a0
Show file tree
Hide file tree
Showing 31 changed files with 1,393 additions and 284 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using FluentAssertions;
using OddsCollector.Common.OddsApi.Configuration;

namespace OddsCollector.Common.Tests.OddsApi.Configuration;

internal sealed class OddsApiOptionsFactoryTests
{
[Test]
public void CreateOddsApiOptions_WithValidLeague_ReturnsNewInstance()
{
string league = nameof(league);

var options = OddsApiOptionsFactory.CreateOddsApiOptions(league);

options.Should().NotBeNull();
options.Leagues.Should().NotBeNull().And.HaveCount(1);
options.Leagues.ElementAt(0).Should().NotBeNull().And.Be(league);
}

[Test]
public void CreateOddsApiOptions_WithValidLeagues_ReturnsNewInstance()
{
var leagues = "league1;league2";

var options = OddsApiOptionsFactory.CreateOddsApiOptions(leagues);

options.Should().NotBeNull();
options.Leagues.Should().NotBeNull().And.HaveCount(2);
options.Leagues.ElementAt(0).Should().NotBeNull().And.Be("league1");
options.Leagues.ElementAt(1).Should().NotBeNull().And.Be("league2");
}

[Test]
public void CreateOddsApiOptions_WithDuplicatedLeagues_ReturnsNewInstance()
{
var leagues = "league1;league1";

var options = OddsApiOptionsFactory.CreateOddsApiOptions(leagues);

options.Should().NotBeNull();
options.Leagues.Should().NotBeNull().And.HaveCount(1);
options.Leagues.ElementAt(0).Should().NotBeNull().And.Be("league1");
}

[TestCase("")]
[TestCase(null)]
public void CreateOddsApiOptions_WithNullOrEmptyLeagues_ThrowsException(string? leagues)
{
var action = () =>
{
_ = OddsApiOptionsFactory.CreateOddsApiOptions(leagues);
};

action.Should().Throw<ArgumentException>().WithParameterName(nameof(leagues));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace OddsCollector.Common.Tests.OddsApi.Converter;

internal class RawUpcomingEventBuilder
internal class Anonymous2Builder
{
public const string DefaultAwayTeam = "Liverpool";
public const string DefaultHomeTeam = "Manchester City";
Expand Down Expand Up @@ -47,59 +47,51 @@ internal class RawUpcomingEventBuilder
}
};

private Anonymous2 _state = new();
private readonly Anonymous2 _state = new();

public RawUpcomingEventBuilder SetDefaults()
public Anonymous2Builder SetDefaults()
{
_state = new Anonymous2
{
Away_team = DefaultAwayTeam,
Commence_time = DefaultCommenceTime,
Home_team = DefaultHomeTeam,
Id = DefaultId,
Bookmakers = DefaultBookmakers
};

return this;
return SetAwayTeam(DefaultAwayTeam)
.SetCommenceTime(DefaultCommenceTime)
.SetHomeTeam(DefaultHomeTeam)
.SetId(DefaultId)
.SetBookmakers(DefaultBookmakers);
}

public RawUpcomingEventBuilder SetAwayTeam(string? awayTeam)
public Anonymous2Builder SetAwayTeam(string? awayTeam)
{
_state.Away_team = awayTeam;

return this;
}

public RawUpcomingEventBuilder SetHomeTeam(string? homeTeam)
public Anonymous2Builder SetHomeTeam(string? homeTeam)
{
_state.Home_team = homeTeam;

return this;
}

public RawUpcomingEventBuilder SetId(string id)
public Anonymous2Builder SetId(string id)
{
_state.Id = id;

return this;
}

public RawUpcomingEventBuilder SetCommenceTime(DateTime commenceTime)
public Anonymous2Builder SetCommenceTime(DateTime commenceTime)
{
_state.Commence_time = commenceTime;

return this;
}

public RawUpcomingEventBuilder SetBookmakers(ICollection<Bookmakers>? bookmakers)
public Anonymous2Builder SetBookmakers(ICollection<Bookmakers>? bookmakers)
{
_state.Bookmakers = bookmakers;

return this;
}

public Anonymous2 GetRawUpcomingEvent()
{
return _state;
}
public Anonymous2 Instance => _state;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace OddsCollector.Common.Tests.OddsApi.Converter;

internal sealed class RawEventResultBuilder
internal sealed class Anonymous3Builder
{
public const string DefaultAwayTeam = "Liverpool";
public const bool DefaultCompleted = true;
Expand All @@ -15,67 +15,59 @@ internal sealed class RawEventResultBuilder
new() { Name = "Manchester City", Score = "1" }, new() { Name = "Liverpool", Score = "0" }
};

private Anonymous3 _state = new();
private readonly Anonymous3 _state = new();

public RawEventResultBuilder SetDefaults()
public Anonymous3Builder SetDefaults()
{
_state = new Anonymous3
{
Away_team = DefaultAwayTeam,
Completed = DefaultCompleted,
Home_team = DefaultHomeTeam,
Id = DefaultId,
Commence_time = DefaultCommenceTime,
Scores = DefaultScores
};

return this;
return SetId(DefaultId)
.SetAwayTeam(DefaultAwayTeam)
.SetCompleted(DefaultCompleted)
.SetHomeTeam(DefaultHomeTeam)
.SetCommenceTime(DefaultCommenceTime)
.SetScores(DefaultScores);
}

public RawEventResultBuilder SetAwayTeam(string? awayTeam)
public Anonymous3Builder SetAwayTeam(string? awayTeam)
{
_state.Away_team = awayTeam;

return this;
}

public RawEventResultBuilder SetCompleted(bool? completed)
public Anonymous3Builder SetCompleted(bool? completed)
{
_state.Completed = completed;

return this;
}

public RawEventResultBuilder SetHomeTeam(string? homeTeam)
public Anonymous3Builder SetHomeTeam(string? homeTeam)
{
_state.Home_team = homeTeam;

return this;
}

public RawEventResultBuilder SetId(string id)
public Anonymous3Builder SetId(string id)
{
_state.Id = id;

return this;
}

public RawEventResultBuilder SetCommenceTime(DateTime commenceTime)
public Anonymous3Builder SetCommenceTime(DateTime commenceTime)
{
_state.Commence_time = commenceTime;

return this;
}

public RawEventResultBuilder SetScores(ICollection<ScoreModel>? scores)
public Anonymous3Builder SetScores(ICollection<ScoreModel>? scores)
{
_state.Scores = scores;

return this;
}

public Anonymous3 GetRawEventResult()
{
return _state;
}
public Anonymous3 Instance => _state;
}
Loading

0 comments on commit cb091a0

Please sign in to comment.