using Amphora; using Clave; using System; using System.Collections.Generic; using UnitTestSharp; namespace Glass.UnitTests { public class FileDialogBehaviorTests : TestFixture { public class DefaultTests : TestFixture { public void UsesTheDefaultDialogBehavior() { CheckTrue(ReferenceEquals(DialogBehavior.Default, FileDialogBehavior.Default.Dialog)); } public void HasASingleLineFileNameBoxBehavior() { CheckFalse(FileDialogBehavior.Default.FileNameBoxBehavior.Multiline); } public void SharesItsFileNameBoxBehaviorWithEveryNewBehavior() { CheckTrue(ReferenceEquals( FileDialogBehavior.Default.FileNameBoxBehavior, new FileDialogBehavior().FileNameBoxBehavior)); } } public class DialogTests : TestFixture { public void Setting_IsKept() { var behavior = new FileDialogBehavior { Dialog = DialogBehavior.NoKeys }; CheckTrue(ReferenceEquals(DialogBehavior.NoKeys, behavior.Dialog)); } public void Null_Throws() { CheckThrow(typeof(ArgumentNullException)); new FileDialogBehavior { Dialog = null }; } public void With_LeavesTheFileNameBoxBehaviorAlone() { FileDialogBehavior changed = FileDialogBehavior.Default with { Dialog = DialogBehavior.NoKeys }; CheckTrue(ReferenceEquals( FileDialogBehavior.Default.FileNameBoxBehavior, changed.FileNameBoxBehavior)); } } public class FileNameBoxBehaviorTests : TestFixture { public void Setting_IsKept() { var typing = new TextBoxBehavior { UndoBudget = 100 }; var behavior = new FileDialogBehavior { FileNameBoxBehavior = typing }; CheckTrue(ReferenceEquals(typing, behavior.FileNameBoxBehavior)); } public void Null_Throws() { CheckThrow(typeof(ArgumentNullException)); new FileDialogBehavior { FileNameBoxBehavior = null }; } public void Multiline_Throws() { CheckThrow(typeof(ArgumentException)); new FileDialogBehavior { FileNameBoxBehavior = new TextBoxBehavior { Multiline = true } }; } public void With_LeavesTheDialogBehaviorAlone() { FileDialogBehavior changed = FileDialogBehavior.Default with { FileNameBoxBehavior = new TextBoxBehavior { UndoBudget = 100 }, }; CheckTrue(ReferenceEquals(DialogBehavior.Default, changed.Dialog)); } } public class HistoryChordsTests : TestFixture { public void Default_HasOneChordEach() { CheckEqual(1, FileDialogBehavior.Default.BackChords.Count); CheckEqual(1, FileDialogBehavior.Default.ForwardChords.Count); } public void TheChords_CanBeReplaced() { var chords = new ChordSetBuilder(); chords.Add(Chord.Press(KeyCode.F6)); ChordSet replacement = chords.Build(); var behavior = FileDialogBehavior.Default with { BackChords = replacement, ForwardChords = replacement, }; CheckTrue(ReferenceEquals(replacement, behavior.BackChords)); CheckTrue(ReferenceEquals(replacement, behavior.ForwardChords)); } public void NullBackChords_Throws() { CheckThrow(typeof(ArgumentNullException)); var behavior = FileDialogBehavior.Default with { BackChords = null }; } public void NullForwardChords_Throws() { CheckThrow(typeof(ArgumentNullException)); var behavior = FileDialogBehavior.Default with { ForwardChords = null }; } } public class RefreshChordsTests : TestFixture { public void Default_HasOneChord() { CheckEqual(1, FileDialogBehavior.Default.RefreshChords.Count); } public void TheChords_CanBeReplaced() { var chords = new ChordSetBuilder(); chords.Add(Chord.Press(KeyCode.F6)); ChordSet replacement = chords.Build(); var behavior = FileDialogBehavior.Default with { RefreshChords = replacement }; CheckTrue(ReferenceEquals(replacement, behavior.RefreshChords)); } public void Null_Throws() { CheckThrow(typeof(ArgumentNullException)); var behavior = FileDialogBehavior.Default with { RefreshChords = null }; } } public class TypeAheadTests : TestFixture { public void Default_TypesAheadAndForgetsAfterOneSecond() { CheckTrue(FileDialogBehavior.Default.TypesAhead); CheckEqual(Duration.FromSeconds(1), FileDialogBehavior.Default.TypeAheadTimeout); } public void TypingAhead_CanBeTurnedOff() { CheckFalse((FileDialogBehavior.Default with { TypesAhead = false }).TypesAhead); } public void TheTimeout_CanBeChanged() { var behavior = FileDialogBehavior.Default with { TypeAheadTimeout = Duration.FromSeconds(3) }; CheckEqual(Duration.FromSeconds(3), behavior.TypeAheadTimeout); } public void NoTimeout_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); var behavior = FileDialogBehavior.Default with { TypeAheadTimeout = Duration.Zero }; } public void ANegativeTimeout_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); var behavior = FileDialogBehavior.Default with { TypeAheadTimeout = Duration.FromSeconds(-1) }; } } public class HiddenFilesTests : TestFixture { public void Default_StartsWithThemLeftOutAndLetsTheUserToggle() { CheckFalse(FileDialogBehavior.Default.ShowsHiddenFiles); CheckTrue(FileDialogBehavior.Default.CanToggleHiddenFiles); } public void TheTwoKnobs_AreKept() { var behavior = new FileDialogBehavior { ShowsHiddenFiles = true, CanToggleHiddenFiles = false }; CheckTrue(behavior.ShowsHiddenFiles); CheckFalse(behavior.CanToggleHiddenFiles); } } public class ColumnsTests : TestFixture { public void Default_IsNameSizeAndModified() { CheckEqual( new[] { FileColumn.Name, FileColumn.Size, FileColumn.Modified }, new List(FileDialogBehavior.Default.Columns).ToArray()); } public void Setting_IsKeptInOrder() { var behavior = new FileDialogBehavior { Columns = new[] { FileColumn.Modified, FileColumn.Name } }; CheckEqual( new[] { FileColumn.Modified, FileColumn.Name }, new List(behavior.Columns).ToArray()); } public void Setting_CopiesWhatWasGiven() { var given = new[] { FileColumn.Name, FileColumn.Size }; var behavior = new FileDialogBehavior { Columns = given }; given[1] = FileColumn.Modified; CheckEqual(FileColumn.Size, behavior.Columns[1]); } public void Null_Throws() { CheckThrow(typeof(ArgumentNullException)); new FileDialogBehavior { Columns = null }; } public void WithoutTheName_Throws() { CheckThrow(typeof(ArgumentException)); new FileDialogBehavior { Columns = new[] { FileColumn.Size } }; } public void Empty_Throws() { CheckThrow(typeof(ArgumentException)); new FileDialogBehavior { Columns = new FileColumn[0] }; } public void ColumnTwice_Throws() { CheckThrow(typeof(ArgumentException)); new FileDialogBehavior { Columns = new[] { FileColumn.Name, FileColumn.Size, FileColumn.Size } }; } public void NotAColumn_Throws() { CheckThrow(typeof(ArgumentException)); new FileDialogBehavior { Columns = new[] { FileColumn.Name, (FileColumn)7 } }; } public void With_LeavesTheDialogBehaviorAlone() { FileDialogBehavior changed = FileDialogBehavior.Default with { Columns = new[] { FileColumn.Name } }; CheckTrue(ReferenceEquals(DialogBehavior.Default, changed.Dialog)); } } public class EntryListTests : TestFixture { public void Default_UsesTheDefaultEntryListBehavior() { CheckTrue(ReferenceEquals(EntryListBehavior.Default, FileDialogBehavior.Default.EntryList)); } public void Setting_IsKept() { var rebound = new EntryListBehavior { NextChords = EntryListBehaviorTests.Pressing(Clave.KeyCode.Q) }; var behavior = new FileDialogBehavior { EntryList = rebound }; CheckTrue(ReferenceEquals(rebound, behavior.EntryList)); } public void Null_Throws() { CheckThrow(typeof(ArgumentNullException)); new FileDialogBehavior { EntryList = null }; } public void With_LeavesTheDialogBehaviorAlone() { FileDialogBehavior changed = FileDialogBehavior.Default with { EntryList = new EntryListBehavior() }; CheckTrue(ReferenceEquals(DialogBehavior.Default, changed.Dialog)); } } } }