Skip to content

Commit

Permalink
Seasons (#46)
Browse files Browse the repository at this point in the history
* Added seasons

* Version bump
  • Loading branch information
mroloux authored Feb 1, 2022
1 parent 636129c commit 449be03
Show file tree
Hide file tree
Showing 16 changed files with 512 additions and 15 deletions.
20 changes: 20 additions & 0 deletions SeatsioDotNet.Test/Seasons/AddEventsToPartialSeasonTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Linq;
using Xunit;

namespace SeatsioDotNet.Test.Seasons
{
public class AddEventsToPartialSeasonTest : SeatsioClientTest
{
[Fact]
public void Test()
{
var chartKey = CreateTestChart();
var topLevelSeason = Client.Seasons.Create(chartKey, eventKeys: new[] {"event1", "event2"});
var partialSeason = Client.Seasons.CreatePartialSeason(topLevelSeason.Key, partialSeasonKey: "aPartialSeason");

var updatedPartialSeason = Client.Seasons.AddEventsToPartialSeason(topLevelSeason.Key, partialSeason.Key, new[] {"event1", "event2"});

Assert.Equal(new[] {"event1", "event2"}, updatedPartialSeason.Events.Select(e => e.Key));
}
}
}
30 changes: 30 additions & 0 deletions SeatsioDotNet.Test/Seasons/CreateEventsInSeasonTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Linq;
using Xunit;

namespace SeatsioDotNet.Test.Seasons
{
public class CreateEventsInSeasonTest : SeatsioClientTest
{
[Fact]
public void EventsKeysCanBePassedIn()
{
var chartKey = CreateTestChart();
var season = Client.Seasons.Create(chartKey);

var updatedSeason = Client.Seasons.CreateEvents(season.Key, eventKeys: new[] {"event1", "event2"});

Assert.Equal(new[] {"event1", "event2"}, updatedSeason.Events.Select(e => e.Key));
}

[Fact]
public void NumberOfEventsCanBePassedIn()
{
var chartKey = CreateTestChart();
var season = Client.Seasons.Create(chartKey);

var updatedSeason = Client.Seasons.CreateEvents(season.Key, numberOfEvents: 2);

Assert.Equal(2, updatedSeason.Events.Count);
}
}
}
30 changes: 30 additions & 0 deletions SeatsioDotNet.Test/Seasons/CreatePartialSeasonTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Linq;
using Xunit;

namespace SeatsioDotNet.Test.Seasons
{
public class CreatePartialSeasonTest : SeatsioClientTest
{
[Fact]
public void KeyCanBePassedIn()
{
var chartKey = CreateTestChart();
var topLevelSeason = Client.Seasons.Create(chartKey);

var partialSeason = Client.Seasons.CreatePartialSeason(topLevelSeason.Key, partialSeasonKey: "aPartialSeason");

Assert.Equal("aPartialSeason", partialSeason.Key);
}

[Fact]
public void EventKeysCanBePassedIn()
{
var chartKey = CreateTestChart();
var topLevelSeason = Client.Seasons.Create(chartKey, eventKeys: new[] {"event1", "event2"});

var partialSeason = Client.Seasons.CreatePartialSeason(topLevelSeason.Key, eventKeys: new[] {"event1", "event2"});

Assert.Equal(new[] {"event1", "event2"}, partialSeason.Events.Select(e => e.Key));
}
}
}
90 changes: 90 additions & 0 deletions SeatsioDotNet.Test/Seasons/CreateSeasonTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SeatsioDotNet.Charts;
using SeatsioDotNet.Events;
using Xunit;

namespace SeatsioDotNet.Test.Seasons
{
public class CreateSeasonTest : SeatsioClientTest
{
[Fact]
public void ChartKeyIsMandatory()
{
var chartKey = CreateTestChart();

var season = Client.Seasons.Create(chartKey);

Assert.NotNull(season.Key);
Assert.NotEqual(0, season.Id);
Assert.Empty(season.PartialSeasonKeys);
Assert.Empty(season.Events);

var seasonEvent = season.SeasonEvent;
Assert.Equal(season.Key, seasonEvent.Key);
Assert.NotEqual(0, seasonEvent.Id);
Assert.Equal(chartKey, seasonEvent.ChartKey);
Assert.Equal("INHERIT", seasonEvent.TableBookingConfig.Mode);
Assert.True(seasonEvent.SupportsBestAvailable);
Assert.Null(seasonEvent.ForSaleConfig);
CustomAssert.CloseTo(DateTimeOffset.Now, seasonEvent.CreatedOn.Value);
Assert.Null(seasonEvent.UpdatedOn);
}

[Fact]
public void KeyCanBePassedIn()
{
var chartKey = CreateTestChart();

var season = Client.Seasons.Create(chartKey, key: "aSeason");

Assert.Equal("aSeason", season.Key);
}

[Fact]
public void NumberOfEventsCanBePassedIn()
{
var chartKey = CreateTestChart();

var season = Client.Seasons.Create(chartKey, numberOfEvents: 2);

Assert.Equal(2, season.Events.Count);
}

[Fact]
public void EventKeysCanBePassedIn()
{
var chartKey = CreateTestChart();

var season = Client.Seasons.Create(chartKey, eventKeys: new[] {"event1", "event2"});

Assert.Equal(new[] {"event1", "event2"}, season.Events.Select(e => e.Key));
}

[Fact]
public void TableBookingConfigCanBePassedIn()
{
var chartKey = CreateTestChart();

var season = Client.Seasons.Create(chartKey, tableBookingConfig: TableBookingConfig.AllBySeat());

Assert.Equal(TableBookingConfig.AllBySeat().Mode, season.SeasonEvent.TableBookingConfig.Mode);
}

[Fact]
public void SocialDistancingRulesetKeyCanBePassedIn()
{
var chartKey = CreateTestChart();
var rulesets = new Dictionary<string, SocialDistancingRuleset>()
{
{ "ruleset1", SocialDistancingRuleset.RuleBased("My first ruleset").Build() },
};
Client.Charts.SaveSocialDistancingRulesets(chartKey, rulesets);

var season = Client.Seasons.Create(chartKey, socialDistancingRulesetKey: "ruleset1");

Assert.Equal("ruleset1", season.SeasonEvent.SocialDistancingRulesetKey);
}
}
}
19 changes: 19 additions & 0 deletions SeatsioDotNet.Test/Seasons/DeletePartialSeasonTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Xunit;

namespace SeatsioDotNet.Test.Seasons
{
public class DeletePartialSeasonTest : SeatsioClientTest
{
[Fact]
public void Test()
{
var chartKey = CreateTestChart();
var season = Client.Seasons.Create(chartKey);
var partialSeason = Client.Seasons.CreatePartialSeason(season.Key);

Client.Seasons.DeletePartialSeason(season.Key, partialSeason.Key);

Assert.Throws<SeatsioException>(() => Client.Seasons.RetrievePartialSeason(season.Key, partialSeason.Key));
}
}
}
18 changes: 18 additions & 0 deletions SeatsioDotNet.Test/Seasons/DeleteSeasonTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Xunit;

namespace SeatsioDotNet.Test.Seasons
{
public class DeleteSeasonTest : SeatsioClientTest
{
[Fact]
public void Test()
{
var chartKey = CreateTestChart();
var season = Client.Seasons.Create(chartKey);

Client.Seasons.Delete(season.Key);

Assert.Throws<SeatsioException>(() => Client.Seasons.Retrieve(season.Key));
}
}
}
21 changes: 21 additions & 0 deletions SeatsioDotNet.Test/Seasons/ListSeasonsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Linq;
using Xunit;

namespace SeatsioDotNet.Test.Seasons
{
public class ListSeasonsTest : SeatsioClientTest
{
[Fact]
public void Test()
{
var chartKey = CreateTestChart();
var season1 = Client.Seasons.Create(chartKey);
var season2 = Client.Seasons.Create(chartKey);
var season3 = Client.Seasons.Create(chartKey);

var seasons = Client.Seasons.ListAll();

Assert.Equal(new[] {season3.Key, season2.Key, season1.Key}, seasons.Select(s => s.Key));
}
}
}
20 changes: 20 additions & 0 deletions SeatsioDotNet.Test/Seasons/RemoveEventFromPartialSeasonTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Linq;
using Xunit;

namespace SeatsioDotNet.Test.Seasons
{
public class RemoveEventFromPartialSeasonTest : SeatsioClientTest
{
[Fact]
public void Test()
{
var chartKey = CreateTestChart();
var topLevelSeason = Client.Seasons.Create(chartKey, eventKeys: new[] {"event1", "event2"});
var partialSeason = Client.Seasons.CreatePartialSeason(topLevelSeason.Key, eventKeys: new[] {"event1", "event2"});

var updatedPartialSeason = Client.Seasons.RemoveEventFromPartialSeason(topLevelSeason.Key, partialSeason.Key, "event2");

Assert.Equal(new[] {"event1"}, updatedPartialSeason.Events.Select(e => e.Key));
}
}
}
32 changes: 32 additions & 0 deletions SeatsioDotNet.Test/Seasons/RetrievePartialSeasonTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using Xunit;

namespace SeatsioDotNet.Test.Seasons
{
public class RetrievePartialSeasonTest : SeatsioClientTest
{
[Fact]
public void Test()
{
var chartKey = CreateTestChart();

var season = Client.Seasons.Create(chartKey);
var partialSeason = Client.Seasons.CreatePartialSeason(season.Key);

var retrievedPartialSeason = Client.Seasons.RetrievePartialSeason(season.Key, partialSeason.Key);

Assert.NotNull(retrievedPartialSeason.Key);
Assert.NotEqual(0, retrievedPartialSeason.Id);

var seasonEvent = retrievedPartialSeason.SeasonEvent;
Assert.Equal(retrievedPartialSeason.Key, seasonEvent.Key);
Assert.NotEqual(0, seasonEvent.Id);
Assert.Equal(chartKey, seasonEvent.ChartKey);
Assert.Equal("INHERIT", seasonEvent.TableBookingConfig.Mode);
Assert.True(seasonEvent.SupportsBestAvailable);
Assert.Null(seasonEvent.ForSaleConfig);
CustomAssert.CloseTo(DateTimeOffset.Now, seasonEvent.CreatedOn.Value);
Assert.Null(seasonEvent.UpdatedOn);
}
}
}
35 changes: 35 additions & 0 deletions SeatsioDotNet.Test/Seasons/RetrieveSeasonTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using Xunit;

namespace SeatsioDotNet.Test.Seasons
{
public class RetrieveSeasonTest : SeatsioClientTest
{
[Fact]
public void Test()
{
var chartKey = CreateTestChart();

var season = Client.Seasons.Create(chartKey);
var partialSeason1 = Client.Seasons.CreatePartialSeason(season.Key);
var partialSeason2 = Client.Seasons.CreatePartialSeason(season.Key);

var retrievedSeason = Client.Seasons.Retrieve(season.Key);

Assert.NotNull(retrievedSeason.Key);
Assert.NotEqual(0, retrievedSeason.Id);
Assert.Equal(new[] {partialSeason1.Key, partialSeason2.Key}, retrievedSeason.PartialSeasonKeys);
Assert.Empty(retrievedSeason.Events);

var seasonEvent = retrievedSeason.SeasonEvent;
Assert.Equal(season.Key, seasonEvent.Key);
Assert.NotEqual(0, seasonEvent.Id);
Assert.Equal(chartKey, seasonEvent.ChartKey);
Assert.Equal("INHERIT", seasonEvent.TableBookingConfig.Mode);
Assert.True(seasonEvent.SupportsBestAvailable);
Assert.Null(seasonEvent.ForSaleConfig);
CustomAssert.CloseTo(DateTimeOffset.Now, seasonEvent.CreatedOn.Value);
Assert.Null(seasonEvent.UpdatedOn);
}
}
}
26 changes: 13 additions & 13 deletions SeatsioDotNet.Test/SeatsioDotNet.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PropertyGroup>
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<ProjectReference Include="..\SeatsioDotNet\SeatsioDotNet.csproj" />
<ProjectReference Include="..\SeatsioDotNet\SeatsioDotNet.csproj" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="RestSharp" Version="106.15.0" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
<ItemGroup>
<Content Include="resources\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
<ItemGroup>
<Content Include="resources\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion SeatsioDotNet/Events/Event.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using RestSharp.Deserializers;

namespace SeatsioDotNet.Events
{
Expand Down
14 changes: 14 additions & 0 deletions SeatsioDotNet/Seasons/Season.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using SeatsioDotNet.Events;

namespace SeatsioDotNet.Seasons
{
public class Season
{
public long Id { get; set; }
public string Key { get; set; }
public List<string> PartialSeasonKeys { get; set; }
public Event SeasonEvent { get; set; }
public List<Event> Events { get; set; }
}
}
Loading

0 comments on commit 449be03

Please sign in to comment.