Пример #1
0
 public StepParserFactory(
     ICodeMetadataGeneratorService codeMetadataGeneratorService,
     IProviderResultsRepository providerResultsRepository,
     ITestRunnerResiliencePolicies resiliencePolicies)
 {
     _codeMetadataGeneratorService = codeMetadataGeneratorService;
     _providerResultsRepository    = providerResultsRepository;
     _resiliencePolicies           = resiliencePolicies;
 }
        public StepParserFactory(
            ICodeMetadataGeneratorService codeMetadataGeneratorService,
            IProviderResultsRepository providerResultsRepository,
            ITestRunnerResiliencePolicies resiliencePolicies)
        {
            Guard.ArgumentNotNull(codeMetadataGeneratorService, nameof(codeMetadataGeneratorService));
            Guard.ArgumentNotNull(providerResultsRepository, nameof(providerResultsRepository));
            Guard.ArgumentNotNull(resiliencePolicies, nameof(resiliencePolicies));

            _codeMetadataGeneratorService = codeMetadataGeneratorService;
            _providerResultsRepository    = providerResultsRepository;
            _resiliencePolicies           = resiliencePolicies;
        }
Пример #3
0
        public void GetTypeInformation_WhenAssemblyIsZeroByteslThenReturnsEmptyEnumerable()
        {
            // Arrange
            ICodeMetadataGeneratorService generator = GetCodeGenerator();

            byte[] assembly = new byte[0];

            // Act
            IEnumerable <TypeInformation> result = generator.GetTypeInformation(assembly);

            // Assert
            result.Should().NotBeNull("Result should not be null");

            result.Should().BeEmpty();
        }
Пример #4
0
        public void GetTypeInformation_WhenListDatasetsThenPropertyDescriptionShouldBeReturned()
        {
            // Arrange
            ICodeMetadataGeneratorService generator = GetCodeGenerator();

            byte[] assembly = GetCalculationClassWithListDescriptionsExampleAssembly();

            // Act
            IEnumerable <TypeInformation> result = generator.GetTypeInformation(assembly);

            // Assert
            result.Should().NotBeNull("Result should not be null");

            result.Should().ContainSingle(c => c.Name == "Calculations");

            TypeInformation datasetType = result.Where(e => e.Name == "HighNeedsStudentNumbersDataset").FirstOrDefault();

            datasetType.Name.Should().Be("HighNeedsStudentNumbersDataset");
            datasetType.Description.Should().BeNull();
            datasetType.Type.Should().Be("HighNeedsStudentNumbersDataset");

            List <PropertyInformation> properties = new List <PropertyInformation>(datasetType.Properties);

            PropertyInformation ridProperty = properties[0];

            ridProperty.Should().NotBeNull("ridProperty should not be null");
            ridProperty.Name.Should().Be("Rid");
            ridProperty.FriendlyName.Should().Be("Rid");
            ridProperty.Description.Should().Be("Rid is the unique reference from The Store");

            PropertyInformation parentRidProperty = properties[1];

            parentRidProperty.Should().NotBeNull("parentRidProperty should not be null");
            parentRidProperty.Name.Should().Be("ParentRid");
            parentRidProperty.FriendlyName.Should().Be("Parent Rid");
            parentRidProperty.Description.Should().Be("The Rid of the parent provider (from The Store)");

            PropertyInformation highNeedsStudentsProperty = properties[11];

            highNeedsStudentsProperty.Should().NotBeNull("parentRidProperty should not be null");
            highNeedsStudentsProperty.Name.Should().Be("HighNeedsStudents1924");
            highNeedsStudentsProperty.FriendlyName.Should().Be("High Needs Students 19-24");
            highNeedsStudentsProperty.Description.Should().Be("Current year high needs students aged 19-24");

            properties.Should().HaveCount(22, "HighNeedsStudentNumbersDataset should contain expected number of properties");
        }
