private 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 <TestResultViewModel> CreateAsync( FileViewModel cardFile, FileViewModel hostConfigFile, string actualError, StorageFile actualImageFile, StorageFile actualJsonFile, StorageFolder expectedFolder, StorageFolder sourceHostConfigsFolder, StorageFolder sourceCardsFolder, UIElement xamlCard) { var answer = new TestResultViewModel() { CardName = cardFile.Name, CardFile = cardFile, XamlCard = xamlCard, HostConfigName = hostConfigFile.Name, HostConfigFile = hostConfigFile, ActualError = actualError, 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 = TestStatus.New; } 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.ActualError != null) { if (answer.ExpectedError == answer.ActualError) { answer.Status = TestStatus.Passed; } else { answer.Status = TestStatus.Failed; } } // 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 = TestStatus.Passed; } else { answer.Status = TestStatus.Failed; } // 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 = (answer.Status == TestStatus.Passed) ? TestStatus.JsonFailed : TestStatus.ImageAndJsonFailed; } } // Otherwise one had image and one had error, so fail else { answer.Status = TestStatus.Failed; } // 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 = (answer.Status == TestStatus.Failed || answer.Status == TestStatus.ImageAndJsonFailed || answer.Status == TestStatus.JsonFailed) ? TestStatus.FailedButSourceWasChanged : TestStatus.PassedButSourceWasChanged; } } 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 = TestStatus.New; } return(answer); }