public void Can_Set_All_Date_Filesystem_Attributes_In_Files() { // Arrange var dateTime = new DateTime(1973, 09, 04, 08, 14, 37); var command = new SetFilesystemDateAttributesInFilesCommand { AccessedDate = dateTime, CommandLog = new ConsoleCommandLog(), CreatedDate = dateTime, DirectoryToSearch = _directoryToSearch, FileNamesToSearch = "TestFile*.txt", ModifiedDate = dateTime, Recursive = true, SetAccessedDate = true, SetCreatedDate = true, SetModifiedDate = true, WriteVerboseLogMessages = true }; // Act var succeeded = command.Execute(); // Assert succeeded.ShouldBeTrue(); foreach (var filename in _testFilenames) { File.Exists(filename).ShouldBeTrue(); var fileInfo = new FileInfo(filename); fileInfo.LastAccessTime.ShouldEqual(dateTime); fileInfo.CreationTime.ShouldEqual(dateTime); fileInfo.LastWriteTime.ShouldEqual(dateTime); } }
/// <summary> /// When implemented in a derived class, performs the execution of the activity. /// </summary> /// <param name="context">The execution context under which the activity executes.</param> protected override void Execute(CodeActivityContext context) { var accessedDate = AccessedDate.Get(context); var createdDate = CreatedDate.Get(context); var modifiedDate = ModifiedDate.Get(context); var directoryToSearch = DirectoryToSearch.Get(context); var fileNamesToSearch = FileNamesToSearch.Get(context); var commandLog = new CodeActivityContextCommandLog(context); var recursive = Recursive.Get(context); var setAccessedDate = SetAccessedDate.Get(context); var setCreatedDate = SetCreatedDate.Get(context); var setModifiedDate = SetModifiedDate.Get(context); var writeVerboseLogMessages = WriteVerboseLogMessages.Get(context); var command = new SetFilesystemDateAttributesInFilesCommand { AccessedDate = accessedDate, CreatedDate = createdDate, ModifiedDate = modifiedDate, DirectoryToSearch = directoryToSearch, FileNamesToSearch = fileNamesToSearch, CommandLog = commandLog, Recursive = recursive, SetAccessedDate = setAccessedDate, SetCreatedDate = setCreatedDate, SetModifiedDate = setModifiedDate, WriteVerboseLogMessages = writeVerboseLogMessages }; var successful = command.Execute(); if (false == successful) { commandLog.Error("The SetFilesystemDateAttributesInFiles activity failed."); } }
/// <summary> /// When implemented in a derived class, performs the execution of the activity. /// </summary> /// <param name="context">The execution context under which the activity executes.</param> protected override void Execute(CodeActivityContext context) { var accessedDate = AccessedDate.Get(context); var createdDate = CreatedDate.Get(context); var modifiedDate = ModifiedDate.Get(context); var directoryToSearch = DirectoryToSearch.Get(context); var fileNamesToSearch = FileNamesToSearch.Get(context); var commandLog = new CodeActivityContextCommandLog(context); var recursive = Recursive.Get(context); var setAccessedDate = SetAccessedDate.Get(context); var setCreatedDate = SetCreatedDate.Get(context); var setModifiedDate = SetModifiedDate.Get(context); var writeVerboseLogMessages = WriteVerboseLogMessages.Get(context); var command = new SetFilesystemDateAttributesInFilesCommand { AccessedDate = accessedDate, CreatedDate = createdDate, ModifiedDate = modifiedDate, DirectoryToSearch = directoryToSearch, FileNamesToSearch = fileNamesToSearch, CommandLog = commandLog, Recursive = recursive, SetAccessedDate = setAccessedDate, SetCreatedDate = setCreatedDate, SetModifiedDate = setModifiedDate, WriteVerboseLogMessages = writeVerboseLogMessages }; var successful = command.Execute(); if (false == successful) commandLog.Error("The SetFilesystemDateAttributesInFiles activity failed."); }