Пример #5
0
 private static SourceCodeService CreateSourceCodeService(
     ISourceFileRepository sourceFilesRepository = null,
     ILogger logger = null,
     ICalculationsRepository calculationsRepository           = null,
     ISourceFileGeneratorProvider sourceFileGeneratorProvider = null,
     ICompilerFactory compilerFactory = null,
     ICodeMetadataGeneratorService codeMetadataGenerator = null,
     ICalcsResiliencePolicies resiliencePolicies         = null)
 {
     return(new SourceCodeService(
                sourceFilesRepository ?? CreateSourceFileRepository(),
                logger ?? CreateLogger(),
                calculationsRepository ?? CreateCalculationsRepository(),
                sourceFileGeneratorProvider ?? CreateSourceFileGeneratorProvider(),
                compilerFactory ?? CreateCompilerFactory(),
                codeMetadataGenerator ?? CreateCodeMetadataGeneratorService(),
                resiliencePolicies ?? CreatePolicies()));
 }
Пример #6
0
        public void GetTypeInformation_ReturnsCalculationObjectWithValidMethodProperties()
        {
            // Arrange
            ICodeMetadataGeneratorService generator = GetCodeGenerator();

            byte[] assembly = GetEmptyDatasetExampleAssembly();

            // Act
            IEnumerable <TypeInformation> result = generator.GetTypeInformation(assembly);

            // Assert
            result.Should().NotBeNull("Result should not be null");

            result.Should().Contain(c => c.Name == "Calculations");

            TypeInformation calculationType = result.Where(e => e.Name == "Calculations").FirstOrDefault();

            calculationType.Methods.Should().NotBeEmpty();
        }
Пример #7
0
        public void GetTypeInformation_WhenListDatasetsThenEnsureKeywordsShouldBeReturned()
        {
            // Arrange
            ICodeMetadataGeneratorService generator = GetCodeGenerator();

            byte[] assembly = GetCalculationClassWithListDescriptionsExampleAssembly();

            // Act
            IEnumerable <TypeInformation> result = generator.GetTypeInformation(assembly);

            // Assert
            result.Should().NotBeNull("Result should not be null");

            result.FirstOrDefault(m => m.Name == "If").Should().NotBeNull();
            result.FirstOrDefault(m => m.Name == "ElseIf").Should().NotBeNull();
            result.FirstOrDefault(m => m.Name == "EndIf").Should().NotBeNull();
            result.FirstOrDefault(m => m.Name == "Then").Should().NotBeNull();
            result.FirstOrDefault(m => m.Name == "If-Then").Should().NotBeNull();
            result.FirstOrDefault(m => m.Name == "If-Then-Else").Should().NotBeNull();
            result.FirstOrDefault(m => m.Name == "If-Then-ElseIf-Then").Should().NotBeNull();
        }
Пример #8
0
        public void GetTypeInformation_ReturnsCalculationObjectWithValidPrintMethod()
        {
            // Arrange
            ICodeMetadataGeneratorService generator = GetCodeGenerator();

            byte[] assembly = GetEmptyDatasetExampleAssembly();

            // Act
            IEnumerable <TypeInformation> result = generator.GetTypeInformation(assembly);

            // Assert
            result.Should().NotBeNull("Result should not be null");

            result.Should().Contain(c => c.Name == "Calculations");

            TypeInformation calculationType = result.Where(e => e.Name == "Calculations").FirstOrDefault();

            calculationType.Methods.Should().ContainSingle(c => c.Name == "Print", "a single Print function should exist");

            MethodInformation printFunction = calculationType.Methods.Where(c => c.Name == "Print").SingleOrDefault();

            printFunction.Name.Should().Be("Print");

            printFunction.Parameters.Should().HaveCount(3);
            List <ParameterInformation> parameters = new List <ParameterInformation>(printFunction.Parameters);

            parameters[0].Name.Should().Be("value");
            parameters[0].Description.Should().Be("value");
            parameters[0].Type.Should().Be("T");

            parameters[1].Name.Should().Be("name");
            parameters[1].Description.Should().Be("name");
            parameters[1].Type.Should().Be("String");

            parameters[2].Name.Should().Be("rid");
            parameters[2].Description.Should().Be("rid");
            parameters[2].Type.Should().Be("String");

            printFunction.ReturnType.Should().BeNull();
        }
