|
| 1 | +using System; |
| 2 | +using OpenActive.NET; |
| 3 | +using System.Collections.Generic; |
| 4 | +using OpenActive.FakeDatabase.NET; |
| 5 | +using Bogus; |
| 6 | +using System.Linq; |
| 7 | +using Bogus.DataSets; |
| 8 | +using OpenActive.Server.NET.OpenBookingHelper; |
| 9 | +using System.Security.Policy; |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +namespace BookingSystem.AspNetCore.Helpers |
| 14 | +{ |
| 15 | + public static class FeedGenerationHelper |
| 16 | + { |
| 17 | + public static IList<T> GetRandomElementsOf<T>(Faker faker, IList<T> list, bool isGoldenRecord, int minimumNumberOfElements = 0, int maximumNumberOfElements = 0) |
| 18 | + { |
| 19 | + // If this is for the golden record, return the whole list so that all the possible data values are returned |
| 20 | + if (isGoldenRecord) return list; |
| 21 | + |
| 22 | + // If maximumNumberOfElements is the default value, use list.Count, if it's been set, use that |
| 23 | + var max = maximumNumberOfElements == 0 ? list.Count : maximumNumberOfElements; |
| 24 | + // Otherwise return a random number of elements from the list |
| 25 | + var randomNumberOfElementsToReturn = faker.Random.Number(minimumNumberOfElements, max); |
| 26 | + return faker.Random.ListItems(list, randomNumberOfElementsToReturn); |
| 27 | + } |
| 28 | + |
| 29 | + |
| 30 | + public static Place GetPlaceById(long placeId) |
| 31 | + { |
| 32 | + // Three hardcoded fake places |
| 33 | + switch (placeId) |
| 34 | + { |
| 35 | + case 1: |
| 36 | + return new Place |
| 37 | + { |
| 38 | + Identifier = 1, |
| 39 | + Id = new Uri($"https://example.com/place/{placeId}"), |
| 40 | + Name = "Post-ercise Plaza", |
| 41 | + Description = "Sorting Out Your Fitness One Parcel Lift at a Time! Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", |
| 42 | + Address = new PostalAddress |
| 43 | + { |
| 44 | + StreetAddress = "Kings Mead House", |
| 45 | + AddressLocality = "Oxford", |
| 46 | + AddressRegion = "Oxfordshire", |
| 47 | + PostalCode = "OX1 1AA", |
| 48 | + AddressCountry = "GB" |
| 49 | + }, |
| 50 | + Geo = new GeoCoordinates |
| 51 | + { |
| 52 | + Latitude = (decimal?)51.7502, |
| 53 | + Longitude = (decimal?)-1.2674 |
| 54 | + }, |
| 55 | + Image = new List<ImageObject> { |
| 56 | + new ImageObject |
| 57 | + { |
| 58 | + Url = new Uri("https://upload.wikimedia.org/wikipedia/commons/e/e5/Oxford_StAldates_PostOffice.jpg") |
| 59 | + }, |
| 60 | + }, |
| 61 | + Telephone = "01865 000001", |
| 62 | + Url = new Uri("https://en.wikipedia.org/wiki/Post_Office_Limited"), |
| 63 | + AmenityFeature = new List<LocationFeatureSpecification> |
| 64 | + { |
| 65 | + new ChangingFacilities { Name = "Changing Facilities", Value = true }, |
| 66 | + new Showers { Name = "Showers", Value = true }, |
| 67 | + new Lockers { Name = "Lockers", Value = true }, |
| 68 | + new Towels { Name = "Towels", Value = false }, |
| 69 | + new Creche { Name = "Creche", Value = false }, |
| 70 | + new Parking { Name = "Parking", Value = false } |
| 71 | + }, |
| 72 | + OpeningHoursSpecification = new List<OpeningHoursSpecification> |
| 73 | + { |
| 74 | + new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Sunday }, Opens = "09:00", Closes = "17:30"}, |
| 75 | + new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Monday }, Opens = "06:30", Closes = "21:30"}, |
| 76 | + new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Tuesday }, Opens = "06:30", Closes = "21:30"}, |
| 77 | + new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Wednesday }, Opens = "06:30", Closes = "21:30"}, |
| 78 | + new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Thursday }, Opens = "06:30", Closes = "21:30"}, |
| 79 | + new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Friday }, Opens = "06:30", Closes = "21:30"}, |
| 80 | + new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Saturday }, Opens = "09:00", Closes = "17:30"} |
| 81 | + } |
| 82 | + }; |
| 83 | + case 2: |
| 84 | + return new Place |
| 85 | + { |
| 86 | + Identifier = 2, |
| 87 | + Id = new Uri($"https://example.com/place/{placeId}"), |
| 88 | + Name = "Premier Lifters", |
| 89 | + Description = "Where your Fitness Goals are Always Inn-Sight. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", |
| 90 | + Address = new PostalAddress |
| 91 | + { |
| 92 | + StreetAddress = "Greyfriars Court, Paradise Square", |
| 93 | + AddressLocality = "Oxford", |
| 94 | + AddressRegion = "Oxfordshire", |
| 95 | + PostalCode = "OX1 1BB", |
| 96 | + AddressCountry = "GB" |
| 97 | + }, |
| 98 | + Geo = new GeoCoordinates |
| 99 | + { |
| 100 | + Latitude = (decimal?)51.7504933, |
| 101 | + Longitude = (decimal?)-1.2620685 |
| 102 | + }, |
| 103 | + Image = new List<ImageObject> { |
| 104 | + new ImageObject |
| 105 | + { |
| 106 | + Url = new Uri("https://upload.wikimedia.org/wikipedia/commons/5/53/Cambridge_Orchard_Park_Premier_Inn.jpg") |
| 107 | + }, |
| 108 | + }, |
| 109 | + Telephone = "01865 000002", |
| 110 | + Url = new Uri("https://en.wikipedia.org/wiki/Premier_Inn"), |
| 111 | + AmenityFeature = new List<LocationFeatureSpecification> |
| 112 | + { |
| 113 | + new ChangingFacilities { Name = "Changing Facilities", Value = false }, |
| 114 | + new Showers { Name = "Showers", Value = false }, |
| 115 | + new Lockers { Name = "Lockers", Value = false }, |
| 116 | + new Towels { Name = "Towels", Value = true }, |
| 117 | + new Creche { Name = "Creche", Value = true }, |
| 118 | + new Parking { Name = "Parking", Value = true } |
| 119 | + }, |
| 120 | + OpeningHoursSpecification = new List<OpeningHoursSpecification> |
| 121 | + { |
| 122 | + new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Sunday }, Opens = "09:00", Closes = "17:30"}, |
| 123 | + new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Monday }, Opens = "06:30", Closes = "21:30"}, |
| 124 | + new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Tuesday }, Opens = "06:30", Closes = "21:30"}, |
| 125 | + new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Wednesday }, Opens = "06:30", Closes = "21:30"}, |
| 126 | + new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Thursday }, Opens = "06:30", Closes = "21:30"}, |
| 127 | + new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Friday }, Opens = "06:30", Closes = "21:30"}, |
| 128 | + new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Saturday }, Opens = "09:00", Closes = "17:30"} |
| 129 | + } |
| 130 | + }; |
| 131 | + case 3: |
| 132 | + return new Place |
| 133 | + { |
| 134 | + Identifier = 3, |
| 135 | + Id = new Uri($"https://example.com/place/{placeId}"), |
| 136 | + Name = "Stroll & Stretch", |
| 137 | + Description = "Casual Calisthenics in the Heart of Commerce. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", |
| 138 | + Address = new PostalAddress |
| 139 | + { |
| 140 | + StreetAddress = "Norfolk Street", |
| 141 | + AddressLocality = "Oxford", |
| 142 | + AddressRegion = "Oxfordshire", |
| 143 | + PostalCode = "OX1 1UU", |
| 144 | + AddressCountry = "GB" |
| 145 | + }, |
| 146 | + Geo = new GeoCoordinates |
| 147 | + { |
| 148 | + Latitude = (decimal?)51.749826, |
| 149 | + Longitude = (decimal?)-1.261492 |
| 150 | + }, |
| 151 | + Image = new List<ImageObject> { |
| 152 | + new ImageObject |
| 153 | + { |
| 154 | + Url = new Uri("https://upload.wikimedia.org/wikipedia/commons/2/28/Westfield_Garden_State_Plaza_-_panoramio.jpg") |
| 155 | + }, |
| 156 | + }, |
| 157 | + Telephone = "01865 000003", |
| 158 | + Url = new Uri("https://en.wikipedia.org/wiki/Shopping_center"), |
| 159 | + OpeningHoursSpecification = new List<OpeningHoursSpecification> |
| 160 | + { |
| 161 | + new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Sunday }, Opens = "09:00", Closes = "17:30"}, |
| 162 | + new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Monday }, Opens = "06:30", Closes = "21:30"}, |
| 163 | + new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Tuesday }, Opens = "06:30", Closes = "21:30"}, |
| 164 | + new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Wednesday }, Opens = "06:30", Closes = "21:30"}, |
| 165 | + new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Thursday }, Opens = "06:30", Closes = "21:30"}, |
| 166 | + new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Friday }, Opens = "06:30", Closes = "21:30"}, |
| 167 | + new OpeningHoursSpecification {DayOfWeek = new List<Schema.NET.DayOfWeek> {Schema.NET.DayOfWeek.Saturday }, Opens = "09:00", Closes = "17:30"} |
| 168 | + } |
| 169 | + }; |
| 170 | + default: |
| 171 | + return null; |
| 172 | + } |
| 173 | + } |
| 174 | + |
| 175 | + public static List<OpenBookingFlowRequirement> OpenBookingFlowRequirement(bool requiresApproval, bool requiresAttendeeValidation, bool requiresAdditionalDetails, bool allowsProposalAmendment) |
| 176 | + { |
| 177 | + List<OpenBookingFlowRequirement> openBookingFlowRequirement = null; |
| 178 | + |
| 179 | + if (requiresApproval) |
| 180 | + { |
| 181 | + openBookingFlowRequirement = openBookingFlowRequirement ?? new List<OpenBookingFlowRequirement>(); |
| 182 | + openBookingFlowRequirement.Add(OpenActive.NET.OpenBookingFlowRequirement.OpenBookingApproval); |
| 183 | + } |
| 184 | + |
| 185 | + if (requiresAttendeeValidation) |
| 186 | + { |
| 187 | + openBookingFlowRequirement = openBookingFlowRequirement ?? new List<OpenBookingFlowRequirement>(); |
| 188 | + openBookingFlowRequirement.Add(OpenActive.NET.OpenBookingFlowRequirement.OpenBookingAttendeeDetails); |
| 189 | + } |
| 190 | + |
| 191 | + if (requiresAdditionalDetails) |
| 192 | + { |
| 193 | + openBookingFlowRequirement = openBookingFlowRequirement ?? new List<OpenBookingFlowRequirement>(); |
| 194 | + openBookingFlowRequirement.Add(OpenActive.NET.OpenBookingFlowRequirement.OpenBookingIntakeForm); |
| 195 | + } |
| 196 | + |
| 197 | + if (allowsProposalAmendment) |
| 198 | + { |
| 199 | + openBookingFlowRequirement = openBookingFlowRequirement ?? new List<OpenBookingFlowRequirement>(); |
| 200 | + openBookingFlowRequirement.Add(OpenActive.NET.OpenBookingFlowRequirement.OpenBookingNegotiation); |
| 201 | + } |
| 202 | + return openBookingFlowRequirement; |
| 203 | + } |
| 204 | + |
| 205 | + public static string GenerateAttendeeInstructions(Faker faker, bool isGoldenRecord) |
| 206 | + { |
| 207 | + var listOfPossibleInstructions = new List<string>(){ |
| 208 | + "wear sportswear/gym clothes", |
| 209 | + "wear comfortable loose clothing", |
| 210 | + "come as you are", |
| 211 | + "bring trainers", |
| 212 | + "wear flat shoes", |
| 213 | + "no footwear required" |
| 214 | + }; |
| 215 | + |
| 216 | + return $"Clothing instructions: {string.Join(", ", GetRandomElementsOf(faker, listOfPossibleInstructions, isGoldenRecord, 1))}"; |
| 217 | + } |
| 218 | + |
| 219 | + public static List<Concept> GenerateAccessibilitySupport(Faker faker, bool isGoldenRecord) |
| 220 | + { |
| 221 | + var listOfAccessibilitySupports = new List<Concept> |
| 222 | + { |
| 223 | + new Concept {Id = new Uri("https://openactive.io/accessibility-support#1393f2dc-3fcc-4be9-a99f-f1e51f5ad277"), PrefLabel = "Visual Impairment", InScheme = new Uri("https://openactive.io/accessibility-support")}, |
| 224 | + new Concept {Id = new Uri("https://openactive.io/accessibility-support#2bfb7228-5969-4927-8435-38b5005a8771"), PrefLabel = "Hearing Impairment", InScheme = new Uri("https://openactive.io/accessibility-support")}, |
| 225 | + new Concept {Id = new Uri("https://openactive.io/accessibility-support#40b9b11f-bdd3-4aeb-8984-2ecf74a14c7a"), PrefLabel = "Mental health issues", InScheme = new Uri("https://openactive.io/accessibility-support")} |
| 226 | + }; |
| 227 | + |
| 228 | + return GetRandomElementsOf(faker, listOfAccessibilitySupports, isGoldenRecord, 1, 2).ToList(); |
| 229 | + } |
| 230 | + |
| 231 | + public static List<ImageObject> GenerateImages(Faker faker, bool isGoldenRecord) |
| 232 | + { |
| 233 | + static Uri GenerateImageUrl(int width, int height, int seed) |
| 234 | + { |
| 235 | + return new Uri($"https://picsum.photos/{width}/{height}?image={seed}"); |
| 236 | + } |
| 237 | + |
| 238 | + var images = new List<ImageObject>(); |
| 239 | + var min = isGoldenRecord ? 4 : 1; |
| 240 | + var imageCount = faker.Random.Number(min, 3); |
| 241 | + for (var i = 0; i < imageCount; i++) |
| 242 | + { |
| 243 | + var imageSeed = faker.Random.Number(1083); |
| 244 | + var thumbnails = new List<ImageObject> { |
| 245 | + new ImageObject{Url = GenerateImageUrl(672, 414, imageSeed), Width = 672, Height = 414}, |
| 246 | + new ImageObject{Url = GenerateImageUrl(300, 200, imageSeed), Width = 300, Height = 200}, |
| 247 | + new ImageObject{Url = GenerateImageUrl(100, 100, imageSeed), Width = 100, Height = 100} |
| 248 | + }; |
| 249 | + var image = new ImageObject |
| 250 | + { |
| 251 | + Url = GenerateImageUrl(1024, 724, imageSeed), |
| 252 | + Thumbnail = GetRandomElementsOf(faker, thumbnails, isGoldenRecord, 1, 1).ToList() |
| 253 | + }; |
| 254 | + images.Add(image); |
| 255 | + } |
| 256 | + return images; |
| 257 | + } |
| 258 | + |
| 259 | + public static Organization GenerateOrganization(Faker faker, SellerTable seller, bool isSingleSeller, Uri organizationId) |
| 260 | + { |
| 261 | + if (isSingleSeller) |
| 262 | + return new Organization |
| 263 | + { |
| 264 | + Id = organizationId, |
| 265 | + Name = "Test Seller", |
| 266 | + TaxMode = TaxMode.TaxGross, |
| 267 | + TermsOfService = new List<Terms> |
| 268 | + { |
| 269 | + new PrivacyPolicy |
| 270 | + { |
| 271 | + Name = "Privacy Policy", |
| 272 | + Url = new Uri("https://example.com/privacy.html"), |
| 273 | + RequiresExplicitConsent = false |
| 274 | + } |
| 275 | + }, |
| 276 | + IsOpenBookingAllowed = true, |
| 277 | + Telephone = faker.Phone.PhoneNumber("0#### ######"), |
| 278 | + SameAs = new List<Uri> { new Uri("https://socialmedia.com/testseller") } |
| 279 | + }; |
| 280 | + |
| 281 | + return new Organization |
| 282 | + { |
| 283 | + Id = organizationId, |
| 284 | + Name = seller.Name, |
| 285 | + TaxMode = seller.IsTaxGross ? TaxMode.TaxGross : TaxMode.TaxNet, |
| 286 | + TermsOfService = new List<Terms> |
| 287 | + { |
| 288 | + new PrivacyPolicy |
| 289 | + { |
| 290 | + Name = "Privacy Policy", |
| 291 | + Url = new Uri("https://example.com/privacy.html"), |
| 292 | + RequiresExplicitConsent = false |
| 293 | + } |
| 294 | + }, |
| 295 | + IsOpenBookingAllowed = true, |
| 296 | + Url = new Uri(faker.Internet.Url()), |
| 297 | + Telephone = faker.Phone.PhoneNumber("0#### ######"), |
| 298 | + SameAs = new List<Uri> { new Uri($"https://socialmedia.com/{seller.Name.Replace(" ", "")}") } |
| 299 | + }; |
| 300 | + |
| 301 | + |
| 302 | + } |
| 303 | + |
| 304 | + } |
| 305 | +} |
0 commit comments