async Task VerifyBinary(IEnumerable <Stream> streams, VerifySettings settings)
    {
        var extension     = settings.ExtensionOrBin();
        var innerVerifier = new VerifyEngine(
            extension,
            settings,
            testType,
            directory,
            testName);
        var list = streams.ToList();

        for (var index = 0; index < list.Count; index++)
        {
            var suffix = GetSuffix(list, index);

            var stream       = list[index];
            var file         = GetFileNames(extension, settings.Namer, suffix);
            var verifyResult = await StreamVerifier.VerifyStreams(stream, file);

            switch (verifyResult)
            {
            case VerifyResult.MissingVerified:
                innerVerifier.AddMissing(file);
                break;

            case VerifyResult.NotEqual:
                innerVerifier.AddNotEquals(file);
                break;

            case VerifyResult.Equal:
                innerVerifier.AddEquals(file);
                break;
            }
        }

        await innerVerifier.ThrowIfRequired();
    }
Esempio n. 2
0
        static bool TestRecursive(string originPath, string restorePath)
        {
//			Console.WriteLine ("O {0}", originPath);
//			Console.WriteLine ("R {0}", restorePath);

            bool same = true;

            IEnumerator <FileSystemInfo> origins = (new DirectoryInfo(originPath)).EnumerateFileSystemInfos()
                                                   .OrderBy(p => p.Name)
                                                   .GetEnumerator();
            IEnumerator <FileSystemInfo> restores = (new DirectoryInfo(restorePath)).EnumerateFileSystemInfos()
                                                    .OrderBy(p => p.Name)
                                                    .GetEnumerator();

            FileSystemInfo origin, restore;

            origin  = origins.MoveNext() ? origins.Current : null;
            restore = restores.MoveNext() ? restores.Current : null;

            while (origin != null || restore != null)
            {
                int iCompare;
                if (origin != null && restore != null)
                {
                    iCompare = string.Compare(
                        origin.Name,
                        restore.Name,
                        StringComparison.InvariantCultureIgnoreCase);
                }
                else if (origin != null)
                {
                    iCompare = -1;
                }
                else                 // if (restore != null)
                {
                    iCompare = 1;
                }

                if (iCompare < 0)
                {
                    same = false;
                    Console.WriteLine("Item not in restore: {0}", origin.Name);
                    origin = origins.MoveNext() ? origins.Current : null;
                }
                else if (iCompare > 0)
                {
                    same = false;
                    Console.WriteLine("Item not in origin: {0}", restore.Name);
                    restore = restores.MoveNext() ? restores.Current : null;
                }
                else if (iCompare == 0)
                {
                    if ((origin.Attributes & FileAttributes.Directory) != (restore.Attributes & FileAttributes.Directory))
                    {
                        Console.WriteLine("Mismatch file/directory {0}", origin.FullName);
                    }
                    else if ((origin.Attributes & FileAttributes.Directory) != 0)
                    {
                        if (!TestRecursive(origin.FullName, restore.FullName))
                        {
                            same = false;
                        }
                    }
                    else
                    {
                        using (Stream input1 = new FileStream(origin.FullName, FileMode.Open, FileAccess.Read)) {
                            using (Stream input2 = new FileStream(restore.FullName, FileMode.Open, FileAccess.Read)) {
                                StreamVerifier streamVerifier = new StreamVerifier();
                                if (!streamVerifier.Verify(input1, input2))
                                {
                                    same = false;
                                }
                            }
                        }
                    }

                    origin  = origins.MoveNext() ? origins.Current : null;
                    restore = restores.MoveNext() ? restores.Current : null;
                }
            }

            return(same);
        }