public void Setup() { _httpService.Reset(); _httpService .Setup(transfer => transfer.DownloadS3FileAsync(It.IsAny <string>())) .Returns(async(string key) => { await Task.Delay(1); var stream = new MemoryStream(); var writer = new StreamWriter(stream); if (key.Equals("microsoftlibs.namespace.lookup.json")) { var test = JsonConvert.SerializeObject(_manifest); writer.Write(test); writer.Flush(); stream.Position = 0; var outputStream = new MemoryStream(); stream.CopyTo(outputStream); outputStream.Position = 0; return(outputStream); } else { var test = JsonConvert.SerializeObject(new Dictionary <string, PackageDetails> { { "Package", _packageDetails } }); writer.Write(test); writer.Flush(); stream.Position = 0; var outputStream = new MemoryStream(); var gzipStream = new GZipStream(outputStream, CompressionLevel.Fastest); stream.CopyTo(gzipStream); gzipStream.Flush(); outputStream.Position = 0; return(outputStream); } }); _internalNuGetCompatibilityHandlerMock.Reset(); _internalNuGetCompatibilityHandlerMock .Setup(checker => checker.CheckCompatibilityAsync( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <IEnumerable <SourceRepository> >())) .Returns((string packageName, string version, string targetFramework, IEnumerable <SourceRepository> sourceRepositories) => { return(GetCompatibilityResult(200, true)); }); _externalPackagesCompatibilityChecker = new ExternalPackagesCompatibilityChecker( _httpService.Object, NullLogger <ExternalPackagesCompatibilityChecker> .Instance ); _portabilityAnalyzerCompatibilityChecker = new PortabilityAnalyzerCompatibilityChecker( _httpService.Object, NullLogger <PortabilityAnalyzerCompatibilityChecker> .Instance ); _sdkCompatibilityChecker = new SdkCompatibilityChecker( _httpService.Object, NullLogger <SdkCompatibilityChecker> .Instance ); _portabilityAnalyzerCompatibilityChecker = new PortabilityAnalyzerCompatibilityChecker( _httpService.Object, NullLogger <PortabilityAnalyzerCompatibilityChecker> .Instance ); _internalPackagesCompatibilityChecker = new Mock <InternalPackagesCompatibilityChecker>( _internalNuGetCompatibilityHandlerMock.Object, NullLogger <InternalPackagesCompatibilityChecker> .Instance); _internalPackagesCompatibilityChecker.Reset(); _internalPackagesCompatibilityChecker.Setup(checker => checker.GetInternalRepositories( It.IsAny <string>())).Returns(() => { return(GetInternalRepository()); }); }
public void Setup() { _httpService.Reset(); _httpService .Setup(transfer => transfer.DownloadS3FileAsync(It.IsAny <string>())) .Returns(async(string key) => { await Task.Delay(1); var stream = new MemoryStream(); var writer = new StreamWriter(stream); if (key.Equals("microsoftlibs.namespace.lookup.json")) { var test = JsonConvert.SerializeObject(_manifest); writer.Write(test); writer.Flush(); stream.Position = 0; var outputStream = new MemoryStream(); stream.CopyTo(outputStream); outputStream.Position = 0; return(outputStream); } else { var test = JsonConvert.SerializeObject(new Dictionary <string, PackageDetails> { { "Package", _packageDetails } }); writer.Write(test); writer.Flush(); stream.Position = 0; var outputStream = new MemoryStream(); var gzipStream = new GZipStream(outputStream, CompressionLevel.Fastest); stream.CopyTo(gzipStream); gzipStream.Flush(); outputStream.Position = 0; return(outputStream); } }); _internalNuGetCompatibilityHandlerMock.Reset(); _internalNuGetCompatibilityHandlerMock .Setup(checker => checker.CheckCompatibilityAsync( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <IEnumerable <SourceRepository> >())) .Returns((string packageName, string version, string targetFramework, IEnumerable <SourceRepository> sourceRepositories) => { return(GetCompatibilityResult(200, true)); }); _externalPackagesCompatibilityChecker = new ExternalPackagesCompatibilityChecker( _httpService.Object, NullLogger <ExternalPackagesCompatibilityChecker> .Instance, _fileSystem.Object ); _portabilityAnalyzerCompatibilityChecker = new PortabilityAnalyzerCompatibilityChecker( _httpService.Object, NullLogger <PortabilityAnalyzerCompatibilityChecker> .Instance ); _sdkCompatibilityChecker = new SdkCompatibilityChecker( _httpService.Object, NullLogger <SdkCompatibilityChecker> .Instance ); _portabilityAnalyzerCompatibilityChecker = new PortabilityAnalyzerCompatibilityChecker( _httpService.Object, NullLogger <PortabilityAnalyzerCompatibilityChecker> .Instance ); _internalPackagesCompatibilityChecker = new Mock <InternalPackagesCompatibilityChecker>( _internalNuGetCompatibilityHandlerMock.Object, NullLogger <InternalPackagesCompatibilityChecker> .Instance); _internalPackagesCompatibilityChecker.Reset(); _internalPackagesCompatibilityChecker.Setup(checker => checker.GetInternalRepositories( It.IsAny <string>())).Returns(() => { return(GetInternalRepository()); }); _fileSystem.Setup(fileSystem => fileSystem.GetTempPath()).Returns(() => { return("tempPath"); }); _fileSystem.Setup(fileSystem => fileSystem.FileExists(It.IsAny <string>())).Returns((string file) => { string solutionId; using (var sha = SHA256.Create()) { byte[] textData = System.Text.Encoding.UTF8.GetBytes(Path.Combine(_testSolutionDirectory, "SolutionWithNugetConfigFile.sln")); byte[] hash = sha.ComputeHash(textData); solutionId = BitConverter.ToString(hash); } var tempSolutionDirectory = Path.Combine("tempPath", solutionId); tempSolutionDirectory = tempSolutionDirectory.Replace("-", ""); if (file == Path.Combine(tempSolutionDirectory, "testpackage.json.gz")) { return(true); } else { return(false); } }); _fileSystem.Setup(fileSystem => fileSystem.FileOpenRead(It.IsAny <string>())).Returns((string file) => { var stream = new MemoryStream(); var writer = new StreamWriter(stream); var test = JsonConvert.SerializeObject(_packageDetailsFromFile); writer.Write(test); writer.Flush(); stream.Position = 0; var outputStream = new MemoryStream(); var gzipStream = new GZipStream(outputStream, CompressionLevel.Fastest); stream.CopyTo(gzipStream); gzipStream.Flush(); outputStream.Position = 0; return(outputStream); }); _fileSystem.Setup(fileSystem => fileSystem.FileOpenWrite(It.IsAny <string>())).Returns(() => { var stream = new MemoryStream(); stream.Position = 0; return(stream); }); }