public void Test_Save_OpenFiles_EvenWhen_OpenFilesNotRemembered() { // Arrange. var appSettings = new DotNetSettings(settings) { RememberOpenFiles = false, OpenFiles = new List <FileInfo> { new FileInfo(@"C:\openFile1"), new FileInfo(@"C:\openFile2") }, }; // Act. appSettings.Save(); // Assert. AssertThat.SequenceEqual(settings.OpenFiles.Cast <string>(), new[] { @"C:\openFile1", @"C:\openFile2" }); }
public void Test_OpenFiles_Preserves_InsertionOrder() { // Arrange. settings.OpenFiles = new StringCollection(); var files = new[] { @"C:\fileC", @"C:\fileA", @"C:\fileB" }.Select(f => new FileInfo(f)).ToList(); var appSettings = new DotNetSettings(settings); // Act. foreach (var file in files) { appSettings.OpenFiles.Add(file); } // Assert. AssertThat.SequenceEqual(appSettings.OpenFiles, files, FileSystemInfoPathEqualityComparer.Instance); }
public void Test_Add(IEnumerable <string> expected, IEnumerable <string> inputPaths, int maximum) { // Arrange. var expectedFiles = expected.Select(fileName => new FileInfo(fileName)); var inputFiles = inputPaths.Select(fileName => new FileInfo(fileName)); recentFiles.MaximumCount = maximum; // Act. foreach (var inputFile in inputFiles) { recentFiles.Add(inputFile); } // Assert. AssertThat.SequenceEqual(expectedFiles, recentFiles, FileInfoPathEqualityComparer.Instance); }
public void Test_ReplaceInSource_WithMapping() { // Arrange. var source = new ObservableCollection <string> { "1", "2", "3" }; var target = new ObservableCollection <int>(); var mirror = new CollectionMirror(source, target, obj => Int32.Parse((string)obj), obj => obj.ToString()); // Act. source[0] = "0"; // Assert. AssertThat.SequenceEqual(new[] { "0", "2", "3" }, source); AssertThat.SequenceEqual(new[] { 0, 2, 3 }, target); }
public void Test_ClearTarget_WithMapping() { // Arrange. var source = new ObservableCollection <string> { "1", "2", "3" }; var target = new ObservableCollection <int>(); var mirror = new CollectionMirror(source, target, obj => Int32.Parse((string)obj), obj => obj.ToString()); // Act. target.Clear(); // Assert. AssertThat.SequenceEqual(new string[0], source); AssertThat.SequenceEqual(new int[0], target); }
public void Test_RemoveIndexFromSource_WithMapping() { // Arrange. var source = new ObservableCollection <string> { "1", "2", "3" }; var target = new ObservableCollection <int>(); var mirror = new CollectionMirror(source, target, obj => Int32.Parse((string)obj), obj => obj.ToString()); // Act. source.RemoveAt(2); // Assert. AssertThat.SequenceEqual(new[] { "1", "2" }, source); AssertThat.SequenceEqual(new[] { 1, 2 }, target); }
public void Test_MoveInTarget_WithMapping() { // Arrange. var source = new ObservableCollection <string> { "1", "2", "3" }; var target = new ObservableCollection <int>(); var mirror = new CollectionMirror(source, target, obj => Int32.Parse((string)obj), obj => obj.ToString()); // Act. target.Move(0, 2); // Assert. AssertThat.SequenceEqual(new[] { "2", "3", "1" }, source); AssertThat.SequenceEqual(new[] { 2, 3, 1 }, target); }
public void Test_Dispose_Unsubscribes() { // Arrange. var source = new ObservableCollection <string> { "1", "2", "3" }; var target = new ObservableCollection <string>(); var mirror = new CollectionMirror(source, target); // Act. mirror.Dispose(); source.Add("4"); target.Remove("1"); // Assert. AssertThat.SequenceEqual(new[] { "1", "2", "3", "4" }, source); AssertThat.SequenceEqual(new[] { "2", "3" }, target); }
public void Test_Tee() { // Arrange. var input = new[] { 1, 2, 3 }; var output = new List <int>(input.Length); // Act. var items = input.Tee(output.Add).Select(x => x.ToString(CultureInfo.InvariantCulture)); // Assert. Assert.Empty(output); // Tests laziness. // Act. items = items.ToList(); // Assert. AssertThat.SequenceEqual(input, output); AssertThat.SequenceEqual(new [] { "1", "2", "3" }, items); }
public void Test_Multiple_Diagrams_Opened() { // Arrange. settings.SetupGet(s => s.RememberOpenFiles).Returns(true); var files = new[] { new FileInfo("fileC"), new FileInfo("fileA"), new FileInfo("fileB") }; // Act. foreach (var file in files) { diagramManager.Raise(dm => dm.DiagramOpened += null, new DiagramOpenedEventArgs(new Diagram { File = file })); } // Assert. AssertThat.SequenceEqual(settings.Object.OpenFiles, files, FileSystemInfoPathEqualityComparer.Instance); }
public void Test_Initialization() { // Arrange. _settings.TFSServerUrls = new StringCollection { "http://testserver/" }; _settings.TFSProjectName = "project1"; _settings.AutoConnectOnStartup = false; _settings["TestDiscoveryPluginLocation"] = @"C:\Plugins"; // Act. var appSettings = new DotNetSettings(_settings); // Assert. AssertThat.SequenceEqual(new [] { new Uri("http://testserver/") }, appSettings.TfsServers); Assert.Equal("project1", appSettings.TfsProjectName); Assert.False(appSettings.AutoConnectOnStartup); Assert.Equal(@"C:\Plugins", appSettings.TestDiscoveryPluginLocation.FullName); }
public void Test_InitialSynchronization_WithMapping() { // Arrange. var source = new ObservableCollection <string> { "1", "2", "3" }; var target = new ObservableCollection <int> { 4, 5, 6 }; // Act. var mirror = new CollectionMirror(source, target, obj => Int32.Parse((string)obj), obj => obj.ToString()); // Assert. AssertThat.SequenceEqual(new[] { "1", "2", "3" }, source); AssertThat.SequenceEqual(new[] { 1, 2, 3 }, target); }
public void Test_AddMultiple() { // Arrange. var source = new Mock <IObservableList> { DefaultValue = DefaultValue.Empty }; source.Setup(s => s.GetEnumerator()).Returns(new[] { "1", "2", "3" }.GetEnumerator()); var target = new ObservableCollection <string>(); var mirror = new CollectionMirror(source.Object, target); // Act. source.Raise(s => s.CollectionChanged += null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, new[] { "4", "5" }, 3)); // Assert. AssertThat.SequenceEqual(new[] { "1", "2", "3", "4", "5" }, target); }
public void Test_DiscoverAutomatedTests() { // Arrange. childDiscoverers.AddRange(new[] { Mock.Of <ITestAutomationDiscoverer>(d => d.DiscoverAutomatedTests(It.IsAny <IEnumerable <string> >()) == Mock.Of <ITestAutomation>(t => t.Name == "Test1").ToEnumerable()), Mock.Of <ITestAutomationDiscoverer>(d => d.DiscoverAutomatedTests(It.IsAny <IEnumerable <string> >()) == new[] { Mock.Of <ITestAutomation>(t => t.Name == "Test2"), Mock.Of <ITestAutomation>(t => t.Name == "Test3") }), Mock.Of <ITestAutomationDiscoverer>(d => d.DiscoverAutomatedTests(It.IsAny <IEnumerable <string> >()) == Mock.Of <ITestAutomation>(t => t.Name == "Test4").ToEnumerable()) }); // Act. var tests = discoverer.DiscoverAutomatedTests(new[] { @"C:\sometests" }).ToList(); // Assert. Assert.Equal(4, tests.Count); AssertThat.SequenceEqual(new[] { "Test1", "Test2", "Test3", "Test4" }, tests.Select(t => t.Name)); }
public void Test_Save() { // Arrange. var appSettings = new DotNetSettings(settings) { RememberOpenFiles = true, OpenFiles = new List <FileInfo> { new FileInfo(@"C:\openFile1"), new FileInfo(@"C:\openFile2") }, MaximumRecentFiles = 20, AutoSaveEnabled = true, AutoSaveInterval = TimeSpan.FromSeconds(15), HighlightCurrentLine = false, ShowLineNumbers = false, EnableVirtualSpace = true, EnableWordWrap = true, EmptySelectionCopiesEntireLine = false, AllowScrollingBelowContent = true, LastDiagramLocation = new DirectoryInfo(@"C:\") }; appSettings.RecentFiles.AddRange(new FileInfo(@"C:\recentFile1"), new FileInfo(@"C:\recentFile2")); // Act. appSettings.Save(); // Assert. Assert.Equal(true, settings.RememberOpenFiles); AssertThat.SequenceEqual(settings.OpenFiles.Cast <string>(), new[] { @"C:\openFile1", @"C:\openFile2" }); Assert.Equal(20, settings.MaximumRecentFiles); AssertThat.SequenceEqual(settings.RecentFiles.Cast <string>(), new[] { @"C:\recentFile2", @"C:\recentFile1" }); Assert.Equal(true, settings.AutoSaveEnabled); Assert.Equal(TimeSpan.FromSeconds(15), settings.AutoSaveInterval); Assert.Equal(false, settings.HighlightCurrentLine); Assert.Equal(false, settings.ShowLineNumbers); Assert.Equal(true, settings.EnableVirtualSpace); Assert.Equal(true, settings.EnableWordWrap); Assert.Equal(false, settings.EmptySelectionCopiesEntireLine); Assert.Equal(true, settings.AllowScrollingBelowContent); Assert.Equal(@"C:\", settings.LastPath); }
public void Test_Save() { // Arrange. _settings.TFSServerUrls = new StringCollection { "http://testserver/" }; var appSettings = new DotNetSettings(_settings) { TfsProjectName = "project1" }; appSettings.TfsServers.Add(new Uri("http://testserver2/")); appSettings.TfsProjectName = "project2"; // Act. appSettings.Save(); // Assert. AssertThat.SequenceEqual(new [] { "http://testserver/", "http://testserver2/" }, _settings.TFSServerUrls.Cast <string>()); Assert.Equal("project2", _settings.TFSProjectName); }
public void Test_RemoveMultiple_WithMapping() { // Arrange. var source = new Mock <IObservableList> { DefaultValue = DefaultValue.Empty }; source.Setup(s => s.GetEnumerator()).Returns(new[] { "1", "2", "3" }.GetEnumerator()); var target = new ObservableCollection <int>(); var mirror = new CollectionMirror(source.Object, target, obj => Int32.Parse((string)obj), obj => obj.ToString()); // Act. source.Raise(s => s.CollectionChanged += null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, new[] { "2", "3" }, 1)); // Assert. AssertThat.SequenceEqual(new[] { 1 }, target); }
public void Test_IsDiagramLocationValid_SuccessfulLoad() { // Arrange. var diagrams = new List <Diagram> { new Diagram { Content = "Diagram 1" }, new Diagram { Content = "Diagram 2" }, null }; diagramIO.Setup(dio => dio.ReadDiagramsAsync(It.IsAny <DirectoryInfo>(), It.IsAny <IProgress <ReadDiagramsProgress> >(), It.IsAny <CancellationToken>())) .Returns(() => Task.FromResult <IEnumerable <Diagram> >(diagrams)) .Callback((DirectoryInfo dir, IProgress <ReadDiagramsProgress> prog, CancellationToken ct) => { foreach (var diagram in diagrams) { prog.Report(new ReadDiagramsProgress(1, 1, diagram)); } }); // Act. explorer.DiagramLocation = diagramLocation; bool isValid = explorer.IsDiagramLocationValid; // Assert. Assert.True(isValid); Assert.Equal(2, explorer.PreviewDiagrams.Count); AssertThat.SequenceEqual(new[] { "Diagram 1", "Diagram 2" }, explorer.PreviewDiagrams.Select(d => d.Diagram.Content)); Assert.Equal(diagramLocation.FullName, settings.Object.LastDiagramLocation.FullName); diagramIO.Verify(dio => dio.StartMonitoring(diagramLocation)); Assert.False(explorer.IsLoadingDiagrams); }