Пример #9
0
        public void GetTypeInformation_WhenListDatasetsThenDatasetPropertyDescriptionsShouldBeReturned()
        {
            // Arrange
            ICodeMetadataGeneratorService generator = GetCodeGenerator();

            byte[] assembly = GetCalculationClassWithListDescriptionsExampleAssembly();

            // Act
            IEnumerable <TypeInformation> result = generator.GetTypeInformation(assembly);

            // Assert
            result.Should().NotBeNull("Result should not be null");

            result.Should().ContainSingle(c => c.Name == "Calculations");

            TypeInformation datasetType = result.Where(e => e.Name == "Datasets").FirstOrDefault();

            datasetType.Name.Should().Be("Datasets");
            datasetType.Description.Should().BeNull();
            datasetType.Type.Should().Be("Datasets");

            List <PropertyInformation> properties = new List <PropertyInformation>(datasetType.Properties);

            PropertyInformation firstDataset = properties[0];

            firstDataset.Should().NotBeNull("firstDataset should not be null");
            firstDataset.Name.Should().Be("ABTestDataset240301001");
            firstDataset.FriendlyName.Should().Be("AB Test Dataset 2403-01-001");
            firstDataset.Description.Should().Be("High Needs Student Numbers");

            PropertyInformation secondDataset = properties[1];

            secondDataset.Should().NotBeNull("firstDataset should not be null");
            secondDataset.Name.Should().Be("ABTestDataset24030020011");
            secondDataset.FriendlyName.Should().Be("AB Test Dataset 2403-002-0011");
            secondDataset.Description.Should().Be("High Needs Student Numbers");

            properties.Should().HaveCount(4, "Datasets should contain expected number of properties");
        }
Пример #10
0
        public void GetTypeInformation_WithListDatasetsReturnsCalculationObjectWithValidProperties()
        {
            // Arrange
            ICodeMetadataGeneratorService generator = GetCodeGenerator();

            byte[] assembly = GetCalculationClassWithListDatasetsExampleAssembly();

            // Act
            IEnumerable <TypeInformation> result = generator.GetTypeInformation(assembly);

            // Assert
            result.Should().NotBeNull("Result should not be null");

            result.Should().ContainSingle(c => c.Name == "Calculations");

            TypeInformation calculationType = result.Where(e => e.Name == "Calculations").FirstOrDefault();

            calculationType.Name.Should().Be("Calculations");
            calculationType.Description.Should().BeNull();
            calculationType.Type.Should().Be("Calculations");

            calculationType.Properties.Should().NotBeNull();

            PropertyInformation datasetsProperty = calculationType.Properties.Where(p => p.Name == "Datasets").SingleOrDefault();

            datasetsProperty.Should().NotBeNull();

            datasetsProperty.Type.Should().Be("Datasets");

            result.Should().ContainSingle(t => t.Name == "Datasets");
            TypeInformation datasetsType = result.Where(t => t.Name == "Datasets").SingleOrDefault();

            datasetsType.Should().NotBeNull();

            PropertyInformation firstPropertyOfDatasets = datasetsType.Properties.First();

            firstPropertyOfDatasets.Type.Should().Be("List(Of DemoTestAPTDatasetSchemaNoRequiredDataset)");
        }
 public DatsetsStepParser(ICodeMetadataGeneratorService codeMetadataGeneratorService) : base(codeMetadataGeneratorService)
 {
 }
