ApprovalTests....Moving the assemblies after compile - approval-tests

First up, great library!
If I compile, then move the assemblies when I verify it still looks for the *.approved.txt in the location it was compiled in, which in my case no longer exists.
I'm running into this issue on Teamcity where we build and test in separate tasks.
So the build step will build in c:\BuildAgent\SomeGuid...
I take the artifacts from the build and run the tests in c:\BuildAgent\SomeOtherGuid...
This fails as Approvals.Verify still references "SomeGuid"
[Fact]
public void ShouldCreateCorrectOutgoingFiles() {
var textToVerfiy = "Here's some text To Verify";
Approvals.Verify(textToVerfiy);
}
...
: System.IO.DirectoryNotFoundException : Could not find a part of the path 'r:\w\254cbbd5ec9b56bc\project\ScenarioTests\myTests'.
Stack Trace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost)
at System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost)
at System.IO.Directory.CreateDirectory(String path)
at ApprovalTests.ApprovalTextWriter.WriteReceivedFile(String received)
at ApprovalTests.Approvers.FileApprover.Approve()
at ApprovalTests.Core.Approvals.Verify(IApprovalApprover approver, IApprovalFailureReporter reporter)
at ApprovalTests.Approvals.Verify(IApprovalWriter writer, IApprovalNamer namer, IApprovalFailureReporter reporter)
at ApprovalTests.Approvals.Verify(IApprovalWriter writer)
at ApprovalTests.Approvals.Verify(String text)
Any ideas on how I can tweak it to look in relative directory to executable.

You have to write a custom namer. It's pretty easy. Take a look at these files.
http://bit.ly/IApprovalNamer
http://bit.ly/XUnitStackTraceParser
http://bit.ly/AttributeStackTraceParser
Once you do that, you'll have to register the namer for use, to do that simply call.
Approvals.RegisterDefaultNamerCreation(()=> new MyCustomNamer());

Related

Visual Studio 2019 Xamarin Dotfuscator CE Config File Creation Problem

