public async Task TestCreatePhotoDirectory() { // arrange var fileSystem = new MockFileSystem(); fileSystem.Directory.CreateDirectory("C:\\test\\folder"); var mockSerializer = new Mock <IDataSerializer>(); mockSerializer.Setup(x => x.Serialize(It.IsAny <PhotoDirectoryConfig>())).Returns("Content"); var service = new PhotoDirectoryCreator(fileSystem, mockSerializer.Object); var config = new PhotoDirectoryConfig("test path"); const string path = "C:\\test\\folder"; // act await service.Create(path, config); // assert var fileInfo = fileSystem.FileInfo.FromFileName("C:\\test\\folder\\" + PhotoFolderConsts.ConfigFileName); Assert.True(fileInfo.Exists); var content = fileSystem.File.ReadAllText(fileInfo.FullName); Assert.Equal("Content", content); }
public async Task Create(string path, PhotoDirectoryConfig config) { var configFilename = _fileSystem.Path.Combine(path, PhotoFolderConsts.ConfigFileName); var serializedConfig = _serializer.Serialize(config); await _fileSystem.File.WriteAllTextAsync(configFilename, serializedConfig); _fileSystem.File.SetAttributes(configFilename, FileAttributes.Hidden); }