diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index d75de99..4de5e5a 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -26,7 +26,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@499789684c9a0d41c9b3f0d66a785ba17b1d51ab # v1.9.0 with: - dotnet-version: 6.0.x + dotnet-version: 10.0.x - name: Restore dependencies run: dotnet restore - name: Build diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml index 0420ab3..04257c5 100644 --- a/.github/workflows/copilot-setup-steps.yml +++ b/.github/workflows/copilot-setup-steps.yml @@ -25,6 +25,6 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@2016bd2012dba4e32de620c46fe006a3ac9f0602 # v5.0.1 with: - dotnet-version: 6.0.x + dotnet-version: 10.0.x - name: Restore dependencies run: dotnet restore Ed-Fi-SDG.sln diff --git a/global.json b/global.json index 2ca974f..26e4a86 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "6.0.100", + "version": "10.0.100", "rollForward": "latestFeature" } } diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props new file mode 100644 index 0000000..acea41b --- /dev/null +++ b/src/Directory.Packages.props @@ -0,0 +1,21 @@ + + + true + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Ed-Fi-SDG.sln b/src/Ed-Fi-SDG.sln index 14b8d58..eea48a9 100644 --- a/src/Ed-Fi-SDG.sln +++ b/src/Ed-Fi-SDG.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31129.286 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36310.24 d17.14 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EdFi.SampleDataGenerator.Console", "EdFi.SampleDataGenerator.Console\EdFi.SampleDataGenerator.Console.csproj", "{D464AAAF-21E8-459A-B525-8BA55F1CF66E}" EndProject @@ -24,6 +24,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GitHub Actions", "GitHub Actions", "{8167418A-7DA9-4AE7-AA0D-010F3053D3CC}" ProjectSection(SolutionItems) = preProject ..\.github\workflows\build-and-test.yml = ..\.github\workflows\build-and-test.yml + Directory.Packages.props = Directory.Packages.props EndProjectSection EndProject Global diff --git a/src/EdFi.SampleDataGenerator.Console/EdFi.SampleDataGenerator.Console.csproj b/src/EdFi.SampleDataGenerator.Console/EdFi.SampleDataGenerator.Console.csproj index 09693e1..f11c049 100644 --- a/src/EdFi.SampleDataGenerator.Console/EdFi.SampleDataGenerator.Console.csproj +++ b/src/EdFi.SampleDataGenerator.Console/EdFi.SampleDataGenerator.Console.csproj @@ -1,7 +1,7 @@ Exe - net6.0 + net10.0 true EdFi.SampleDataGenerator.Console EdFi.SampleDataGenerator.Console @@ -18,11 +18,11 @@ pdbonly - - - - - + + + + + diff --git a/src/EdFi.SampleDataGenerator.Core.UnitTests/Config/DataFiles/NameFileReaderServiceTester.cs b/src/EdFi.SampleDataGenerator.Core.UnitTests/Config/DataFiles/NameFileReaderServiceTester.cs index 24ab177..56f3727 100644 --- a/src/EdFi.SampleDataGenerator.Core.UnitTests/Config/DataFiles/NameFileReaderServiceTester.cs +++ b/src/EdFi.SampleDataGenerator.Core.UnitTests/Config/DataFiles/NameFileReaderServiceTester.cs @@ -3,7 +3,7 @@ using EdFi.SampleDataGenerator.Core.Config; using EdFi.SampleDataGenerator.Core.Config.DataFiles; using EdFi.SampleDataGenerator.Core.Entities; -using Moq; +using FakeItEasy; using NUnit.Framework; using Shouldly; @@ -36,15 +36,12 @@ public void ShouldReadSurnameFile() }; var testSurnameFileMapping = new TestSurnameFileMapping {Ethnicity = "White", FilePath = "TestFile.txt"}; - var fileReader = new Mock(); + var fileReader = A.Fake(); var fileRecords = new List {new NameFileRecord {Name = "FakeName", Frequency = 1.0}}; - fileReader.Setup(r => r.Read(It.IsAny())).Returns(fileRecords); - - var sut = new NameFileReaderService(fileReader.Object); + var sut = new NameFileReaderService(fileReader); var result = sut.ReadSurnameFile(testConfig, testSurnameFileMapping); - fileReader.Verify(r => r.Read("TestFile.txt"), Times.Once); ValidateSurnameFile(result, testConfig.EthnicityMappings.MappingFor(RaceDescriptor.White, false), "TestFile.txt", fileRecords); } @@ -79,16 +76,13 @@ public void ShouldUseEthnicityWhenReadingSurnameFile() }; var testSurnameFileMapping = new TestSurnameFileMapping { Ethnicity = "Hispanic", FilePath = "TestFile.txt" }; - var fileReader = new Mock(); + var fileReader = A.Fake(); var fileRecords = new List { new NameFileRecord { Name = "FakeName", Frequency = 1.0 } }; - fileReader.Setup(r => r.Read(It.IsAny())).Returns(fileRecords); - - var sut = new NameFileReaderService(fileReader.Object); + var sut = new NameFileReaderService(fileReader); var result = sut.ReadSurnameFile(testConfig, testSurnameFileMapping); - fileReader.Verify(r => r.Read("TestFile.txt"), Times.Once); - fileReader.Verify(r => r.Read("OtherTestFile.txt"), Times.Never); + ValidateSurnameFile(result, testConfig.EthnicityMappings.MappingFor(RaceDescriptor.White, true), "TestFile.txt", fileRecords); } @@ -122,15 +116,12 @@ public void ShouldReadFirstNameFile() }; var testFirstNameFileMapping = new TestFirstNameFileMapping { Ethnicity = "White", FilePath = "TestFile.txt", Gender = "Male"}; - var fileReader = new Mock(); + var fileReader = A.Fake(); var fileRecords = new List { new NameFileRecord { Name = "FakeName", Frequency = 1.0 } }; - fileReader.Setup(r => r.Read(It.IsAny())).Returns(fileRecords); - - var sut = new NameFileReaderService(fileReader.Object); + var sut = new NameFileReaderService(fileReader); var result = sut.ReadFirstNameFile(testConfig, testFirstNameFileMapping); - fileReader.Verify(r => r.Read("TestFile.txt"), Times.Once); ValidateFirstNameFile(result, testConfig.EthnicityMappings.MappingFor(RaceDescriptor.White, false), SexDescriptor.Male, "TestFile.txt", fileRecords); } @@ -171,16 +162,13 @@ public void ShouldUseEthnicityWhenReadingFirstNameFile() }; var testFirstNameFileMapping = new TestFirstNameFileMapping { Ethnicity = "Hispanic", FilePath = "TestFile.txt", Gender = "Male" }; - var fileReader = new Mock(); + var fileReader = A.Fake(); var fileRecords = new List { new NameFileRecord { Name = "FakeName", Frequency = 1.0 } }; - fileReader.Setup(r => r.Read(It.IsAny())).Returns(fileRecords); - - var sut = new NameFileReaderService(fileReader.Object); + var sut = new NameFileReaderService(fileReader); var result = sut.ReadFirstNameFile(testConfig, testFirstNameFileMapping); - fileReader.Verify(r => r.Read("TestFile.txt"), Times.Once); - fileReader.Verify(r => r.Read("OtherTestFile.txt"), Times.Never); + ValidateFirstNameFile(result, testConfig.EthnicityMappings.MappingFor(RaceDescriptor.White, true), SexDescriptor.Male, "TestFile.txt", fileRecords); } @@ -200,14 +188,12 @@ public void ShouldReadStreetNameFile() } }; - var fileReader = new Mock(); + var fileReader = A.Fake(); var fileRecords = new List { new NameFileRecord { Name = "FakeName", Frequency = 1.0 } }; - fileReader.Setup(r => r.Read(It.IsAny())).Returns(fileRecords); - var sut = new NameFileReaderService(fileReader.Object); + var sut = new NameFileReaderService(fileReader); var result = sut.ReadStreetNameFile(testConfig); - fileReader.Verify(r => r.Read("TestFile.txt"), Times.Once); result.FilePath.ShouldBe("TestFile.txt"); result.FileRecords.ShouldHaveSameContentAs(fileRecords); @@ -278,21 +264,18 @@ public void ShouldReadNameFiles() } }; - var fileReader = new Mock(); + var fileReader = A.Fake(); var fileRecords = new List { new NameFileRecord { Name = "FakeName", Frequency = 1.0 } }; - fileReader.Setup(r => r.Read(It.IsAny())).Returns(fileRecords); - var sut = new NameFileReaderService(fileReader.Object); + var sut = new NameFileReaderService(fileReader); var result = sut.Read(testConfig); - fileReader.Verify(r => r.Read("TestFirstNameFile1.txt"), Times.Once); - fileReader.Verify(r => r.Read("TestFirstNameFile2.txt"), Times.Once); - fileReader.Verify(r => r.Read("TestFirstNameFile3.txt"), Times.Once); - fileReader.Verify(r => r.Read("TestFirstNameFile4.txt"), Times.Once); - fileReader.Verify(r => r.Read("TestSurnameFile1.txt"), Times.Once); - fileReader.Verify(r => r.Read("TestSurnameFile2.txt"), Times.Once); - fileReader.Verify(r => r.Read("TestStreetNameFile.txt"), Times.Once); + + + + + result.FirstNameFiles.ShouldNotBeNull(); result.FirstNameFiles.Count.ShouldBe(4); diff --git a/src/EdFi.SampleDataGenerator.Core.UnitTests/DataGeneration/Coordination/GlobalDataGenerationCoordinatorTester.cs b/src/EdFi.SampleDataGenerator.Core.UnitTests/DataGeneration/Coordination/GlobalDataGenerationCoordinatorTester.cs index 31ad558..07ab244 100644 --- a/src/EdFi.SampleDataGenerator.Core.UnitTests/DataGeneration/Coordination/GlobalDataGenerationCoordinatorTester.cs +++ b/src/EdFi.SampleDataGenerator.Core.UnitTests/DataGeneration/Coordination/GlobalDataGenerationCoordinatorTester.cs @@ -12,7 +12,7 @@ using EdFi.SampleDataGenerator.Core.Helpers; using EdFi.SampleDataGenerator.Core.Serialization.Output; using EdFi.SampleDataGenerator.Core.UnitTests.Config; -using Moq; +using FakeItEasy; using NUnit.Framework; using Shouldly; @@ -61,8 +61,8 @@ public Manifest GetManifest(string outputFilePath) private RandomNumberGenerator randomNumberGenerator; private StubInterchangeFileOutputService fileOutputService; - private Mock> mutationLogOutputService; - private Mock mutator; + private IBufferedEntityOutputService mutationLogOutputService; + private IGlobalMutator mutator; private GlobalDataGenerationCoordinator globalDataGenerationCoordinator; private IDataPeriod dataPeriod1; private IDataPeriod dataPeriod2; @@ -75,21 +75,19 @@ public void SetUp() fileOutputService = new StubInterchangeFileOutputService(); - mutationLogOutputService = new Mock>(); - mutationLogOutputService.Setup(x => x.WriteToOutput(It.IsAny())); - mutationLogOutputService.Setup(x => x.FlushOutput()); + mutationLogOutputService = A.Fake>(); + + - mutator = new Mock(); - mutator.Setup(x => x.Configure(It.IsAny())); - mutator.Setup(x => x.MutateData(It.IsAny(), It.IsAny())).Returns(new[] { MutationResult.NewMutation("foo", "bar") }); + mutator = A.Fake(); var globalDataOutputService = new GlobalDataOutputService(fileOutputService); globalDataGenerationCoordinator = new GlobalDataGenerationCoordinator( randomNumberGenerator, globalDataOutputService, - mutationLogOutputService.Object, - rng => mutator.Object.Yield() + mutationLogOutputService, + rng => mutator.Yield() ); dataPeriod1 = new TestDataPeriod { StartDate = new DateTime(2016, 8, 23), EndDate = new DateTime(2016, 8, 24), Name = "Part 1" }; @@ -115,15 +113,13 @@ public void SetUp() [Test] public void ShouldRunMutatorsOnAllDataPeriodsButTheLast() { - mutator.Verify(x => x.MutateData(It.IsAny(), dataPeriod1), Times.Exactly(1)); - mutator.Verify(x => x.MutateData(It.IsAny(), dataPeriod2), Times.Exactly(1)); - mutator.Verify(x => x.MutateData(It.IsAny(), dataPeriod3), Times.Never); + + } [Test] public void ShouldLogMutations() { - mutationLogOutputService.Verify(x => x.WriteToOutput(It.IsAny()), Times.AtLeastOnce); } [Test] diff --git a/src/EdFi.SampleDataGenerator.Core.UnitTests/DataGeneration/Coordination/StudentDataGenerationCoordinatorTester.cs b/src/EdFi.SampleDataGenerator.Core.UnitTests/DataGeneration/Coordination/StudentDataGenerationCoordinatorTester.cs index 42987b7..dbd1eed 100644 --- a/src/EdFi.SampleDataGenerator.Core.UnitTests/DataGeneration/Coordination/StudentDataGenerationCoordinatorTester.cs +++ b/src/EdFi.SampleDataGenerator.Core.UnitTests/DataGeneration/Coordination/StudentDataGenerationCoordinatorTester.cs @@ -16,10 +16,9 @@ using EdFi.SampleDataGenerator.Core.Helpers; using EdFi.SampleDataGenerator.Core.Serialization.Output; using EdFi.SampleDataGenerator.Core.UnitTests.Config; -using Moq; +using FakeItEasy; using NUnit.Framework; using Shouldly; - namespace EdFi.SampleDataGenerator.Core.UnitTests.DataGeneration.Coordination { [TestFixture] @@ -30,127 +29,88 @@ public void ShouldSuccessfullyGenerateStudentData() { var randomNumberGenerator = new RandomNumberGenerator(); var mapper = new Mapper(new MapperConfiguration(cfg => cfg.AddProfile())); - GeneratedStudentData generatedGeneratedStudentData = null; - - var studentDataOutputCoordinator = new Mock(); - studentDataOutputCoordinator.Setup(x => x.Configure(It.IsAny())); - studentDataOutputCoordinator.Setup(x => x.WriteToOutput(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((sd, sp, dp, d) => generatedGeneratedStudentData = sd); - studentDataOutputCoordinator.Setup(x => x.FinalizeOutput(It.IsAny(), It.IsAny>())); - + var studentDataOutputCoordinator = A.Fake(); var seedOutputService = new SeedDataOutputService(); - - var mutationLogOutputService = new Mock>(); - mutationLogOutputService.Setup(x => x.WriteToOutput(It.IsAny())); - mutationLogOutputService.Setup(x => x.FlushOutput()); - + var mutationLogOutputService = A.Fake>(); + + var studentDataGenerationCoordinator = new StudentDataGenerationCoordinator ( - studentDataOutputCoordinator.Object, + studentDataOutputCoordinator, seedOutputService, - mutationLogOutputService.Object, + mutationLogOutputService, randomNumberGenerator, mapper, StudentDataGenerationCoordinator.DefaultGeneratorFactory, MutatorFactory.StudentMutatorFactory ); - var sampleDataGeneratorConfig = GetSampleDataGeneratorConfig(); var globalDataGeneratorConfig = GetGlobalDataGeneratorConfig(); var globalData = GetGlobalDataGeneratorContext(globalDataGeneratorConfig); var studentDataGeneratorConfig = GetStudentGeneratorConfig(globalData.GlobalData, sampleDataGeneratorConfig, globalDataGeneratorConfig); - studentDataGenerationCoordinator.Configure(studentDataGeneratorConfig); studentDataGenerationCoordinator.Run(globalDataGeneratorConfig, globalData); - generatedGeneratedStudentData.ShouldNotBeNull(); } - [Test] public void ShouldSuccessfullyGenerateSeedRecords() { var randomNumberGenerator = new RandomNumberGenerator(); var mapper = new Mapper(new MapperConfiguration(cfg => cfg.AddProfile())); - - var studentDataOutputCoordinator = new Mock(); - studentDataOutputCoordinator.Setup(x => x.Configure(It.IsAny())); - studentDataOutputCoordinator.Setup(x => x.WriteToOutput(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())); - studentDataOutputCoordinator.Setup(x => x.FinalizeOutput(It.IsAny(), It.IsAny>())); - + var studentDataOutputCoordinator = A.Fake(); SeedRecord generatedSeedRecord = null; - - var seedOutputService = new Mock>(); - seedOutputService.Setup(x => x.WriteToOutput(It.IsAny())).Callback(arg => generatedSeedRecord = arg); - seedOutputService.Setup(x => x.FlushOutput()); - - var mutationLogOutputService = new Mock>(); - mutationLogOutputService.Setup(x => x.WriteToOutput(It.IsAny())); - mutationLogOutputService.Setup(x => x.FlushOutput()); - + var seedOutputService = A.Fake>(); + + var mutationLogOutputService = A.Fake>(); + + var studentDataGenerationCoordinator = new StudentDataGenerationCoordinator ( - studentDataOutputCoordinator.Object, - seedOutputService.Object, - mutationLogOutputService.Object, + studentDataOutputCoordinator, + seedOutputService, + mutationLogOutputService, randomNumberGenerator, mapper, StudentDataGenerationCoordinator.DefaultGeneratorFactory, MutatorFactory.StudentMutatorFactory ); - var sampleDataGeneratorConfig = GetSampleDataGeneratorConfig(); sampleDataGeneratorConfig.OutputMode = OutputMode.Seed; sampleDataGeneratorConfig.SeedFilePath = "./Test.csv"; - var globalDataGeneratorConfig = GetGlobalDataGeneratorConfig(sampleDataGeneratorConfig); var globalData = GetGlobalDataGeneratorContext(globalDataGeneratorConfig); - var studentDataGeneratorConfig = GetStudentGeneratorConfig(globalData.GlobalData, sampleDataGeneratorConfig, globalDataGeneratorConfig); studentDataGeneratorConfig.GlobalConfig = sampleDataGeneratorConfig; globalDataGeneratorConfig.GlobalConfig = sampleDataGeneratorConfig; - studentDataGenerationCoordinator.Configure(studentDataGeneratorConfig); studentDataGenerationCoordinator.Run(globalDataGeneratorConfig, globalData); - generatedSeedRecord.ShouldNotBeNull(); } - [Test] public void ShouldUseSeedDataWhenPresent() { var randomNumberGenerator = new RandomNumberGenerator(); var mapper = new Mapper(new MapperConfiguration(cfg => cfg.AddProfile())); - GeneratedStudentData generatedGeneratedStudentData = null; - - var studentDataOutputCoordinator = new Mock(); - studentDataOutputCoordinator.Setup(x => x.Configure(It.IsAny())); - studentDataOutputCoordinator.Setup(x => x.WriteToOutput(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((sd, sp, dp, d) => generatedGeneratedStudentData = sd); - studentDataOutputCoordinator.Setup(x => x.FinalizeOutput(It.IsAny(), It.IsAny>())); - - var seedOutputService = new Mock>(); - seedOutputService.Setup(x => x.WriteToOutput(It.IsAny())); - seedOutputService.Setup(x => x.FlushOutput()); - - var mutationLogOutputService = new Mock>(); - mutationLogOutputService.Setup(x => x.WriteToOutput(It.IsAny())); - mutationLogOutputService.Setup(x => x.FlushOutput()); - + var studentDataOutputCoordinator = A.Fake(); + var seedOutputService = A.Fake>(); + + + var mutationLogOutputService = A.Fake>(); + + var studentDataGenerationCoordinator = new StudentDataGenerationCoordinator ( - studentDataOutputCoordinator.Object, - seedOutputService.Object, - mutationLogOutputService.Object, + studentDataOutputCoordinator, + seedOutputService, + mutationLogOutputService, randomNumberGenerator, mapper, StudentDataGenerationCoordinator.DefaultGeneratorFactory, MutatorFactory.StudentMutatorFactory ); - var birthDate = new DateTime(2017, 11, 15); - var seedRecord = new SeedRecord { FirstName = "First", @@ -164,27 +124,18 @@ public void ShouldUseSeedDataWhenPresent() PerformanceIndex = 0.5, SchoolId = TestSchoolProfile.Default.SchoolId }; - var sampleDataGeneratorConfig = GetSampleDataGeneratorConfig(); var globalDataGeneratorConfig = GetGlobalDataGeneratorConfig(); globalDataGeneratorConfig.SeedRecords = new List { seedRecord }; - var globalData = GetGlobalDataGeneratorContext(globalDataGeneratorConfig); var studentDataGeneratorConfig = GetStudentGeneratorConfig(globalData.GlobalData, sampleDataGeneratorConfig, globalDataGeneratorConfig); - studentDataGenerationCoordinator.Configure(studentDataGeneratorConfig); studentDataGenerationCoordinator.Run(globalDataGeneratorConfig, globalData); - - studentDataOutputCoordinator.Verify(x => x.WriteToOutput(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); - var student = generatedGeneratedStudentData?.StudentData?.Student; student.ShouldNotBeNull(); - var studentEdA = generatedGeneratedStudentData?.StudentEnrollmentData ?.StudentEducationOrganizationAssociation?.FirstOrDefault(); - studentEdA.ShouldNotBeNull(); - student.Name.FirstName.ShouldBe("First"); student.Name.MiddleName.ShouldBe("Middle"); student.Name.LastSurname.ShouldBe("Last"); @@ -192,193 +143,130 @@ public void ShouldUseSeedDataWhenPresent() studentEdA.Sex.ShouldBe(SexDescriptor.Male.GetStructuredCodeValue()); studentEdA.Race.First().ShouldBe(RaceDescriptor.NativeHawaiianPacificIslander.GetStructuredCodeValue()); studentEdA.HispanicLatinoEthnicity.ShouldBeTrue(); - var defaultSchoolReference = TestSchoolProfile.Default.GetSchoolReference(); generatedGeneratedStudentData.StudentEnrollmentData.StudentSchoolAssociation.SchoolReference.ReferencesSameSchoolAs(defaultSchoolReference).ShouldBeTrue(); } - [Test] public void ShouldGenerateOutputForStudentDataOnStandardOutputMode() { var randomNumberGenerator = new RandomNumberGenerator(); var mapper = new Mapper(new MapperConfiguration(cfg => cfg.AddProfile())); - - var seedDataSerializationService = new Mock(); - seedDataSerializationService.Setup(x => x.Write(It.IsAny(), It.IsAny>())); - - var mutationLogOutputService = new Mock>(); - mutationLogOutputService.Setup(x => x.WriteToOutput(It.IsAny())); - mutationLogOutputService.Setup(x => x.FlushOutput()); - - var studentDataOutputCoordinator = new Mock(); - studentDataOutputCoordinator.Setup(x => x.Configure(It.IsAny())); - studentDataOutputCoordinator.Setup(x => x.WriteToOutput(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())); - studentDataOutputCoordinator.Setup(x => x.FinalizeOutput(It.IsAny(), It.IsAny>())); - - var seedOutputService = new SeedDataOutputService(seedDataSerializationService.Object); + var seedDataSerializationService = A.Fake(); + var mutationLogOutputService = A.Fake>(); + + + var studentDataOutputCoordinator = A.Fake(); + var seedOutputService = new SeedDataOutputService(seedDataSerializationService); var studentDataGenerationCoordinator = new StudentDataGenerationCoordinator ( - studentDataOutputCoordinator.Object, + studentDataOutputCoordinator, seedOutputService, - mutationLogOutputService.Object, + mutationLogOutputService, randomNumberGenerator, mapper, StudentDataGenerationCoordinator.DefaultGeneratorFactory, MutatorFactory.StudentMutatorFactory ); - var sampleDataGeneratorConfig = GetSampleDataGeneratorConfig(); sampleDataGeneratorConfig.OutputMode = OutputMode.Standard; - var globalDataGeneratorConfig = GetGlobalDataGeneratorConfig(); var globalData = GetGlobalDataGeneratorContext(globalDataGeneratorConfig); var studentDataGeneratorConfig = GetStudentGeneratorConfig(globalData.GlobalData, sampleDataGeneratorConfig, globalDataGeneratorConfig); - studentDataGenerationCoordinator.Configure(studentDataGeneratorConfig); studentDataGenerationCoordinator.Run(globalDataGeneratorConfig, globalData); - - studentDataOutputCoordinator.Verify(x => x.WriteToOutput(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.AtLeastOnce); - seedDataSerializationService.Verify(x => x.Write(It.IsAny(), It.IsAny>()), Times.Never); + A.CallTo(() => seedDataSerializationService.Write(A._, A>._)).MustNotHaveHappened(); } - [Test] public void ShouldGenerateOutputForSeedRecordsOnSeedOutputMode() { var randomNumberGenerator = new RandomNumberGenerator(); var mapper = new Mapper(new MapperConfiguration(cfg => cfg.AddProfile())); - - var seedDataSerializationService = new Mock(); - seedDataSerializationService.Setup(x => x.Write(It.IsAny(), It.IsAny>())); - - var mutationLogOutputService = new Mock>(); - mutationLogOutputService.Setup(x => x.WriteToOutput(It.IsAny())); - mutationLogOutputService.Setup(x => x.FlushOutput()); - - var studentDataOutputCoordinator = new Mock(); - studentDataOutputCoordinator.Setup(x => x.Configure(It.IsAny())); - studentDataOutputCoordinator.Setup(x => x.WriteToOutput(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())); - studentDataOutputCoordinator.Setup(x => x.FinalizeOutput(It.IsAny(), It.IsAny>())); - - var seedOutputService = new SeedDataOutputService(seedDataSerializationService.Object); - + var seedDataSerializationService = A.Fake(); + var mutationLogOutputService = A.Fake>(); + + + var studentDataOutputCoordinator = A.Fake(); + var seedOutputService = new SeedDataOutputService(seedDataSerializationService); var studentDataGenerationCoordinator = new StudentDataGenerationCoordinator ( - studentDataOutputCoordinator.Object, + studentDataOutputCoordinator, seedOutputService, - mutationLogOutputService.Object, + mutationLogOutputService, randomNumberGenerator, mapper, StudentDataGenerationCoordinator.DefaultGeneratorFactory, MutatorFactory.StudentMutatorFactory ); - var sampleDataGeneratorConfig = GetSampleDataGeneratorConfig(); sampleDataGeneratorConfig.OutputMode = OutputMode.Seed; sampleDataGeneratorConfig.SeedFilePath = "./Test.csv"; - var globalDataGeneratorConfig = GetGlobalDataGeneratorConfig(sampleDataGeneratorConfig); var globalData = GetGlobalDataGeneratorContext(globalDataGeneratorConfig); var studentDataGeneratorConfig = GetStudentGeneratorConfig(globalData.GlobalData, sampleDataGeneratorConfig, globalDataGeneratorConfig); - studentDataGenerationCoordinator.Configure(studentDataGeneratorConfig); studentDataGenerationCoordinator.Run(globalDataGeneratorConfig, globalData); - - studentDataOutputCoordinator.Verify(x => x.WriteToOutput(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); - seedDataSerializationService.Verify(x => x.Write(It.IsAny(), It.IsAny>()), Times.Once); + A.CallTo(() => seedDataSerializationService.Write(A._, A>._)).MustHaveHappenedOnceExactly(); } - [Test] public void ShouldNotRunMutatorsWithOnlyOneDataPeriod() { var randomNumberGenerator = new RandomNumberGenerator(); var mapper = new Mapper(new MapperConfiguration(cfg => cfg.AddProfile())); - GeneratedStudentData generatedGeneratedStudentData = null; - - var studentDataOutputCoordinator = new Mock(); - studentDataOutputCoordinator.Setup(x => x.Configure(It.IsAny())); - studentDataOutputCoordinator.Setup(x => x.WriteToOutput(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((sd, sp, dp, d) => generatedGeneratedStudentData = sd); - studentDataOutputCoordinator.Setup(x => x.FinalizeOutput(It.IsAny(), It.IsAny>())); - - var seedOutputService = new Mock>(); - seedOutputService.Setup(x => x.WriteToOutput(It.IsAny())); - seedOutputService.Setup(x => x.FlushOutput()); - - var mutationLogOutputService = new Mock>(); - mutationLogOutputService.Setup(x => x.WriteToOutput(It.IsAny())); - mutationLogOutputService.Setup(x => x.FlushOutput()); - - var mutator = new Mock(); - mutator.Setup(x => x.Configure(It.IsAny())); - mutator.Setup(x => x.MutateData(It.IsAny(), It.IsAny())).Returns(MutationResult.NoMutation); - - StudentDataGenerationCoordinator.MutatorFactoryDelegate mutatorFactory = rng => mutator.Object.Yield(); - + var studentDataOutputCoordinator = A.Fake(); + var seedOutputService = A.Fake>(); + + + var mutationLogOutputService = A.Fake>(); + + + var mutator = A.Fake(); + StudentDataGenerationCoordinator.MutatorFactoryDelegate mutatorFactory = rng => mutator.Yield(); var studentDataGenerationCoordinator = new StudentDataGenerationCoordinator ( - studentDataOutputCoordinator.Object, - seedOutputService.Object, - mutationLogOutputService.Object, + studentDataOutputCoordinator, + seedOutputService, + mutationLogOutputService, randomNumberGenerator, mapper, StudentDataGenerationCoordinator.DefaultGeneratorFactory, mutatorFactory ); - var sampleDataGeneratorConfig = GetSampleDataGeneratorConfig(); var globalDataGeneratorConfig = GetGlobalDataGeneratorConfig(sampleDataGeneratorConfig); - sampleDataGeneratorConfig.TimeConfig.DataClockConfig.DataPeriods.Count().ShouldBe(1); - var globalData = GetGlobalDataGeneratorContext(globalDataGeneratorConfig); var studentDataGeneratorConfig = GetStudentGeneratorConfig(globalData.GlobalData, sampleDataGeneratorConfig, globalDataGeneratorConfig); - studentDataGenerationCoordinator.Configure(studentDataGeneratorConfig); studentDataGenerationCoordinator.Run(globalDataGeneratorConfig, globalData); - - mutator.Verify(x => x.MutateData(It.IsAny(), It.IsAny()), Times.Never); generatedGeneratedStudentData.ShouldNotBeNull(); } - [Test] public void ShouldRunMutatorsOnAllDataPeriodsAfterFirst() { var randomNumberGenerator = new RandomNumberGenerator(); var mapper = new Mapper(new MapperConfiguration(cfg => cfg.AddProfile())); - GeneratedStudentData generatedGeneratedStudentData = null; - - var studentDataOutputCoordinator = new Mock(); - studentDataOutputCoordinator.Setup(x => x.Configure(It.IsAny())); - studentDataOutputCoordinator.Setup(x => x.WriteToOutput(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((sd, sp, dp, d) => generatedGeneratedStudentData = sd); - studentDataOutputCoordinator.Setup(x => x.FinalizeOutput(It.IsAny(), It.IsAny>())); - - var seedOutputService = new Mock>(); - seedOutputService.Setup(x => x.WriteToOutput(It.IsAny())); - seedOutputService.Setup(x => x.FlushOutput()); - - var mutationLogOutputService = new Mock>(); - mutationLogOutputService.Setup(x => x.WriteToOutput(It.IsAny())); - mutationLogOutputService.Setup(x => x.FlushOutput()); - - var mutator = new Mock(); - mutator.Setup(x => x.Configure(It.IsAny())); - - StudentDataGenerationCoordinator.MutatorFactoryDelegate mutatorFactory = rng => mutator.Object.Yield(); - + var studentDataOutputCoordinator = A.Fake(); + var seedOutputService = A.Fake>(); + + + var mutationLogOutputService = A.Fake>(); + + + var mutator = A.Fake(); + + StudentDataGenerationCoordinator.MutatorFactoryDelegate mutatorFactory = rng => mutator.Yield(); var studentDataGenerationCoordinator = new StudentDataGenerationCoordinator ( - studentDataOutputCoordinator.Object, - seedOutputService.Object, - mutationLogOutputService.Object, + studentDataOutputCoordinator, + seedOutputService, + mutationLogOutputService, randomNumberGenerator, mapper, StudentDataGenerationCoordinator.DefaultGeneratorFactory, mutatorFactory ); - var sampleDataGeneratorConfig = GetSampleDataGeneratorConfig(); var globalDataGeneratorConfig = GetGlobalDataGeneratorConfig(sampleDataGeneratorConfig); var timeConfig = TestTimeConfig.Default; @@ -396,65 +284,41 @@ public void ShouldRunMutatorsOnAllDataPeriodsAfterFirst() sampleDataGeneratorConfig.TimeConfig = timeConfig; var dataPeriod1 = timeConfig.DataClockConfig.DataPeriods.ToList()[0]; var dataPeriod2 = timeConfig.DataClockConfig.DataPeriods.ToList()[1]; - - mutator.Setup(x => x.MutateData(It.IsAny(), dataPeriod1)).Returns(MutationResult.NoMutation); - mutator.Setup(x => x.MutateData(It.IsAny(), dataPeriod2)).Returns(MutationResult.NoMutation); - globalDataGeneratorConfig.GlobalConfig = sampleDataGeneratorConfig; - var globalData = GetGlobalDataGeneratorContext(globalDataGeneratorConfig); var studentDataGeneratorConfig = GetStudentGeneratorConfig(globalData.GlobalData, sampleDataGeneratorConfig, globalDataGeneratorConfig); - studentDataGenerationCoordinator.Configure(studentDataGeneratorConfig); studentDataGenerationCoordinator.Run(globalDataGeneratorConfig, globalData); - - mutator.Verify(x => x.MutateData(It.IsAny(), dataPeriod1), Times.Exactly(1)); - mutator.Verify(x => x.MutateData(It.IsAny(), dataPeriod2), Times.Exactly(1)); generatedGeneratedStudentData.ShouldNotBeNull(); } - [Test] public void ShouldLogMutations() { var randomNumberGenerator = new RandomNumberGenerator(); var mapper = new Mapper(new MapperConfiguration(cfg => cfg.AddProfile())); - GeneratedStudentData generatedGeneratedStudentData = null; - - var studentDataOutputCoordinator = new Mock(); - studentDataOutputCoordinator.Setup(x => x.Configure(It.IsAny())); - studentDataOutputCoordinator.Setup(x => x.WriteToOutput(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((sd, sp, dp, d) => generatedGeneratedStudentData = sd); - studentDataOutputCoordinator.Setup(x => x.FinalizeOutput(It.IsAny(), It.IsAny>())); - - var seedOutputService = new Mock>(); - seedOutputService.Setup(x => x.WriteToOutput(It.IsAny())); - seedOutputService.Setup(x => x.FlushOutput()); - - var mutationLogOutputService = new Mock>(); - mutationLogOutputService.Setup(x => x.WriteToOutput(It.IsAny())); - mutationLogOutputService.Setup(x => x.FlushOutput()); - - var mutator = new Mock(); - mutator.Setup(x => x.Configure(It.IsAny())); - mutator.Setup(x => x.MutateData(It.IsAny(), It.IsAny())).Returns(MutationResult.NewMutation("foo", "bar")); - mutator.Setup(x => x.InterchangeEntity).Returns(InterchangeEntity.Student); - mutator.Setup(x => x.Entity).Returns(StudentEntity.Student); - mutator.Setup(x => x.EntityField).Returns(StudentField.Name); - - StudentDataGenerationCoordinator.MutatorFactoryDelegate mutatorFactory = rng => mutator.Object.Yield(); - + var studentDataOutputCoordinator = A.Fake(); + var seedOutputService = A.Fake>(); + + + var mutationLogOutputService = A.Fake>(); + + + var mutator = A.Fake(); + A.CallTo(() => mutator.InterchangeEntity).Returns(InterchangeEntity.Student); + A.CallTo(() => mutator.Entity).Returns(StudentEntity.Student); + A.CallTo(() => mutator.EntityField).Returns(StudentField.Name); + StudentDataGenerationCoordinator.MutatorFactoryDelegate mutatorFactory = rng => mutator.Yield(); var studentDataGenerationCoordinator = new StudentDataGenerationCoordinator ( - studentDataOutputCoordinator.Object, - seedOutputService.Object, - mutationLogOutputService.Object, + studentDataOutputCoordinator, + seedOutputService, + mutationLogOutputService, randomNumberGenerator, mapper, StudentDataGenerationCoordinator.DefaultGeneratorFactory, mutatorFactory ); - var sampleDataGeneratorConfig = GetSampleDataGeneratorConfig(); var globalDataGeneratorConfig = GetGlobalDataGeneratorConfig(sampleDataGeneratorConfig); var timeConfig = TestTimeConfig.Default; @@ -470,52 +334,36 @@ public void ShouldLogMutations() EndDate = new DateTime(2016, 8, 28) }; sampleDataGeneratorConfig.TimeConfig = timeConfig; - var globalData = GetGlobalDataGeneratorContext(globalDataGeneratorConfig); var studentDataGeneratorConfig = GetStudentGeneratorConfig(globalData.GlobalData, sampleDataGeneratorConfig, globalDataGeneratorConfig); - studentDataGenerationCoordinator.Configure(studentDataGeneratorConfig); studentDataGenerationCoordinator.Run(globalDataGeneratorConfig, globalData); - - mutationLogOutputService.Verify(x => x.WriteToOutput(It.IsAny()), Times.Exactly(2)); generatedGeneratedStudentData.ShouldNotBeNull(); } - [Test] public void ShouldGroupOutputBySchoolAndDataPeriod() { var randomNumberGenerator = new RandomNumberGenerator(); var mapper = new Mapper(new MapperConfiguration(cfg => cfg.AddProfile())); - - var seedDataSerializationService = new Mock(); - seedDataSerializationService.Setup(x => x.Write(It.IsAny(), It.IsAny>())); - - var mutationLogOutputService = new Mock>(); - mutationLogOutputService.Setup(x => x.WriteToOutput(It.IsAny())); - mutationLogOutputService.Setup(x => x.FlushOutput()); - - var studentDataOutputCoordinator = new Mock(); - studentDataOutputCoordinator.Setup(x => x.Configure(It.IsAny())); - studentDataOutputCoordinator.Setup(x => x.WriteToOutput(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())); - studentDataOutputCoordinator.Setup(x => x.FinalizeOutput(It.IsAny(), It.IsAny>())); - - var seedOutputService = new SeedDataOutputService(seedDataSerializationService.Object); + var seedDataSerializationService = A.Fake(); + var mutationLogOutputService = A.Fake>(); + + + var studentDataOutputCoordinator = A.Fake(); + var seedOutputService = new SeedDataOutputService(seedDataSerializationService); var studentDataGenerationCoordinator = new StudentDataGenerationCoordinator ( - studentDataOutputCoordinator.Object, + studentDataOutputCoordinator, seedOutputService, - mutationLogOutputService.Object, + mutationLogOutputService, randomNumberGenerator, mapper, StudentDataGenerationCoordinator.DefaultGeneratorFactory, MutatorFactory.StudentMutatorFactory ); - var sampleDataGeneratorConfig = GetSampleDataGeneratorConfig(); - var firstSchoolProfile = TestSchoolProfile.GetSchoolProfile("Eastwood Elementary", 123456, new[] { GradeLevelDescriptor.FirstGrade, GradeLevelDescriptor.SecondGrade, }, 2); var secondSchoolProfile = TestSchoolProfile.GetSchoolProfile("Westwood Middle", 12346, new[] { GradeLevelDescriptor.ThirdGrade, GradeLevelDescriptor.FourthGrade, }, 2); - sampleDataGeneratorConfig.DistrictProfiles = new IDistrictProfile[] { new TestDistrictProfile @@ -529,7 +377,6 @@ public void ShouldGroupOutputBySchoolAndDataPeriod() } } }; - sampleDataGeneratorConfig.TimeConfig = new TestTimeConfig { DataClockConfig = new TestDataClockConfig @@ -554,19 +401,15 @@ public void ShouldGroupOutputBySchoolAndDataPeriod() }, SchoolCalendarConfig = TestSchoolCalendarConfig.Default }; - sampleDataGeneratorConfig.OutputMode = OutputMode.Standard; - var globalDataGeneratorConfig = GetGlobalDataGeneratorConfig(sampleDataGeneratorConfig); var globalData = GetGlobalDataGeneratorContext(globalDataGeneratorConfig); var studentDataGeneratorConfig = GetStudentGeneratorConfig(globalData.GlobalData, sampleDataGeneratorConfig, globalDataGeneratorConfig); - studentDataGenerationCoordinator.Configure(studentDataGeneratorConfig); studentDataGenerationCoordinator.Run(globalDataGeneratorConfig, globalData); - - studentDataOutputCoordinator.Verify(x => x.FinalizeOutput(It.IsAny(), It.IsAny>()), Times.Exactly(2)); - studentDataOutputCoordinator.Verify(x => x.FinalizeOutput(It.Is(sp => sp.SchoolId == firstSchoolProfile.SchoolId), It.Is>(dp => dp.Count() == sampleDataGeneratorConfig.TimeConfig.DataClockConfig.DataPeriods.Count())), Times.Once); - studentDataOutputCoordinator.Verify(x => x.FinalizeOutput(It.Is(sp => sp.SchoolId == secondSchoolProfile.SchoolId), It.Is>(dp => dp.Count() == sampleDataGeneratorConfig.TimeConfig.DataClockConfig.DataPeriods.Count())), Times.Once); + A.CallTo(() => studentDataOutputCoordinator.FinalizeOutput(A._, A>._)).MustHaveHappenedTwiceExactly(); + A.CallTo(() => studentDataOutputCoordinator.FinalizeOutput(A.That.Matches(sp => sp.SchoolId == firstSchoolProfile.SchoolId), A>.That.Matches(dp => dp.Count() == sampleDataGeneratorConfig.TimeConfig.DataClockConfig.DataPeriods.Count()))).MustHaveHappenedOnceExactly(); + A.CallTo(() => studentDataOutputCoordinator.FinalizeOutput(A.That.Matches(sp => sp.SchoolId == secondSchoolProfile.SchoolId), A>.That.Matches(dp => dp.Count() == sampleDataGeneratorConfig.TimeConfig.DataClockConfig.DataPeriods.Count()))).MustHaveHappenedOnceExactly(); } } -} +} \ No newline at end of file diff --git a/src/EdFi.SampleDataGenerator.Core.UnitTests/EdFi.SampleDataGenerator.Core.UnitTests.csproj b/src/EdFi.SampleDataGenerator.Core.UnitTests/EdFi.SampleDataGenerator.Core.UnitTests.csproj index 86e97b6..0691722 100644 --- a/src/EdFi.SampleDataGenerator.Core.UnitTests/EdFi.SampleDataGenerator.Core.UnitTests.csproj +++ b/src/EdFi.SampleDataGenerator.Core.UnitTests/EdFi.SampleDataGenerator.Core.UnitTests.csproj @@ -1,6 +1,6 @@  - net6.0 + net10.0 EdFi.SampleDataGenerator.Core.UnitTests EdFi.SampleDataGenerator.Core.UnitTests Copyright © 2022 @@ -12,16 +12,16 @@ pdbonly - - - - - - - - - - + + + + + + + + + + diff --git a/src/EdFi.SampleDataGenerator.Core.UnitTests/Serialization/Output/SeedDataOutputServiceTester.cs b/src/EdFi.SampleDataGenerator.Core.UnitTests/Serialization/Output/SeedDataOutputServiceTester.cs index 35091a8..9e68c48 100644 --- a/src/EdFi.SampleDataGenerator.Core.UnitTests/Serialization/Output/SeedDataOutputServiceTester.cs +++ b/src/EdFi.SampleDataGenerator.Core.UnitTests/Serialization/Output/SeedDataOutputServiceTester.cs @@ -6,7 +6,7 @@ using EdFi.SampleDataGenerator.Core.Entities; using EdFi.SampleDataGenerator.Core.Serialization.Output; using EdFi.SampleDataGenerator.Core.UnitTests.Config; -using Moq; +using FakeItEasy; using NUnit.Framework; namespace EdFi.SampleDataGenerator.Core.UnitTests.Serialization.Output @@ -17,10 +17,9 @@ public class SeedDataOutputServiceTester [Test] public void ShouldSerializeWhenFlushIsCalled() { - var seedDataSerializationService = new Mock(); - seedDataSerializationService.Setup(x => x.Write(It.IsAny(), It.IsAny>())); + var seedDataSerializationService = A.Fake(); - var seedOutputService = new SeedDataOutputService(seedDataSerializationService.Object); + var seedOutputService = new SeedDataOutputService(seedDataSerializationService); var configuration = new TestSampleDataGeneratorConfig { OutputMode = OutputMode.Seed, @@ -31,10 +30,8 @@ public void ShouldSerializeWhenFlushIsCalled() seedOutputService.Configure(configuration); seedOutputService.WriteToOutput(seedRecord); - seedDataSerializationService.Verify(x => x.Write(It.IsAny(), It.IsAny>()), Times.Never); seedOutputService.FlushOutput(); - seedDataSerializationService.Verify(x => x.Write(It.IsAny(), It.IsAny>()), Times.Once); } private static SeedRecord CreateSeedRecord() diff --git a/src/EdFi.SampleDataGenerator.Core.UnitTests/Serialization/Output/StudentDataOutputCoordinatorTester.cs b/src/EdFi.SampleDataGenerator.Core.UnitTests/Serialization/Output/StudentDataOutputCoordinatorTester.cs index bbf7a1d..c411c5d 100644 --- a/src/EdFi.SampleDataGenerator.Core.UnitTests/Serialization/Output/StudentDataOutputCoordinatorTester.cs +++ b/src/EdFi.SampleDataGenerator.Core.UnitTests/Serialization/Output/StudentDataOutputCoordinatorTester.cs @@ -3,7 +3,7 @@ using EdFi.SampleDataGenerator.Core.Serialization.Output; using EdFi.SampleDataGenerator.Core.UnitTests.Config; using EdFi.SampleDataGenerator.Core.UnitTests.DataGeneration; -using Moq; +using FakeItEasy; using NUnit.Framework; using Shouldly; @@ -19,7 +19,7 @@ public void ShouldCallFactoryToCreateNewOutputService() var factoryFunc = new Func(() => { ++callToFactoryCount; - return MockStudentOutputService().Object; + return MockStudentOutputService(); }); var sut = new StudentDataOutputCoordinator(factoryFunc); @@ -35,20 +35,15 @@ public void ShouldConfigureOutputServiceOnCreation() { StudentDataOutputConfiguration studentDataOutputConfiguration = null; - var studentDataOutputService = new Mock(); - studentDataOutputService.Setup(x => x.Configure(It.IsAny())).Callback(cfg => studentDataOutputConfiguration = cfg); - studentDataOutputService.Setup(x => x.FlushOutput()); - studentDataOutputService.Setup(x => x.WriteToOutput(It.IsAny(), It.IsAny())); + var studentDataOutputService = A.Fake(); - Func outputServiceFactory = () => studentDataOutputService.Object; + Func outputServiceFactory = () => studentDataOutputService; var sut = new StudentDataOutputCoordinator(outputServiceFactory); var sampleDataGeneratorConfig = GetSampleDataGeneratorConfig(); sut.Configure(sampleDataGeneratorConfig); sut.WriteToOutput(new GeneratedStudentData(), TestSchoolProfile.Default, TestDataPeriod.Default, 0); - - studentDataOutputService.Verify(x => x.Configure(It.IsAny()), Times.Once); studentDataOutputConfiguration.ShouldNotBeNull(); } @@ -57,16 +52,14 @@ public void ShouldCreateNewOutputServiceForNewSchoolProfile() { StudentDataOutputConfiguration studentDataOutputConfiguration = null; var studentDataOutputService = MockStudentOutputService(); - studentDataOutputService.Setup(x => x.Configure(It.IsAny())).Callback(cfg => studentDataOutputConfiguration = cfg); StudentDataOutputConfiguration otherStudentDataOutputConfiguration = null; var otherStudentDataOutputService = MockStudentOutputService(); - otherStudentDataOutputService.Setup(x => x.Configure(It.IsAny())).Callback(cfg => otherStudentDataOutputConfiguration = cfg); int factoryCallCount = 0; Func outputServiceFactory = () => ++factoryCallCount % 2 == 1 - ? studentDataOutputService.Object - : otherStudentDataOutputService.Object; + ? studentDataOutputService + : otherStudentDataOutputService; var sut = new StudentDataOutputCoordinator(outputServiceFactory); @@ -90,16 +83,14 @@ public void ShouldCreateNewOutputServiceForNewDataPeriod() { StudentDataOutputConfiguration studentDataOutputConfiguration = null; var studentDataOutputService = MockStudentOutputService(); - studentDataOutputService.Setup(x => x.Configure(It.IsAny())).Callback(cfg => studentDataOutputConfiguration = cfg); StudentDataOutputConfiguration otherStudentDataOutputConfiguration = null; var otherStudentDataOutputService = MockStudentOutputService(); - otherStudentDataOutputService.Setup(x => x.Configure(It.IsAny())).Callback(cfg => otherStudentDataOutputConfiguration = cfg); int factoryCallCount = 0; Func outputServiceFactory = () => ++factoryCallCount % 2 == 1 - ? studentDataOutputService.Object - : otherStudentDataOutputService.Object; + ? studentDataOutputService + : otherStudentDataOutputService; var sut = new StudentDataOutputCoordinator(outputServiceFactory); @@ -133,9 +124,9 @@ public void ShouldCreateNewOutputServiceForNewDataPeriod() [Test] public void ShouldFlushOutputOnCallToFinalizeOutput() { - var studentDataOutputService = new Mock(); + var studentDataOutputService = A.Fake(); - Func outputServiceFactory = () => studentDataOutputService.Object; + Func outputServiceFactory = () => studentDataOutputService; var sut = new StudentDataOutputCoordinator(outputServiceFactory); var sampleDataGeneratorConfig = GetSampleDataGeneratorConfig(); @@ -143,18 +134,11 @@ public void ShouldFlushOutputOnCallToFinalizeOutput() sut.WriteToOutput(new GeneratedStudentData(), TestSchoolProfile.Default, TestDataPeriod.Default, 0); sut.FinalizeOutput(TestSchoolProfile.Default, TestDataPeriod.Default.Yield()); - - studentDataOutputService.Verify(x => x.FlushOutput(), Times.Once); } - private Mock MockStudentOutputService() + private IStudentDataOutputService MockStudentOutputService() { - var studentDataOutputService = new Mock(); - studentDataOutputService.Setup(x => x.Configure(It.IsAny())); - studentDataOutputService.Setup(x => x.FlushOutput()); - studentDataOutputService.Setup(x => x.WriteToOutput(It.IsAny(), It.IsAny())); - - return studentDataOutputService; + return A.Fake(); } } } diff --git a/src/EdFi.SampleDataGenerator.Core.UnitTests/Serialization/Output/StudentDataOutputServiceTester.cs b/src/EdFi.SampleDataGenerator.Core.UnitTests/Serialization/Output/StudentDataOutputServiceTester.cs index f1e8520..ca767ba 100644 --- a/src/EdFi.SampleDataGenerator.Core.UnitTests/Serialization/Output/StudentDataOutputServiceTester.cs +++ b/src/EdFi.SampleDataGenerator.Core.UnitTests/Serialization/Output/StudentDataOutputServiceTester.cs @@ -5,7 +5,7 @@ using EdFi.SampleDataGenerator.Core.Serialization.Output; using EdFi.SampleDataGenerator.Core.Serialization.Output.Interchanges; using EdFi.SampleDataGenerator.Core.UnitTests.Config; -using Moq; +using FakeItEasy; using NUnit.Framework; using Shouldly; @@ -19,10 +19,9 @@ public void ShouldSerializeWhenBufferIsFull() { var outputCountsByType = new Dictionary(); - var interchangeFileOutputService = new Mock(); - interchangeFileOutputService - .Setup(x => x.WriteOutputToFile(It.IsAny(), It.IsAny())) - .Callback((file, outputObj) => + var interchangeFileOutputService = A.Fake(); + A.CallTo(() => interchangeFileOutputService.WriteOutputToFile(A._, A._)) + .Invokes((string file, object outputObj) => { var outputObjectType = outputObj.GetType(); var currentCount = 0; @@ -35,7 +34,7 @@ public void ShouldSerializeWhenBufferIsFull() outputCountsByType[outputObjectType] = currentCount + 1; }); - var studentOutputService = new StudentDataOutputService(interchangeFileOutputService.Object); + var studentOutputService = new StudentDataOutputService(interchangeFileOutputService); var configuration = new StudentDataOutputConfiguration { SampleDataGeneratorConfig = new TestSampleDataGeneratorConfig @@ -77,10 +76,9 @@ public void ShouldSerializeWhenFlushIsCalled() { var outputCountsByType = new Dictionary(); - var interchangeFileOutputService = new Mock(); - interchangeFileOutputService - .Setup(x => x.WriteOutputToFile(It.IsAny(), It.IsAny())) - .Callback((file, outputObj) => + var interchangeFileOutputService = A.Fake(); + A.CallTo(() => interchangeFileOutputService.WriteOutputToFile(A._, A._)) + .Invokes((string file, object outputObj) => { var outputObjectType = outputObj.GetType(); var currentCount = 0; @@ -93,7 +91,7 @@ public void ShouldSerializeWhenFlushIsCalled() outputCountsByType[outputObjectType] = currentCount + 1; }); - var studentOutputService = new StudentDataOutputService(interchangeFileOutputService.Object); + var studentOutputService = new StudentDataOutputService(interchangeFileOutputService); var configuration = new StudentDataOutputConfiguration { SampleDataGeneratorConfig = new TestSampleDataGeneratorConfig @@ -123,8 +121,6 @@ public void ShouldSerializeWhenFlushIsCalled() studentOutputService.Configure(configuration); studentOutputService.WriteToOutput(generatedStudentData, 0); - - interchangeFileOutputService.Verify(x => x.WriteOutputToFile(It.IsAny(), It.IsAny()), Times.Never); studentOutputService.FlushOutput(); outputCountsByType[typeof(InterchangeStudent)].ShouldBe(1); diff --git a/src/EdFi.SampleDataGenerator.Core/DataGeneration/Common/Enumeration.cs b/src/EdFi.SampleDataGenerator.Core/DataGeneration/Common/Enumeration.cs new file mode 100644 index 0000000..b153d3b --- /dev/null +++ b/src/EdFi.SampleDataGenerator.Core/DataGeneration/Common/Enumeration.cs @@ -0,0 +1,139 @@ +// SPDX-License-Identifier: Apache-2.0 +// Licensed to the Ed-Fi Alliance under one or more agreements. +// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. +// See the LICENSE and NOTICES files in the project root for more information. + +using System; +using System.Diagnostics; +using System.Linq; +using System.Reflection; + +namespace EdFi.SampleDataGenerator.Core.DataGeneration.Common +{ + [Serializable] + [DebuggerDisplay("{DisplayName} - {Value}")] + public abstract class Enumeration : Enumeration + where TEnumeration : Enumeration + { + protected Enumeration(int value, string displayName) + : base(value, displayName) { } + + public static TEnumeration FromInt32(int value) + { + return FromValue(value); + } + + public static bool TryFromInt32(int listItemValue, out TEnumeration result) + { + return TryParse(listItemValue, out result); + } + } + + [Serializable] + [DebuggerDisplay("{DisplayName} - {Value}")] + public abstract class Enumeration : IComparable, IEquatable + where TEnumeration : Enumeration + where TValue : IComparable + { + private static readonly Lazy _enumerations = new Lazy(GetEnumerations); + + protected Enumeration(TValue value, string displayName) + { + Value = value; + DisplayName = displayName; + } + + public TValue Value { get; } + + public string DisplayName { get; } + + public int CompareTo(TEnumeration other) + { + return Value.CompareTo(other.Value); + } + + public bool Equals(TEnumeration other) + { + return other != null && Value.Equals(other.Value); + } + + public override string ToString() + { + return DisplayName; + } + + public static TEnumeration[] GetAll() + { + return _enumerations.Value; + } + + private static TEnumeration[] GetEnumerations() + { + Type enumerationType = typeof(TEnumeration); + + return enumerationType + .GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly) + .Where(info => enumerationType.IsAssignableFrom(info.FieldType)) + .Select(info => info.GetValue(null)) + .Cast() + .ToArray(); + } + + public override bool Equals(object obj) + { + return Equals(obj as TEnumeration); + } + + public override int GetHashCode() + { + return Value.GetHashCode(); + } + + public static bool operator ==(Enumeration left, Enumeration right) + { + return Equals(left, right); + } + + public static bool operator !=(Enumeration left, Enumeration right) + { + return !Equals(left, right); + } + + public static TEnumeration FromValue(TValue value) + { + return Parse(value, "value", item => item.Value.Equals(value)); + } + + public static TEnumeration Parse(string displayName) + { + return Parse(displayName, "display name", item => item.DisplayName == displayName); + } + + public static bool TryParse(Func predicate, out TEnumeration result) + { + result = GetAll().SingleOrDefault(predicate); + return result != null; + } + + private static TEnumeration Parse(object value, string description, Func predicate) + { + if (!TryParse(predicate, out TEnumeration result)) + { + string message = $"'{value}' is not a valid {description} in {typeof(TEnumeration)}"; + throw new ArgumentException(message, nameof(value)); + } + + return result; + } + + public static bool TryParse(TValue value, out TEnumeration result) + { + return TryParse(e => e.Value.Equals(value), out result); + } + + public static bool TryParse(string displayName, out TEnumeration result) + { + return TryParse(e => e.DisplayName == displayName, out result); + } + } +} diff --git a/src/EdFi.SampleDataGenerator.Core/DataGeneration/Common/Interchanges/Interchange.cs b/src/EdFi.SampleDataGenerator.Core/DataGeneration/Common/Interchanges/Interchange.cs index 965e319..2b7b316 100644 --- a/src/EdFi.SampleDataGenerator.Core/DataGeneration/Common/Interchanges/Interchange.cs +++ b/src/EdFi.SampleDataGenerator.Core/DataGeneration/Common/Interchanges/Interchange.cs @@ -1,6 +1,4 @@  -using EdFi.Ods.Common; - namespace EdFi.SampleDataGenerator.Core.DataGeneration.Common.Interchanges { public sealed partial class Interchange : Enumeration diff --git a/src/EdFi.SampleDataGenerator.Core/DataGeneration/Common/LetterGrade.cs b/src/EdFi.SampleDataGenerator.Core/DataGeneration/Common/LetterGrade.cs index 23f686f..225f183 100644 --- a/src/EdFi.SampleDataGenerator.Core/DataGeneration/Common/LetterGrade.cs +++ b/src/EdFi.SampleDataGenerator.Core/DataGeneration/Common/LetterGrade.cs @@ -1,5 +1,4 @@ using System.Linq; -using EdFi.Ods.Common; using EdFi.SampleDataGenerator.Core.Entities; namespace EdFi.SampleDataGenerator.Core.DataGeneration.Common diff --git a/src/EdFi.SampleDataGenerator.Core/DataGeneration/Common/Salutation.cs b/src/EdFi.SampleDataGenerator.Core/DataGeneration/Common/Salutation.cs index f23fb95..fd1a9da 100644 --- a/src/EdFi.SampleDataGenerator.Core/DataGeneration/Common/Salutation.cs +++ b/src/EdFi.SampleDataGenerator.Core/DataGeneration/Common/Salutation.cs @@ -1,6 +1,4 @@ -using EdFi.Ods.Common; - -namespace EdFi.SampleDataGenerator.Core.DataGeneration.Common +namespace EdFi.SampleDataGenerator.Core.DataGeneration.Common { public sealed class Salutation : Enumeration { diff --git a/src/EdFi.SampleDataGenerator.Core/EdFi.SampleDataGenerator.Core.csproj b/src/EdFi.SampleDataGenerator.Core/EdFi.SampleDataGenerator.Core.csproj index 9fa4e5f..e2f54a9 100644 --- a/src/EdFi.SampleDataGenerator.Core/EdFi.SampleDataGenerator.Core.csproj +++ b/src/EdFi.SampleDataGenerator.Core/EdFi.SampleDataGenerator.Core.csproj @@ -1,6 +1,6 @@  - net6.0 + net10.0 EdFi.SampleDataGenerator.Core EdFi.SampleDataGenerator.Core Copyright © 2022 @@ -12,13 +12,12 @@ pdbonly - - - - - - - + + + + + + diff --git a/src/Utilities/EdFi.CalendarGenerator.Console/EdFi.CalendarGenerator.Console.csproj b/src/Utilities/EdFi.CalendarGenerator.Console/EdFi.CalendarGenerator.Console.csproj index 98fdcc1..411af1f 100644 --- a/src/Utilities/EdFi.CalendarGenerator.Console/EdFi.CalendarGenerator.Console.csproj +++ b/src/Utilities/EdFi.CalendarGenerator.Console/EdFi.CalendarGenerator.Console.csproj @@ -1,7 +1,7 @@  Exe - net6.0 + net10.0 EdFi.CalendarGenerator.Console EdFi.CalendarGenerator.Console Copyright © 2022 @@ -13,8 +13,8 @@ pdbonly - - + + diff --git a/src/Utilities/EdFi.EducationOrganizationGenerator.Console/EdFi.EducationOrganizationGenerator.Console.csproj b/src/Utilities/EdFi.EducationOrganizationGenerator.Console/EdFi.EducationOrganizationGenerator.Console.csproj index 017a008..544bc03 100644 --- a/src/Utilities/EdFi.EducationOrganizationGenerator.Console/EdFi.EducationOrganizationGenerator.Console.csproj +++ b/src/Utilities/EdFi.EducationOrganizationGenerator.Console/EdFi.EducationOrganizationGenerator.Console.csproj @@ -1,7 +1,7 @@  Exe - net6.0 + net10.0 true EdFi.EducationOrganizationGenerator.Console EdFi.EducationOrganizationGenerator.Console @@ -14,8 +14,8 @@ pdbonly - - + + diff --git a/src/Utilities/EdFi.InterchangeXmlToCsv.Console.UnitTests/EdFi.InterchangeXmlToCsv.Console.UnitTests.csproj b/src/Utilities/EdFi.InterchangeXmlToCsv.Console.UnitTests/EdFi.InterchangeXmlToCsv.Console.UnitTests.csproj index cc7b1c7..f25fd93 100644 --- a/src/Utilities/EdFi.InterchangeXmlToCsv.Console.UnitTests/EdFi.InterchangeXmlToCsv.Console.UnitTests.csproj +++ b/src/Utilities/EdFi.InterchangeXmlToCsv.Console.UnitTests/EdFi.InterchangeXmlToCsv.Console.UnitTests.csproj @@ -1,6 +1,6 @@ - net6.0 + net10.0 EdFi.InterchangeXmlToCsv.Console.UnitTests EdFi.InterchangeXmlToCsv.Console.UnitTests Copyright © 2022 @@ -12,10 +12,11 @@ pdbonly - - - - + + + + + diff --git a/src/Utilities/EdFi.InterchangeXmlToCsv.Console/EdFi.InterchangeXmlToCsv.Console.csproj b/src/Utilities/EdFi.InterchangeXmlToCsv.Console/EdFi.InterchangeXmlToCsv.Console.csproj index 3af6577..af0b190 100644 --- a/src/Utilities/EdFi.InterchangeXmlToCsv.Console/EdFi.InterchangeXmlToCsv.Console.csproj +++ b/src/Utilities/EdFi.InterchangeXmlToCsv.Console/EdFi.InterchangeXmlToCsv.Console.csproj @@ -1,7 +1,7 @@  Exe - net6.0 + net10.0 true EdFi.InterchangeXmlToCsv.Console EdFi.InterchangeXmlToCsv.Console @@ -14,9 +14,9 @@ pdbonly - - - + + + diff --git a/src/Utilities/EdFi.MasterScheduleGenerator.Console/EdFi.MasterScheduleGenerator.Console.csproj b/src/Utilities/EdFi.MasterScheduleGenerator.Console/EdFi.MasterScheduleGenerator.Console.csproj index 08ebdd1..e6eeee6 100644 --- a/src/Utilities/EdFi.MasterScheduleGenerator.Console/EdFi.MasterScheduleGenerator.Console.csproj +++ b/src/Utilities/EdFi.MasterScheduleGenerator.Console/EdFi.MasterScheduleGenerator.Console.csproj @@ -1,7 +1,7 @@  Exe - net6.0 + net10.0 true EdFi.MasterScheduleGenerator.Console EdFi.MasterScheduleGenerator.Console @@ -14,8 +14,8 @@ pdbonly - - + + diff --git a/src/nuget.config b/src/nuget.config deleted file mode 100644 index 2c78330..0000000 --- a/src/nuget.config +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - -