public void AddToUserPathWithBackup() { var userPath = new UserPath(); userPath.AddToPath("LibraryTests_AddToUserPathWithBackup", true); string path = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.User); bool isAddedToThePath = path.Contains("LibraryTests_AddToUserPathWithBackup;"); bool backupExists = File.Exists(userPath.BackupDirectory + userPath.BackupFilename); output.WriteLine(isAddedToThePath ? "Variable is added to the path" : "Variable is NOT added to the path"); output.WriteLine(backupExists ? "Path is backed up" : "Path is NOT backed up"); output.WriteLine(userPath.BackupDirectory + userPath.BackupFilename); Assert.True((isAddedToThePath && backupExists)); }
// TODO: Refactor it soon. /// <summary> /// Handle arguments relating to the <c>Path</c>. /// </summary> /// <param name="eventType">The type of the event to handle.</param> /// <param name="options">Options for to be used according to <paramref name="eventType"/>.</param> static void HandleArgument(HandleEventType eventType, AddOptions options = null) { switch (eventType) { case HandleEventType.NoValue: Console.WriteLine("Please provide a value to be added."); break; case HandleEventType.UserPath: userPath.AddToPath( options.Value, options.BackupPathVariable, DateTime.Now.ToFileTime().ToString() ); if (Environment.GetEnvironmentVariable( "Path", EnvironmentVariableTarget.User) .EndsWith( $"{options.Value};" ) ) { Console.WriteLine($"Successfully added `{options.Value}` to the Path!"); } else { Console.WriteLine( "There seems to be an error, we could not verify if that value is actually added to the Path or not, it's nothing to worry about though!" ); } break; case HandleEventType.SystemPath: throw new NotImplementedException("Cannot add to System Path as it's not implemented."); case HandleEventType.UserAndSystemPath: throw new NotImplementedException("Cannot add to User and System Path as it's not implemented."); case HandleEventType.NoUserOrSystemPath: Console.WriteLine("Did not modify any content, exiting..."); break; } }