Skip to content

Commit 79a642d

Browse files
committed
some fixes
1 parent d73724a commit 79a642d

10 files changed

Lines changed: 101 additions & 64 deletions

File tree

.github/workflows/openactive-test-suite.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ jobs:
107107

108108
# runs `dotnet restore` to install the dependencies for the "OpenActive.Server.NET" project. It is conditional and
109109
# depends on the "profile" value not being 'no-auth' or 'single-seller'
110-
# LW: Why?
110+
# LW: Why is it conditional?
111111
- name: Install OpenActive.Server.NET dependencies
112112
if: ${{ matrix.profile != 'no-auth' && matrix.profile != 'single-seller' }}
113113
run: dotnet restore ./server/

Examples/BookingSystem.AspNetCore/BackgroundServices/FakeDataRefresherService.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@
99

1010
namespace BookingSystem
1111
{
12-
// Background task
13-
// More information: https://docs.microsoft.com/en-us/dotnet/architecture/microservices/multi-container-microservice-net-applications/background-tasks-with-ihostedservice#implementing-ihostedservice-with-a-custom-hosted-service-class-deriving-from-the-backgroundservice-base-class
12+
/// <summary>
13+
/// A background task which periodically refreshes the data in the
14+
/// FakeBookingSystem. This means that past data is deleted and new copies
15+
/// are created in the future.
16+
///
17+
/// It is a background task. More information on that here:
18+
/// https://docs.microsoft.com/en-us/dotnet/architecture/microservices/multi-container-microservice-net-applications/background-tasks-with-ihostedservice#implementing-ihostedservice-with-a-custom-hosted-service-class-deriving-from-the-backgroundservice-base-class
19+
/// </summary>
1420
public class FakeDataRefresherService : BackgroundService
1521
{
1622
private readonly ILogger<FakeDataRefresherService> _logger;

Examples/BookingSystem.AspNetFramework/Extensions/BookedOrderItemHelper.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,13 @@ public static void AddPropertiesToBookedOrderItem(IOrderItemContext ctx, BookedO
5252
}
5353
}
5454

55+
public static void RemovePropertiesFromBookedOrderItem(IOrderItemContext ctx)
56+
{
57+
// Set RemainingAttendeeCapacity and MaximumAttendeeCapacity to null as the do not belong in the B and P responses.
58+
// For more information see: https://github.com/openactive/open-booking-api/issues/156#issuecomment-926643733
59+
ctx.ResponseOrderItem.OrderedItem.Object.RemainingAttendeeCapacity = null;
60+
ctx.ResponseOrderItem.OrderedItem.Object.MaximumAttendeeCapacity = null;
61+
}
62+
5563
}
5664
}

Examples/BookingSystem.AspNetFramework/Feeds/FacilitiesFeeds.cs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using Bogus;
2-
using BookingSystem.AspNetCore.Helpers;
1+
using Bogus;
2+
using BookingSystem.AspNetCore.Helpers;
33
using OpenActive.DatasetSite.NET;
44
using OpenActive.FakeDatabase.NET;
55
using OpenActive.NET;
@@ -26,6 +26,7 @@ public AcmeFacilityUseRpdeGenerator(AppSettings appSettings, FakeBookingSystem f
2626
this._fakeBookingSystem = fakeBookingSystem;
2727
}
2828

