Skip to content

Commit

Permalink
Added disableDiagonalSeatsInFrontAndBehind to SocialDistancingRuleset…
Browse files Browse the repository at this point in the history
… + switched to builder pattern for creating rulesets
  • Loading branch information
mroloux committed Nov 13, 2020
1 parent d910b2f commit 449e222
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 119 deletions.
128 changes: 49 additions & 79 deletions SeatsioDotNet.Test/Charts/SaveSocialDistancingRulesetsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,94 +11,64 @@ public class SaveSocialDistancingRulesetsTest : SeatsioClientTest
public void SaveRulesets()
{
var chartKey = CreateTestChart();
var rulesets = new Dictionary<string, SocialDistancingRuleset>()
var ruleset1 = SocialDistancingRuleset.RuleBased("My first ruleset")
.WithIndex(0)
.WithNumberOfDisabledSeatsToTheSides(1)
.WithDisableSeatsInFrontAndBehind(true)
.WithDisableDiagonalSeatsInFrontAndBehind(true)
.WithNumberOfDisabledAisleSeats(2)
.WithMaxGroupSize(1)
.WithMaxOccupancyAbsolute(10)
.WithOneGroupPerTable(true)
.WithDisabledSeats(new List<string> {"A-1"})
.WithEnabledSeats(new List<string> {"A-2"})
.Build();

var ruleset2 = SocialDistancingRuleset.Fixed("My second ruleset")
.WithIndex(1)
.WithDisabledSeats(new List<string> {"A-1"})
.Build();

var rulesets = new Dictionary<string, SocialDistancingRuleset>
{
{"ruleset1", new SocialDistancingRuleset(0, "My first ruleset", 1, true, 2, 1, 10, 0, true, false, new List<string> {"A-1"}, new List<string> {"A-2"})},
{"ruleset2", new SocialDistancingRuleset(1, "My second ruleset")}
{"ruleset1", ruleset1},
{"ruleset2", ruleset2}
};

Client.Charts.SaveSocialDistancingRulesets(chartKey, rulesets);

var retrievedChart = Client.Charts.Retrieve(chartKey);
Assert.Equal(2, retrievedChart.SocialDistancingRulesets.Count);

var ruleset1 = retrievedChart.SocialDistancingRulesets["ruleset1"];
Assert.Equal(0, ruleset1.Index);
Assert.Equal("My first ruleset", ruleset1.Name);
Assert.Equal(1, ruleset1.NumberOfDisabledSeatsToTheSides);
Assert.True(ruleset1.DisableSeatsInFrontAndBehind);
Assert.Equal(2, ruleset1.NumberOfDisabledAisleSeats);
Assert.Equal(1, ruleset1.MaxGroupSize);
Assert.Equal(10, ruleset1.MaxOccupancyAbsolute);
Assert.Equal(0, ruleset1.MaxOccupancyPercentage);
Assert.True(ruleset1.OneGroupPerTable);
Assert.False(ruleset1.FixedGroupLayout);
Assert.Equal(new List<string> {"A-1"}, ruleset1.DisabledSeats);
Assert.Equal(new List<string> {"A-2"}, ruleset1.EnabledSeats);
var retrievedRuleset1 = retrievedChart.SocialDistancingRulesets["ruleset1"];
Assert.Equal(0, retrievedRuleset1.Index);
Assert.Equal("My first ruleset", retrievedRuleset1.Name);
Assert.Equal(1, retrievedRuleset1.NumberOfDisabledSeatsToTheSides);
Assert.True(retrievedRuleset1.DisableSeatsInFrontAndBehind);
Assert.True(retrievedRuleset1.DisableDiagonalSeatsInFrontAndBehind);
Assert.Equal(2, retrievedRuleset1.NumberOfDisabledAisleSeats);
Assert.Equal(1, retrievedRuleset1.MaxGroupSize);
Assert.Equal(10, retrievedRuleset1.MaxOccupancyAbsolute);
Assert.Equal(0, retrievedRuleset1.MaxOccupancyPercentage);
Assert.True(retrievedRuleset1.OneGroupPerTable);
Assert.False(retrievedRuleset1.FixedGroupLayout);
Assert.Equal(new List<string> {"A-1"}, retrievedRuleset1.DisabledSeats);
Assert.Equal(new List<string> {"A-2"}, retrievedRuleset1.EnabledSeats);

var ruleset2 = retrievedChart.SocialDistancingRulesets["ruleset2"];
Assert.Equal(1, ruleset2.Index);
Assert.Equal("My second ruleset", ruleset2.Name);
Assert.Equal(0, ruleset2.NumberOfDisabledSeatsToTheSides);
Assert.False(ruleset2.DisableSeatsInFrontAndBehind);
Assert.Equal(0, ruleset2.NumberOfDisabledAisleSeats);
Assert.Equal(0, ruleset2.MaxGroupSize);
Assert.Equal(0, ruleset2.MaxOccupancyAbsolute);
Assert.Equal(0, ruleset2.MaxOccupancyPercentage);
Assert.False(ruleset2.OneGroupPerTable);
Assert.False(ruleset2.FixedGroupLayout);
Assert.Empty(ruleset2.DisabledSeats);
Assert.Empty(ruleset2.EnabledSeats);
}

