コード例 #1
0
        public async Task <AuditResult> Run(AuditRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var cmd = new WhereCmd()
            {
                EnableDebugging = request.EnableLogging
            };
            var nodePath = await cmd.GetNodePath();

            if (String.IsNullOrEmpty(nodePath) || !File.Exists(nodePath))
            {
                throw new Exception("Couldn't find NodeJs. Please, install NodeJs and make shure than PATH variable defined.");
            }

            var npm = new Npm(nodePath)
            {
                EnableDebugging = request.EnableLogging
            };
            var npmPath = await npm.GetNpmPath();

            var sm      = new ScriptMaker();
            var content = sm.Produce(request, npmPath);

            if (!sm.Save(content))
            {
                throw new Exception($"Couldn't save JS script to %temp% directory. Path: {sm.TempFileName}");
            }

            try
            {
                var node = new Node()
                {
                    EnableDebugging = request.EnableLogging
                };
                var stdoutJson = await node.Run(sm.TempFileName);

                var obj = parseJson(stdoutJson);
                return(await Task.FromResult(obj));
            }
            catch (Exception ex)
            {
                if (!String.IsNullOrEmpty(ex.Message) && Regex.IsMatch(ex.Message, @"Cannot find module[\s\S]+?node_modules\\lighthouse'"))
                {
                    throw new Exception("Lighthouse is not installed. Please, execute `npm install -g lighthouse` in console.");
                }
                throw;
            }
            finally
            {
                if (!npm.EnableDebugging)
                {
                    sm.Delete();
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///     Returns true if Profitability instances are equal
        /// </summary>
        /// <param name="other">Instance of Profitability to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Profitability other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Roe == other.Roe ||
                     Roe != null &&
                     Roe.Equals(other.Roe)
                     ) &&
                 (
                     Npm == other.Npm ||
                     Npm != null &&
                     Npm.Equals(other.Npm)
                 ) &&
                 (
                     Gpm == other.Gpm ||
                     Gpm != null &&
                     Gpm.Equals(other.Gpm)
                 ) &&
                 (
                     Np == other.Np ||
                     Np != null &&
                     Np.Equals(other.Np)
                 ) &&
                 (
                     Eps == other.Eps ||
                     Eps != null &&
                     Eps.Equals(other.Eps)
                 ) &&
                 (
                     Mbr == other.Mbr ||
                     Mbr != null &&
                     Mbr.Equals(other.Mbr)
                 ) &&
                 (
                     Ts == other.Ts ||
                     Ts != null &&
                     Ts.Equals(other.Ts)
                 ) &&
                 (
                     Cs == other.Cs ||
                     Cs != null &&
                     Cs.Equals(other.Cs)
                 ));
        }
コード例 #3
0
        public static Task <(IDependencyScanner, ILicenseScanner)> Create(IFileAccess fileSystem, Config config)
        {
            var npm                    = new Npm();
            var packagePolicies        = PackagePolicies.LoadFrom(config.PackagePolicies);
            IDependencyScanner scanner = new DependencyScanner(npm, fileSystem, packagePolicies, config.DiskCache);

            Func <IPackage, Task <PackageDetailsResult> > getDetails =
                p => npm.GetPackage(p).ContinueWith(ConvertPackageDetails);

            ILicenseScanner licenseScanner = new LicenseScanner(getDetails, packagePolicies, config);

            return(Task.FromResult((scanner, licenseScanner)));
        }
コード例 #4
0
        // Rather than using [Theory] to pass each of the different values for 'template',
        // it's important to distribute the SPA template tests over different test classes
        // so they can be run in parallel. Xunit doesn't parallelize within a test class.
        protected void SpaTemplateImpl(string template, bool noHttps = false)
        {
            RunDotNetNew(template, noHttps: noHttps);

            // For some SPA templates, the NPM root directory is './ClientApp'. In other
            // templates it's at the project root. Strictly speaking we shouldn't have
            // to do the NPM restore in tests because it should happen automatically at
            // build time, but by doing it up front we can avoid having multiple NPM
            // installs run concurrently which otherwise causes errors when tests run
            // in parallel.
            var clientAppSubdirPath = Path.Combine(TemplateOutputDir, "ClientApp");

            Assert.True(File.Exists(Path.Combine(clientAppSubdirPath, "package.json")), "Missing a package.json");

            Npm.RestoreWithRetry(Output, clientAppSubdirPath);
            Npm.Test(Output, clientAppSubdirPath);

            TestApplication(publish: false);
            TestApplication(publish: true);
        }
コード例 #5
0
 /// <summary>
 ///     Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked            // Overflow is fine, just wrap
     {
         int hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Roe != null)
         {
             hashCode = hashCode * 59 + Roe.GetHashCode();
         }
         if (Npm != null)
         {
             hashCode = hashCode * 59 + Npm.GetHashCode();
         }
         if (Gpm != null)
         {
             hashCode = hashCode * 59 + Gpm.GetHashCode();
         }
         if (Np != null)
         {
             hashCode = hashCode * 59 + Np.GetHashCode();
         }
         if (Eps != null)
         {
             hashCode = hashCode * 59 + Eps.GetHashCode();
         }
         if (Mbr != null)
         {
             hashCode = hashCode * 59 + Mbr.GetHashCode();
         }
         if (Ts != null)
         {
             hashCode = hashCode * 59 + Ts.GetHashCode();
         }
         if (Cs != null)
         {
             hashCode = hashCode * 59 + Cs.GetHashCode();
         }
         return(hashCode);
     }
 }
コード例 #6
0
ファイル: MenuMethods.cs プロジェクト: kollerdada/Feleves
        /// <summary>
        /// This lists the payment method changing method.
        /// </summary>
        /// <param name="shopLogic">Logic for Orders repository and SkiEqupments repository.</param>
        public static void ChangePayment(ShopLogic shopLogic)
        {
            int  id    = IntParse(Enter.ToString());
            bool valid = false;

            try
            {
                shopLogic?.GetOrderById(id);
                valid = true;
            }
            catch (ArgumentException)
            {
                Console.WriteLine(Other.ToString());
            }

            if (valid)
            {
                Console.WriteLine(Selected.ToString());

                Console.WriteLine(shopLogic?.GetOrderById(id).ToString());
                Console.WriteLine(PressEnter.ToString());
                valid = false;
                string payment = string.Empty;
                do
                {
                    const string Npm = "Enter new payment method here: (Credit Card/PayPal)";
                    payment = Console.ReadLine();
                    Console.WriteLine(Npm.ToString());
                    if (payment == "Credit Card" || payment == "PayPal")
                    {
                        valid = true;
                    }
                }while (!valid);

                shopLogic?.ChangePayment(id, payment);

                Console.WriteLine(Saved.ToString());
            }

            Console.ReadLine();
        }
コード例 #7
0
        public void Execute_CallInstallCommand_ExecutesNpmInstall()
        {
            // arrange
            TestHelper.DeleteDirectoryIfExists("npmtest");
            TestHelper.CopyFile(@"TestData\package.json", @"npmtest\package.json");

            var target = new Npm();
            WorkflowInvokerTest invoker = TestHelper.CreateWorkflowInvoker(target);

            // act
            var parameters = new Dictionary <string, object>
            {
                { "WorkingDirectory", "npmtest" },
                { "Command", "install" },
            };

            invoker.TestActivity(parameters);

            // assert
            Assert.IsTrue(Directory.Exists(@"npmtest\node_modules"));
        }