Exemple #1
0
        protected void AssertVisual(string expectedHash, VisualElement root, int width = 1920, int height = 1080)
        {
            var testMethod     = new StackTrace().GetFrame(1)?.GetMethod();
            var testMethodName = $"{testMethod?.ReflectedType?.Name}_{testMethod?.Name}";

            var surface = new IxenSurface(root);

            surface.ComputeLayout(width, height);
            SKBitmap bitmap = surface.RenderToBitmap();

            byte[] md5hash = _md5.ComputeHash(bitmap.Bytes);
            string hash    = Convert.ToHexString(md5hash).ToLower();

            string fileExpectedPath = Path.Combine(_outputRendersDir, $"{testMethodName}_EXPECTED.png");
            string fileErrorPath    = Path.Combine(_outputRendersDir, $"{testMethodName}_NOK.png");

            if (expectedHash == hash)
            {
                File.Delete(fileErrorPath);
                if (!File.Exists(fileExpectedPath))
                {
                    DumpBitmapToFile(fileExpectedPath, bitmap);
                }
            }
            else
            {
                DumpBitmapToFile(fileErrorPath, bitmap);

                Assert.Fail();
            }
        }