public static async Task LoadAsync(
            ObservableCollection <FileViewModel> cards,
            ObservableCollection <FileViewModel> hostConfigs)
        {
            await LoadFilesAsync("LinkedCards", cards);

            // Load two host configs to test
            var hostConfigFolder = await Package.Current.InstalledLocation.GetFolderAsync("LinkedHostConfigs");

            hostConfigs.Add(await FileViewModel.LoadAsync(await hostConfigFolder.GetFileAsync("sample")));
            hostConfigs.Add(await FileViewModel.LoadAsync(await hostConfigFolder.GetFileAsync("windows-timeline")));

            // Remove the WeatherLarge card since it contains a background image and often fails image comparisons
            var weatherLarge = cards.FirstOrDefault(i => i.Name.EndsWith("WeatherLarge"));

            if (weatherLarge != null)
            {
                cards.Remove(weatherLarge);
            }
        }
示例#2
0
        public static async Task LoadAsync(
            ObservableCollection <FileViewModel> cards,
            ObservableCollection <FileViewModel> hostConfigs)
        {
            await LoadFilesAsync("LinkedCards", cards);

            // Create two dummy host config file views, one for default values and one for default
            // values but with fixed height and interactivity turned off
            FileViewModel noFileModel = new FileViewModel();

            noFileModel.Name = defaultHostConfigName;
            hostConfigs.Add(noFileModel);

            FileViewModel fixedNonInteractive = new FileViewModel();

            fixedNonInteractive.Name = fixedNonInteractiveName;
            hostConfigs.Add(fixedNonInteractive);

            // Load the testVariantHostConfig to test non-default host config values
            var hostConfigFolder = await Package.Current.InstalledLocation.GetFolderAsync("LinkedHostConfigs");

            hostConfigs.Add(await FileViewModel.LoadAsync(await hostConfigFolder.GetFileAsync(testVarientHostConfigName)));
        }
示例#3
0
        public static async Task <FileViewModel> LoadAsync(StorageFile file)
        {
            var answer = new FileViewModel();

            const string linkedCardsFolder       = "LinkedCards\\";
            const string linkedHostConfigsFolder = "LinkedHostConfigs\\";
            const string expected = "Expected\\";
            const string results  = "Results\\";

            if (file.Path.Contains(linkedCardsFolder))
            {
                answer.Name = file.Path.Substring(file.Path.IndexOf(linkedCardsFolder) + linkedCardsFolder.Length);
            }
            else if (file.Path.Contains(linkedHostConfigsFolder))
            {
                answer.Name = file.Path.Substring(file.Path.IndexOf(linkedHostConfigsFolder) + linkedHostConfigsFolder.Length);
            }
            else if (file.Path.Contains(expected))
            {
                answer.Name = file.Path.Substring(file.Path.IndexOf(expected) + expected.Length);
            }
            else if (file.Path.Contains(results))
            {
                answer.Name = file.Path.Substring(file.Path.IndexOf(results) + results.Length);
            }
            else
            {
                throw new NotImplementedException("Unknown path: " + file.Path);
            }

            answer.Contents = await FileIO.ReadTextAsync(file);

            answer.Contents = answer.Contents.Replace("\r\n", "\n");
            answer.Hash     = ToSha1(answer.Contents).Substring(0, 7);

            return(answer);
        }
