This project is read-only.
2
Vote

ExistsStep.SeachPattern Error:Directory does not contain the correct number of files!Found: 0 files matching the pattern

description

Hi,
 
I am writing unit test for BizTalk 2010 application using BizUnit4.0 framework. The unit test is written for testing to check file is received at the output fileshare. I am getting the below error "System.ApplicationException: Directory does not contain the correct number of files!
Found: 0 files matching the pattern ".
But the same test passes while i am debugging via BizUnit source code. I have tried specifing the timeout via .Timeout and increased it to 3 minutes. But still no luck.
 
Any help is greatly apprecieated.
 
Thanks,
Basawa

comments

basawa_raj wrote Feb 3, 2012 at 6:55 PM

Sorry this not the issue , i have mistakely created in the Issue Trakcer

HaraldWolkenfelt wrote May 9, 2012 at 12:17 PM

I do think it is an issue.
In the (tight) do{}while loop, the exception is immediately thrown without consideration of the timeout.
When debugging, you get a timeout due to your slow-stepping.
The implementation of the now obsolete BizUnit.CoreSteps.TestSteps.FilesExistStep does work.

Harald

wrote May 9, 2012 at 12:17 PM

HaraldWolkenfelt wrote May 9, 2012 at 12:36 PM

I reworked the ExistsStep like this:

public override void Execute(Context context)
    {
        var now = DateTime.Now;
        string[] filelist = null;
        bool foundCorrectNo = false;

        do
        {
            Thread.Sleep(500);

            // Get the list of files in the directory
            filelist = Directory.GetFiles(DirectoryPath, SearchPattern);

            if (filelist.Length == ExpectedNoOfFiles)
            {
                foundCorrectNo = true;
                break;
            }

        } while (now.AddMilliseconds(Timeout) > DateTime.Now);

        context.LogInfo("FilesExistStep found: \"{0}\" files", filelist.Length);

        if (!foundCorrectNo)
        {
            // Expecting more than one file 
            throw new ApplicationException(
                String.Format(
                    "Directory does not contain the correct number of files!\n Found: {0} files matching the pattern {1}.",
                    filelist.Length,
                    SearchPattern));
        }
    }

wrote Feb 14, 2013 at 8:43 PM