I have followed the instructions at https://www.preemptive.com/dotfuscator/ce/docs/help/getting_started_xamarin.html#setup-targets and verified the accuracy multiple times. It says the first build will create DotfuscatorConfig.xml but it fails with Error 1. Then it says to set verbosity to Normal, so I did, but still no revelation why it won't create the file. I can change the build back to Debug and it builds fine, but changing back to release produces the same two errors. Has anyone experienced this and solved it?
Severity Code Description Project File Line Suppression State
Error The command ""C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\PreEmptiveSolutions\DotfuscatorCE\dotfuscator.exe" /p:InDir="obj\Release\100\DotfuscatorXamarin\dfin",OutDir="obj\Release\100\DotfuscatorXamarin\dfout",ReportDir="DotfuscatorReports\Release" "obj\Release\100\DotfuscatorXamarin\Template.dfconfig" /in:+"${configdir}${InDir}\WetYourWhistle.Android.dll",+"${configdir}${InDir}\WetYourWhistle.dll" /makeconfig:"DotfuscatorConfig.xml"" exited with code 1. WetYourWhistle.Android C:\Users\leuol\source\repos\WetYourWhistle\PreEmptive.Dotfuscator.Xamarin\PreEmptive.Dotfuscator.Xamarin.targets 508
Severity Code Description Project File Line Suppression State
Error The "_DotfuscatorXamarin_SetProjectPropsTask" task failed unexpectedly.
System.IO.FileNotFoundException: Could not find file 'C:\Users\leuol\source\repos\WetYourWhistle\WetYourWhistle\WetYourWhistle.Android\DotfuscatorConfig.xml'.
File name: 'C:\Users\leuol\source\repos\WetYourWhistle\WetYourWhistle\WetYourWhistle.Android\DotfuscatorConfig.xml'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlTextReaderImpl.FinishInitUriString()
at System.Xml.XmlTextReaderImpl..ctor(String uriStr, XmlReaderSettings settings, XmlParserContext context, XmlResolver uriResolver)
at System.Xml.XmlReaderSettings.CreateReader(String inputUri, XmlParserContext inputContext)
at System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings, XmlParserContext inputContext)
at System.Xml.Linq.XDocument.Load(String uri, LoadOptions options)
at System.Xml.Linq.XDocument.Load(String uri)
at InlineCode._DotfuscatorXamarin_SetProjectPropsTask.Execute() in c:\Users\leuol\AppData\Local\Temp\r0wqtkdr\r0wqtkdr.0.cs:line 93
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() WetYourWhistle.Android C:\Users\leuol\source\repos\WetYourWhistle\PreEmptive.Dotfuscator.Xamarin\PreEmptive.Dotfuscator.Xamarin.targets 520
Error The command ""C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\PreEmptiveSolutions\DotfuscatorCE\dotfuscator.exe" /p:InDir="obj\Release\100\DotfuscatorXamarin\dfin",OutDir="obj\Release\100\DotfuscatorXamarin\dfout",ReportDir="DotfuscatorReports\Release" "obj\Release\100\DotfuscatorXamarin\Template.dfconfig" /in:+"${configdir}${InDir}\WetYourWhistle.Android.dll",+"${configdir}${InDir}\WetYourWhistle.dll" /makeconfig:"DotfuscatorConfig.xml"" exited with code 1. WetYourWhistle.Android C:\Users\leuol\source\repos\WetYourWhistle\PreEmptive.Dotfuscator.Xamarin\PreEmptive.Dotfuscator.Xamarin.targets 508
UPDATE - Now the code is compiling without error but still will not produce the DotfuscatorConfig.xml file. Not sure what else to try and it appears that nobody else knows either.
The solution is to temporary change the command dotfuscator.exe to dotfuscatorUI.exe :
<PropertyGroup>
<DotfuscatorXamarinConfigFileName>DotfuscatorConfig.xml</DotfuscatorXamarinConfigFileNam
<DotfuscatorXamarinCliPath>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\PreEmptiveSolutions\DotfuscatorCE\dotfuscatorUI.exe</DotfuscatorXamarinCliPath>
<DotfuscatorGenerateConfigFileIfMissing>true</DotfuscatorGenerateConfigFileIfMissing>
<DotfuscatorEnabled>true</DotfuscatorEnabled>
<DotfuscatorXamarinEnabled Condition="'$(Configuration)' == 'Release'">true</DotfuscatorXamarinEnabled>
</PropertyGroup>
<Import Project="../../PreEmptive.Dotfuscator.Xamarin/PreEmptive.Dotfuscator.Xamarin.targets" />
Then start build. The dotfuscator UI starts with a window:
Show Image
Then press "Build". After it finishes, close then window by clicking "x" on top right. Then the output on Visual Studio shows a successful result:
Build started: Project: [AppName].Android, Configuration: Release Any CPU ------
[AppName].Android -> D:\Users\[UserName]\source\repos\[FolderName]\[AppName]\[AppName].Android\bin\Release\[AppName].Android.dll
Running Dotfuscator with a new config file based on project references...
Finished running Dotfuscator with a new config file.
D:\Users\[UserName]\source\repos\[FolderName]\[AppName]\[AppName].Android\[AppName].Android.csproj : warning : A new Dotfuscator config file was generated because it did not exist: 'DotfuscatorConfig.xml'.
You can see dotfuscatorconfig.xml is created at a folder [AppName].Android.
Then revert back from dotfuscatorUI.exe to dotfuscator.exe .
<PropertyGroup>
<DotfuscatorXamarinConfigFileName>DotfuscatorConfig.xml</DotfuscatorXamarinConfigFileNam
<DotfuscatorXamarinCliPath>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\PreEmptiveSolutions\DotfuscatorCE\dotfuscator.exe</DotfuscatorXamarinCliPath>
<DotfuscatorGenerateConfigFileIfMissing>true</DotfuscatorGenerateConfigFileIfMissing>
<DotfuscatorEnabled>true</DotfuscatorEnabled>
<DotfuscatorXamarinEnabled Condition="'$(Configuration)' == 'Release'">true</DotfuscatorXamarinEnabled>
</PropertyGroup>
<Import Project="../../PreEmptive.Dotfuscator.Xamarin/PreEmptive.Dotfuscator.Xamarin.targets" />
Then the build should work without a UI popup.

Visual Studio 2017 crash on startup Show some dependent package error