29+
// TODO this method should use async queries so as not to block the main thread
2930
protected override async Task<List<RpdeItem<FacilityUse>>> GetRpdeItems(long? afterTimestamp, long? afterId)
3031
{
3132
var facilityTypeId = Environment.GetEnvironmentVariable("FACILITY_TYPE_ID") ?? "https://openactive.io/facility-types#a1f82b7a-1258-4d9a-8dc5-bfc2ae961651";
@@ -48,9 +49,8 @@ protected override async Task<List<RpdeItem<FacilityUse>>> GetRpdeItems(long? af
4849
.Select(result =>
4950
{
5051
var faker = new Faker() { Random = new Randomizer((int)result.Item1.Id) };
51-
var isGoldenRecord = faker.Random.Bool();
52-
53-
return new RpdeItem<FacilityUse>
52+
var isGoldenRecord = faker.Random.Number(0, 1) > 0.75;
53+
var facilityUseRpdeItem = new RpdeItem<FacilityUse>
5454
{
5555
Kind = RpdeKind.FacilityUse,
5656
Id = result.Item1.Id,
@@ -68,22 +68,14 @@ protected override async Task<List<RpdeItem<FacilityUse>>> GetRpdeItems(long? af
6868
}),
6969
Identifier = result.Item1.Id,
7070
Name = GetNameAndFacilityTypeForFacility(result.Item1.Name, isGoldenRecord).Name,
71-
Description = faker.Lorem.Paragraphs(isGoldenRecord ? 4 : faker.Random.Number(4)),
7271
Provider = FeedGenerationHelper.GenerateOrganization(
7372
faker,
7473
result.Item2,
7574
_appSettings.FeatureFlags.SingleSeller,
7675
_appSettings.FeatureFlags.SingleSeller ? RenderSingleSellerId() : RenderSellerId(new SimpleIdComponents { IdLong = result.Item2.Id })
7776
),
78-
Url = new Uri($"https://www.example.com/facilities/{result.Item1.Id}"),
79-
AttendeeInstructions = FeedGenerationHelper.GenerateAttendeeInstructions(faker, isGoldenRecord),
80-
AccessibilitySupport = FeedGenerationHelper.GenerateAccessibilitySupport(faker, isGoldenRecord),
81-
AccessibilityInformation = faker.Lorem.Paragraphs(isGoldenRecord ? 2 : faker.Random.Number(2)),
82-
IsWheelchairAccessible = isGoldenRecord || faker.Random.Bool() ? faker.Random.Bool() : faker.Random.ListItem(new List<bool?> { true, false, null, null }),
83-
Category = GenerateCategory(faker, isGoldenRecord),
84-
Image = FeedGenerationHelper.GenerateImages(faker, isGoldenRecord),
85-
Video = isGoldenRecord || faker.Random.Bool() ? new List<VideoObject> { new VideoObject { Url = new Uri("https://www.youtube.com/watch?v=xvDZZLqlc-0") } } : null,
8677
Location = FeedGenerationHelper.GetPlaceById(result.Item1.PlaceId),
78+
Url = new Uri($"https://www.example.com/facilities/{result.Item1.Id}"),
8779
FacilityType = GetNameAndFacilityTypeForFacility(result.Item1.Name, isGoldenRecord).Facility,
8880
IndividualFacilityUse = result.Item1.IndividualFacilityUses != null ? result.Item1.IndividualFacilityUses.Select(ifu => new OpenActive.NET.IndividualFacilityUse
8981
{
@@ -97,6 +89,23 @@ protected override async Task<List<RpdeItem<FacilityUse>>> GetRpdeItems(long? af
9789
}).ToList() : null,
9890
}
9991
};
92+
93+
// If this instance of the Reference Implementation is in Lorem Fitsum mode, then generate a comprehensive data.
94+
// If it is not (eg for a CI run), return only the minimal properties needed
95+
var IsLoremFitsumMode = _appSettings.FeatureFlags.IsLoremFitsumMode;
96+
if (IsLoremFitsumMode)
97+
{
98+
facilityUseRpdeItem.Data.Description = faker.Lorem.Paragraphs(isGoldenRecord ? 4 : faker.Random.Number(4));
99+
facilityUseRpdeItem.Data.AttendeeInstructions = FeedGenerationHelper.GenerateAttendeeInstructions(faker, isGoldenRecord);
100+
facilityUseRpdeItem.Data.AccessibilitySupport = FeedGenerationHelper.GenerateAccessibilitySupport(faker, isGoldenRecord);
101+
facilityUseRpdeItem.Data.AccessibilityInformation = faker.Lorem.Paragraphs(isGoldenRecord ? 2 : faker.Random.Number(2));
102+
facilityUseRpdeItem.Data.IsWheelchairAccessible = isGoldenRecord || faker.Random.Bool() ? faker.Random.Bool() : faker.Random.ListItem(new List<bool?> { true, false, null, null });
103+
facilityUseRpdeItem.Data.Category = GenerateCategory(faker, isGoldenRecord);
104+
facilityUseRpdeItem.Data.Image = FeedGenerationHelper.GenerateImages(faker, isGoldenRecord);
105+
facilityUseRpdeItem.Data.Video = isGoldenRecord || faker.Random.Bool() ? new List<VideoObject> { new VideoObject { Url = new Uri("https://www.youtube.com/watch?v=xvDZZLqlc-0") } } : null;
106+
}
107+
108+
return facilityUseRpdeItem;
100109
});
101110

102111
return query.ToList();
@@ -181,19 +190,6 @@ private List<string> GenerateCategory(Faker faker, bool isGoldenRecord)
181190
return FeedGenerationHelper.GetRandomElementsOf(faker, listOfPossibleCategories, isGoldenRecord, 1).ToList();
182191
}
183192

