FakeDriver.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. //
  2. // FakeDriver.cs: A fake ConsoleDriver for unit tests.
  3. //
  4. using System;
  5. using System.Buffers;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.Linq;
  9. using System.Runtime.InteropServices;
  10. using System.Threading;
  11. using System.Text;
  12. // Alias Console to MockConsole so we don't accidentally use Console
  13. using Console = Terminal.Gui.FakeConsole;
  14. using Unix.Terminal;
  15. using static Terminal.Gui.WindowsConsole;
  16. using System.Drawing;
  17. namespace Terminal.Gui;
  18. /// <summary>
  19. /// Implements a mock ConsoleDriver for unit testing
  20. /// </summary>
  21. public class FakeDriver : ConsoleDriver {
  22. #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
  23. public class Behaviors {
  24. public bool UseFakeClipboard { get; internal set; }
  25. public bool FakeClipboardAlwaysThrowsNotSupportedException { get; internal set; }
  26. public bool FakeClipboardIsSupportedAlwaysFalse { get; internal set; }
  27. public Behaviors (bool useFakeClipboard = false, bool fakeClipboardAlwaysThrowsNotSupportedException = false, bool fakeClipboardIsSupportedAlwaysTrue = false)
  28. {
  29. UseFakeClipboard = useFakeClipboard;
  30. FakeClipboardAlwaysThrowsNotSupportedException = fakeClipboardAlwaysThrowsNotSupportedException;
  31. FakeClipboardIsSupportedAlwaysFalse = fakeClipboardIsSupportedAlwaysTrue;
  32. // double check usage is correct
  33. Debug.Assert (useFakeClipboard == false && fakeClipboardAlwaysThrowsNotSupportedException == false);
  34. Debug.Assert (useFakeClipboard == false && fakeClipboardIsSupportedAlwaysTrue == false);
  35. }
  36. }
  37. public static FakeDriver.Behaviors FakeBehaviors = new Behaviors ();
  38. public override bool SupportsTrueColor => false;
  39. public FakeDriver ()
  40. {
  41. if (FakeBehaviors.UseFakeClipboard) {
  42. Clipboard = new FakeClipboard (FakeBehaviors.FakeClipboardAlwaysThrowsNotSupportedException, FakeBehaviors.FakeClipboardIsSupportedAlwaysFalse);
  43. } else {
  44. if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) {
  45. Clipboard = new WindowsClipboard ();
  46. } else if (RuntimeInformation.IsOSPlatform (OSPlatform.OSX)) {
  47. Clipboard = new MacOSXClipboard ();
  48. } else {
  49. if (CursesDriver.Is_WSL_Platform ()) {
  50. Clipboard = new WSLClipboard ();
  51. } else {
  52. Clipboard = new CursesClipboard ();
  53. }
  54. }
  55. }
  56. }
  57. public override void End ()
  58. {
  59. FakeConsole.ResetColor ();
  60. FakeConsole.Clear ();
  61. }
  62. public override void Init (Action terminalResized)
  63. {
  64. FakeConsole.MockKeyPresses.Clear ();
  65. TerminalResized = terminalResized;
  66. Cols = FakeConsole.WindowWidth = FakeConsole.BufferWidth = FakeConsole.WIDTH;
  67. Rows = FakeConsole.WindowHeight = FakeConsole.BufferHeight = FakeConsole.HEIGHT;
  68. FakeConsole.Clear ();
  69. ResizeScreen ();
  70. // Call InitializeColorSchemes before UpdateOffScreen as it references Colors
  71. CurrentAttribute = MakeColor (Color.White, Color.Black);
  72. InitializeColorSchemes ();
  73. ClearContents ();
  74. }
  75. public override void UpdateScreen ()
  76. {
  77. var savedRow = FakeConsole.CursorTop;
  78. var savedCol = FakeConsole.CursorLeft;
  79. var savedCursorVisible = FakeConsole.CursorVisible;
  80. var top = 0;
  81. var left = 0;
  82. var rows = Rows;
  83. var cols = Cols;
  84. System.Text.StringBuilder output = new System.Text.StringBuilder ();
  85. Attribute redrawAttr = new Attribute ();
  86. var lastCol = -1;
  87. for (var row = top; row < rows; row++) {
  88. if (!_dirtyLines [row]) {
  89. continue;
  90. }
  91. FakeConsole.CursorTop = row;
  92. FakeConsole.CursorLeft = 0;
  93. _dirtyLines [row] = false;
  94. output.Clear ();
  95. for (var col = left; col < cols; col++) {
  96. lastCol = -1;
  97. var outputWidth = 0;
  98. for (; col < cols; col++) {
  99. if (!Contents [row, col].IsDirty) {
  100. if (output.Length > 0) {
  101. WriteToConsole (output, ref lastCol, row, ref outputWidth);
  102. } else if (lastCol == -1) {
  103. lastCol = col;
  104. }
  105. if (lastCol + 1 < cols)
  106. lastCol++;
  107. continue;
  108. }
  109. if (lastCol == -1) {
  110. lastCol = col;
  111. }
  112. Attribute attr = Contents [row, col].Attribute.Value;
  113. // Performance: Only send the escape sequence if the attribute has changed.
  114. if (attr != redrawAttr) {
  115. redrawAttr = attr;
  116. FakeConsole.ForegroundColor = (ConsoleColor)attr.Foreground.Value;
  117. FakeConsole.BackgroundColor = (ConsoleColor)attr.Background.Value;
  118. }
  119. outputWidth++;
  120. var rune = (Rune)Contents [row, col].Runes [0];
  121. output.Append (rune.ToString ());
  122. if (rune.IsSurrogatePair () && rune.GetColumns () < 2) {
  123. WriteToConsole (output, ref lastCol, row, ref outputWidth);
  124. FakeConsole.CursorLeft--;
  125. }
  126. Contents [row, col].IsDirty = false;
  127. }
  128. }
  129. if (output.Length > 0) {
  130. FakeConsole.CursorTop = row;
  131. FakeConsole.CursorLeft = lastCol;
  132. foreach (var c in output.ToString ()) {
  133. FakeConsole.Write (c);
  134. }
  135. }
  136. }
  137. FakeConsole.CursorTop = 0;
  138. FakeConsole.CursorLeft = 0;
  139. //SetCursorVisibility (savedVisibitity);
  140. void WriteToConsole (StringBuilder output, ref int lastCol, int row, ref int outputWidth)
  141. {
  142. FakeConsole.CursorTop = row;
  143. FakeConsole.CursorLeft = lastCol;
  144. foreach (var c in output.ToString ()) {
  145. FakeConsole.Write (c);
  146. }
  147. output.Clear ();
  148. lastCol += outputWidth;
  149. outputWidth = 0;
  150. }
  151. FakeConsole.CursorTop = savedRow;
  152. FakeConsole.CursorLeft = savedCol;
  153. FakeConsole.CursorVisible = savedCursorVisible;
  154. }
  155. public override void Refresh ()
  156. {
  157. UpdateScreen ();
  158. UpdateCursor ();
  159. }
  160. #region Color Handling
  161. // Cache the list of ConsoleColor values.
  162. private static readonly HashSet<int> ConsoleColorValues = new HashSet<int> (
  163. Enum.GetValues (typeof (ConsoleColor)).OfType<ConsoleColor> ().Select (c => (int)c)
  164. );
  165. void SetColor (int color)
  166. {
  167. if (ConsoleColorValues.Contains (color & 0xffff)) {
  168. FakeConsole.BackgroundColor = (ConsoleColor)(color & 0xffff);
  169. }
  170. if (ConsoleColorValues.Contains ((color >> 16) & 0xffff)) {
  171. FakeConsole.ForegroundColor = (ConsoleColor)((color >> 16) & 0xffff);
  172. }
  173. }
  174. /// <remarks>
  175. /// In the FakeDriver, colors are encoded as an int; same as NetDriver
  176. /// Extracts the foreground and background colors from the encoded value.
  177. /// Assumes a 4-bit encoded value for both foreground and background colors.
  178. /// </remarks>
  179. internal override void GetColors (int value, out ColorNames foreground, out ColorNames background)
  180. {
  181. // Assume a 4-bit encoded value for both foreground and background colors.
  182. foreground = (ColorNames)((value >> 16) & 0xF);
  183. background = (ColorNames)(value & 0xF);
  184. }
  185. /// <remarks>
  186. /// In the FakeDriver, colors are encoded as an int; same as NetDriver
  187. /// However, the foreground color is stored in the most significant 16 bits,
  188. /// and the background color is stored in the least significant 16 bits.
  189. /// </remarks>
  190. public override Attribute MakeColor (Color foreground, Color background)
  191. {
  192. // Encode the colors into the int value.
  193. return new Attribute (
  194. platformColor: ((((int)foreground) & 0xffff) << 16) | (((int)background) & 0xffff),
  195. foreground: foreground,
  196. background: background
  197. );
  198. }
  199. public override Attribute MakeColor (ColorNames foreground, ColorNames background)
  200. {
  201. return MakeColor (new Color (foreground), new Color (background));
  202. }
  203. #endregion
  204. public ConsoleKeyInfo FromVKPacketToKConsoleKeyInfo (ConsoleKeyInfo consoleKeyInfo)
  205. {
  206. if (consoleKeyInfo.Key != ConsoleKey.Packet) {
  207. return consoleKeyInfo;
  208. }
  209. var mod = consoleKeyInfo.Modifiers;
  210. var shift = (mod & ConsoleModifiers.Shift) != 0;
  211. var alt = (mod & ConsoleModifiers.Alt) != 0;
  212. var control = (mod & ConsoleModifiers.Control) != 0;
  213. var keyChar = ConsoleKeyMapping.GetKeyCharFromConsoleKey (consoleKeyInfo.KeyChar, consoleKeyInfo.Modifiers, out uint virtualKey, out _);
  214. return new ConsoleKeyInfo ((char)keyChar, (ConsoleKey)virtualKey, shift, alt, control);
  215. }
  216. Key MapKey (ConsoleKeyInfo keyInfo)
  217. {
  218. switch (keyInfo.Key) {
  219. case ConsoleKey.Escape:
  220. return MapKeyModifiers (keyInfo, Key.Esc);
  221. case ConsoleKey.Tab:
  222. return keyInfo.Modifiers == ConsoleModifiers.Shift ? Key.BackTab : Key.Tab;
  223. case ConsoleKey.Clear:
  224. return MapKeyModifiers (keyInfo, Key.Clear);
  225. case ConsoleKey.Home:
  226. return MapKeyModifiers (keyInfo, Key.Home);
  227. case ConsoleKey.End:
  228. return MapKeyModifiers (keyInfo, Key.End);
  229. case ConsoleKey.LeftArrow:
  230. return MapKeyModifiers (keyInfo, Key.CursorLeft);
  231. case ConsoleKey.RightArrow:
  232. return MapKeyModifiers (keyInfo, Key.CursorRight);
  233. case ConsoleKey.UpArrow:
  234. return MapKeyModifiers (keyInfo, Key.CursorUp);
  235. case ConsoleKey.DownArrow:
  236. return MapKeyModifiers (keyInfo, Key.CursorDown);
  237. case ConsoleKey.PageUp:
  238. return MapKeyModifiers (keyInfo, Key.PageUp);
  239. case ConsoleKey.PageDown:
  240. return MapKeyModifiers (keyInfo, Key.PageDown);
  241. case ConsoleKey.Enter:
  242. return MapKeyModifiers (keyInfo, Key.Enter);
  243. case ConsoleKey.Spacebar:
  244. return MapKeyModifiers (keyInfo, keyInfo.KeyChar == 0 ? Key.Space : (Key)keyInfo.KeyChar);
  245. case ConsoleKey.Backspace:
  246. return MapKeyModifiers (keyInfo, Key.Backspace);
  247. case ConsoleKey.Delete:
  248. return MapKeyModifiers (keyInfo, Key.DeleteChar);
  249. case ConsoleKey.Insert:
  250. return MapKeyModifiers (keyInfo, Key.InsertChar);
  251. case ConsoleKey.PrintScreen:
  252. return MapKeyModifiers (keyInfo, Key.PrintScreen);
  253. case ConsoleKey.Oem1:
  254. case ConsoleKey.Oem2:
  255. case ConsoleKey.Oem3:
  256. case ConsoleKey.Oem4:
  257. case ConsoleKey.Oem5:
  258. case ConsoleKey.Oem6:
  259. case ConsoleKey.Oem7:
  260. case ConsoleKey.Oem8:
  261. case ConsoleKey.Oem102:
  262. case ConsoleKey.OemPeriod:
  263. case ConsoleKey.OemComma:
  264. case ConsoleKey.OemPlus:
  265. case ConsoleKey.OemMinus:
  266. if (keyInfo.KeyChar == 0) {
  267. return Key.Unknown;
  268. }
  269. return (Key)((uint)keyInfo.KeyChar);
  270. }
  271. var key = keyInfo.Key;
  272. if (key >= ConsoleKey.A && key <= ConsoleKey.Z) {
  273. var delta = key - ConsoleKey.A;
  274. if (keyInfo.Modifiers == ConsoleModifiers.Control) {
  275. return (Key)(((uint)Key.CtrlMask) | ((uint)Key.A + delta));
  276. }
  277. if (keyInfo.Modifiers == ConsoleModifiers.Alt) {
  278. return (Key)(((uint)Key.AltMask) | ((uint)Key.A + delta));
  279. }
  280. if (keyInfo.Modifiers == (ConsoleModifiers.Shift | ConsoleModifiers.Alt)) {
  281. return MapKeyModifiers (keyInfo, (Key)((uint)Key.A + delta));
  282. }
  283. if ((keyInfo.Modifiers & (ConsoleModifiers.Alt | ConsoleModifiers.Control)) != 0) {
  284. if (keyInfo.KeyChar == 0) {
  285. return (Key)(((uint)Key.AltMask | (uint)Key.CtrlMask) | ((uint)Key.A + delta));
  286. } else {
  287. return (Key)((uint)keyInfo.KeyChar);
  288. }
  289. }
  290. return (Key)((uint)keyInfo.KeyChar);
  291. }
  292. if (key >= ConsoleKey.D0 && key <= ConsoleKey.D9) {
  293. var delta = key - ConsoleKey.D0;
  294. if (keyInfo.Modifiers == ConsoleModifiers.Alt) {
  295. return (Key)(((uint)Key.AltMask) | ((uint)Key.D0 + delta));
  296. }
  297. if (keyInfo.Modifiers == ConsoleModifiers.Control) {
  298. return (Key)(((uint)Key.CtrlMask) | ((uint)Key.D0 + delta));
  299. }
  300. if (keyInfo.Modifiers == (ConsoleModifiers.Shift | ConsoleModifiers.Alt)) {
  301. return MapKeyModifiers (keyInfo, (Key)((uint)Key.D0 + delta));
  302. }
  303. if ((keyInfo.Modifiers & (ConsoleModifiers.Alt | ConsoleModifiers.Control)) != 0) {
  304. if (keyInfo.KeyChar == 0 || keyInfo.KeyChar == 30) {
  305. return MapKeyModifiers (keyInfo, (Key)((uint)Key.D0 + delta));
  306. }
  307. }
  308. return (Key)((uint)keyInfo.KeyChar);
  309. }
  310. if (key >= ConsoleKey.F1 && key <= ConsoleKey.F12) {
  311. var delta = key - ConsoleKey.F1;
  312. if ((keyInfo.Modifiers & (ConsoleModifiers.Shift | ConsoleModifiers.Alt | ConsoleModifiers.Control)) != 0) {
  313. return MapKeyModifiers (keyInfo, (Key)((uint)Key.F1 + delta));
  314. }
  315. return (Key)((uint)Key.F1 + delta);
  316. }
  317. if (keyInfo.KeyChar != 0) {
  318. return MapKeyModifiers (keyInfo, (Key)((uint)keyInfo.KeyChar));
  319. }
  320. return (Key)(0xffffffff);
  321. }
  322. KeyModifiers keyModifiers;
  323. private Key MapKeyModifiers (ConsoleKeyInfo keyInfo, Key key)
  324. {
  325. Key keyMod = new Key ();
  326. if ((keyInfo.Modifiers & ConsoleModifiers.Shift) != 0) {
  327. keyMod = Key.ShiftMask;
  328. }
  329. if ((keyInfo.Modifiers & ConsoleModifiers.Control) != 0) {
  330. keyMod |= Key.CtrlMask;
  331. }
  332. if ((keyInfo.Modifiers & ConsoleModifiers.Alt) != 0) {
  333. keyMod |= Key.AltMask;
  334. }
  335. return keyMod != Key.Null ? keyMod | key : key;
  336. }
  337. Action<KeyEvent> _keyDownHandler;
  338. Action<KeyEvent> _keyHandler;
  339. Action<KeyEvent> _keyUpHandler;
  340. private CursorVisibility _savedCursorVisibility;
  341. public override void PrepareToRun (MainLoop mainLoop, Action<KeyEvent> keyHandler, Action<KeyEvent> keyDownHandler, Action<KeyEvent> keyUpHandler, Action<MouseEvent> mouseHandler)
  342. {
  343. _keyDownHandler = keyDownHandler;
  344. _keyHandler = keyHandler;
  345. _keyUpHandler = keyUpHandler;
  346. // Note: Net doesn't support keydown/up events and thus any passed keyDown/UpHandlers will never be called
  347. (mainLoop.MainLoopDriver as FakeMainLoop).KeyPressed += (consoleKey) => ProcessInput (consoleKey);
  348. }
  349. void ProcessInput (ConsoleKeyInfo consoleKey)
  350. {
  351. if (consoleKey.Key == ConsoleKey.Packet) {
  352. consoleKey = FromVKPacketToKConsoleKeyInfo (consoleKey);
  353. }
  354. keyModifiers = new KeyModifiers ();
  355. if (consoleKey.Modifiers.HasFlag (ConsoleModifiers.Shift)) {
  356. keyModifiers.Shift = true;
  357. }
  358. if (consoleKey.Modifiers.HasFlag (ConsoleModifiers.Alt)) {
  359. keyModifiers.Alt = true;
  360. }
  361. if (consoleKey.Modifiers.HasFlag (ConsoleModifiers.Control)) {
  362. keyModifiers.Ctrl = true;
  363. }
  364. var map = MapKey (consoleKey);
  365. if (map == (Key)0xffffffff) {
  366. if ((consoleKey.Modifiers & (ConsoleModifiers.Shift | ConsoleModifiers.Alt | ConsoleModifiers.Control)) != 0) {
  367. _keyDownHandler (new KeyEvent (map, keyModifiers));
  368. _keyUpHandler (new KeyEvent (map, keyModifiers));
  369. }
  370. return;
  371. }
  372. _keyDownHandler (new KeyEvent (map, keyModifiers));
  373. _keyHandler (new KeyEvent (map, keyModifiers));
  374. _keyUpHandler (new KeyEvent (map, keyModifiers));
  375. }
  376. /// <inheritdoc/>
  377. public override bool GetCursorVisibility (out CursorVisibility visibility)
  378. {
  379. visibility = FakeConsole.CursorVisible
  380. ? CursorVisibility.Default
  381. : CursorVisibility.Invisible;
  382. return FakeConsole.CursorVisible;
  383. }
  384. /// <inheritdoc/>
  385. public override bool SetCursorVisibility (CursorVisibility visibility)
  386. {
  387. _savedCursorVisibility = visibility;
  388. return FakeConsole.CursorVisible = visibility == CursorVisibility.Default;
  389. }
  390. /// <inheritdoc/>
  391. public override bool EnsureCursorVisibility ()
  392. {
  393. if (!(Col >= 0 && Row >= 0 && Col < Cols && Row < Rows)) {
  394. GetCursorVisibility (out CursorVisibility cursorVisibility);
  395. _savedCursorVisibility = cursorVisibility;
  396. SetCursorVisibility (CursorVisibility.Invisible);
  397. return false;
  398. }
  399. SetCursorVisibility (_savedCursorVisibility);
  400. return FakeConsole.CursorVisible;
  401. }
  402. public override void SendKeys (char keyChar, ConsoleKey key, bool shift, bool alt, bool control)
  403. {
  404. ProcessInput (new ConsoleKeyInfo (keyChar, key, shift, alt, control));
  405. }
  406. public void SetBufferSize (int width, int height)
  407. {
  408. FakeConsole.SetBufferSize (width, height);
  409. Cols = width;
  410. Rows = height;
  411. SetWindowSize (width, height);
  412. ProcessResize ();
  413. }
  414. public void SetWindowSize (int width, int height)
  415. {
  416. FakeConsole.SetWindowSize (width, height);
  417. if (width != Cols || height != Rows) {
  418. SetBufferSize (width, height);
  419. Cols = width;
  420. Rows = height;
  421. }
  422. ProcessResize ();
  423. }
  424. public void SetWindowPosition (int left, int top)
  425. {
  426. if (Left > 0 || Top > 0) {
  427. Left = 0;
  428. Top = 0;
  429. }
  430. FakeConsole.SetWindowPosition (Left, Top);
  431. }
  432. void ProcessResize ()
  433. {
  434. ResizeScreen ();
  435. ClearContents ();
  436. TerminalResized?.Invoke ();
  437. }
  438. public virtual void ResizeScreen ()
  439. {
  440. if (FakeConsole.WindowHeight > 0) {
  441. // Can raise an exception while is still resizing.
  442. try {
  443. FakeConsole.CursorTop = 0;
  444. FakeConsole.CursorLeft = 0;
  445. FakeConsole.WindowTop = 0;
  446. FakeConsole.WindowLeft = 0;
  447. } catch (System.IO.IOException) {
  448. return;
  449. } catch (ArgumentOutOfRangeException) {
  450. return;
  451. }
  452. }
  453. Clip = new Rect (0, 0, Cols, Rows);
  454. }
  455. public override void UpdateCursor ()
  456. {
  457. if (!EnsureCursorVisibility ()) {
  458. return;
  459. }
  460. // Prevents the exception of size changing during resizing.
  461. try {
  462. // BUGBUG: Why is this using BufferWidth/Height and now Cols/Rows?
  463. if (Col >= 0 && Col < FakeConsole.BufferWidth && Row >= 0 && Row < FakeConsole.BufferHeight) {
  464. FakeConsole.SetCursorPosition (Col, Row);
  465. }
  466. } catch (System.IO.IOException) {
  467. } catch (ArgumentOutOfRangeException) {
  468. }
  469. }
  470. #region Not Implemented
  471. public override void Suspend ()
  472. {
  473. throw new NotImplementedException ();
  474. }
  475. #endregion
  476. public class FakeClipboard : ClipboardBase {
  477. public Exception FakeException = null;
  478. string _contents = string.Empty;
  479. bool _isSupportedAlwaysFalse = false;
  480. public override bool IsSupported => !_isSupportedAlwaysFalse;
  481. public FakeClipboard (bool fakeClipboardThrowsNotSupportedException = false, bool isSupportedAlwaysFalse = false)
  482. {
  483. _isSupportedAlwaysFalse = isSupportedAlwaysFalse;
  484. if (fakeClipboardThrowsNotSupportedException) {
  485. FakeException = new NotSupportedException ("Fake clipboard exception");
  486. }
  487. }
  488. protected override string GetClipboardDataImpl ()
  489. {
  490. if (FakeException != null) {
  491. throw FakeException;
  492. }
  493. return _contents;
  494. }
  495. protected override void SetClipboardDataImpl (string text)
  496. {
  497. if (text == null) {
  498. throw new ArgumentNullException (nameof (text));
  499. }
  500. if (FakeException != null) {
  501. throw FakeException;
  502. }
  503. _contents = text;
  504. }
  505. }
  506. #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
  507. }