Exemplo n.º 1
0
        public void CanGetPageElementCollection()
        {
            //Setup
            var destFolderName = "PageObject";
            var destFolder     = Path.Combine(
                FileAndFolder.GetExecutionDirectory(),
                SolutionFolders.Resources.ToString(),
                SolutionFolders.Resources.ToString(),
                destFolderName
                );

            if (!Directory.Exists(destFolder))
            {
                Directory.CreateDirectory(destFolder);
            }


            var exePath  = FileAndFolder.GetProjectPath();
            var filePath = Path.Combine(exePath, "DevTests", SolutionFolders.Resources.ToString());

            FileAndFolder.CopyFile(FileName, filePath, FileName, destFolder);
            // instanciate
            var pageElement           = new PageElement();
            var folderStructure       = new string[] { SolutionFolders.Resources.ToString(), SolutionFolders.Resources.ToString(), destFolderName };
            var pageElementCollection = pageElement.GetPageElementsFromExccelFile(FileName, folderStructure);

            // Assert
            Assert.IsTrue(pageElementCollection.Count == 3);
            // Tear Down
            File.Delete(Path.Combine(destFolder, FileName));
            Directory.Delete(destFolder);
        }
Exemplo n.º 2
0
        public void GetRowByRowData()
        {
            Assert.IsTrue(File.Exists(Path.Combine(_filePath, FileName)));
            // copy file
            _destFolder = Path.Combine(
                FileAndFolder.GetExecutionDirectory(),
                SolutionFolders.Resources.ToString(),
                SolutionFolders.Resources.ToString(),
                "HomePageLocator"
                );
            if (!Directory.Exists(_destFolder))
            {
                Directory.CreateDirectory(_destFolder);
            }
            FileAndFolder.CopyFile(FileName, _filePath, FileName, _destFolder);

            _destFile = Path.Combine(_destFolder, FileName);
            Assert.IsTrue(File.Exists(_destFile));
            var allObjects = _excel.GetExcelFileObjects(_destFile);

            var rows = allObjects.GetLength(0);

            //var columns = allObjects.GetLength(1);
            for (var r = 1; r < rows; r++)
            {
                var pageObject = new PageElement
                {
                    Name  = allObjects.GetValue(r, 0).ToString(),
                    By    = allObjects.GetValue(r, 1).ToString(),
                    Query = allObjects.GetValue(r, 2).ToString(),
                };
                Console.WriteLine(pageObject);
                Assert.NotNull(pageObject);
            }
        }
Exemplo n.º 3
0
        public void TestGetARowData()
        {
            var uatRowId = 2;

            Assert.IsTrue(File.Exists(Path.Combine(_filePath, FileName)));
            // copy file
            _destFolder = Path.Combine(
                FileAndFolder.GetExecutionDirectory(),
                SolutionFolders.Resources.ToString(),
                SolutionFolders.Resources.ToString(),
                "HomePageLocator"
                );
            if (!Directory.Exists(_destFolder))
            {
                Directory.CreateDirectory(_destFolder);
            }
            FileAndFolder.CopyFile(FileName, _filePath, FileName, _destFolder);

            _destFile = Path.Combine(_destFolder, FileName);
            Assert.IsTrue(File.Exists(_destFile));

            var row = _excel.GetRow(_destFile, uatRowId);

            Console.WriteLine(row);
            Assert.NotNull(row, "Row Should not be null");
            Assert.IsTrue(row.Count == 3, "Expecting 3 Columns in the row id: " + uatRowId);
        }
Exemplo n.º 4
0
        public void ThenTheExistUnderReprtLogs(string logFileName)
        {
            var exe       = FileAndFolder.GetExecutionDirectory();
            var logFolder = Path.Combine(exe, SolutionFolders.Reports.ToString(), SolutionFolders.Logs.ToString());

            Assert.True(Directory.Exists(logFolder), "Log fololder should be in " + logFolder);
            var logfile = Path.Combine(logFolder, logFileName);

            Assert.True(File.Exists(logfile), $"Log File Name: {logFileName} - Full Path: {logfile}");
        }
 public void OverwriteSaveFileOnDisk()
 {
     byte[] fileBytes = Convert.FromBase64String(_fileBase64Content);
     if (File.Exists(_testFileName))
     {
         File.Delete(_testFileName);
     }
     FileAndFolder.SaveFileAsync(_testFileName, new byte[] { }, default).Wait();
     FileAndFolder.SaveFileAsync(_testFileName, fileBytes, true, default).Wait();
     Assert.True(File.Exists(_testFileName));
     File.Delete(_testFileName);
 }
        public async Task SaveFileOnDiskThrowsException()
        {
            byte[] fileBytes = Convert.FromBase64String(_fileBase64Content);
            await FileAndFolder.SaveFileAsync(_testFileName, new byte[] { }, default);

            InvalidOperationException ex = await Assert.ThrowsAsync <InvalidOperationException>(async() => await FileAndFolder.SaveFileAsync(_testFileName, fileBytes, false, default));

            Assert.IsType <InvalidOperationException>(ex);
            if (File.Exists(_testFileName))
            {
                File.Delete(_testFileName);
            }
        }