When I am trying to launch VS 2017, is throwing some missing package error stating "Something went wrong".
Error Log:
[2544:0006][2018-06-01T11:21:08] Error 0x80131500: The dependent
package of
'Microsoft.VisualStudio.Product.Enterprise,version=15.7.27703.2018'
cannot be found:
Component.Redgate.SQLPrompt.VsPackage,version=9.1.12.5083. at
Microsoft.VisualStudio.Setup.Dependencies.DependencyManager.FindDependentPackages(Dependency
dependency, DependencyComparer comparer, Dictionary2 packageIndex,
IPackage holder) at
Microsoft.VisualStudio.Setup.Dependencies.DependencyManager.BuildGraphRecursive(IPackage
graphRoot, DependencyNode node, DependencyComparer comparer,
Dictionary2 packageIndex, Dictionary2 nodeIndex, Boolean splitNodes)
at
Microsoft.VisualStudio.Setup.Dependencies.DependencyManager.BuildGraphCore(IPackage
root, IEnumerable1 packages, DependencyComparer comparer,
Dictionary2 packageIndex, Dictionary2 nodeIndex, Boolean splitNodes,
DependencyCollection deprecated) at
Microsoft.VisualStudio.Setup.Dependencies.DependencyManager.BuildGraph(IPackage
root, IEnumerable`1 packages, Boolean isUpdate,
IDependencyComparisonSeed seed, DependencyCollection deprecated) at
Microsoft.VisualStudio.Setup.Engine.GetDependencyGraph(Product
product) at
Microsoft.VisualStudio.Setup.Engine.TryBuildDependencyGraph(Product
product, Exception& error, Boolean overwrite, ITelemetryOperation
telemetryOperation) [2544:0006][2018-06-01T11:21:08] Error 0x80131500:
The dependent package of
'Microsoft.VisualStudio.Product.Enterprise,version=15.7.27703.2018'
cannot be found:
Component.Redgate.SQLPrompt.VsPackage,version=9.1.12.5083. at
Microsoft.VisualStudio.Setup.Engine.CreateInstallOperation(Product
product, String destination, ExecuteAction action, ITelemetryOperation
telemetryOperation) at
Microsoft.VisualStudio.Setup.Engine.Repair(CancellationToken token)
T wasn't able to launch or Repair but after a long and exhausted research, I silly thing worked for me.
I choose to modify option and then again modify to repair selected packages. Once Done everything looks good.

Operation not permitted on IsolatedStorageFileStream. when using MvvmCross file plugin

I have an instance of IMvxFileStore implementation for for Windows Phone injected into my service.
Let say I want to store settings in a file located at appsettings\userprofiles\profile1.txt
Using the file plugin, I first call the API EnsureFolder exists, passing in the full path to my profile settings file appsettings\userprofiles\profile1.txt to ensure that this folder has been created and does exist.
Just for sanity, I check to ensure that the folder has been created using the FolderExist API. This always returns true atleast for now.
The code looks like this:
private string GetStorageItemFileName(string filename)
{
Guard.ThrowIfNull(string.IsNullOrWhiteSpace(BaseDirectory), Messages.RepositorBackingStoreIsNull);
filename = _fileStore.PathCombine(BaseDirectory, filename);
_fileStore.EnsureFolderExists(filename);
if (_fileStore.FolderExists(filename))
{
// what do do????
}
return filename;
}
However, when I attempt to write content to the file using WriteToFile API, passing in the file name returned from the method above and some string, as follows
try
{
_fileStore.WriteFile(filename, content);
}
catch (Exception ex)
{
Logger.Error(ex);
}
, I get the following exception:
System.IO.IsolatedStorage.IsolatedStorageException was caught
HResult=-2146233264 Message=Operation not permitted on
IsolatedStorageFileStream. Source=mscorlib StackTrace:
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path,
FileMode mode, FileAccess access, FileShare share, Int32 bufferSize,
IsolatedStorageFile isf)
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path,
FileMode mode, IsolatedStorageFile isf)
at Cirrious.MvvmCross.Plugins.File.WindowsPhone.MvxIsolatedStorageFileStore.WriteFileCommon(String
path, Action`1 streamAction)
at Cirrious.MvvmCross.Plugins.File.WindowsPhone.MvxIsolatedStorageFileStore.WriteFile(String
path, String contents)
at TrackuTransit.Core.Services.DataStore.StorageItemFileRepository.Put(String
filename, StorageItem data) InnerException:
My dev environment is setup as follows:
- Surface Pro 3
- Visual Studio 2013 Community
- Windows Phone 8.1 SDK and Simulator
- MvvmCross 3.0.0.4. (yes,, it is old and will be updated after MVP).
Before I go digging into the MvvmCross code base, anyone with ideas on what I could be doing wrong here?
Upgraded the project to .NET 4.5 and also upgraded to MvvmCross 3.5.1 and still ran into the same problem. Although I lost a couple of days due from the upgrade, I am glad it is over with.
The problem I am running into here has to do with the fact that I am calling
_fileStore.EnsureFolderExists(filename);
and passing in the full path to the file. Underneath the scenes, MvvmCross is calling
IsolatedStorageFile.CreateDirectory(filename);
which appears to be creating a directory with the same file name. So passing in "images\image1.png" to the above API appears to create a directory or hold some IO resource related to "images\images.png".
When you attempt to write to file using
_fileStore.WriteFile(filename, content);
MvvmCross is attempting to create a file stream using
var fileStream = new IsolatedStorageFileStream(path, FileMode.Create, isf))
and the exception is thrown right here.
Fix is to ensure you are passing to IMvxFileStore.EnsureFolderExists API just the folder in question. In this case it is "images". Then you pass to IMvxFileStore.WriteFile the relative path to the file including the file name such as "images\image1.png" and you are good to go.
Fixed code looks like this:
private string GetStorageItemFileName(string filename)
{
Guard.ThrowIfNull(string.IsNullOrWhiteSpace(BaseDirectory), Messages.RepositorBackingStoreIsNull);
filename = _fileStore.PathCombine(BaseDirectory, filename);
// assumption is that filename does not contain directory information
_fileStore.EnsureFolderExists(BaseDirectory);
return filename;
}

