public async Task Test_ArtifactAccess_StoreWithClean() { var fileSystemMock = new FileSystemMock(); var configuration = new ConfigurationBuilder().Build(); var serviceProvider = new ServiceCollection() .AddArtifactAccess(configuration) .AddSingleton(fileSystemMock.Object) .BuildServiceProvider(); var sut = serviceProvider.GetRequiredService <IArtifactAccess>(); await sut.Store(new StoreArtifactsRequest { OutputLocation = new FileSystemOutputLocation() { Path = "dist", Clean = true }, Artifacts = new Artifact[] { new Artifact() { Path = "test.txt", Contents = Encoding.UTF8.GetBytes(string.Empty) } } }); fileSystemMock.CreatedDirectories.Count.Should().Be(1); }
public async Task Test_SeoPlugin_WithoutUsingResultsInEmptyString() { var fileSystemMock = new FileSystemMock(); var metadataProviderMock = new YamlFrontMatterMetadataProvider(new YamlParser()); var configuration = new ConfigurationBuilder().Build(); var serviceProvider = new ServiceCollection() .AddTransient <IPlugin, SeoPlugin>() .AddTransformationEngine(configuration) .AddSingleton(fileSystemMock.Object) .AddSingleton <IMetadataProvider>(metadataProviderMock) .BuildServiceProvider(); var engine = serviceProvider.GetRequiredService <ITransformationEngine>(); var model = new Mock <RenderData>(); var renderResult = await engine.Render(new MetadataRenderRequest[] { new MetadataRenderRequest { Metadata = model.Object } }); renderResult.Should().NotBeNull(); renderResult.Length.Should().Be(1); var renderContent = renderResult[0].Content; renderContent.Should().BeEmpty(); }
public async Task ImportingWorks(bool providedFileMD5Matches) { 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(); } }
public void LoggerUsersIDateProviderToChooseLogFile() { Logger.Log(TestMessage); DateProviderMock.VerifyGet(dp => dp.Today, Times.AtLeastOnce); FileSystemMock.Verify(fs => fs.Append(DefaultLogFileName, TestMessage), Times.Once); }
private IgnoreOnExtensionsChecker CreateIgnoreOnExtensionsChecker(string[] exclusiveEx) { IFileSystem fileSystem = new FileSystemMock(); IExceptionHandler exceptionHandler = MockBuilder.CreateIExceptionHandler().Object; return(new IgnoreOnExtensionsChecker(exclusiveEx, fileSystem, exceptionHandler)); }
public async Task Test_SiteManager_GenerateSite() { var fileProcessorMock = new FileProcessorMock(); var artifactAccessMock = new ArtifactAccessMock(); var fileSystemMock = new FileSystemMock(); var yamlParserMock = new YamlParserMock(); var transformEngineMock = new Mock <ITransformationEngine>(); var rootDirectory = Path.Combine(Environment.CurrentDirectory); var configuration = new ConfigurationBuilder().Build(); var serviceProvider = new ServiceCollection() .AddFileSystem(rootDirectory) .AddArtifactAccess(configuration) .AddTransformationEngine(configuration) .AddSiteManager(configuration) .AddSingleton(fileProcessorMock.Object) .AddSingleton(artifactAccessMock.Object) .AddSingleton(fileSystemMock.Object) .AddSingleton(yamlParserMock.Object) .AddSingleton(transformEngineMock.Object) .Configure <SiteInfo>(_ => { _.Url = "https://example.com"; }) .BuildServiceProvider(); var siteManager = serviceProvider.GetService <ISiteManager>(); await siteManager.GenerateSite(new GenerateSiteRequest { Configuration = new SiteConfiguration { } }); }
public async Task <Project> Identify_base_project(string name, Project expectedProject) { if (expectedProject == null) { throw new ArgumentNullException(nameof(expectedProject)); } var expectedProjectContents = GetFileSystemDictionary(expectedProject); string expectedPath = $"./{name}"; FileSystemMock.Setup(m => m.GetRelativePath(expectedProjectContents.Path)) .Returns(expectedPath); var identifier = CreateTestClass(); bool shouldIdentify = await identifier.ShouldIdentify(null, expectedProjectContents); ShouldHaveIdentified(expectedProject, shouldIdentify); bool isMatch = await identifier.IsMatchAsync(null, expectedProjectContents); ShouldHaveMatched(expectedProject, isMatch); var actualProject = await identifier.CreateOrModifyAsync(null, expectedProjectContents); // no project created yet FileSystemMock.VerifyAll(); Assert.Equal(name, actualProject.Name); // used for labeling test Assert.Equal(expectedProjectContents.Name, actualProject.Name); Assert.Equal(expectedPath, actualProject.Paths.Single()); return(actualProject); }
public void LogAppendsMessageToExistingLogFile() { Logger.Log(TestMessage); FileSystemMock.Verify(fs => fs.Exists(DefaultLogFileName), Times.Once); FileSystemMock.Verify(fs => fs.Create(DefaultLogFileName), Times.Never); FileSystemMock.Verify(fs => fs.Append(DefaultLogFileName, TestMessage), Times.Once); }
public void NeedToCopy_Filenew() { FileMock file = new FileMock(null); FileSystemMock fileSystem = new FileSystemMock(file); NeedToCopyWithConfirmation needToCopyUpdatedOnlyChecker = new NeedToCopyWithConfirmation(fileSystem, null); Assert.True(needToCopyUpdatedOnlyChecker.NeedToCopy(null, "dummy", "dummy")); }
private void AddConfigFile(FileSystemMock fileSystem, string name) { var path = new FullPath(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)) .Combine(new RelativePath(ConfigurationDirectoryNames.LocalUserConfigurationDirectoryName)); var cfgdir = fileSystem.AddDirectories(path.Value); cfgdir.AddFile(name, LoadConfigFile(name)); }
// Analysis disable once InconsistentNaming public void LoadThumbnail_ReturnsNull_IfThumbnailDoesNotExist() { var fileSystem = new FileSystemMock(); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.LoadThumbnail(largeThumbnailUri); Assert.IsNull(result); }
// Analysis disable once InconsistentNaming public void GetThumbnailPath_ReturnsPathForNormalThumbnail() { var fileSystem = new FileSystemMock(); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.GetThumbnailPath(fileUri, ThumbnailSize.Normal); Assert.AreEqual(normalThumbnailUri, result); }
// Analysis disable once InconsistentNaming public void Constructor_CreatesThumbnailFolders_IfTheyDontExist() { var fileSystem = new FileSystemMock(); // Analysis disable once ObjectCreationAsStatement new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); fileSystem.DirectoryMock.Verify(m => m.CreateDirectory(new SafeUri(largeThumbnailPath)), Times.Once()); fileSystem.DirectoryMock.Verify(m => m.CreateDirectory(new SafeUri(normalThumbnailPath)), Times.Once()); }
// Analysis disable once InconsistentNaming public void IsValid_ReturnsFalse_IfFileDoesNotExist() { var fileSystem = new FileSystemMock(); var pixbuf = PixbufMock.CreatePixbuf(fileUri, fileMTime + 1); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.IsValid(fileUri, pixbuf); Assert.IsFalse(result); }
public void LogCreatesLogFileIfNotExistsAndAppendsMessage() { FileSystemMock.Setup(fs => fs.Exists(DefaultLogFileName)).Returns(false); Logger.Log(TestMessage); FileSystemMock.Verify(fs => fs.Exists(DefaultLogFileName), Times.Once); FileSystemMock.Verify(fs => fs.Create(DefaultLogFileName), Times.Once); FileSystemMock.Verify(fs => fs.Append(DefaultLogFileName, TestMessage), Times.Once); }
// Analysis disable once InconsistentNaming public void DeleteThumbnail_DoesNotDeleteThumbnails_IfNotExist() { var fileSystem = new FileSystemMock(); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); thumbnailService.DeleteThumbnails(fileUri); fileSystem.FileMock.Verify(m => m.Delete(largeThumbnailUri), Times.Never()); fileSystem.FileMock.Verify(m => m.Delete(normalThumbnailUri), Times.Never()); }
// Analysis disable once InconsistentNaming public void GetThumbnail_ReturnsNull_IfNoThumbnailerFound() { var fileSystem = new FileSystemMock(); var thumbnailerFactoryMock = new Mock <IThumbnailerFactory> (); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactoryMock.Object, fileSystem); var result = thumbnailService.GetThumbnail(fileUri, ThumbnailSize.Large); Assert.IsNull(result); }
public void AssemblyProbingServiceImpl_Can_Copy() { var sourcePath = @"C:\test\hello"; var targetPath = @"C:\foo\bar"; FileSystemMock.Setup(fs => fs.GetFiles(sourcePath)).Returns(new[] { @"C:\test\hello\world.txt", @"C:\test\hello\bar.txt" }); Service.Copy(sourcePath, targetPath); FileSystemMock.Verify(fs => fs.CopyFile(sourcePath + @"\world.txt", targetPath + @"\world.txt", true)); FileSystemMock.Verify(fs => fs.CopyFile(sourcePath + @"\bar.txt", targetPath + @"\bar.txt", true)); }
// Analysis disable once InconsistentNaming public void IsValid_ReturnsFalse_IfPixbufIsNull() { var fileSystem = new FileSystemMock(); fileSystem.SetFile(fileUri, fileMTime); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.IsValid(fileUri, null); Assert.IsFalse(result); }
// Analysis disable once InconsistentNaming public void LoadThumbnail_ReturnsPixbuf_IfThumbnailExists() { var fileSystem = new FileSystemMock(); fileSystem.SetFile(largeThumbnailUri, 0, thumbnail); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.LoadThumbnail(largeThumbnailUri); Assert.IsNotNull(result); }
public void LoggerLogsToWeekendTxtFileOnSundays() { var expectedLogFile = "weekend.txt"; DateProviderMock.Setup(dp => dp.Today).Returns(Sunday); Logger.Log(TestMessage); DateProviderMock.VerifyGet(dp => dp.Today, Times.AtLeastOnce); FileSystemMock.Verify(fs => fs.Append(expectedLogFile, TestMessage), Times.Once); }
// Analysis disable once InconsistentNaming public void IsValid_ReturnsTrue_IfPixbufIsValid() { var fileSystem = new FileSystemMock(); fileSystem.SetFile(fileUri, fileMTime); var pixbuf = PixbufMock.CreatePixbuf(fileUri, fileMTime); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.IsValid(fileUri, pixbuf); Assert.IsTrue(result); }
// Analysis disable once InconsistentNaming public void IsValid_ReturnsFalse_IfFileUriIsDifferent() { var fileSystem = new FileSystemMock(); fileSystem.SetFile(fileUri, fileMTime); var pixbuf = PixbufMock.CreatePixbuf(new SafeUri("file:///some-uri"), fileMTime); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.IsValid(fileUri, pixbuf); Assert.IsFalse(result); }
// Analysis disable once InconsistentNaming public void Constructor_DoesNotCreateThumbnailFolders_IfTheyExist() { var fileSystem = new FileSystemMock(); fileSystem.SetDirectory(new Uri(largeThumbnailPath)); fileSystem.SetDirectory(new Uri(normalThumbnailPath)); // Analysis disable once ObjectCreationAsStatement new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); fileSystem.DirectoryMock.Verify(m => m.CreateDirectory(It.IsAny <Uri> ()), Times.Never()); }
// Analysis disable once InconsistentNaming public void GetThumbnail_ReturnsNull_IfThumbnailCreationFails() { var fileSystem = new FileSystemMock(); fileSystem.SetFile(fileUri, fileMTime); thumbnailerMock.Setup(thumb => thumb.TryCreateThumbnail(largeThumbnailUri, ThumbnailSize.Large)).Returns(false); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.GetThumbnail(fileUri, ThumbnailSize.Large); Assert.IsNull(result); }
// Analysis disable once InconsistentNaming public void GetThumbnail_ReturnsPixbuf_IfValidPngExists() { var fileSystem = new FileSystemMock(); fileSystem.SetFile(fileUri, fileMTime); fileSystem.SetFile(largeThumbnailUri, 0, thumbnail); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.GetThumbnail(fileUri, ThumbnailSize.Large); Assert.IsNotNull(result); }
// Analysis disable once InconsistentNaming public void IsValid_ReturnsFalse_IfMTimeIsDifferent() { var fileSystem = new FileSystemMock(); fileSystem.SetFile(fileUri, fileLastWrite); var pixbuf = PixbufMock.CreatePixbuf(fileUri, fileLastWrite.AddMilliseconds(1.0)); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.IsValid(fileUri, pixbuf); Assert.IsFalse(result); }
// Analysis disable once InconsistentNaming public void LoadThumbnail_DeletesThumbnail_IfLoadFails() { var fileSystem = new FileSystemMock(); fileSystem.SetFile(largeThumbnailUri, 0, thumbnail); fileSystem.FileMock.Setup(m => m.Read(largeThumbnailUri)).Throws <Exception> (); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.LoadThumbnail(largeThumbnailUri); Assert.IsNull(result); fileSystem.FileMock.Verify(file => file.Delete(largeThumbnailUri), Times.Once()); }
// Analysis disable once InconsistentNaming public void DeleteThumbnail_DeletesLargeAndNormalThumbnails_IfTheyExist() { var fileSystem = new FileSystemMock(); fileSystem.SetFile(largeThumbnailUri); fileSystem.SetFile(normalThumbnailUri); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); thumbnailService.DeleteThumbnails(fileUri); fileSystem.FileMock.Verify(m => m.Delete(largeThumbnailUri), Times.Once()); fileSystem.FileMock.Verify(m => m.Delete(normalThumbnailUri), Times.Once()); }
public void AssemblyProbingServiceImpl_Can_Load() { var assembly = this.GetType().Assembly; var targetPath = @"C:\test\hello"; FileSystemMock.Setup(fs => fs.GetFiles(targetPath)).Returns(new[] { @"C:\test\hello\world.dll", @"C:\test\hello\bar.dll" }); AssemblyLoaderMock.Setup(al => al.Load("world")).Returns(assembly); AssemblyLoaderMock.Setup(al => al.Load("bar")).Returns(assembly); Service.Load(targetPath); AssemblyLoaderMock.Verify(al => al.Load("world")); AssemblyLoaderMock.Verify(al => al.Load("bar")); BuildManagerMock.Verify(bm => bm.AddReferencedAssembly(assembly), Times.Exactly(2)); }