public void Connection_Disconnect()
 {
     try
     {
         using (var share = new UncShare(@"\\nas01\BatMonTestFolder", "usrBatMonTest", "*=%$p$")) {}
     }
     catch (Exception unknown) { Assert.Fail(ExceptionFailMessage(unknown)); }
 }
 public void EnumerateFiles()
 {
     try
     {
         using (var share = new UncShare(@"\\nas01\BatMonTestFolder", "usrBatMonTest", "*=%$p$"))
         {
             Assert.IsTrue(share.GetFiles().Length >= 1);
         }
     }
     catch (Exception unknown) { Assert.Fail(ExceptionFailMessage(unknown)); }
 }
Beispiel #3
0
        protected override Result[] fetchResults()
        {
            List <Result>       r        = new List <Result>();
            WindowsShareSection settings = WindowsShareSection.getCurrentInstance;

            foreach (FolderElement f in settings.Folders)
            {
                logger.Trace(string.Format("Path: {0} User: {1}", f.Path, f.User ?? ""));

                UncShare Credentials = null;
                try
                {
                    //Initialize Credentials if needed
                    if (f.User != null)
                    {
                        Credentials = new UncShare(f.Path, f.User, f.Password);
                    }

                    //Run Filesystem Test
                    if (!System.IO.Directory.Exists(f.Path))
                    {
                        r.Add(new Result(f.ApplicationName, f.TierName, f.ProcessName, "Failure", string.Format("Path could not be found {0}", f.Path)));
                    }
                    else
                    {
                        if (f.ContentCheck & System.IO.Directory.GetFiles(f.Path).Length <= 0 & System.IO.Directory.GetDirectories(f.Path).Length <= 0)
                        {
                            r.Add(new Result(f.ApplicationName, f.TierName, f.ProcessName, "Error", string.Format("Path contains 0 files and directories {0}", f.Path)));
                        }
                        else
                        {
                            r.Add(new Result(f.ApplicationName, f.TierName, f.ProcessName, "Successful", "Folder or Network share is acessable"));
                        }
                    }
                }
                catch (System.ComponentModel.Win32Exception ex)
                {
                    r.Add(new Result(f.ApplicationName, f.TierName, f.ProcessName, "Failure", ex.Message));
                }
                finally
                {
                    //Clean up credentials if needed
                    if (Credentials != null)
                    {
                        Credentials.Dispose();
                    }
                }
            }
            return(r.ToArray());
        }
 public void Invalid_Password_ErrorHandling()
 {
     try
     {
         using (var share = new UncShare(@"\\nas01\BatMonTestFolder", "usrBatMonTest", "wrongPassword")) { }
     }
     catch (System.ComponentModel.Win32Exception ex)
     {
         if (ex.Message == "The user name or password is incorrect")
         {
             Assert.IsTrue(true);
         }
         else
         {
             Assert.Fail(ExceptionFailMessage(ex));
         }
     }
     catch (Exception unknown) { Assert.Fail(ExceptionFailMessage(unknown)); }
 }
 public void Invalid_Path_ErrorHandling()
 {
     try
     {
         using (var share = new UncShare(@"\\nas01\NonExistantFolder", "usrBatMonTest", "*=%$p$")) { }
     }
     catch (System.ComponentModel.Win32Exception ex)
     {
         if (ex.Message == "The network path was not found")
         {
             Assert.IsTrue(true);
         }
         else
         {
             Assert.Fail(ExceptionFailMessage(ex));
         }
     }
     catch (Exception unknown) { Assert.Fail(ExceptionFailMessage(unknown)); }
 }
 public void Invalid_Path_ErrorHandling()
 {
     try
     {
         using (var share = new UncShare(@"\\nas01\NonExistantFolder", "usrBatMonTest", "*=%$p$")) { }
     }
     catch (System.ComponentModel.Win32Exception ex)
     {
         //Win32Exception Error Codes
         //https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/18d8fbe8-a967-4f1c-ae50-99ca8e491d2d
         //Message = "The network path was not found"
         if (ex.NativeErrorCode == 53)
         {
             Assert.IsTrue(true);
         }
         else
         {
             Assert.Fail(ExceptionFailMessage(ex));
         }
     }
     catch (Exception unknown) { Assert.Fail(ExceptionFailMessage(unknown)); }
 }
 public void Invalid_Password_ErrorHandling()
 {
     try
     {
         using (var share = new UncShare(@"\\nas01\BatMonTestFolder", "usrBatMonTest", "wrongPassword")) { }
     }
     catch (System.ComponentModel.Win32Exception ex)
     {
         //Win32Exception Error Codes
         //https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/18d8fbe8-a967-4f1c-ae50-99ca8e491d2d
         //NativeErrorCode = 86      Message = "The specified network password is not correct"
         //NativeErrorCode = 1326    Message = "The user name or password is incorrect"
         if (ex.NativeErrorCode == 86 | ex.NativeErrorCode == 1326)
         {
             Assert.IsTrue(true);
         }
         else
         {
             Assert.Fail(ExceptionFailMessage(ex));
         }
     }
     catch (Exception unknown) { Assert.Fail(ExceptionFailMessage(unknown)); }
 }