Esempio n. 1
0
        private async Task <Tuple <RenderedTestResult, StorageFile, StorageFile> > RenderCard(FileViewModel cardFile, FileViewModel hostConfigFile, Dictionary <string, IAdaptiveCardResourceResolver> resourceResolvers)
        {
            var renderResult = await UWPTestLibrary.RenderTestHelpers.RenderCard(cardFile, hostConfigFile, resourceResolvers);

            UWPTestLibrary.ImageWaiter imageWaiter = new ImageWaiter(renderResult.Tree);

            CurrentCardVisual      = renderResult.Tree;
            CurrentCardVisualWidth = renderResult.CardWidth;

            await imageWaiter.WaitOnAllImagesAsync();

            StorageFile imageResultFile = null;
            StorageFile jsonResultFile  = null;

            if (renderResult.Error == null)
            {
                imageResultFile = await _tempResultsFolder.CreateFileAsync("Result.png", CreationCollisionOption.GenerateUniqueName);

                jsonResultFile = await _tempResultsFolder.CreateFileAsync("Result.json", CreationCollisionOption.GenerateUniqueName);

                await UWPTestLibrary.RenderTestHelpers.ResultsToFile(imageResultFile, jsonResultFile, renderResult.RoundTrippedJSON, CurrentCardVisual);
            }

            return(new Tuple <RenderedTestResult, StorageFile, StorageFile>(renderResult, imageResultFile, jsonResultFile));
        }
Esempio n. 2
0
        private async Task <Tuple <string, StorageFile, StorageFile, UIElement> > RenderCard(FileViewModel cardFile, FileViewModel hostConfigFile)
        {
            var renderResult = await UWPTestLibrary.RenderTestHelpers.RenderCard(cardFile, hostConfigFile);

            UWPTestLibrary.ImageWaiter imageWaiter = new ImageWaiter(renderResult.Item3);

            CurrentCardVisual      = renderResult.Item3;
            CurrentCardVisualWidth = renderResult.Item4;

            await imageWaiter.WaitOnAllImagesAsync();

            StorageFile imageResultFile = null;
            StorageFile jsonResultFile  = null;

            if (renderResult.Item1 == null)
            {
                imageResultFile = await _tempResultsFolder.CreateFileAsync("Result.png", CreationCollisionOption.GenerateUniqueName);

                jsonResultFile = await _tempResultsFolder.CreateFileAsync("Result.json", CreationCollisionOption.GenerateUniqueName);

                await UWPTestLibrary.RenderTestHelpers.ResultsToFile(imageResultFile, jsonResultFile, renderResult.Item2, CurrentCardVisual);
            }

            return(new Tuple <string, StorageFile, StorageFile, UIElement>(renderResult.Item1, imageResultFile, jsonResultFile, CurrentCardVisual));
        }
Esempio n. 3
0
        async public Task TestCard(FileViewModel hostConfigFile, FileViewModel cardFile)
        {
            var renderResult = await UWPTestLibrary.RenderTestHelpers.RenderCard(cardFile, hostConfigFile);

            if (renderResult.Tree != null)
            {
                UWPTestLibrary.ImageWaiter imageWaiter = new ImageWaiter(renderResult.Tree);

                StackPanel stackPanel = new StackPanel();
                stackPanel.Children.Add(renderResult.Tree);

                Border border = new Border();
                border.Width = renderResult.CardWidth;
                border.Child = stackPanel;

                ScrollViewer scrollViewer = new ScrollViewer();
                scrollViewer.Content = border;

                (Window.Current.Content as Frame).Content = scrollViewer;

                await imageWaiter.WaitOnAllImagesAsync();
            }

            StorageFile imageResultFile = null;
            StorageFile jsonResultFile  = null;

            if (renderResult.Error == null)
            {
                imageResultFile = await _tempResultsFolder.CreateFileAsync("Result.png", CreationCollisionOption.GenerateUniqueName);

                jsonResultFile = await _tempResultsFolder.CreateFileAsync("Result.json", CreationCollisionOption.GenerateUniqueName);

                await UWPTestLibrary.RenderTestHelpers.ResultsToFile(imageResultFile, jsonResultFile, renderResult.RoundTrippedJSON, renderResult.Tree);
            }

            await Task.Delay(10);

            TestResultViewModel result = await TestResultViewModel.CreateAsync(
                cardFile : cardFile,
                hostConfigFile : hostConfigFile,
                renderedTestResult : renderResult,
                actualImageFile : imageResultFile,
                actualJsonFile : jsonResultFile,
                expectedFolder : _expectedFolder,
                sourceHostConfigsFolder : _sourceHostConfigsFolder,
                sourceCardsFolder : _sourceCardsFolder);

            // For the unit test, only check that the renderer succeeded (or not) as expected, and that the round tripped json is unchanged.
            // Image comparison for the time being is not quite stable enough to run as a unit test.
            // Allow new cards to pass as long as they don't have an error
            bool testPass =
                result.Status.MatchedViaError ||
                result.Status.JsonRoundTripMatched ||
                (result.Status.NewCard && (result.Status.Error == null));

            if (!testPass)
            {
                throw new Exception(result.Status.ToString() + ": " + result.HostConfigName + "\\" + result.CardName);
            }
        }