184-
private List<OpeningHoursSpecification> GenerateOpeningHours(Faker faker)
185-
{
186-
return new List<OpeningHoursSpecification>
187-
{
188-
new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Sunday }, Opens = $"{faker.Random.Number(9,12)}:00", Closes = $"{faker.Random.Number(15,17)}:30"},
189-
new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Monday }, Opens = $"{faker.Random.Number(6,10)}:00", Closes = $"{faker.Random.Number(18,21)}:30"},
190-
new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Tuesday }, Opens = $"{faker.Random.Number(6,10)}:00", Closes = $"{faker.Random.Number(18,21)}:30"},
191-
new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Wednesday }, Opens = $"{faker.Random.Number(6,10)}:00", Closes = $"{faker.Random.Number(18,21)}:30"},
192-
new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Thursday }, Opens = $"{faker.Random.Number(6,10)}:00", Closes = $"{faker.Random.Number(18,21)}:30"},
193-
new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Friday }, Opens = $"{faker.Random.Number(6,10)}:00", Closes = $"{faker.Random.Number(18,21)}:30"},
194-
new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Saturday }, Opens = $"{faker.Random.Number(9,12)}:00", Closes = $"{faker.Random.Number(15,17)}:30"}
195-
};
196-
}
197193
}
198194

199195
public class AcmeFacilityUseSlotRpdeGenerator : RpdeFeedModifiedTimestampAndIdLong<FacilityOpportunity, Slot>
@@ -209,6 +205,7 @@ public AcmeFacilityUseSlotRpdeGenerator(AppSettings appSettings, FakeBookingSyst
209205
this._fakeBookingSystem = fakeBookingSystem;
210206
}
211207

