Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge branch 'crwilcox-feature/UITests'
Browse files Browse the repository at this point in the history
  • Loading branch information
crwilcox committed Feb 8, 2016
2 parents 83ab368 + 7ceeb40 commit e127be6
Show file tree
Hide file tree
Showing 580 changed files with 21,451 additions and 10,031 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ src/R.sdf
# R files
.Rproj.user
src/R.VC.opendb
TestFiles/
1 change: 1 addition & 0 deletions nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="VS External" value="\\cpvsbuild\drops\dd\NuGet" />
<add key="VS Android Emulator" value="\\cpvsbuild\Drops\Emulator\Nuget" />
<add key="StevDo Share" value="\\stevdopc\Share\" />
</packageSources>
</configuration>
35 changes: 35 additions & 0 deletions src/CodeCoverage.runsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0"
assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Configuration>
<CodeCoverage>
<ModulePaths>
<Include>
<ModulePath>.*\.dll$</ModulePath>
<ModulePath>.*\.exe</ModulePath>
</Include>
<Exclude>
<ModulePath>.*test.*</ModulePath>
<ModulePath>.*xunit.*</ModulePath>
<ModulePath>.*fluent.*</ModulePath>
<ModulePath>.*mocks.*</ModulePath>
<ModulePath>.*editor.application.*</ModulePath>
</Exclude>
</ModulePaths>
<Functions>
<Exclude>
<Function>^std::.*</Function>
<Function>^boost::.*</Function>
<Function>^websocketpp::.*</Function>
<Function>^__sc.*</Function>
</Exclude>
</Functions>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
11 changes: 11 additions & 0 deletions src/Common/Core/Impl/Extensions/AssemblyExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Reflection;

namespace Microsoft.Common.Core {
public static class AssemblyExtensions {
public static string GetAssemblyPath(this Assembly assembly) {
var codeBase = Assembly.GetExecutingAssembly().CodeBase;
return new Uri(codeBase).LocalPath;
}
}
}
17 changes: 17 additions & 0 deletions src/Common/Core/Impl/Extensions/StackExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;