Esempio n. 4
0
        async public Task TestCard(FileViewModel hostConfigFile, FileViewModel cardFile)
        {
            var renderResult = await UWPTestLibrary.RenderTestHelpers.RenderCard(cardFile, hostConfigFile, new Dictionary <string, AdaptiveCards.Rendering.Uwp.IAdaptiveCardResourceResolver>());

            if (renderResult.Tree != null)
            {
                UWPTestLibrary.ImageWaiter imageWaiter = new ImageWaiter(renderResult.Tree);

                StackPanel stackPanel = new StackPanel();
                stackPanel.Children.Add(renderResult.Tree);

                Border border = new Border();
                border.Width = renderResult.CardWidth;
                border.Child = stackPanel;
                (Window.Current.Content as Frame).Content = border;

                await imageWaiter.WaitOnAllImagesAsync();
            }

            StorageFile imageResultFile = null;
            StorageFile jsonResultFile  = null;

            if (renderResult.Error == null)
            {
                imageResultFile = await _tempResultsFolder.CreateFileAsync("Result.png", CreationCollisionOption.GenerateUniqueName);

                jsonResultFile = await _tempResultsFolder.CreateFileAsync("Result.json", CreationCollisionOption.GenerateUniqueName);

                await UWPTestLibrary.RenderTestHelpers.ResultsToFile(imageResultFile, jsonResultFile, renderResult.RoundTrippedJSON, renderResult.Tree);
            }

            await Task.Delay(10);

            var result = await TestResultViewModel.CreateAsync(
                cardFile : cardFile,
                hostConfigFile : hostConfigFile,
                renderedTestResult : renderResult,
                actualImageFile : imageResultFile,
                actualJsonFile : jsonResultFile,
                expectedFolder : _expectedFolder,
                sourceHostConfigsFolder : _sourceHostConfigsFolder,
                sourceCardsFolder : _sourceCardsFolder);

            // We pass if it's not a new or changed card, and if either the image and json match or they match via error
            bool testPass = !result.Status.NewCard && !result.Status.OriginalMatched &&
                            ((result.Status.ImageMatched && result.Status.JsonRoundTripMatched) || result.Status.MatchedViaError);

            if (!testPass)
            {
                throw new Exception(result.Status.ToString() + ": " + result.HostConfigName + "\\" + result.CardName);
            }
        }