208+
// TODO this method should use async queries so as not to block the main thread
212209
protected override async Task<List<RpdeItem<Slot>>> GetRpdeItems(long? afterTimestamp, long? afterId)
213210
{
214211
using (var db = _fakeBookingSystem.Database.Mem.Database.Open())

Examples/BookingSystem.AspNetFramework/Feeds/SessionsFeeds.cs

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ protected override async Task<List<RpdeItem<SessionSeries>>> GetRpdeItems(long?
105105
.SelectMulti<ClassTable, SellerTable>(q)
106106
.Select(result =>
107107
{
108-
var intt = (int)result.Item1.Modified;
109108

110109
var faker = new Faker() { Random = new Randomizer((int)result.Item1.Id) };
111110
// here we randomly decide whether the item is going to be a golden record or not by using Faker
112111
// See the README for more detail on golden records.
113-
var isGoldenRecord = faker.Random.Bool();
112+
var isGoldenRecord = faker.Random.Number(0, 1) > 0.75;
114113

115-
return new RpdeItem<SessionSeries>
114+
115+
var sessionSeriesRpdeItem = new RpdeItem<SessionSeries>
116116
{
117117
Kind = RpdeKind.SessionSeries,
118118
Id = result.Item1.Id,
@@ -131,37 +131,48 @@ protected override async Task<List<RpdeItem<SessionSeries>>> GetRpdeItems(long?
131131
Identifier = result.Item1.Id,
132132
Name = GetNameAndActivityForSessions(result.Item1.Title, isGoldenRecord).Name,
133133
EventAttendanceMode = MapAttendanceMode(result.Item1.AttendanceMode),
134-
Description = faker.Lorem.Paragraphs(isGoldenRecord ? 4 : faker.Random.Number(4)),
135-
AttendeeInstructions = FeedGenerationHelper.GenerateAttendeeInstructions(faker, isGoldenRecord),
136-
GenderRestriction = faker.Random.Enum<GenderRestrictionType>(),
137-
AgeRange = GenerateAgeRange(faker, isGoldenRecord),
138-
Level = faker.Random.ListItems(new List<string> { "Beginner", "Intermediate", "Advanced" }, 1).ToList(),
139134
Organizer = GenerateOrganizerOrPerson(faker, result.Item2),
140-
AccessibilitySupport = FeedGenerationHelper.GenerateAccessibilitySupport(faker, isGoldenRecord),
141-
AccessibilityInformation = faker.Lorem.Paragraphs(isGoldenRecord ? 2 : faker.Random.Number(2)),
142-
IsWheelchairAccessible = isGoldenRecord || faker.Random.Bool() ? faker.Random.Bool() : faker.Random.ListItem(new List<bool?> { true, false, null, null }),
143-
Category = GenerateCategory(faker, isGoldenRecord),
144-
Image = FeedGenerationHelper.GenerateImages(faker, isGoldenRecord),
145-
Video = isGoldenRecord || faker.Random.Bool() ? new List<VideoObject> { new VideoObject { Url = new Uri("https://www.youtube.com/watch?v=xvDZZLqlc-0") } } : null,
146-
Leader = GenerateListOfPersons(faker, isGoldenRecord, 2),
147-
Contributor = GenerateListOfPersons(faker, isGoldenRecord, 2),
148-
IsCoached = isGoldenRecord || faker.Random.Bool() ? faker.Random.Bool() : faker.Random.ListItem(new List<bool?> { true, false, null, null }),
149135
Offers = GenerateOffers(faker, isGoldenRecord, result.Item1),
150136
// location MUST not be provided for fully virtual sessions
151137
Location = result.Item1.AttendanceMode == AttendanceMode.Online ? null : FeedGenerationHelper.GetPlaceById(result.Item1.PlaceId),
152-
// beta:affiliatedLocation MAY be provided for fully virtual sessions
153-
AffiliatedLocation = (result.Item1.AttendanceMode == AttendanceMode.Offline && faker.Random.Bool()) ? null : FeedGenerationHelper.GetPlaceById(result.Item1.PlaceId),
154-
EventSchedule = GenerateSchedules(faker, isGoldenRecord),
155-
SchedulingNote = GenerateSchedulingNote(faker, isGoldenRecord),
156-
IsAccessibleForFree = result.Item1.Price == 0,
157138
Url = new Uri($"https://www.example.com/sessions/{result.Item1.Id}"),
158139
Activity = GetNameAndActivityForSessions(result.Item1.Title, isGoldenRecord).Activity,
159-
Programme = GenerateBrand(faker, isGoldenRecord),
160-
IsInteractivityPreferred = result.Item1.AttendanceMode == AttendanceMode.Offline ? null : (isGoldenRecord ? true : faker.Random.ListItem(new List<bool?> { true, false, null })),
161-
IsVirtuallyCoached = result.Item1.AttendanceMode == AttendanceMode.Offline ? null : (isGoldenRecord ? true : faker.Random.ListItem(new List<bool?> { true, false, null })),
162-
ParticipantSuppliedEquipment = result.Item1.AttendanceMode == AttendanceMode.Offline ? null : (isGoldenRecord ? OpenActive.NET.RequiredStatusType.Optional : faker.Random.ListItem(new List<OpenActive.NET.RequiredStatusType?> { OpenActive.NET.RequiredStatusType.Optional, OpenActive.NET.RequiredStatusType.Required, OpenActive.NET.RequiredStatusType.Unavailable, null })),
163140
}
164141
};
142+
143+
// If this instance of the Reference Implementation is in Lorem Fitsum mode, then generate a comprehensive data.
144+
// If it is not (eg for a CI run), return only the minimal properties needed
145+
var IsLoremFitsumMode = _appSettings.FeatureFlags.IsLoremFitsumMode;
146+
if (IsLoremFitsumMode)
147+
{
148+
sessionSeriesRpdeItem.Data.Description = faker.Lorem.Paragraphs(isGoldenRecord ? 4 : faker.Random.Number(4));
149+
sessionSeriesRpdeItem.Data.AttendeeInstructions = FeedGenerationHelper.GenerateAttendeeInstructions(faker, isGoldenRecord);
150+
sessionSeriesRpdeItem.Data.GenderRestriction = faker.Random.Enum<GenderRestrictionType>();
151+
sessionSeriesRpdeItem.Data.AccessibilitySupport = FeedGenerationHelper.GenerateAccessibilitySupport(faker, isGoldenRecord);
152+
sessionSeriesRpdeItem.Data.AccessibilityInformation = faker.Lorem.Paragraphs(isGoldenRecord ? 2 : faker.Random.Number(2));
153+
sessionSeriesRpdeItem.Data.IsWheelchairAccessible = isGoldenRecord || faker.Random.Bool() ? faker.Random.Bool() : faker.Random.ListItem(new List<bool?> { true, false, null, null });
154+
sessionSeriesRpdeItem.Data.Category = GenerateCategory(faker, isGoldenRecord);
155+
sessionSeriesRpdeItem.Data.Video = isGoldenRecord || faker.Random.Bool() ? new List<VideoObject> { new VideoObject { Url = new Uri("https://www.youtube.com/watch?v=xvDZZLqlc-0") } } : null;
156+
sessionSeriesRpdeItem.Data.Leader = GenerateListOfPersons(faker, isGoldenRecord, 2);
157+
sessionSeriesRpdeItem.Data.Contributor = GenerateListOfPersons(faker, isGoldenRecord, 2);
158+
sessionSeriesRpdeItem.Data.AgeRange = GenerateAgeRange(faker, isGoldenRecord);
159+
sessionSeriesRpdeItem.Data.Image = FeedGenerationHelper.GenerateImages(faker, isGoldenRecord);
160+
sessionSeriesRpdeItem.Data.Level = faker.Random.ListItems(new List<string> { "Beginner", "Intermediate", "Advanced" }, 1).ToList();
161+
sessionSeriesRpdeItem.Data.IsCoached = isGoldenRecord || faker.Random.Bool() ? faker.Random.Bool() : faker.Random.ListItem(new List<bool?> { true, false, null, null });
162+
// beta:affiliatedLocation MAY be provided for fully virtual sessions
163+
sessionSeriesRpdeItem.Data.AffiliatedLocation = (result.Item1.AttendanceMode == AttendanceMode.Offline && faker.Random.Bool()) ? null : FeedGenerationHelper.GetPlaceById(result.Item1.PlaceId);
164+
sessionSeriesRpdeItem.Data.EventSchedule = GenerateSchedules(faker, isGoldenRecord);
165+
sessionSeriesRpdeItem.Data.SchedulingNote = GenerateSchedulingNote(faker, isGoldenRecord);
166+
sessionSeriesRpdeItem.Data.IsAccessibleForFree = result.Item1.Price == 0;
167+
sessionSeriesRpdeItem.Data.Programme = GenerateBrand(faker, isGoldenRecord);
168+
sessionSeriesRpdeItem.Data.IsInteractivityPreferred = result.Item1.AttendanceMode == AttendanceMode.Offline ? null : (isGoldenRecord ? true : faker.Random.ListItem(new List<bool?> { true, false, null }));
169+
sessionSeriesRpdeItem.Data.IsVirtuallyCoached = result.Item1.AttendanceMode == AttendanceMode.Offline ? null : (isGoldenRecord ? true : faker.Random.ListItem(new List<bool?> { true, false, null }));
170+
sessionSeriesRpdeItem.Data.ParticipantSuppliedEquipment = result.Item1.AttendanceMode == AttendanceMode.Offline ? null : (isGoldenRecord ? OpenActive.NET.RequiredStatusType.Optional : faker.Random.ListItem(new List<OpenActive.NET.RequiredStatusType?> { OpenActive.NET.RequiredStatusType.Optional, OpenActive.NET.RequiredStatusType.Required, OpenActive.NET.RequiredStatusType.Unavailable, null }));
171+
172+
}
173+
174+
175+
return sessionSeriesRpdeItem;
165176
});
166177

167178
return query.ToList();

0 commit comments

Comments
 (0)