Exemplo n.º 7
0
        List <Mat> Detect(Image <Bgr, byte> img, bool xoay = true)
        {
            string _dir        = FileAndFolder.GetRunningPath();
            string modelDetect = Path.Combine(_dir, "lib", "pcn_model");
            var    api         = new APIGetFace(
                Path.Combine(modelDetect, "PCN-1.prototxt"),
                Path.Combine(modelDetect, "PCN-2.prototxt"),
                Path.Combine(modelDetect, "PCN-3.prototxt"),
                Path.Combine(modelDetect, "PCN.caffemodel")
                );
            //  var list = API.Recognize_FaceKit(img);
            var list = api.GetFace(img, 30, xoay);

            return(list);
        }
Exemplo n.º 8
0
        List <float[]> FaceNet(Image <Bgr, byte> imgRoot)
        {
            var    result      = new List <float[]>();
            string _dir        = FileAndFolder.GetRunningPath();
            string modelFace   = Path.Combine(_dir, "lib", "FaceModel", "facemodel.pb");
            string modelTensor = Path.Combine(_dir, "lib", "FaceModel", "facetesor.dll");
            var    api         = new APIRecognizeFace(modelFace, modelTensor);
            var    facesInRoot = Detect(imgRoot);

            foreach (var item in facesInRoot)
            {
                var ar = api.FaceNet(item);
                result.Add(ar);
            }
            return(result);
        }
        public void GlobalTeardown()
        {
            var exeDir       = FileAndFolder.GetExecutionDirectory();
            var allureReport = Path.GetFullPath(Path.Combine(exeDir, "..\\..\\"));

            allureReport = Path.Combine(allureReport, SolutionFolders.Reports.ToString());
            var filename             = "TestResult.xml";
            var allureReportFullPath = Path.Combine(allureReport, filename);

            Assert.True(File.Exists(allureReportFullPath));

            var configurationReader = new ConfigurationReader();
            var uat = configurationReader.ReadFolderPathFromConfigurationFile(SolutionFolders.Reports);

            FileAndFolder.CopyFile(filename, allureReport, filename, uat);
            Assert.IsTrue(File.Exists(Path.Combine(uat, filename)));
        }
Exemplo n.º 10
0
        public void GlobalSetup()
        {
            XmlConfigurator.Configure();
            var dir = AppContext.BaseDirectory;
            var allureConfigJson         = Path.GetFullPath(Path.Combine(dir, "..\\..\\"));
            var allureConfigJsonFullPath = Path.Combine(allureConfigJson, AllureConfigurationFileName);

            if (!File.Exists(Path.Combine(dir, AllureConfigurationFileName)))
            {
                FileAndFolder.CopyFile(AllureConfigurationFileName, allureConfigJsonFullPath,
                                       AllureConfigurationFileName, dir);
            }
            Environment.SetEnvironmentVariable(
                AllureConstants.ALLURE_CONFIG_ENV_VARIABLE,
                Path.Combine(dir, AllureConstants.CONFIG_FILENAME));
            Log.Info($"ALLURE_CONFIG_ENV_VARIABLE Environment Variable Set to: {dir}");
            var config = AllureLifecycle.Instance.JsonConfiguration;

            Log.Info(config);
        }
