Skip to content

Commit

Permalink
♻️ refactor(tests): rename test data constant var
Browse files Browse the repository at this point in the history
Signed-off-by: csc530 <[email protected]>
  • Loading branch information
csc530 committed Dec 22, 2023
1 parent ebe705f commit 5287265
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
9 changes: 4 additions & 5 deletions TestResumeBuilder/commands/add/AddJobTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ public void AddJob_WithNoArgs_ShouldFail()
public void AddJob_WithNameAndStartOptions_ShouldSucceed(string jobTitle, string companyName, DateOnly startDate)
{
//when
var result = TestApp.Run([.. cmdArgs, "-t", jobTitle, "-s", startDate.ToString(), "-c", companyName]);
var result = TestApp.Run(cmdArgs, "-t", jobTitle, "-s", startDate.ToString(), "-c", companyName);
var resultSettings = result.Settings as AddJobSettings;
//then
Assert.Multiple(() =>
{
Assert.Multiple(() => {
Assert.Equal(0, result.ExitCode);
Assert.NotNull(resultSettings);
Assert.Equal(jobTitle, resultSettings.JobTitle);
Expand Down Expand Up @@ -117,15 +116,15 @@ internal class AddJobTestData: JobTestData
public static TheoryData<string, string, DateOnly> JobTitleAndStartDate()
{
var data = new TheoryData<string, string, DateOnly>();
for(var i = TestRepetitions - 1; i >= 0; i--)
for(var i = TestRepetition - 1; i >= 0; i--)
data.Add(RandomJobTitle(), RandomCompany(), RandomPastDate());
return data;
}

public static TheoryData<string, string, DateOnly, string?, string?, DateOnly?> AllOptions()
{
var data = new TheoryData<string, string, DateOnly, string?, string?, DateOnly?>();
for(var i = TestRepetitions - 1; i >= 0; i--)
for(var i = TestRepetition - 1; i >= 0; i--)
data.Add(RandomJobTitle(), RandomCompany(), RandomPastDate(), WaffleOrNull(), WaffleOrNull(),
RandomFutureDate().OrNull(Faker));
return data;
Expand Down
6 changes: 3 additions & 3 deletions TestResumeBuilder/commands/add/AddProfileTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void AddProfile_WithInvalidEmail_ShouldFail(string email, Profile profile
var args = CreateCmdOptions(profile.FirstName, profile.LastName, null, profile.PhoneNumber,
profile.MiddleName, profile.Website, profile.Summary);
//then
Assert.ThrowsAny<Exception>(() => TestApp.Run([..args, "-e", email]));
Assert.ThrowsAny<Exception>(() => TestApp.Run(args, "-e", email));
Assert.Empty(TestDb.Profiles);
}

Expand Down Expand Up @@ -219,7 +219,7 @@ internal class AddProfileTestData: ProfileTestData
public static TheoryData<string, Profile> InvalidEmails()
{
var data = new TheoryData<string, Profile>();
for(var i = 0; i < TestRepetitions; i++)
for(var i = 0; i < TestRepetition; i++)
data.Add(Faker.Random.String().Replace("@", ""), GetFakeProfile());
return data;
}
Expand All @@ -235,7 +235,7 @@ public static TheoryData<string, Profile> WhiteSpaceStringAndProfile()
public static TheoryData<Profile> AllOptions()
{
var data = new TheoryData<Profile>();
for(var i = TestRepetitions - 1; i >= 0; i--)
for(var i = TestRepetition - 1; i >= 0; i--)
data.Add(ProfileTestData.GetFakeProfile());
return data;
}
Expand Down
2 changes: 1 addition & 1 deletion TestResumeBuilder/data/JobTestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ internal class JobTestData: TestData
public static DateOnly? RandomEndDate() => RandomPastDate().OrNull(Faker);
public static IEnumerable<Job> EternalJobs() => BogusJob.GenerateForever();
public static Job RandomJob() => BogusJob.Generate();
public static IEnumerable<Job> RandomJobs(int count = TestRepetitions) => BogusJob.GenerateLazy(count);
public static IEnumerable<Job> RandomJobs(int count = TestRepetition) => BogusJob.GenerateLazy(count);
}
2 changes: 1 addition & 1 deletion TestResumeBuilder/data/ProfileTestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ internal class ProfileTestData: TestData
Faker.Lorem.Paragraph().OrNull(Faker));

static public IEnumerable<Profile> InfiniteFakeProfiles => BogusProfile.GenerateForever();
static public List<Profile> GetFakeProfiles(int count = TestRepetitions) => BogusProfile.Generate(count);
static public List<Profile> GetFakeProfiles(int count = TestRepetition) => BogusProfile.Generate(count);
static public Profile GetFakeProfile() => BogusProfile.Generate();
}
11 changes: 4 additions & 7 deletions TestResumeBuilder/data/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace TestResumeBuilder;

internal class TestData
public class TestData
{
private protected const int TestRepetitions = 10;
private protected const int TestRepetition = 10;

public const string space = " ";
public const string tab = "\t";
Expand Down Expand Up @@ -44,19 +44,16 @@ static private protected int MaxRandomYearsBeforeToday()
return todayYear - minYear;
}

public static TheoryData<object[]> RandomArgs() => [Faker.Random.WordsArray(2)];


public static DateOnly RandomPastDate() => Faker.Date.PastDateOnly(MaxRandomYearsBeforeToday());
public static DateOnly RandomFutureDate() => Faker.Date.FutureDateOnly(MaxRandomYearsAfterToday());
public static DateOnly RandomDate() => Faker.Date.BetweenDateOnly(RandomPastDate(), RandomFutureDate());
public static string? RandomTextOrNull() => Faker.Lorem.Paragraph().OrNull(Faker);

public static string Waffle() => WaffleEngine.Text(Random.Next(TestRepetitions), Faker.Random.Bool());
public static string Waffle() => WaffleEngine.Text(Random.Next(TestRepetition), Faker.Random.Bool());
public static string? WaffleOrNull() => Waffle().OrNull(Faker);

//#region white spaces
public static IEnumerable<string> RandomWhiteSpaceString(int count = TestRepetitions)
public static IEnumerable<string> RandomWhiteSpaceString(int count = TestRepetition)
{
yield return Faker.Random.String2(Random.Next(count), space);
yield return Faker.Random.String2(Random.Next(count), tab);
Expand Down

0 comments on commit 5287265

Please sign in to comment.