public InstallService(string extractPath, Package installPackage = null, Package uninstallPackage = null, Package isInstalledPackage = null)
        {
            Mock <IInstallService> mock = new Mock <IInstallService>();

            mock
            .Setup(i => i.Install(It.Is <IPackage>(p => p == InstallPackages[InstallCalled])))
            .Callback(() => InstallCalled.Increment());

            mock
            .Setup(i => i.Uninstall(It.Is <IPackage>(p => p == UninstallPackages[UninstallCalled])))
            .Callback(() => UninstallCalled.Increment());

            mock
            .Setup(i => i.IsInstalled(It.Is <IPackage>(p => p == IsInstalledPackages[IsInstalledCalled])))
            .Callback(() => IsInstalledCalled.Increment())
            .Returns(true);

            mock
            .Setup(i => i.Path)
            .Returns(() => extractPath);

            if (installPackage != null)
            {
                InstallPackages.Add(installPackage.Object);
            }

            if (uninstallPackage != null)
            {
                UninstallPackages.Add(uninstallPackage.Object);
            }

            if (isInstalledPackage != null)
            {
                IsInstalledPackages.Add(isInstalledPackage.Object);
            }

            Object = mock.Object;
        }
示例#2
0
        public void Initialize(string nugetApiKey)
        {
            NugetApiKey = nugetApiKey;
            var outputDir =
                OutputDirectory ?? Path.Combine(Path.GetTempPath(), "ursa", DateTime.Now.Ticks.ToString());

            var ursaAbstractionsPackage = new PackageInfo
            {
                PackageName    = "Ubaba.Abstractions",
                PackageVersion = "0.0.1-beta2"
            };
            var annotationsPackage = new PackageInfo
            {
                PackageName    = "System.ComponentModel.Annotations",
                PackageVersion = "4.7.0"
            };

            if (InstallPackages.All(p => p.PackageName != ursaAbstractionsPackage.PackageName))
            {
                InstallPackages.Add(ursaAbstractionsPackage);
            }

            if (InstallPackages.All(p => p.PackageName != annotationsPackage.PackageName))
            {
                InstallPackages.Add(annotationsPackage);
            }

            var nugetPackageDir = Path.Combine(outputDir, "nuget");

            OutputDir           = outputDir;
            ClientSdkCodePath   = Path.Combine(outputDir, $"{ClassName}.cs");
            ClientSdkCsprojPath = Path.Combine(outputDir, $"{Package.PackageName}.csproj");
            NugetPackageDir     = nugetPackageDir;
            NugetPackagePath    = Path.Combine(nugetPackageDir, $"{Package.PackageName}.{Package.PackageVersion}.nupkg");
            ApiExceptionFullName ??= typeof(UrsaApiException).FullName;
            ApiResponseFullName ??= typeof(NSwagApiResponse).FullName;
        }