Exemplo n.º 11
0
        public List <PageElement> GetPageElementsFromExccelFile(string filename, string[] folderStructure)
        {
            var exeDir = FileAndFolder.GetExecutionDirectory();

            Log.Info("Execution directory is: " + exeDir);
            var fileLocation = exeDir;

            foreach (var folder in folderStructure)
            {
                fileLocation = Path.Combine(fileLocation, folder);
                Log.Info("New Path: " + fileLocation);
            }
            fileLocation = Path.Combine(fileLocation, filename);
            if (!File.Exists(fileLocation))
            {
                var message = $"Trying to Open {filename} from {fileLocation}";
                Log.Error(message);
                throw new FileNotFoundException(message);
            }
            var spreadsheet  = new SpreadsheetUtility();
            var excelObjects = spreadsheet.GetExcelFileObjects(fileLocation);
            var pageElements = new List <PageElement>();

            var rows = excelObjects.GetLength(0);

            //var columns = allObjects.GetLength(1);
            for (var r = 1; r < rows; r++)
            {
                var pageElement = new PageElement()
                {
                    Name  = excelObjects.GetValue(r, 0).ToString(),
                    By    = excelObjects.GetValue(r, 1).ToString(),
                    Query = excelObjects.GetValue(r, 2).ToString(),
                };
                Log.Info(pageElement + " Added To the Collection");
                Console.WriteLine(pageElement);
                Assert.NotNull(pageElement);
                pageElements.Add(pageElement);
            }
            return(pageElements);
        }
