public void WeekendLogFileRotatesWhenNewLogStartsOnSaturday() { var lastSunday = Saturday.AddDays(-6); var secondOfLastSunday = lastSunday.Add(new TimeSpan(23, 59, 59)); var expectedLogFile = "weekend.txt"; var expectedArchivedLogFile = $"weekend-{lastSunday:yyyyMMdd}.txt"; DateProviderMock.Setup(dp => dp.Today).Returns(Saturday); FileSystemMock.Setup(fs => fs.GetLastWriteTime(expectedLogFile)).Returns(secondOfLastSunday); Logger.Log(TestMessage); FileSystemMock.Verify(fs => fs.Rename(expectedLogFile, expectedArchivedLogFile), Times.Once); FileSystemMock.Verify(fs => fs.GetLastWriteTime(expectedLogFile), Times.AtLeastOnce); }
public async Task NoFileSelectionIsHandled() { await Task.Delay(50); Assert.False(Target.FileAvailable); FileSystemMock.Setup(d => d.PickFileAsync(It.Is <IEnumerable <string> >(e => e.Contains(Path.GetExtension(Target.TargetFileName))))).Returns(Task.FromResult(default(IFileInfo))); CryptographyServiceMock.Verify(d => d.ComputeMD5Async(It.IsAny <IFileInfo>()), Times.Never); LocalizationServiceMock.Verify(d => d.GetLocalizedString(It.IsAny <string>()), Times.Never); DialogsServiceMock.Verify(d => d.AlertAsync(It.IsAny <string>(), It.IsAny <string>(), null, null), Times.Never); Target.ImportCommand.Execute(null); await Task.Delay(100); Assert.False(Target.FileAvailable); }
public async Task ImportingWorks(bool providedFileMD5Matches) { await Task.Delay(50); Assert.False(Target.FileAvailable); Assert.Null(await Target.GetTargetFileAsync()); Assert.True(Target.ImportCommand.CanExecute(null)); var folder = await GetTestFilesFolderAsync(); var pickedFile = await folder.GetFileAsync("TestFile.txt"); FileSystemMock.Setup(d => d.PickFileAsync(It.Is <IEnumerable <string> >(e => e.Contains(Path.GetExtension(Target.TargetFileName))))).Returns(Task.FromResult(pickedFile)); var computedHash = providedFileMD5Matches ? Target.TargetMD5.ToUpperInvariant() : "otherHash"; CryptographyServiceMock.Setup(d => d.ComputeMD5Async(pickedFile)).Returns(Task.FromResult(computedHash)); string localizedString = nameof(localizedString); LocalizationServiceMock.Setup(d => d.GetLocalizedString(It.IsAny <string>())).Returns(localizedString); Target.ImportCommand.Execute(null); await Task.Delay(100); var expectedDialogServiceCalledTimes = providedFileMD5Matches ? Times.Never() : Times.Once(); DialogsServiceMock.Verify(d => d.AlertAsync(localizedString, localizedString, null, null), expectedDialogServiceCalledTimes); Assert.Equal(providedFileMD5Matches, Target.FileAvailable); Assert.Equal(!providedFileMD5Matches, Target.ImportCommand.CanExecute(null)); if (providedFileMD5Matches) { var targetFile = await Target.GetTargetFileAsync(); Assert.NotNull(targetFile); await targetFile.DeleteAsync(); } }
protected override IStorageService GetTarget() { FileSystemMock.Setup(d => d.LocalStorage).Returns(LocalFolder); return(new StorageService(SecureStorageMock.Object, FileSystemMock.Object)); }