示例#4
0
        public static async Task <RenderedTestResult> RenderCard(FileViewModel cardFile, FileViewModel hostConfigFile, Dictionary <string, IAdaptiveCardResourceResolver> resourceResolvers)
        {
            string           error = null;
            string           roundTrippedJsonString = null;
            FrameworkElement xaml        = null;
            double           cardWidth   = 400;
            WeakReference    weakRefCard = null;

            try
            {
                AdaptiveHostConfig hostConfig = AdaptiveHostConfig.FromJsonString(hostConfigFile.Contents).HostConfig;

                if (hostConfig == null)
                {
                    error = "Parsing hostConfig failed";
                }

                else
                {
                    AdaptiveCard card = AdaptiveCard.FromJsonString(cardFile.Contents).AdaptiveCard;

                    if (card == null)
                    {
                        error = "Parsing card failed";
                    }

                    else
                    {
                        roundTrippedJsonString = card.ToJson().ToString();
                        card = AdaptiveCard.FromJsonString(roundTrippedJsonString).AdaptiveCard;

                        AdaptiveFeatureRegistration featureRegistration = new AdaptiveFeatureRegistration();
                        featureRegistration.Set("acTest", "1.0");

                        var renderer = new AdaptiveCardRenderer()
                        {
                            HostConfig          = hostConfig,
                            FeatureRegistration = featureRegistration
                        };

                        foreach (var resourceResolver in resourceResolvers)
                        {
                            renderer.ResourceResolvers.Set(resourceResolver.Key, resourceResolver.Value);
                        }

                        if (hostConfigFile.Name.Contains("windows-timeline"))
                        {
                            renderer.SetFixedDimensions(320, 180);
                            cardWidth = 320;
                        }
                        else if (hostConfigFile.Name.Contains("windows-live-tile"))
                        {
                            renderer.SetFixedDimensions(310, 310);
                            cardWidth = 310;
                        }

                        RenderedAdaptiveCard renderedCard = renderer.RenderAdaptiveCard(card);
                        weakRefCard = new WeakReference(renderedCard);

                        xaml = renderedCard.FrameworkElement as FrameworkElement;

                        if (xaml == null)
                        {
                            error = "Rendering card failed";
                        }

                        else
                        {
                            xaml = new Border()
                            {
                                Background       = new SolidColorBrush(Colors.White),
                                Child            = xaml,
                                IsHitTestVisible = false // Disable HitTest so that mouse pointer can't accidently hover over a button
                            };

                            // The theme is important to set since it'll ensure buttons/inputs appear correctly
                            if (hostConfigFile.Name.Contains("windows-notification"))
                            {
                                xaml.RequestedTheme = ElementTheme.Dark;
                            }
                            else
                            {
                                xaml.RequestedTheme = ElementTheme.Light;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                error = ex.ToString();
            }

            return(new RenderedTestResult
            {
                Error = error,
                RoundTrippedJSON = roundTrippedJsonString,
                Tree = xaml,
                CardWidth = cardWidth,
                WeakCard = weakRefCard
            });
        }
示例#5
0
        public static async Task <Tuple <string, string, UIElement, double> > RenderCard(FileViewModel cardFile, FileViewModel hostConfigFile)
        {
            string           error = null;
            string           roundTrippedJsonString = null;
            FrameworkElement xaml      = null;
            double           cardWidth = 400;

            try
            {
                AdaptiveHostConfig hostConfig = AdaptiveHostConfig.FromJsonString(hostConfigFile.Contents).HostConfig;

                if (hostConfig == null)
                {
                    error = "Parsing hostConfig failed";
                }

                else
                {
                    AdaptiveCard card = AdaptiveCard.FromJsonString(cardFile.Contents).AdaptiveCard;

                    if (card == null)
                    {
                        error = "Parsing card failed";
                    }

                    else
                    {
                        roundTrippedJsonString = card.ToJson().ToString();
                        card = AdaptiveCard.FromJsonString(roundTrippedJsonString).AdaptiveCard;

                        var renderer = new AdaptiveCardRenderer()
                        {
                            HostConfig = hostConfig
                        };

                        if (hostConfigFile.Name.Contains("windows-timeline"))
                        {
                            renderer.SetFixedDimensions(320, 180);
                            cardWidth = 320;
                        }
                        else if (hostConfigFile.Name.Contains("windows-live-tile"))
                        {
                            renderer.SetFixedDimensions(310, 310);
                            cardWidth = 310;
                        }

                        xaml = renderer.RenderAdaptiveCard(card).FrameworkElement as FrameworkElement;

                        if (xaml == null)
                        {
                            error = "Rendering card failed";
                        }

                        else
                        {
                            xaml = new Border()
                            {
                                Background       = new SolidColorBrush(Colors.White),
                                Child            = xaml,
                                IsHitTestVisible = false // Disable HitTest so that mouse pointer can't accidently hover over a button
                            };

                            // The theme is important to set since it'll ensure buttons/inputs appear correctly
                            if (hostConfigFile.Name.Contains("windows-notification"))
                            {
                                xaml.RequestedTheme = ElementTheme.Dark;
                            }
                            else
                            {
                                xaml.RequestedTheme = ElementTheme.Light;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                error = ex.ToString();
            }

            return(new Tuple <string, string, UIElement, double>(error, roundTrippedJsonString, xaml, cardWidth));
        }
 private static string GetStrippedFileName(FileViewModel file)
 {
     return(GetStrippedFileName(file.Name));
 }
        public static async Task <TestResultViewModel> CreateAsync(
            FileViewModel cardFile,
            FileViewModel hostConfigFile,
            RenderedTestResult renderedTestResult,
            StorageFile actualImageFile,
            StorageFile actualJsonFile,
            StorageFolder expectedFolder,
            StorageFolder sourceHostConfigsFolder,
            StorageFolder sourceCardsFolder)
        {
            var answer = new TestResultViewModel()
            {
                CardName                          = cardFile.Name,
                CardFile                          = cardFile,
                TestResult                        = renderedTestResult,
                HostConfigName                    = hostConfigFile.Name,
                HostConfigFile                    = hostConfigFile,
                ActualImageFile                   = actualImageFile,
                ActualRoundTrippedJsonFile        = actualJsonFile,
                _expectedFolder                   = expectedFolder,
                _sourceHostConfigsFolder          = sourceHostConfigsFolder,
                _sourceCardsFolder                = sourceCardsFolder,
                _expectedFileNameWithoutExtension = GetStrippedFileName(hostConfigFile) + "." + GetStrippedFileName(cardFile)
            };

            try
            {
                var storedInfo = await StoredTestResultInfo.DeserializeFromFileAsync(expectedFolder, answer._expectedFileNameWithoutExtension);

                if (storedInfo == null)
                {
                    answer.Status.NewCard = true;
                }
                else
                {
                    answer._oldHostConfigHash = storedInfo.HostConfigHash;
                    answer._oldCardHash       = storedInfo.CardHash;

                    if (storedInfo.Error != null)
                    {
                        answer.ExpectedError = storedInfo.Error;
                    }
                    else
                    {
                        answer.ExpectedImageFile = await expectedFolder.GetFileAsync(answer._expectedFileNameWithoutExtension + ".png");

                        answer.ExpectedRoundtrippedJsonFile = await expectedFolder.GetFileAsync(GetStrippedFileName(answer.CardFile) + "ToJson.json");
                    }
                }

                // If both had error, compare via the error
                if (answer.ExpectedError != null && answer.TestResult.Error != null)
                {
                    if (answer.ExpectedError == answer.TestResult.Error)
                    {
                        answer.Status.MatchedViaError = true;
                    }
                }

                // If neither had error, compare via the image
                else if (answer.ExpectedImageFile != null && answer.ActualImageFile != null)
                {
                    byte[] oldBytes = await GetPixelDataBytesAsync(answer.ExpectedImageFile);

                    byte[] newBytes = await GetPixelDataBytesAsync(answer.ActualImageFile);

                    if (ImageBytesAreTheSame(oldBytes, newBytes))
                    {
                        answer.Status.ImageMatched = true;
                    }

                    // Check if the round tripped json is the same
                    answer.ExpectedRoundtrippedJsonModel = await FileViewModel.LoadAsync(answer.ExpectedRoundtrippedJsonFile);

                    answer.RoundtrippedJsonModel = await FileViewModel.LoadAsync(answer.ActualRoundTrippedJsonFile);

                    if (!answer.DidRoundtrippedJsonChange)
                    {
                        answer.Status.JsonRoundTripMatched = true;
                    }
                }

                // See if the source chagned by checking
                // if the hashes have changed since the stored info
                if (storedInfo.HostConfigHash == hostConfigFile.Hash &&
                    storedInfo.CardHash == cardFile.Hash)
                {
                    answer.Status.OriginalMatched = true;
                }
            }
            catch
            {
                // Any exceptions being thrown get reported as "New", typically this results from file
                // not found of an expected file, which means it genuinely is new
                answer.Status.NewCard = true;
            }

            return(answer);
        }
示例#8
0
        public static async Task <RenderedTestResult> RenderCard(FileViewModel cardFile, FileViewModel hostConfigFile)
        {
            string           error = null;
            string           roundTrippedJsonString = null;
            FrameworkElement xaml        = null;
            double           cardWidth   = 400;
            WeakReference    weakRefCard = null;

            try
            {
                AdaptiveHostConfig hostConfig = null;
                if (hostConfigFile.Contents != null)
                {
                    hostConfig = AdaptiveHostConfig.FromJsonString(hostConfigFile.Contents).HostConfig;

                    if (hostConfig == null)
                    {
                        error = "Parsing hostConfig failed";
                    }
                }

                if (error == null)
                {
                    AdaptiveCard card = AdaptiveCard.FromJsonString(cardFile.Contents).AdaptiveCard;

                    if (card == null)
                    {
                        error = "Parsing card failed";
                    }

                    else
                    {
                        roundTrippedJsonString = card.ToJson().ToString();
                        card = AdaptiveCard.FromJsonString(roundTrippedJsonString).AdaptiveCard;

                        AdaptiveFeatureRegistration featureRegistration = new AdaptiveFeatureRegistration();
                        featureRegistration.Set("acTest", "1.0");

                        var renderer = new AdaptiveCardRenderer()
                        {
                            FeatureRegistration = featureRegistration
                        };

                        if (hostConfig != null)
                        {
                            renderer.HostConfig = hostConfig;
                        }

                        renderer.ResourceResolvers.Set("symbol", new SampleResourceResolver());

                        if (hostConfigFile.Name.Contains(FileLoadHelpers.fixedNonInteractiveName))
                        {
                            renderer.SetFixedDimensions(320, 180);
                            cardWidth = 320;

                            renderer.HostConfig.SupportsInteractivity = false;
                        }

                        RenderedAdaptiveCard renderedCard = renderer.RenderAdaptiveCard(card);
                        weakRefCard = new WeakReference(renderedCard);

                        xaml = renderedCard.FrameworkElement as FrameworkElement;

                        if (xaml == null)
                        {
                            error = "Rendering card failed";
                        }

                        else
                        {
                            xaml = new Border()
                            {
                                Background       = new SolidColorBrush(Colors.White),
                                Child            = xaml,
                                IsHitTestVisible = false // Disable HitTest so that mouse pointer can't accidently hover over a button
                            };

                            // The theme is important to set since it'll ensure buttons/inputs appear correctly
                            if (hostConfigFile.Name.Contains(FileLoadHelpers.testVarientHostConfigName))
                            {
                                xaml.RequestedTheme = ElementTheme.Dark;
                            }
                            else
                            {
                                xaml.RequestedTheme = ElementTheme.Light;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                error = ex.ToString();
            }

            return(new RenderedTestResult
            {
                Error = error,
                RoundTrippedJSON = roundTrippedJsonString,
                Tree = xaml,
                CardWidth = cardWidth,
                WeakCard = weakRefCard
            });
        }