Skip to content

Commit 73e75c0

Browse files
committed
Fixed static ordering issue in Tests.Domain and made sure unit tests pass
1 parent 9d0336c commit 73e75c0

File tree

3 files changed

+96
-88
lines changed

3 files changed

+96
-88
lines changed

src/Tests/Tests.Domain/CommitActivity.cs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,10 @@ public class CommitActivity
1515

1616
private string _projectName;
1717

18-
public static IList<CommitActivity> CommitActivities { get; } = Generator.Clone().Generate(1000);
1918
public Developer Committer { get; set; }
2019
public double ConfidenceFactor { get; set; }
2120
public TimeSpan? Duration { get; set; }
2221

23-
public static Faker<CommitActivity> Generator { get; } =
24-
new Faker<CommitActivity>()
25-
.UseSeed(TestConfiguration.Instance.Seed)
26-
.RuleFor(p => p.Id, p => Guid.NewGuid().ToString("N").Substring(0, 8))
27-
.RuleFor(p => p.ProjectName, p => Project.Projects[Gimme.Random.Number(0, Project.Projects.Count - 1)].Name)
28-
.RuleFor(p => p.Committer, p => Developer.Developers[Gimme.Random.Number(0, Developer.Developers.Count - 1)])
29-
.RuleFor(p => p.Message, p => p.Lorem.Paragraph(Gimme.Random.Number(1, 3)))
30-
.RuleFor(p => p.SizeInBytes, p => p.Random.Number(0, 100000))
31-
.RuleFor(p => p.ConfidenceFactor, p => p.Random.Double())
32-
.RuleFor(p => p.Duration, p => p.Random.ArrayElement(new TimeSpan?[]
33-
{
34-
TimeSpan.MinValue,
35-
TimeSpan.MaxValue,
36-
TimeSpan.FromMinutes(7.5),
37-
TimeSpan.Zero,
38-
null,
39-
TimeSpan.FromHours(4.23),
40-
TimeSpan.FromDays(5),
41-
}));
42-
4322
public string Id { get; set; }
4423
public JoinField Join { get; set; }
4524

@@ -67,5 +46,28 @@ public TimeSpan? StringDuration
6746
}
6847

6948
public string Type => TypeName;
49+
50+
// @formatter:off — disable formatter after this line
51+
public static Faker<CommitActivity> Generator { get; } =
52+
new Faker<CommitActivity>()
53+
.UseSeed(TestConfiguration.Instance.Seed)
54+
.RuleFor(p => p.Id, p => Guid.NewGuid().ToString("N").Substring(0, 8))
55+
.RuleFor(p => p.ProjectName, p => Project.Projects[Gimme.Random.Number(0, Project.Projects.Count - 1)].Name)
56+
.RuleFor(p => p.Committer, p => Developer.Developers[Gimme.Random.Number(0, Developer.Developers.Count - 1)])
57+
.RuleFor(p => p.Message, p => p.Lorem.Paragraph(Gimme.Random.Number(1, 3)))
58+
.RuleFor(p => p.SizeInBytes, p => p.Random.Number(0, 100000))
59+
.RuleFor(p => p.ConfidenceFactor, p => p.Random.Double())
60+
.RuleFor(p => p.Duration, p => p.Random.ArrayElement(new TimeSpan?[]
61+
{
62+
TimeSpan.MinValue,
63+
TimeSpan.MaxValue,
64+
TimeSpan.FromMinutes(7.5),
65+
TimeSpan.Zero,
66+
null,
67+
TimeSpan.FromHours(4.23),
68+
TimeSpan.FromDays(5),
69+
}));
70+
public static IList<CommitActivity> CommitActivities { get; } = Generator.Clone().Generate(1000);
71+
// @formatter:on — enable formatter after this line
7072
}
7173
}

src/Tests/Tests.Domain/Developer.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ namespace Tests.Domain
99
{
1010
public class Developer : Person
1111
{
12-
public static IList<Developer> Developers { get; } = Generator.Clone().Generate(1000);
1312
public Gender Gender { get; set; }
1413

14+
// not populated by generator. Used by ingest geoip test
15+
public GeoIp GeoIp { get; set; }
16+
public string IpAddress { get; set; }
17+
public string OnlineHandle { get; set; }
18+
public string PrivateValue { get; set; }
19+
20+
// @formatter:off — disable formatter after this line
1521
public static new Faker<Developer> Generator { get; } =
1622
new Faker<Developer>()
1723
.UseSeed(TestConfiguration.Instance.Seed)
@@ -24,11 +30,7 @@ public class Developer : Person
2430
.RuleFor(p => p.Gender, p => p.PickRandom<Gender>())
2531
.RuleFor(p => p.PrivateValue, p => "THIS SHOULD NEVER BE INDEXED")
2632
.RuleFor(p => p.IpAddress, p => p.Internet.Ip());
27-
28-
// not populated by generator. Used by ingest geoip test
29-
public GeoIp GeoIp { get; set; }
30-
public string IpAddress { get; set; }
31-
public string OnlineHandle { get; set; }
32-
public string PrivateValue { get; set; }
33+
public static IList<Developer> Developers { get; } = Generator.Clone().Generate(1000);
34+
// @formatter:on — enable formatter after this line
3335
}
3436
}