Пример #12
0
        public async Task Execute_WhenFieldNameCaseIsDifferent_ThenTestIsSuccessfullyExecuted()
        {
            // Arrange
            string dataSetName = "Test Dataset";
            string fieldName   = "URN";
            string calcName    = "Test Calc";
            string gherkin     = $"Given the dataset '{dataSetName}' field '{fieldName.ToLower()}' is equal to '100050'\n\nThen the result for '{calcName}' is greater than '12' ";

            ICodeMetadataGeneratorService codeMetadataGeneratorService = CreateCodeMetadataGeneratorService();

            codeMetadataGeneratorService
            .GetTypeInformation(Arg.Any <byte[]>())
            .Returns(new List <TypeInformation>
            {
                new TypeInformation {
                    Type = "Calculations", Methods = new List <MethodInformation> {
                        new MethodInformation {
                            FriendlyName = calcName
                        }
                    }
                },
                new TypeInformation {
                    Type = "Datasets", Properties = new List <PropertyInformation> {
                        new PropertyInformation {
                            FriendlyName = dataSetName, Type = "DSType"
                        }
                    }
                },
                new TypeInformation {
                    Type = "DSType", Properties = new List <PropertyInformation> {
                        new PropertyInformation {
                            FriendlyName = fieldName, Type = "String"
                        }
                    }
                }
            });

            IProviderResultsRepository providerResultsRepository = CreateProviderResultsRepository();

            ITestRunnerResiliencePolicies resiliencePolicies = CreateResiliencePolicies();

            IStepParserFactory stepParserFactory = new StepParserFactory(codeMetadataGeneratorService, providerResultsRepository, resiliencePolicies);

            ICalculationsRepository calculationsRepository = CreateCalculationsRepository();

            calculationsRepository
            .GetAssemblyBySpecificationId(Arg.Is("spec1"))
            .Returns(new byte[1]);

            ILogger logger = CreateLogger();

            GherkinParser gherkinParser = new GherkinParser(stepParserFactory, calculationsRepository, logger);

            ICacheProvider cacheProvider = CreateCacheProvider();

            GherkinExecutor gherkinExecutor = CreateGherkinExecutor(gherkinParser, cacheProvider);

            ProviderResult providerResult = new ProviderResult
            {
                Provider = new ProviderSummary {
                    Id = "prov1"
                },
                CalculationResults = new List <CalculationResult>
                {
                    new CalculationResult {
                        Calculation = new Common.Models.Reference {
                            Name = calcName
                        }, Value = 14
                    }
                }
            };
            IEnumerable <ProviderSourceDataset> datasets = new List <ProviderSourceDataset>
            {
                new ProviderSourceDataset
                {
                    DataRelationship = new Common.Models.Reference {
                        Name = dataSetName
                    },
                    Current = new ProviderSourceDatasetVersion
                    {
                        Rows = new List <Dictionary <string, object> >
                        {
                            new Dictionary <string, object> {
                                { fieldName, 100050 }
                            }
                        }
                    }
                }
            };
            IEnumerable <TestScenario> testScenarios = new List <TestScenario>
            {
                new TestScenario {
                    Id = "ts1", Name = "Test Scenario 1", SpecificationId = "spec1", Current = new TestScenarioVersion {
                        Gherkin = gherkin
                    }
                }
            };
            BuildProject buildProject = new BuildProject {
                Build = new Build()
            };

            // Act
            IEnumerable <ScenarioResult> scenarioResults = await gherkinExecutor.Execute(providerResult, datasets, testScenarios, buildProject);

            // Assert
            scenarioResults
            .Should()
            .HaveCount(1);

            scenarioResults
            .First().HasErrors
            .Should()
            .BeFalse("there should be no errors");

            scenarioResults
            .First().StepsExecuted
            .Should()
            .Be(scenarioResults.First().TotalSteps, "all steps should be executed");
        }
        public CalcStepParser(ICodeMetadataGeneratorService codeMetadataGeneratorService)
        {
            Guard.ArgumentNotNull(codeMetadataGeneratorService, nameof(codeMetadataGeneratorService));

            _codeMetadataGeneratorService = codeMetadataGeneratorService;
        }
 public AssertDatasetCalcStepParser(ICodeMetadataGeneratorService codeMetadataGeneratorService) : base(codeMetadataGeneratorService)
 {
 }
 public void SetUp()
 {
     generator = GetCodeGenerator();
 }