public void Invoke_InvalidFiles_WritesErrorsToConsole() { var fileSystem = MockFileSystemFactory.CreateFileSystemWithInvalidFiles(); var mockMainArmTemplateFileData = fileSystem.GetFile(MainArmTemplateFile.FileName); var processProxy = MockProcessProxyFactory.CreateProcessProxy(callback: () => fileSystem.SetTempFile(mockMainArmTemplateFileData)); var console = new MockConsole().ExpectErrorLines( $@"The file ""{fileSystem.Path.GetFullPath(MainArmTemplateParametersFile.FileName)}"" is invalid: #/parameters/dnsPrefix: Expected 1 matching subschema but found 0 #/parameters/dnsPrefix: Required properties [value] were not present #/parameters/dnsPrefix: Required properties [reference] were not present #/parameters/linuxAdminUsername: Expected 1 matching subschema but found 0 #/parameters/linuxAdminUsername: Required properties [value] were not present #/parameters/linuxAdminUsername: Required properties [reference] were not present ".ReplaceLineEndings(), $@"The file ""{fileSystem.Path.GetFullPath(MetadataFile.FileName)}"" is invalid: #/description: Value is not longer than or equal to 10 characters #/summary: Value is not longer than or equal to 10 characters ".ReplaceLineEndings(), $@"The file ""{fileSystem.Path.GetFullPath(ReadmeFile.FileName)}"" is modified or outdated. Please regenerate the file to fix it. ".ReplaceLineEndings(), $@"The file ""{fileSystem.Path.GetFullPath(VersionFile.FileName)}"" is modified or outdated. Please regenerate the file to fix it. ".ReplaceLineEndings()); Invoke(fileSystem, processProxy, console); console.Verify(); }
public void Invoke_BicepBuildError_ReturnsOne() { var fileSystem = MockFileSystemFactory.CreateFileSystemWithNewlyGeneratedFiles(); var processProxy = MockProcessProxyFactory.CreateProcessProxy(exitCode: 1, standardError: "Build error."); var exitCode = Invoke(fileSystem, processProxy); exitCode.Should().Be(1); }
public void Invoke_OnSuccess_ProducesExpectedFiles(MockFileSystem fileSystemBeforeGeneration, MockFileSystem fileSystemAfterGeneration) { var mockMainArmTemplateFileData = fileSystemAfterGeneration.GetFile(MainArmTemplateFile.FileName); var processProxy = MockProcessProxyFactory.CreateProcessProxy(() => fileSystemBeforeGeneration.SetTempFile(mockMainArmTemplateFileData)); Invoke(fileSystemBeforeGeneration, processProxy); fileSystemBeforeGeneration.Should().HaveSameFilesAs(fileSystemAfterGeneration); }
public void Invoke_OnSuccess_ReturnsZero(MockFileSystem fileSystemBeforeGeneration, MockFileSystem fileSystemAfterGeneration) { var mockMainArmTemplateFileData = fileSystemAfterGeneration.GetFile(MainArmTemplateFile.FileName); var processProxy = MockProcessProxyFactory.CreateProcessProxy(() => fileSystemBeforeGeneration.SetTempFile(mockMainArmTemplateFileData)); var exitCode = Invoke(fileSystemBeforeGeneration, processProxy); exitCode.Should().Be(0); }
public void Invoke_InvalidJsonFile_ReturnsOne(MockFileSystem fileSystem, string _) { var mockMainArmTemplateFileData = fileSystem.GetFile(MainArmTemplateFile.FileName); var processProxy = MockProcessProxyFactory.CreateProcessProxy(callback: () => fileSystem.SetTempFile(mockMainArmTemplateFileData)); var exitCode = Invoke(fileSystem, processProxy); exitCode.Should().Be(1); }
public void Invoke_ValidFiles_ReturnsZero() { var fileSystem = MockFileSystemFactory.CreateFileSystemWithValidFiles(); var mockMainArmTemplateFileData = fileSystem.GetFile(MainArmTemplateFile.FileName); var processProxy = MockProcessProxyFactory.CreateProcessProxy(callback: () => fileSystem.SetTempFile(mockMainArmTemplateFileData)); var exitCode = Invoke(fileSystem, processProxy); exitCode.Should().Be(0); }
public void Invoke_BicepBuildError_WritesErrorsToConsole() { var fileSystem = MockFileSystemFactory.CreateFileSystemWithNewlyGeneratedFiles(); var processProxy = MockProcessProxyFactory.CreateProcessProxy(exitCode: 1, standardError: "Build error one.\nBuild error two."); var console = new MockConsole().ExpectErrorLines("Build error one.", "Build error two.", $"Failed to build \"{fileSystem.Path.GetFullPath(MainBicepFile.FileName)}\"."); Invoke(fileSystem, processProxy, console); console.Verify(); }
public void Invoke_InvalidJsonFile_WritesErrorsToConsole(MockFileSystem fileSystem, string error) { var mockMainArmTemplateFileData = fileSystem.GetFile(MainArmTemplateFile.FileName); var processProxy = MockProcessProxyFactory.CreateProcessProxy(callback: () => fileSystem.SetTempFile(mockMainArmTemplateFileData)); var console = new MockConsole().ExpectErrorLines(error); var exitCode = Invoke(fileSystem, processProxy, console); console.Verify(); }
public void Invoke_MultipleTimes_ProduceSameFiles(MockFileSystem fileSystemBeforeGeneration, MockFileSystem fileSystemAfterGeneration) { var mockMainArmTemplateFileData = fileSystemAfterGeneration.GetFile(MainArmTemplateFile.FileName); var processProxy = MockProcessProxyFactory.CreateProcessProxy(callback: () => fileSystemBeforeGeneration.SetTempFile(mockMainArmTemplateFileData)); for (int i = 0; i < 6; i++) { Invoke(fileSystemBeforeGeneration, processProxy); } fileSystemBeforeGeneration.Should().HaveSameFilesAs(fileSystemAfterGeneration); }
public void Build_BicepFileWithWarnings_LogsWarnings(IEnvironmentProxy environmentProxy, IFileSystem fileSystem) { // Arrange. var processProxy = MockProcessProxyFactory.CreateProcessProxy(0, "", string.Join('\n', SampleWarnings)); var mockConsole = new MockConsole().ExpectOutLines(SampleWarnings.Append("")); var sut = CreateBicepCliProxy(environmentProxy, processProxy, fileSystem, console: mockConsole); // Act. sut.Build("/main.bicep", "main.json"); // Assert. mockConsole.Verify(); }
public void Build_ValidBicepFile_DoesNotLogAnyWarningsAndErrors(IEnvironmentProxy environmentProxy, IFileSystem fileSystem) { // Arrange. var processProxy = MockProcessProxyFactory.CreateProcessProxy(0, "", ""); var mockConsole = new MockConsole(); var sut = CreateBicepCliProxy(environmentProxy, processProxy, fileSystem, console: mockConsole); // Act. sut.Build("/main.bicep", "main.json"); // Assert. mockConsole.Verify(); }
public void Build_BicepFileWithWarningsAndErrors_LogsWarningAndErrorAndThrowsException(IEnvironmentProxy environmentProxy, IFileSystem fileSystem) { // Arrange. var mockProcessProxy = MockProcessProxyFactory.CreateProcessProxy(1, "", string.Join('\n', SampleWarnings.Concat(SampleErrors))); var mockConsole = new MockConsole() .ExpectOutLines(SampleWarnings) .ExpectErrorLines(SampleErrors); var sut = CreateBicepCliProxy(environmentProxy, mockProcessProxy, fileSystem, console: mockConsole); // Act & Assert. FluentActions.Invoking(() => sut.Build("/main.bicep", "/main.json")).Should() .Throw <BicepException>() .WithMessage("Failed to build \"/main.bicep\"."); mockConsole.Verify(); }