diff --git a/src/LinqTestsTypes/Target.cs b/src/LinqTestsTypes/Target.cs new file mode 100644 index 0000000000..5c7fc54ded --- /dev/null +++ b/src/LinqTestsTypes/Target.cs @@ -0,0 +1,257 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.Json.Serialization; +using JasperFx.Core; +using Microsoft.FSharp.Core; + +#nullable enable +namespace Marten.Testing.Documents; + +public enum Colors +{ + Red, + Blue, + Green, + Purple, + Yellow, + Orange +} + +public class Target +{ + private static readonly Random _random = new Random(67); + + private static readonly string[] _strings = + { + "Red", "Orange", "Yellow", "Green", "Blue", "Purple", "Violet", "Pink", "Gray", "Black" + }; + + private static readonly string[] _otherStrings = + { + "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" + }; + + public static IEnumerable GenerateRandomData(int number) + { + var i = 0; + while (i < number) + { + yield return Random(true); + + i++; + } + } + + public static Target Random(bool deep = false) + { + var target = new Target(); + target.String = _strings[_random.Next(0, 10)]; + target.FSharpGuidOption = new FSharpOption(Guid.NewGuid()); + target.FSharpIntOption = new FSharpOption(_random.Next(0, 10)); + target.FSharpDateOption = new FSharpOption(DateTime.Now); + target.FSharpDateTimeOffsetOption = new FSharpOption(new DateTimeOffset(DateTime.UtcNow)); + target.FSharpDecimalOption = new FSharpOption(_random.Next(0, 10)); + target.FSharpLongOption = new FSharpOption(_random.Next(0, 10)); + target.FSharpStringOption = new FSharpOption(_strings[_random.Next(0, 10)]); + + target.PaddedString = " " + target.String + " "; + target.AnotherString = _otherStrings[_random.Next(0, 10)]; + target.Number = _random.Next(); + target.AnotherNumber = _random.Next(); + target.OtherGuid = Guid.NewGuid(); + + target.Flag = _random.Next(0, 10) > 5; + + target.Float = float.Parse(_random.NextDouble().ToString()); + + target.NumberArray = _random.Next(0, 10) > 8 + ? new[] { _random.Next(0, 10), _random.Next(0, 10), _random.Next(0, 10) } + : Array.Empty(); + + target.NumberArray = target.NumberArray.Distinct().ToArray(); + + switch (_random.Next(0, 2)) + { + case 0: + target.Color = Colors.Blue; + break; + + case 1: + target.Color = Colors.Green; + break; + + default: + target.Color = Colors.Red; + break; + } + + var value = _random.Next(0, 100); + if (value > 10) target.NullableNumber = value; + + if (value > 20) + { + var list = new List(); + for (int i = 0; i < 5; i++) + { + list.Add(_strings[_random.Next(0, 10)]); + } + + target.StringArray = list.Distinct().ToArray(); + } + + target.Long = 100 * _random.Next(); + target.Double = _random.NextDouble(); + target.Long = _random.Next() * 10000; + + target.HowLong = TimeSpan.FromSeconds(target.Long); + + target.Date = DateTime.Today.AddDays(_random.Next(-10000, 10000)); + + if (value > 15) + { + target.NullableDateOffset = DateTimeOffset.Now.Subtract(_random.Next(-60, 60).Seconds()); + } + + if (deep) + { + target.Inner = Random(); + + var number = _random.Next(1, 10); + target.Children = new Target[number]; + for (var i = 0; i < number; i++) + { + target.Children[i] = Random(); + } + + target.StringDict = Enumerable.Range(0, _random.Next(0, 10)).ToDictionary(i => $"key{i}", i => $"value{i}"); + target.String = _strings[_random.Next(0, 10)]; + target.OtherGuid = Guid.NewGuid(); + } + + return target; + } + + public string PaddedString { get; set; } + + public Target() + { + Id = Guid.NewGuid(); + StringDict = new Dictionary(); + StringList = new List(); + GuidDict = new Dictionary(); + } + + public Guid Id { get; set; } + + public int Number { get; set; } + + public int AnotherNumber { get; set; } + + public long Long { get; set; } + public string String { get; set; } + + public FSharpOption FSharpGuidOption { get; set; } + public FSharpOption FSharpIntOption { get; set; } + public FSharpOption FSharpBoolOption { get; set; } + public FSharpOption FSharpLongOption { get; set; } + public FSharpOption FSharpDecimalOption { get; set; } + public FSharpOption FSharpStringOption { get; set; } + public FSharpOption FSharpDateOption { get; set; } + public FSharpOption FSharpDateTimeOffsetOption { get; set; } + + public string AnotherString { get; set; } + + public string[] StringArray { get; set; } + + public Guid OtherGuid { get; set; } + + public Target Inner { get; set; } + + public Colors Color { get; set; } + + public Colors? NullableEnum { get; set; } + + public bool Flag { get; set; } + + [JsonInclude] // this is needed to make System.Text.Json happy + public string StringField; + + public double Double { get; set; } + public decimal Decimal { get; set; } + public DateTime Date { get; set; } + public DateTimeOffset DateOffset { get; set; } + public DateTimeOffset? NullableDateOffset { get; set; } + + [JsonInclude] // this is needed to make System.Text.Json happy + public float Float; + + public int[] NumberArray { get; set; } + + public string[] TagsArray { get; set; } + + public HashSet TagsHashSet { get; set; } + + public Target[] Children { get; set; } + + public int? NullableNumber { get; set; } + public DateTime? NullableDateTime { get; set; } + public bool? NullableBoolean { get; set; } + public Colors? NullableColor { get; set; } + + public string? NullableString { get; set; } + + public IDictionary StringDict { get; set; } + public Dictionary GuidDict { get; set; } + + public Guid UserId { get; set; } + + public List StringList { get; set; } + + public Guid[] GuidArray { get; set; } + + public TimeSpan HowLong { get; set; } +} + +public class Address +{ + public Address() + { + } + + public Address(string text) + { + var parts = text.ToDelimitedArray(); + Address1 = parts[0]; + City = parts[1]; + StateOrProvince = parts[2]; + } + + public string Address1 { get; set; } + public string Address2 { get; set; } + public string City { get; set; } + public string StateOrProvince { get; set; } + public string Country { get; set; } + public string PostalCode { get; set; } + + public bool Primary { get; set; } + public string Street { get; set; } + public string HouseNumber { get; set; } +} + +public class Squad +{ + public string Id { get; set; } +} + +public class BasketballTeam: Squad +{ +} + +public class FootballTeam: Squad +{ +} + +public class BaseballTeam: Squad +{ +}