namespace Microsoft.Common.Core {
public static class StackExtensions {
public static IEnumerable<T> PopWhile<T>(this Stack<T> stack, Func<T, bool> predicate) {
while (stack.Count > 0) {
var item = stack.Peek();
if (!predicate(item)) {
break;
}

yield return stack.Pop();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,23 @@ public static T WaitAndUnwrapExceptions<T>(this Task<T> task) {
/// Silently handles the specified exception.
/// </summary>
public static Task SilenceException<T>(this Task task) where T : Exception {
return task.ContinueWith(t => {
var tcs = new TaskCompletionSource<object>();
task.ContinueWith(t => {
try {
t.Wait();
tcs.SetResult(null);
} catch (AggregateException ex) {
ex.Handle(e => e is T);
}
});
}

/// <summary>
/// Silently handles the specified exception.
/// </summary>
public static Task<U> SilenceException<T, U>(this Task<U> task) where T : Exception {
return task.ContinueWith(t => {
try {
return t.Result;
} catch (AggregateException ex) {
ex.Handle(e => e is T);
return default(U);
try {
ex.Handle(e => e is T);
tcs.SetResult(null);
} catch (AggregateException ex2) {
tcs.SetException(ex2.InnerExceptions);
}
} catch (OperationCanceledException) {
tcs.SetCanceled();
}
});
return tcs.Task;
}
}
}
11 changes: 6 additions & 5 deletions src/Common/Core/Impl/Microsoft.Common.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<Compile Include="..\..\..\GlobalAssemblyInfo.cs">
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Extensions\AssemblyExtensions.cs" />
<Compile Include="Collections\DictionaryExtension.cs" />
<Compile Include="Diagnostics\Check.cs" />
<Compile Include="Disposables\CountdownDisposable.cs" />
Expand All @@ -49,7 +50,7 @@
<Compile Include="IO\IDirectoryInfo.cs" />
<Compile Include="IO\IFileInfo.cs" />
<Compile Include="Collections\EnumerableExtensions.cs" />
<Compile Include="ExceptionExtensions.cs" />
<Compile Include="Extensions\ExceptionExtensions.cs" />
<Compile Include="IO\IFileSystem.cs" />
<Compile Include="IO\IFileSystemInfo.cs" />
<Compile Include="IO\IFileSystemWatcher.cs" />
Expand All @@ -59,10 +60,10 @@
<Compile Include="Shell\ICoreShell.cs" />
<Compile Include="Shell\IIdleTimeService.cs" />
<Compile Include="Shell\MessageButtons.cs" />
<Compile Include="StackExtensions.cs" />
<Compile Include="StringExtensions.cs" />
<Compile Include="StringBuilderExtensions.cs" />
<Compile Include="TaskExtensions.cs" />
<Compile Include="Extensions\StackExtensions.cs" />
<Compile Include="Extensions\StringExtensions.cs" />
<Compile Include="Extensions\StringBuilderExtensions.cs" />
<Compile Include="Extensions\TaskExtensions.cs" />
<Compile Include="TaskUtilities.cs" />
<Compile Include="Telemetry\ITelemetryActivity.cs" />
<Compile Include="Telemetry\ITelemetryRecorder.cs" />
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Core/Impl/Shell/CoreShell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class CoreShell {
// service provider with a specific name.
public static void TryCreateTestInstance(string assemblyName, string className) {
try {
string thisAssembly = Assembly.GetExecutingAssembly().Location;
string thisAssembly = Assembly.GetExecutingAssembly().GetAssemblyPath();
string assemblyLoc = Path.GetDirectoryName(thisAssembly);
string packageTestAssemblyPath = Path.Combine(assemblyLoc, assemblyName);

Expand Down
22 changes: 0 additions & 22 deletions src/Common/Core/Impl/StackExtensions.cs

This file was deleted.

33 changes: 33 additions & 0 deletions src/Common/Core/Test/Controls/ControlTestScript.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Common.Core.Test.Script;
using Microsoft.Common.Core.Test.Utility;
using Microsoft.UnitTests.Core.Threading;

namespace Microsoft.Common.Core.Test.Controls {
[ExcludeFromCodeCoverage]
public sealed class ControlTestScript : TestScript, IDisposable {
public ControlTestScript(Type type) {
ControlWindow.Create(type);
}
/// <summary>
/// Invokes a particular action in the control window thread
/// </summary>
public void Invoke(Action action) {
UIThreadHelper.Instance.Invoke(action);
}

public void Dispose() {
ControlWindow.Close();
}

public string WriteVisualTree(bool writeProperties = true) {
VisualTreeWriter w = new VisualTreeWriter();
string tree = null;
Invoke(() => {
tree = w.WriteTree(ControlWindow.Control, writeProperties);
});
return tree;
}
}
}
85 changes: 85 additions & 0 deletions src/Common/Core/Test/Controls/ControlWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Microsoft.UnitTests.Core.Threading;
using Screen = System.Windows.Forms.Screen;

namespace Microsoft.Common.Core.Test.Controls {
/// <summary>
/// Control window
/// </summary>
[ExcludeFromCodeCoverage]
internal static class ControlWindow {
[ExcludeFromCodeCoverage]
class ControlTestRequest {
public Type ControlType { get; }

public ControlTestRequest(Type controlType) {
ControlType = controlType;
}
}

/// <summary>
/// Control that is being tested
/// </summary>
public static Control Control { get; private set; }
/// <summary>
/// WPF window that contains the control
/// </summary>
public static Window Window { get; private set; }

/// <summary>
/// <summary>
/// Creates WPF window and control instance then hosts control in the window.
/// </summary>
public static void Create(Type controlType) {
var evt = new ManualResetEventSlim(false);
Task.Run(() => UIThreadHelper.Instance.Invoke(() => CreateWindowInstance(new ControlTestRequest(controlType), evt)));
evt.Wait();
}

private static void CreateWindowInstance(ControlTestRequest request, ManualResetEventSlim evt) {

Window = new Window();

if (Screen.AllScreens.Length == 1) {
Window.Left = 0;
Window.Top = 50;
}
else {
Screen secondary = Screen.AllScreens.FirstOrDefault(x => !x.Primary);
Window.Left = secondary.WorkingArea.Left;
Window.Top = secondary.WorkingArea.Top + 50;
}

Window.Width = 800;
Window.Height = 600;

Control = Activator.CreateInstance(request.ControlType) as Control;
Window.Title = "Control - " + request.ControlType.ToString();
Window.Content = Control;

evt.Set();

Window.Topmost = true;
Window.ShowDialog();
}

/// <summary>
/// Closes editor window
/// </summary>
public static void Close() {
var action = new Action(() => {
IDisposable disp = Window.Content as IDisposable;
disp?.Dispose();
Window.Close();
});

UIThreadHelper.Instance.Invoke(action);
}
}
}
2 changes: 2 additions & 0 deletions src/Common/Core/Test/Disposables/CountdownDisposableTest.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Diagnostics.CodeAnalysis;
using FluentAssertions;
using Microsoft.Common.Core.Disposables;
using Microsoft.UnitTests.Core.XUnit;

namespace Microsoft.Common.Core.Test.Disposables
{
[ExcludeFromCodeCoverage]
public class CountdownDisposableTest
{
[Test]
Expand Down
2 changes: 2 additions & 0 deletions src/Common/Core/Test/Disposables/DisposableTest.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Diagnostics.CodeAnalysis;
using FluentAssertions;
using Microsoft.Common.Core.Disposables;
using Microsoft.UnitTests.Core.XUnit;

namespace Microsoft.Common.Core.Test.Disposables
{
[ExcludeFromCodeCoverage]
public class DisposableTest
{
[Test]
Expand Down
3 changes: 3 additions & 0 deletions src/Common/Core/Test/EnumerableExtensionsTest.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using FluentAssertions;
using Microsoft.UnitTests.Core.XUnit;

namespace Microsoft.Common.Core.Test
{
[ExcludeFromCodeCoverage]
public class EnumerableExtensionsTest
{
[Test]
Expand Down Expand Up @@ -142,6 +144,7 @@ public void TraverseDepthFirst() {
actual.Select(i => i.Value).Should().Equal(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
}

[ExcludeFromCodeCoverage]
public class TreeItem
{
public int Value { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
Expand All @@ -9,6 +10,7 @@

namespace Microsoft.Common.Core.Test.IO.SubstituteFactories
{
[ExcludeFromCodeCoverage]
public static class DirectoryInfoFactory
{
public static IDirectoryInfo Create(IFileSystem fileSystem, string path)
Expand Down
Loading

0 comments on commit e127be6

Please sign in to comment.