src/Tests/Tests.Domain/Project.cs

Lines changed: 64 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,69 @@ public class Project
1515
{
1616
public static string TypeName = "project";
1717

18+
public IEnumerable<string> Branches { get; set; }
19+
public IList<Tag> CuratedTags { get; set; }
20+
public string DateString { get; set; }
21+
public string Description { get; set; }
22+
23+
public JoinField Join => JoinField.Root<Project>();
24+
public DateTime LastActivity { get; set; }
25+
public Developer LeadDeveloper { get; set; }
26+
public SimpleGeoPoint Location { get; set; }
27+
public Dictionary<string, Metadata> Metadata { get; set; }
28+
public string Name { get; set; }
29+
public int? NumberOfCommits { get; set; }
30+
public int NumberOfContributors { get; set; }
31+
32+
public Ranges Ranges { get; set; }
33+
public int? RequiredBranches => Branches?.Count();
34+
35+
public SourceOnlyObject SourceOnly { get; set; }
36+
public DateTime StartedOn { get; set; }
37+
public StateOfBeing State { get; set; }
38+
public CompletionField Suggest { get; set; }
39+
public IEnumerable<Tag> Tags { get; set; }
40+
public string Type => TypeName;
41+
42+
//the first applies when using internal source serializer the latter when using JsonNetSourceSerializer
43+
[StringEnum] [JsonConverter(typeof(StringEnumConverter))]
44+
public Visibility Visibility { get; set; }
45+
46+
// @formatter:off — disable formatter after this line
47+
public static Faker<Project> Generator { get; } =
48+
new Faker<Project>()
49+
.UseSeed(TestConfiguration.Instance.Seed)
50+
.RuleFor(p => p.Name, f => f.Person.Company.Name + f.UniqueIndex.ToString())
51+
.RuleFor(p => p.Description, f => f.Lorem.Paragraphs(3))
52+
.RuleFor(p => p.State, f => f.PickRandom<StateOfBeing>())
53+
.RuleFor(p => p.Visibility, f => f.PickRandom<Visibility>())
54+
.RuleFor(p => p.StartedOn, p => p.Date.Past())
55+
.RuleFor(p => p.DateString, (p, d) => d.StartedOn.ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffffffzzz"))
56+
.RuleFor(p => p.LastActivity, p => p.Date.Recent())
57+
.RuleFor(p => p.LeadDeveloper, p => Developer.Developers[Gimme.Random.Number(0, Developer.Developers.Count - 1)])
58+
.RuleFor(p => p.Tags, f => Tag.Generator.Generate(Gimme.Random.Number(2, 50)))
59+
.RuleFor(p => p.CuratedTags, f => Tag.Generator.Generate(Gimme.Random.Number(1, 5)))
60+
.RuleFor(p => p.Location, f => SimpleGeoPoint.Generator.Generate())
61+
.RuleFor(p => p.NumberOfCommits, f => Gimme.Random.Number(1, 1000))
62+
.RuleFor(p => p.NumberOfContributors, f => Gimme.Random.Number(1, 200))
63+
.RuleFor(p => p.Ranges, f => Ranges.Generator.Generate())
64+
.RuleFor(p => p.Branches, f => Gimme.Random.ListItems(new List<string> { "master", "dev", "release", "qa", "test" }))
65+
.RuleFor(p => p.SourceOnly, f =>
66+
TestConfiguration.Instance.Random.SourceSerializer ? new SourceOnlyObject() : null
67+
)
68+
.RuleFor(p => p.Suggest, f => new CompletionField
69+
{
70+
Input = new[] { f.Person.Company.Name },
71+
Contexts = new Dictionary<string, IEnumerable<string>>
72+
{
73+
{ "color", new[] { "red", "blue", "green", "violet", "yellow" }.Take(Gimme.Random.Number(1, 4)) }
74+
}
75+
});
76+
77+
public static IList<Project> Projects { get; } = Generator.Clone().Generate(100);
78+
79+
public static Project First { get; } = Projects.First();
80+
1881
public static readonly Project Instance = new Project
1982
{
2083
Name = Projects.First().Name,
@@ -59,70 +122,11 @@ public class Project
59122
};
60123

61124

62-
public IEnumerable<string> Branches { get; set; }
63-
public IList<Tag> CuratedTags { get; set; }
64-
public string DateString { get; set; }
65-
public string Description { get; set; }
66-
67-
public static Project First { get; } = Projects.First();
68-
69-
public static Faker<Project> Generator { get; } =
70-
new Faker<Project>()
71-
.UseSeed(TestConfiguration.Instance.Seed)
72-
.RuleFor(p => p.Name, f => f.Person.Company.Name + f.UniqueIndex.ToString())
73-
.RuleFor(p => p.Description, f => f.Lorem.Paragraphs(3))
74-
.RuleFor(p => p.State, f => f.PickRandom<StateOfBeing>())
75-
.RuleFor(p => p.Visibility, f => f.PickRandom<Visibility>())
76-
.RuleFor(p => p.StartedOn, p => p.Date.Past())
77-
.RuleFor(p => p.DateString, (p, d) => d.StartedOn.ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffffffzzz"))
78-
.RuleFor(p => p.LastActivity, p => p.Date.Recent())
79-
.RuleFor(p => p.LeadDeveloper, p => Developer.Developers[Gimme.Random.Number(0, Developer.Developers.Count - 1)])
80-
.RuleFor(p => p.Tags, f => Tag.Generator.Generate(Gimme.Random.Number(2, 50)))
81-
.RuleFor(p => p.CuratedTags, f => Tag.Generator.Generate(Gimme.Random.Number(1, 5)))
82-
.RuleFor(p => p.Location, f => SimpleGeoPoint.Generator.Generate())
83-
.RuleFor(p => p.NumberOfCommits, f => Gimme.Random.Number(1, 1000))
84-
.RuleFor(p => p.NumberOfContributors, f => Gimme.Random.Number(1, 200))
85-
.RuleFor(p => p.Ranges, f => Ranges.Generator.Generate())
86-
.RuleFor(p => p.Branches, f => Gimme.Random.ListItems(new List<string> { "master", "dev", "release", "qa", "test" }))
87-
.RuleFor(p => p.SourceOnly, f =>
88-
TestConfiguration.Instance.Random.SourceSerializer ? new SourceOnlyObject() : null
89-
)
90-
.RuleFor(p => p.Suggest, f => new CompletionField
91-
{
92-
Input = new[] { f.Person.Company.Name },
93-
Contexts = new Dictionary<string, IEnumerable<string>>
94-
{
95-
{ "color", new[] { "red", "blue", "green", "violet", "yellow" }.Take(Gimme.Random.Number(1, 4)) }
96-
}
97-
});
98-
99125
public static object InstanceAnonymous => TestConfiguration.Instance.Random.SourceSerializer
100126
? InstanceAnonymousSourceSerializer
101127
: InstanceAnonymousDefault;
102128

103-
public JoinField Join => JoinField.Root<Project>();
104-
public DateTime LastActivity { get; set; }
105-
public Developer LeadDeveloper { get; set; }
106-
public SimpleGeoPoint Location { get; set; }
107-
public Dictionary<string, Metadata> Metadata { get; set; }
108-
public string Name { get; set; }
109-
public int? NumberOfCommits { get; set; }
110-
public int NumberOfContributors { get; set; }
111-
112-
public static IList<Project> Projects { get; } = Generator.Clone().Generate(100);
113-
public Ranges Ranges { get; set; }
114-
public int? RequiredBranches => Branches?.Count();
115-
116-
public SourceOnlyObject SourceOnly { get; set; }
117-
public DateTime StartedOn { get; set; }
118-
public StateOfBeing State { get; set; }
119-
public CompletionField Suggest { get; set; }
120-
public IEnumerable<Tag> Tags { get; set; }
121-
public string Type => TypeName;
122-
123-
//the first applies when using internal source serializer the latter when using JsonNetSourceSerializer
124-
[StringEnum] [JsonConverter(typeof(StringEnumConverter))]
125-
public Visibility Visibility { get; set; }
129+
// @formatter:on — enable formatter after this line
126130
}
127131

128132
//the first applies when using internal source serializer the latter when using JsonNetSourceSerializer

0 commit comments

Comments
 (0)