Esempio n. 5
0
        async public Task TestCard(FileViewModel hostConfigFile, FileViewModel cardFile)
        {
            var renderResult = await UWPTestLibrary.RenderTestHelpers.RenderCard(cardFile, hostConfigFile);

            if (renderResult.Item3 != null)
            {
                UWPTestLibrary.ImageWaiter imageWaiter = new ImageWaiter(renderResult.Item3);

                StackPanel stackPanel = new StackPanel();
                stackPanel.Children.Add(renderResult.Item3);

                Border border = new Border();
                border.Width = renderResult.Item4;
                border.Child = stackPanel;
                (Window.Current.Content as Frame).Content = border;

                await imageWaiter.WaitOnAllImagesAsync();
            }

            StorageFile imageResultFile = null;
            StorageFile jsonResultFile  = null;

            if (renderResult.Item1 == null)
            {
                imageResultFile = await _tempResultsFolder.CreateFileAsync("Result.png", CreationCollisionOption.GenerateUniqueName);

                jsonResultFile = await _tempResultsFolder.CreateFileAsync("Result.json", CreationCollisionOption.GenerateUniqueName);

                await UWPTestLibrary.RenderTestHelpers.ResultsToFile(imageResultFile, jsonResultFile, renderResult.Item2, renderResult.Item3);
            }

            await Task.Delay(10);

            var result = await TestResultViewModel.CreateAsync(
                cardFile : cardFile,
                hostConfigFile : hostConfigFile,
                actualError : renderResult.Item1,
                actualImageFile : imageResultFile,
                actualJsonFile : jsonResultFile,
                xamlCard : renderResult.Item3,
                expectedFolder : _expectedFolder,
                sourceHostConfigsFolder : _sourceHostConfigsFolder,
                sourceCardsFolder : _sourceCardsFolder);

            if ((result.Status != TestStatus.Passed) &&
                (result.Status != TestStatus.PassedButSourceWasChanged))
            {
                throw new Exception(result.Status.ToString() + ": " + result.HostConfigName + "\\" + result.CardName);
            }
        }
Esempio n. 6
0
        async public Task TestCard(FileViewModel hostConfigFile, FileViewModel cardFile)
        {
            uint reruns = 0;
            TestResultViewModel result = null;
            bool retryImage            = true;
            bool testPass = false;

            while (retryImage)
            {
                var renderResult = await UWPTestLibrary.RenderTestHelpers.RenderCard(cardFile, hostConfigFile);

                if (renderResult.Tree != null)
                {
                    UWPTestLibrary.ImageWaiter imageWaiter = new ImageWaiter(renderResult.Tree);

                    StackPanel stackPanel = new StackPanel();
                    stackPanel.Children.Add(renderResult.Tree);

                    Border border = new Border();
                    border.Width = renderResult.CardWidth;
                    border.Child = stackPanel;

                    ScrollViewer scrollViewer = new ScrollViewer();
                    scrollViewer.Content = border;

                    (Window.Current.Content as Frame).Content = scrollViewer;

                    await imageWaiter.WaitOnAllImagesAsync();
                }

                StorageFile imageResultFile = null;
                StorageFile jsonResultFile  = null;
                if (renderResult.Error == null)
                {
                    imageResultFile = await _tempResultsFolder.CreateFileAsync("Result.png", CreationCollisionOption.GenerateUniqueName);

                    jsonResultFile = await _tempResultsFolder.CreateFileAsync("Result.json", CreationCollisionOption.GenerateUniqueName);

                    await UWPTestLibrary.RenderTestHelpers.ResultsToFile(imageResultFile, jsonResultFile, renderResult.RoundTrippedJSON, renderResult.Tree);
                }

                await Task.Delay(10);

                result = await TestResultViewModel.CreateAsync(
                    cardFile : cardFile,
                    hostConfigFile : hostConfigFile,
                    renderedTestResult : renderResult,
                    actualImageFile : imageResultFile,
                    actualJsonFile : jsonResultFile,
                    expectedFolder : _expectedFolder,
                    sourceHostConfigsFolder : _sourceHostConfigsFolder,
                    sourceCardsFolder : _sourceCardsFolder);

                testPass = result.Status.IsPassingStatus() && result.Status.OriginalMatched;

                if (!testPass)
                {
                    // Retry if we failed on image matching for an unchanged card to allow for
                    // occasional differences in image rendering
                    retryImage = result.Status.OriginalMatched && !result.Status.ImageMatched && (reruns < 3);
                    reruns++;
                }
                else
                {
                    retryImage = false;
                }
            }

            if (!testPass)
            {
                throw new Exception(result.Status.ToString() + ": " + result.HostConfigName + "\\" + result.CardName);
            }
        }