Exemplo n.º 12
0
        /// <summary>
        /// attempts to parse stdout for any runtime errors
        /// </summary>
        /// <returns></returns>
        public string GetErrors()
        {
            string data = string.Empty;

            try
            {
                var ar  = FileAndFolder.StreamAllLines(LogPath);
                int len = ar.Length;

                // get the last 2 lines
                for (int i = len - 2; i < len; i++)
                {
                    data += ar[i] + "\n";
                }
                data.TrimEnd('\n');

                return(data);
            }
            catch (Exception)
            {
                return(data);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Read the contents of the stdout.txt log file into a List<string>
        /// </summary>
        /// <returns></returns>
        public static List <string> ReadLog()
        {
            LogParser lp = new LogParser();

            // check whether stdout.txt doesnt exist or not
            if (!File.Exists(lp.LogPath))
            {
                EmptyLoad();

                if (!File.Exists(lp.LogPath))
                {
                    return(new List <string>());
                }
            }
            else
            {
                // it does exist - emptyload anyways (in case the version has changed)
                EmptyLoad();
            }


            string[] arr = FileAndFolder.StreamAllLines(lp.LogPath); // File.ReadAllLines(lp.LogPath);
            return(arr.ToList());
        }
Exemplo n.º 14
0
        public void TestCanCopyFiles()
        {
            var uat      = FileAndFolder.GetExecutionDirectory();
            var filename = "Test.txt";
            var path     = Path.Combine(uat, filename);

            try
            {
                Assert.IsFalse(File.Exists(path));
                var newPath = Path.Combine(uat, SolutionFolders.Reports.ToString());
                Assert.IsFalse(File.Exists(Path.Combine(newPath, filename)));
                using (var fs = File.Create(path))
                {
                    var info = new UTF8Encoding(true).GetBytes("This is some text in the file.");
                    // Add some information to the file.
                    fs.Write(info, 0, info.Length);
                }
                FileAndFolder.CopyFile(filename, uat, filename, newPath);
                Console.WriteLine("Solution Dir: " + uat);
                Assert.IsTrue(File.Exists(Path.Combine(newPath, filename)));
                File.Delete(path);
                newPath = Path.Combine(newPath, filename);
                File.SetAttributes(newPath, FileAttributes.Normal);

                File.Delete(newPath);
                Assert.IsFalse(File.Exists(path));
                Assert.IsFalse(File.Exists(newPath));
            }
            finally
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
            }
        }
Exemplo n.º 15
0
 public ConfigurationReader()
 {
     _solutionDir = FileAndFolder.GetExecutionDirectory();
     Log.Info(GetType() + " Dir= " + _solutionDir);
 }
Exemplo n.º 16
0
        public void GivenICanGetProjectExecutionDirectory()
        {
            var exe = FileAndFolder.GetExecutionDirectory();

            Log.Info("Execution Directory is: " + exe);
        }
Exemplo n.º 17
0
        // Start ROM scan and import process for specific system
        public void BeginRomImport(int _systemId, ProgressDialogController _dialog)
        {
            allowedFiles = new List <string>();
            dialog       = _dialog;
            systemId     = _systemId;

            Common.Eventing.Listeners.ProgressDialogListener l = new Common.Eventing.Listeners.ProgressDialogListener(dialog, SignatureType.Archive);
            l.Subscribe(archive);

            // get path to ROM folder
            romFolderPath = GetPath(systemId);
            // get allowed file types for this particular system
            HashSet <string> exts = GSystem.GetAllowedFileExtensions(systemId);

            // get a list of games for this system currently already in the database
            presentGames = (from g in Games
                            where g.systemId == systemId
                            select g).ToList();
            // get all files from romfolderpath and sub directories that have an allowed extension
            IEnumerable <string> romFiles = FileAndFolder.GetFiles(romFolderPath, true);

            // if romfiles is null break
            if (romFiles == null)
            {
                return;
            }

            // populate list of allowed file paths
            foreach (string s in exts)
            {
                foreach (string p in romFiles)
                {
                    if (p.EndsWith(s))
                    {
                        //MessageBoxResult result5 = MessageBox.Show(p);
                        allowedFiles.Add(p);
                    }
                }
            }

            // calculate the number of files to be processed
            numFiles = allowedFiles.Count;
            progress = 0;
            // set base dialog message
            strBase = "Scanning: ";

            // now we have a list of allowed files, loop through them
            foreach (string file in allowedFiles)
            {
                if (_dialog.IsCanceled)
                {
                    return;
                }
                ProcessFile(file);
            }

            // whatever games are left in the presentGames list should be marked as hidden as they have not been found
            if (presentGames.Count > 0)
            {
                foreach (Game g in presentGames)
                {
                    g.hidden = true;
                    RomsToUpdate.Add(g);
                    HiddenStats++;
                }
            }

            //GameListBuilder.UpdateFlag();
        }
Exemplo n.º 18
0
        /// <summary>
        /// Attempts to parse data from either stdout or console
        /// </summary>
        public void ParseData()
        {
            // check whether this is the first parse or not (so it has to be forced)
            if (IsInit)
            {
                IsDirty = true;
                IsInit  = false;
            }


            Paths paths = Paths.GetPaths();

            if (paths != null)
            {
                LogPath     = paths.mednafenExe + @"\stdout.txt";
                MednafenEXE = paths.mednafenExe + @"\mednafen.exe";
            }

            if (!IsDirty)
            {
                return;
            }

            // With mednafen >= 1.21.0 we can now call mednafen from an existing console and get
            // the required output from the console itself - try this method first
            // if no data is returned check stdout.txt
            if (File.Exists(MednafenEXE))
            {
                // first try new method
                string args = "\"" + MednafenEXE + "\" EmptyTriggerConsole";

                /*
                 *
                 * var conProcess = new Process
                 * {
                 *  StartInfo = new ProcessStartInfo
                 *  {
                 *      FileName = "cmd.exe",
                 *      //Arguments = args,
                 *      UseShellExecute = false,
                 *      RedirectStandardOutput = true,
                 *      RedirectStandardInput = true,
                 *      CreateNoWindow = true,
                 *      WindowStyle = ProcessWindowStyle.Hidden
                 * }
                 * };
                 *
                 * // set the environment variable to hide popups
                 * conProcess.StartInfo.EnvironmentVariables["MEDNAFEN_NOPOPUPS"] = "1";
                 *
                 * conProcess.Start();
                 * int procId = conProcess.Id;
                 *
                 * conProcess.StandardInput.WriteLine(args);
                 * conProcess.StandardInput.Flush();
                 * conProcess.StandardInput.Close();
                 *
                 * Output = string.Empty;
                 *
                 * while (!conProcess.StandardOutput.EndOfStream)
                 * {
                 *  string line = conProcess.StandardOutput.ReadLine();
                 *  Output += line;
                 *  Output += "\n";
                 * }
                 *
                 * if (!Output.Contains("Starting Mednafen"))
                 * {
                 *
                 */
                // no output detected - try old method
                Output = string.Empty;

                //Thread.Sleep(500);

                var winProcess = new Process
                {
                    StartInfo = new ProcessStartInfo
                    {
                        FileName        = MednafenEXE,
                        Arguments       = "EmptyTriggerWindow",
                        WindowStyle     = ProcessWindowStyle.Hidden,
                        CreateNoWindow  = true,
                        UseShellExecute = false
                    }
                };

                // set the environment variable to hide popups
                winProcess.StartInfo.EnvironmentVariables["MEDNAFEN_NOPOPUPS"] = "1";

                winProcess.Start();
                winProcess.WaitForExit();

                // attempt to read from stdout.txt
                // check whether stdout.txt doesnt exist or not
                if (!File.Exists(LogPath))
                {
                    Thread.Sleep(10);
                    ParseData();
                    Thread.Sleep(10);

                    if (!File.Exists(LogPath))
                    {
                        Output = string.Empty;
                    }
                    else
                    {
                        var ar = FileAndFolder.StreamAllLines(LogPath);
                        foreach (var a in ar)
                        {
                            Output += a + "\n";
                        }
                    }
                }
                else
                {
                    var ar = FileAndFolder.StreamAllLines(LogPath);
                    foreach (var a in ar)
                    {
                        Output += a + "\n";
                    }
                }

                /*
                 * }
                 */

                // attempt to parse the output
                List <string> list = Output.Replace("\r", "\n").Split('\n').ToList();

                if (list.Count() < 1 || list == null)
                {
                    // no data
                    return;
                }

                // get version info
                string versionLine = (from a in list
                                      where a.Contains(" Mednafen ")
                                      select a).FirstOrDefault();

                if (versionLine != null && versionLine.Trim() != "")
                {
                    // split line
                    string[] spl = versionLine.Split(new string[] { "Mednafen " }, StringSplitOptions.None);

                    // get the last item in the array (the version number)
                    VersionString = spl.Last().Trim();

                    // process version number
                    MedVersionDesc = MednafenVersionDescriptor.ReturnVersionDescriptor(VersionString);
                }

                IsDirty = false;

                // get joystick IDs
                Controllers.Clear();

                if (VersionChecker.Instance.IsNewConfig)
                {
                    // new version
                    var lines = list.Where(a => a.Contains("ID: ")).ToList();

                    foreach (var l in lines)
                    {
                        ControllerInfo ci = new ControllerInfo();

                        if (l.ToLower().Contains("xinput") ||
                            l.ToLower().Contains("XBOX 360") ||
                            l.Contains("00000000000000000001"))
                        {
                            // mednafen has probably detected this as an xinput controller
                            ci.Type = ControllerType.XInput;
                        }
                        else
                        {
                            // mednafen has probably detected this as a directinput controller
                            ci.Type = ControllerType.DirectInput;
                        }

                        // split the string up
                        string[] arr  = l.TrimStart().Replace("ID: ", "").Split(new string[] { " - " }, StringSplitOptions.None);
                        string   ID   = arr[0]; //.TrimStart('0').TrimStart('x');
                        string   Name = arr[1].Trim();

                        ci.ID   = ID;
                        ci.Name = Name;

                        Controllers.Add(ci);
                    }
                }
                else
                {
                    // old version
                    var lines = list.Where(a => a.TrimStart().StartsWith("Joystick ")).ToList();

                    foreach (var l in lines)
                    {
                        ControllerInfo ci = new ControllerInfo();

                        if (l.ToLower().Contains("xinput") ||
                            l.ToLower().Contains("XBOX 360") ||
                            l.Contains("000000000001"))
                        {
                            // mednafen has probably detected this as an xinput controller
                            ci.Type = ControllerType.XInput;
                        }
                        else
                        {
                            // mednafen has probably detected this as a directinput controller
                            ci.Type = ControllerType.DirectInput;
                        }

                        string trimmed = l.Trim();

                        // split the string up
                        string[] arr = trimmed.Split(new string[] { " - " }, StringSplitOptions.None);
                        ci.Name = arr[1];
                        ci.ID   = arr[2].Replace("Unique ID: ", "");

                        Controllers.Add(ci);
                    }
                }



                IsDirty = false;
            }
        }
Exemplo n.º 19
0
 public void ReturnFileNameTest(string fullFileName)
 => Assert.Equal("file.ext", FileAndFolder.RemovePath(fullFileName));
Exemplo n.º 20
0
        public void ReturnNetworkPathBaseTest(string fullFileName)
        {
            string result = FileAndFolder.NetworkPathBase(fullFileName);

            Assert.Equal(@"\\server\sharedfolder", result);
        }
Exemplo n.º 21
0
        public void ReturnNetworkPathEmptyTest(string fullFileName)
        {
            string result = FileAndFolder.NetworkPathBase(fullFileName);

            Assert.True(string.IsNullOrWhiteSpace(result));
        }
Exemplo n.º 22
0
 public void SaveFileOnDisk()
 {
     byte[] fileBytes = Convert.FromBase64String(_fileBase64Content);
     FileAndFolder.SaveFileAsync(_testFileName, fileBytes, default).Wait();
     Assert.True(File.Exists(_testFileName));
 }
Exemplo n.º 23
0
 public void Setup()
 {
     _excel    = new SpreadsheetUtility();
     _exePath  = FileAndFolder.GetProjectPath();
     _filePath = Path.Combine(_exePath, "DevTests", SolutionFolders.Resources.ToString());
 }