[Fact]
public void RuleBased()
{
var chartKey = CreateTestChart();
var rulesets = new Dictionary<string, SocialDistancingRuleset>()
{
{ "ruleset1", SocialDistancingRuleset.RuleBased(0, "My first ruleset", 1, true, 2, 1, 10, 0, true, new List<string> {"A-1"}, new List<string> {"A-2"})},
};

Client.Charts.SaveSocialDistancingRulesets(chartKey, rulesets);

var retrievedChart = Client.Charts.Retrieve(chartKey);
Assert.Equal(1, retrievedChart.SocialDistancingRulesets.Count);

var ruleset1 = retrievedChart.SocialDistancingRulesets["ruleset1"];
Assert.Equal(0, ruleset1.Index);
Assert.Equal("My first ruleset", ruleset1.Name);
Assert.Equal(1, ruleset1.NumberOfDisabledSeatsToTheSides);
Assert.True(ruleset1.DisableSeatsInFrontAndBehind);
Assert.Equal(2, ruleset1.NumberOfDisabledAisleSeats);
Assert.Equal(1, ruleset1.MaxGroupSize);
Assert.Equal(10, ruleset1.MaxOccupancyAbsolute);
Assert.Equal(0, ruleset1.MaxOccupancyPercentage);
Assert.True(ruleset1.OneGroupPerTable);
Assert.False(ruleset1.FixedGroupLayout);
Assert.Equal(new List<string> {"A-1"}, ruleset1.DisabledSeats);
Assert.Equal(new List<string> {"A-2"}, ruleset1.EnabledSeats);
}

[Fact]
public void Fixed()
{
var chartKey = CreateTestChart();
var rulesets = new Dictionary<string, SocialDistancingRuleset>()
{
{"ruleset1", SocialDistancingRuleset.Fixed(0, "My first ruleset", new List<string> {"A-1"})},
};

Client.Charts.SaveSocialDistancingRulesets(chartKey, rulesets);

var retrievedChart = Client.Charts.Retrieve(chartKey);
Assert.Equal(1, retrievedChart.SocialDistancingRulesets.Count);

var ruleset1 = retrievedChart.SocialDistancingRulesets["ruleset1"];
Assert.Equal(0, ruleset1.Index);
Assert.Equal("My first ruleset", ruleset1.Name);
Assert.True(ruleset1.FixedGroupLayout);
Assert.Equal(new List<string> {"A-1"}, ruleset1.DisabledSeats);
var retrievedRuleset2 = retrievedChart.SocialDistancingRulesets["ruleset2"];
Assert.Equal(1, retrievedRuleset2.Index);
Assert.Equal("My second ruleset", retrievedRuleset2.Name);
Assert.Equal(0, retrievedRuleset2.NumberOfDisabledSeatsToTheSides);
Assert.False(retrievedRuleset2.DisableSeatsInFrontAndBehind);
Assert.False(retrievedRuleset2.DisableDiagonalSeatsInFrontAndBehind);
Assert.Equal(0, retrievedRuleset2.NumberOfDisabledAisleSeats);
Assert.Equal(0, retrievedRuleset2.MaxGroupSize);
Assert.Equal(0, retrievedRuleset2.MaxOccupancyAbsolute);
Assert.Equal(0, retrievedRuleset2.MaxOccupancyPercentage);
Assert.False(retrievedRuleset2.OneGroupPerTable);
Assert.True(retrievedRuleset2.FixedGroupLayout);
Assert.Equal(new List<string> {"A-1"}, retrievedRuleset1.DisabledSeats);
Assert.Empty(retrievedRuleset2.EnabledSeats);
}
}
}
2 changes: 1 addition & 1 deletion SeatsioDotNet.Test/Events/CreateEventTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void SocialDistancingRulesetKeyCanBepassedIn()
var chartKey = CreateTestChart();
var rulesets = new Dictionary<string, SocialDistancingRuleset>()
{
{ "ruleset1", new SocialDistancingRuleset(0, "My first ruleset") },
{ "ruleset1", SocialDistancingRuleset.RuleBased("My first ruleset").Build() },
};
Client.Charts.SaveSocialDistancingRulesets(chartKey, rulesets);

Expand Down
2 changes: 1 addition & 1 deletion SeatsioDotNet.Test/Events/CreateEventsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void SocialDistancingRulesetKeyCanBePassedIn()
var chartKey = CreateTestChart();
var rulesets = new Dictionary<string, SocialDistancingRuleset>()
{
{ "ruleset1", new SocialDistancingRuleset(0, "My first ruleset") },
{ "ruleset1", SocialDistancingRuleset.RuleBased("My first ruleset").Build() },
};
Client.Charts.SaveSocialDistancingRulesets(chartKey, rulesets);
var eventCreationParams = new[]
Expand Down
6 changes: 3 additions & 3 deletions SeatsioDotNet.Test/Events/UpdateEventTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public void UpdateSocialDistancingRulesetKey()
var chartKey = CreateTestChart();
var rulesets = new Dictionary<string, SocialDistancingRuleset>()
{
{ "ruleset1", SocialDistancingRuleset.RuleBased(0, "My first ruleset") },
{ "ruleset2", SocialDistancingRuleset.RuleBased(0, "My second ruleset") }
{ "ruleset1", SocialDistancingRuleset.RuleBased("My first ruleset").Build() },
{ "ruleset2", SocialDistancingRuleset.RuleBased("My second ruleset").Build() }
};
Client.Charts.SaveSocialDistancingRulesets(chartKey, rulesets);
var evnt = Client.Events.Create(chartKey, null, null, "ruleset1");
Expand All @@ -75,7 +75,7 @@ public void RemoveSocialDistancingRulesetKey()
var chartKey = CreateTestChart();
var rulesets = new Dictionary<string, SocialDistancingRuleset>()
{
{ "ruleset1", new SocialDistancingRuleset(0, "My first ruleset") }
{ "ruleset1", SocialDistancingRuleset.RuleBased("My first ruleset").Build() }
};
Client.Charts.SaveSocialDistancingRulesets(chartKey, rulesets);
var evnt = Client.Events.Create(chartKey, null, null, "ruleset1");
Expand Down
Loading

0 comments on commit 449e222

Please sign in to comment.