Exception in SonarQube.Msbuild.Runner

Running the SonarQube.MsBuild.Runner.exe I get the following exception:
Using environment variables to determine the download directory...
Creating the analysis bin directory:
Unhandled Exception: System.ArgumentException: Path cannot be the empty string or all whitespace.
at System.IO.Directory.CreateDirectory(String path)
at SonarQube.Bootstrapper.Program.preprocess(ILogger logger, IBootstrapperSettings settings, String[] args)
at SonarQube.Bootstrapper.Program.Main(String[] args)
I have the environment variables SONAR_RUNNER_HOME and SONAR_RUNNER_OPTS set like this:
Name Value
---- -----
SONAR_RUNNER_HOME C:\Program Files\SonarQube\sonar-runner-2.4
SONAR_RUNNER_OPTS -Xmx512m -XX:MaxPermSize=128m
What is missing?
Could it be due to the space in C:\Program Files\SonarQube\sonar-runner-2.4 ?
Try to add quotation mark around the path or move the location of SonarQube runner to C:\SonarQube\sonar-runner-2.4
Also verify that you are not running Java 8, because then you should remove the SONAR_RUNNER_OPTS variable as described on page 20 here https://vsarguidance.codeplex.com/downloads/get/1452516
I am using Sonar.MsBuild.Runner 1.0 now. The problem does not exist in MsBuild Runner.

PlatformVerificationTask internal error: "The file exists"

Anyone have any insight as to what this error is, and how to fix/avoid it?
Warning 1 An internal error occurred in PlatformVerificationTask. System.IO.IOException: The file exists.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.__Error.WinIOError()
at System.IO.Path.GetTempFileName()
at Microsoft.CompactFramework.Build.DeviceTypeResolver.CreateDynamicAssembly(String fileName)
at Microsoft.CompactFramework.Build.DeviceTypeResolver.LoadAssembly(String codebase, Boolean canlock)
at Microsoft.CompactFramework.Build.DeviceTypeResolver..ctor(ICollection references)
at Microsoft.CompactFramework.Build.AsmmetaContext..ctor(String ndpversion, String platformFamily, String platformID, ICollection references)
at Microsoft.CompactFramework.Build.Tasks.PlatformVerificationTask.Execute()
I have doctored up a project to run the compiler to build .NET CF dlls from within VS2010, according to this SO question ( Building Compact Framework applications with VS2010 (without VS2005) ) . The build was working but now it stopped with this odd error.
I figured it out. By... uh.... Reading the documentation.
The doc page for System.IO.Path.GetTempPathName says
The GetTempFileName method will raise an IOException if it is used to create more than 65535 files without deleting previous temporary files.
The GetTempFileName method will raise an IOException if no unique temporary file name is available. To resolve this error, delete all unneeded temporary files.
So... I deleted the tmp????.tmp files from C:\Users\USERNAME\AppData\Local\Temp, and everything worked again.

Resources