Exemple #1
0
        private static async Task LoadFilesAsyncHelper(string currentName, StorageFolder currentFolder, IList <FileViewModel> insertInto)
        {
            foreach (var file in await currentFolder.GetFilesAsync())
            {
                insertInto.Add(await FileViewModel.LoadAsync(file));
            }

            foreach (var folder in await currentFolder.GetFoldersAsync())
            {
                await LoadFilesAsyncHelper(currentName + "/" + folder.Name, folder, insertInto);
            }
        }
        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);
            }
        }
Exemple #3
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)));
        }
        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);
        }