public void Validate(ReadmeFile file) { var latestMetadataFile = MetadataFile.ReadFromFileSystem(this.fileSystem); var latestReadmeFile = ReadmeFile.Generate(this.fileSystem, latestMetadataFile, latestMainArmTemplateFile); this.Validate(file.Path, file.Content, latestReadmeFile.Content); }
protected override int Invoke(InvocationContext context) { // Read or create main Bicep file. this.Logger.LogInformation("Ensure {MainBicepFile} exists...", "main Bicep file"); var mainBicepFile = MainBicepFile.EnsureInFileSystem(this.FileSystem); // Read or create metadata file. this.Logger.LogInformation("Ensure {MetadataFile} exists...", "metadata file"); var metadataFile = MetadataFile.EnsureInFileSystem(this.FileSystem); // Generate main ARM template file. var bicepCliProxy = new BicepCliProxy(this.environmentProxy, this.processProxy, this.FileSystem, this.Logger, context.Console); var mainArmTemplateFile = this.GenerateFileAndLogInformation("main ARM template file", () => MainArmTemplateFile .Generate(this.FileSystem, bicepCliProxy, mainBicepFile) .WriteToFileSystem(FileSystem)); // Generate main ARM template parameters file. var mainArmTemplateParametersFile = this.GenerateFileAndLogInformation("main ARM template parameters file", () => MainArmTemplateParametersFile .Generate(this.FileSystem, mainArmTemplateFile) .WriteToFileSystem(this.FileSystem)); // Generate README file. this.GenerateFileAndLogInformation("README file", () => ReadmeFile .Generate(this.FileSystem, metadataFile, mainArmTemplateFile) .WriteToFileSystem(this.FileSystem)); // Generate version file. this.GenerateFileAndLogInformation("version file", () => VersionFile .Generate(this.FileSystem) .WriteToFileSystem(this.FileSystem)); return(0); }
public void Validate_EmptyExamplesSectionInReadmeFile_ThrowsException(string readmeFileContents) { this.fileSystem.AddFile(this.fileSystem.Path.GetFullPath(ReadmeFile.FileName), readmeFileContents); var fileToValidate = ReadmeFile.ReadFromFileSystem(this.fileSystem); Invoking(() => this.sut.Validate(fileToValidate)).Should() .Throw <InvalidModuleException>() .WithMessage($@"The file ""{fileToValidate.Path}"" is modified or outdated. Please regenerate the file to fix it.{Environment.NewLine}"); }
protected override int Invoke(InvocationContext context) { var valid = true; this.Logger.LogInformation("Validating module path..."); valid &= Validate(context.Console, () => ValidateModulePath(this.FileSystem)); this.Logger.LogInformation("Validating main Bicep file..."); var bicepCliProxy = new BicepCliProxy(this.environmentProxy, this.processProxy, this.FileSystem, this.Logger, context.Console); var mainBicepFile = MainBicepFile.ReadFromFileSystem(this.FileSystem); // This also validates that the main Bicep file can be built without errors. var latestMainArmTemplateFile = MainArmTemplateFile.Generate(this.FileSystem, bicepCliProxy, mainBicepFile); var descriptionsValidator = new DescriptionsValidator(this.Logger, latestMainArmTemplateFile); valid &= Validate(context.Console, () => mainBicepFile.ValidatedBy(descriptionsValidator)); var testValidator = new TestValidator(this.FileSystem, this.Logger, bicepCliProxy, latestMainArmTemplateFile); var jsonSchemaValidator = new JsonSchemaValidator(this.Logger); var diffValidator = new DiffValidator(this.FileSystem, this.Logger, latestMainArmTemplateFile); this.Logger.LogInformation("Validating main Bicep test file..."); valid &= Validate(context.Console, () => MainBicepTestFile.ReadFromFileSystem(this.FileSystem).ValidatedBy(testValidator)); this.Logger.LogInformation("Validating main ARM template file..."); valid &= Validate(context.Console, () => MainArmTemplateFile.ReadFromFileSystem(this.FileSystem).ValidatedBy(diffValidator)); this.Logger.LogInformation("Validating metadata file..."); valid &= Validate(context.Console, () => MetadataFile.ReadFromFileSystem(this.FileSystem).ValidatedBy(jsonSchemaValidator)); this.Logger.LogInformation("Validating README file..."); valid &= Validate(context.Console, () => ReadmeFile.ReadFromFileSystem(this.FileSystem).ValidatedBy(diffValidator)); this.Logger.LogInformation("Validating version file..."); valid &= Validate(context.Console, () => VersionFile.ReadFromFileSystem(this.FileSystem).ValidatedBy(jsonSchemaValidator, diffValidator)); return(valid ? 0 : 1); }
private static IEnumerable <object[]> GetEmptyExamplesSectionData() { var fileSystem = MockFileSystemFactory.CreateFileSystemWithValidFiles(); var validReadmeFile = ReadmeFile.ReadFromFileSystem(fileSystem); var emptyExamplesSections = new string[] { "## Examples", "## Examples\r\n\r\n", "## Examples\r\n\t ", "## Examples\n \n", }; foreach (var section in emptyExamplesSections) { yield return(new object[] { Regex.Replace(validReadmeFile.Contents, "## Examples.+", section, RegexOptions.Singleline) }); } }
public void Validate_ValidReadmeFile_Succeeds() { var fileToValidate = ReadmeFile.ReadFromFileSystem(this.fileSystem); Invoking(() => this.sut.Validate(fileToValidate)).Should().NotThrow(); }