Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Porting latest changes. #2

Merged
merged 1 commit into from
Aug 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Services\CoreTestDataSource.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Services\CoreTestDeployment.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Services\CoreTestSourceHost.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Services\CoreTraceListener.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Services\CoreTraceListenerManager.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void Load(XmlReader reader)
// if we have to read any thing from runsettings special for this platform service then we have to implement it.
}

public IDictionary<string, object> GetProperties()
public IDictionary<string, object> GetProperties(string source)
{
return new Dictionary<string, object>();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using System.IO;
using System;

namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices
{
/// <summary>
/// Internal implementation of TraceListener exposed to the user.
/// </summary>
/// <remarks>
/// The virtual operations of the TraceListener are implemented here
/// like Close(), Dispose() etc.
/// </remarks>
public class TraceListenerWrapper : ITraceListener
{

/// <summary>
/// Initializes a new instance of an object using the specified writer as recipient of the
/// tracing or debugging output.
/// </summary>
public TraceListenerWrapper(TextWriter textWriter)
{
}

/// <summary>
/// Returning as this feature is not supported in ASP .net and UWP
/// </summary>
public void Close()
{
return;
}

/// <summary>
/// Returning as this feature is not supported in ASP .net and UWP
/// </summary>
public void Dispose()
{
return;
}

/// <summary>
/// Returning as this feature is not supported in ASP .net and UWP
/// </summary>
public TextWriter GetWriter()
{
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) Microsoft. All rights reserved.

namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices
{
using System;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using System.IO;

/// <summary>
/// Internal implementation of TraceListenerManager exposed to the user.
/// Responsible for performing Add(), Remove(), Close(), Dispose() operations on traceListener object.
/// </summary>
public class TraceListenerManager : ITraceListenerManager
{
/// <summary>
/// Initializes a new instance of a TraceListenerManager object.
/// </summary>
public TraceListenerManager(TextWriter outputWriter, TextWriter errorWriter)
{
}

/// <summary>
/// Returning as this feature is not supported in ASP .net and UWP
/// </summary>
public void Add(ITraceListener traceListener)
{
return;
}

/// <summary>
/// Returning as this feature is not supported in ASP .net and UWP
/// </summary>
public void Close(ITraceListener traceListener)
{
return;
}

/// <summary>
/// Returning as this feature is not supported in ASP .net and UWP
/// </summary>
public void Dispose(ITraceListener traceListener)
{
return;
}

/// <summary>
/// Returning as this feature is not supported in ASP .net and UWP
/// </summary>
public void Remove(ITraceListener traceListner)
{
return;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private string GetTargetFrameworkStringFromAssembly(Assembly assembly)
if (declaringType != null)
{
string attributeName = declaringType.FullName;
if (string.Equals(attributeName, Constants.TargetFrameworkAttributeFullName, StringComparison.OrdinalIgnoreCase))
if (string.Equals(attributeName, PlatformServices.Constants.TargetFrameworkAttributeFullName, StringComparison.OrdinalIgnoreCase))
{
dotNetVersion = data.ConstructorArguments[0].Value.ToString();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RecursiveDirectoryPath.cs" />
<Compile Include="Services\DesktopTestContextImplementation.cs" />
<Compile Include="Services\DesktopTraceListener.cs" />
<Compile Include="Services\DesktopTraceListenerManager.cs" />
<Compile Include="Utilities\AppDomainUtilities.cs" />
<Compile Include="Utilities\AssemblyUtility.cs" />
<Compile Include="Utilities\DeploymentItemUtility.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices

using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Navigation;

/// <summary>
/// This service is responsible for any file based operations.
Expand Down Expand Up @@ -46,7 +45,7 @@ public bool DoesFileExist(string assemblyFileName)
public object CreateNavigationSession(string source)
{
var messageFormatOnException =
string.Join("MSTestDiscoverer:DiaSession: Could not create diaSession for source:", source, ". Reason:{1}");
string.Join("MSTestDiscoverer:DiaSession: Could not create diaSession for source:", source, ". Reason:{0}");
return SafeInvoke<DiaSession>(() => new DiaSession(source), messageFormatOnException) as DiaSession;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public void Load(XmlReader reader)
settings = MSTestAdapterSettings.ToSettings(reader);
}

public IDictionary<string, object> GetProperties()
public IDictionary<string, object> GetProperties(string source)
{
return TestDeployment.GetDeploymentInformation();
return TestDeployment.GetDeploymentInformation(source);
}

public const string SettingsName = "MSTestV2";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;

Expand Down Expand Up @@ -113,16 +114,29 @@ public bool Deploy(IEnumerable<TestCase> tests, IRunContext runContext, IFramewo
{
Debug.Assert(tests != null, "tests");

//Reset runDirectories before doing deployment, so that older values of runDirectories is not picked
//even if test host is kept alive.
RunDirectories = null;

this.adapterSettings = MSTestSettingsProvider.Settings;
bool canDeploy = this.CanDeploy();
var hasDeploymentItems = tests.Any(test => this.deploymentItemUtility.HasDeploymentItems(test));

if (!canDeploy || (canDeploy && !hasDeploymentItems))
// deployment directories should not be created in this case,simply return
if (!canDeploy && hasDeploymentItems)
{
return false;
}

RunDirectories = this.deploymentUtility.CreateDeploymentDirectories(runContext);

//Deployment directories are created but deployment will not happen.
//This is added just to keep consistency with MSTestv1 behaviour.
if (!hasDeploymentItems)
{
return false;
}

var isDeploymentDone = false;

using (new SuspendCodeCoverage())
Expand All @@ -146,16 +160,17 @@ group test by test.Source into testGroup
return true;
}

internal static IDictionary<string, object> GetDeploymentInformation()
internal static IDictionary<string, object> GetDeploymentInformation(string source)
{
var properties = new Dictionary<string, object>();

var applicationBaseDirectory = string.Empty;

// Run directories can be null in win8.
if (RunDirectories == null)
if (RunDirectories == null && !string.IsNullOrEmpty(source))
{
applicationBaseDirectory = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
// applicationBaseDirectory is set at source level
applicationBaseDirectory = Path.GetDirectoryName(source);
}

properties[TestContextPropertyStrings.TestRunDirectory] = RunDirectories != null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using System.Diagnostics;
using System;
using System.IO;

namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices
{
/// <summary>
/// Internal implementation of TraceListener exposed to the user.
/// The virtual operations of the TraceListener are implemented here
/// like Close(), Dispose() etc.
/// </summary>
public class TraceListenerWrapper : TextWriterTraceListener, ITraceListener
{
// Summary:
// Initializes a new instance of an object that derives from System.Diagnostics.TextWriterTraceListener
// Class and initializes TextWriterTraceListener object using the specified writer as recipient of the
// tracing or debugging output.
public TraceListenerWrapper(TextWriter textWriter):base(textWriter)
{
}

// Summary:
// Wrapper over Close() of System.Diagnostics.TextWriterTraceListener.Writer
public override void Close()
{
base.Close();
}

// Summary:
// Wrapper over Dispose() of System.Diagnostics.TextWriterTraceListener object
public new void Dispose()
{
base.Dispose();
}

// Summary:
// Gets the text writer of System.Diagnostics.TextWriterTraceListener.Writer
// that receives the tracing or debugging output.
public TextWriter GetWriter()
{
return base.Writer;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright (c) Microsoft. All rights reserved.

namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices
{
using System;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using System.Diagnostics;
using System.IO;
using System.Globalization;

/// <summary>
/// Internal implementation of TraceListenerManager exposed to the user.
/// Responsible for performing Add(), Remove(), Close(), Dispose() operations on traceListener object.
/// </summary>
public class TraceListenerManager : ITraceListenerManager
{
/// <summary>
/// Original output stream
/// </summary>
private TextWriter origStdOut;

/// <summary>
/// Original error stream
/// </summary>
private TextWriter origStdErr;

/// <summary>
/// Initializes a new instance of a TraceListenerManager object.
/// Also, updates the output/error streams with redirected outputWriter and errorWriter
/// </summary>
public TraceListenerManager(TextWriter outputWriter, TextWriter errorWriter)
{
origStdOut = Console.Out;
origStdErr = Console.Error;

// Update the output/error streams with redirected streams
Console.SetOut(outputWriter);
Console.SetError(errorWriter);
}

/// <summary>
/// Adds the arguement traceListener object to System.Diagnostics.TraceListenerCollection.
/// </summary>
public void Add(ITraceListener traceListener)
{
try
{
Trace.Listeners.Add(traceListener as TextWriterTraceListener);
}
catch (Exception ex)
{
// Catch exceptions if the configuration file is invalid and allow a stack
// trace to show the error on the test method instead of here.
if (!(ex.InnerException is System.Configuration.ConfigurationErrorsException))
{
throw;
}
}
}

/// <summary>
/// Removes the arguement traceListener object from System.Diagnostics.TraceListenerCollection.
/// </summary>
public void Remove(ITraceListener traceListner)
{
Trace.Listeners.Remove(traceListner as TextWriterTraceListener);
}

/// <summary>
/// Wrapper over Close() of ITraceListener.
/// </summary>
public void Close(ITraceListener traceListener)
{
traceListener.Close();
}

/// <summary>
/// Wrapper over Dispose() of ITraceListener.
/// Also resets the standard output/error streams.
/// </summary>
public void Dispose(ITraceListener traceListener)
{
traceListener.Dispose();
Console.SetOut(origStdOut);
Console.SetError(origStdErr);

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal static void SetAppDomainFrameworkVersionBasedOnTestSource(AppDomainSetu
string assemblyVersionString = GetTargetFrameworkVersionString(testSource);
if (GetTargetFrameworkVersionFromVersionString(assemblyVersionString).CompareTo(version45) > 0)
{
PropertyInfo pInfo = typeof(AppDomainSetup).GetProperty(Constants.TargetFrameworkName);
PropertyInfo pInfo = typeof(AppDomainSetup).GetProperty(PlatformServices.Constants.TargetFrameworkName);
if (pInfo != null)
{
pInfo.SetValue(setup, assemblyVersionString, null);
Expand Down Expand Up @@ -121,9 +121,9 @@ internal static string GetTargetFrameworkVersionString(string path)
/// <returns>Framework Version</returns>
internal static Version GetTargetFrameworkVersionFromVersionString(string version)
{
if (version.Length > Constants.DotNetFrameWorkStringPrefix.Length + 1)
if (version.Length > PlatformServices.Constants.DotNetFrameWorkStringPrefix.Length + 1)
{
string versionPart = version.Substring(Constants.DotNetFrameWorkStringPrefix.Length + 1);
string versionPart = version.Substring(PlatformServices.Constants.DotNetFrameWorkStringPrefix.Length + 1);
return new Version(versionPart);
}

Expand Down
Loading