Resharper External Attributes with MSTest's [DeploymentItem] - c#

In certain cases (like when writing URIs in XAML), ReSharper magically figures out I am writing out a relative path to a file in the current project and offers very useful smart-completion for it, and a warning if I misspell something and get it wrong, and even goes to the file if I ctrl+click it.
Can I somehow tell ReSharper to do the same when I'm typing in the parameter to MSTest's DeploymentItem attribute?

This should work through an external annotation. Open the following file:
C:\Program Files (x86)\JetBrains\ReSharper\v7.1\Bin\ExternalAnnotations\Visual Studio\Microsoft.VisualStudio.QualityTools.UnitTestFramework.xml
(Or whatever version of Resharper you're using.)
Add these lines inside the assembly tag:
<member name="M:Microsoft.VisualStudio.TestTools.UnitTesting.DeploymentItemAttribute.#ctor(System.String)">
<parameter name="path">
<attribute ctor="M:JetBrains.Annotations.PathReferenceAttribute.#ctor" />
</parameter>
</member>
<member name="M:Microsoft.VisualStudio.TestTools.UnitTesting.DeploymentItemAttribute.#ctor(System.String,System.String)">
<parameter name="path">
<attribute ctor="M:JetBrains.Annotations.PathReferenceAttribute.#ctor" />
</parameter>
</member>
That tells Resharper to throw the PathReference attribute on the path parameter of both constructors of DeploymentItem.
However, after testing for some time now I cannot see this attribute working on anything that I try within the C# text editor. It could be that it doesn't work for my version (7.1), but I'm a bit stumped. Perhaps someone can add to this?

Related

Is it possile to sent build number to csproj as a parameter without using the Build.proj

I am not pretty familiar with msbuild technique.
Currently I have a build.proj in my solution to assign a build number to the exe, by using a following param:
<PropertyGroup Condition=" '$(BUILD_NUMBER)' != '' ">
<!-- Build Server Number -->
<Version>$(BUILD_NUMBER)Version>
<FileVersion>$(BUILD_NUMBER)FileVersion>
<InformationalVersion>$(BUILD_NUMBER)InformationalVersion></PropertyGroup><Target Name="Version">
<Attrib Files="$(MSBuildProjectDirectory)\AssemblyInfo.cs" ReadOnly="False" />
<AssemblyInfo CodeLanguage="CS"
OutputFile="$(MSBuildProjectDirectory)\GlobalAssemblyInfo.cs"
GenerateClass="true"
AssemblyCopyright="Copyright © $(Year). All rights reserved."
AssemblyConfiguration="$(BuildConfiguration)"
AssemblyVersion="$(Version)"
AssemblyFileVersion="$(FileVersion)"
AssemblyInformationalVersion="$(InformationalVersion)" /> </Target>
Now I can't use build.proj. Is it any alternative way to assign a build number to csproj?
We generate a AssemblyInfo.cs file to put in all assembly attributes we need to define. You could do this on pre-build time if that suits you. There we define the AssemblyVersion, AssemblyFileVersion attribute and other related attributes.
Those properties will be used compiling the assembly.

Word VSTO CustomXMLNode.SelectSingleNode fails after Office upgrade

A word vsto addin fails with exception on calling CustomXMLNode.SelectSingleNode.
The addin runs fine with word 2007 - 2013, but on version 2016 it fails with Reference to undeclared namespace prefix: 'ns0'.
I've made a workaround navigating the XML without the use of xpath and these methods, but still need to figure out how to solve this issue.
var xPathExpression = String.Format(
"{0}:{1}[1]",
customXml.NamespaceManager.LookupPrefix(xmlRef.DefaultNamespace),
xmlRef.ElementNames.DisplayText.LocalName);
groupMembers[j].SelectSingleNode(xPathExpression);
The resulting xPathExpression is
ns0:DisplayText[1]
The xml looks like this:
<MyXmlTest xmlns="http://www.myxmltest.com/document">
<Ribbon visible="true">
<Group name="xmlProperties">Document Properties</Group>
<Group name="xmlActions">Other Properties</Group>
</Ribbon>
<DocumentList>
<Document>
<Properties ribbonLabel="Hello World Menu">
<Property name="helloWorld">
<RibbonButton groupName="xmlActions">
<DisplayText>Hello World</DisplayText>
<PlaceholderText>N/A</PlaceholderText>
<Tooltip>Some text goes here.</Tooltip>
</RibbonButton>
<Content/>
</Property>
<Property name="title">
<RibbonButton groupName="xmlProperties">
<DisplayText>Hello World Text</DisplayText>
<PlaceholderText>N/A</PlaceholderText>
<Tooltip>Insert Hello World in Document</Tooltip>
</RibbonButton>
<Content>Testing</Content>
</Property>
</Properties>
</Document>
</DocumentList>
</MyXmlTest>
Usually, to execute XPath containing namespace prefix you need to pass along namespace manager containing the prefix-URI mapping. Since this option isn't available in your case, as a workaround, you can try to ignore namespaces by using local-name() :
*[local-name()='DisplayText'][1]

Invoking browsers with Baseclass.Contrib.Specflow in C# using Browser.Current

I'm currently trying to use Selenium Grid 2 to run automation tests on multiple browsers. During my research I came across using Baseclass.Contrib.Specflow which enables me to use the browsers as tags in the feature files without having to declare it in my main driver class. The problem I have is that one of the blogs I read had the following as the set up code
[SetUp]
public void Test_Setup(){
CurrentDriver = Browser.Current;}
My app config file looks contains the following:
<components>
<!-- <component name="Firefox" type="OpenQA.Selenium.Firefox.FirefoxDriver, WebDriver" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency">
</component>-->
<component name="Firefox"
type="Baseclass.Contrib.SpecFlow.Selenium.NUnit.RemoteWebDriver, Baseclass.Contrib.SpecFlow.Selenium.NUnit.SpecFlowPlugin"
service="OpenQA.Selenium.IWebDriver, WebDriver"
instance-scope="per-dependency">
<parameters>
<parameter name="url" value=" http://localhost/wd/hub" />
<parameter name="browser" value="Firefox" />
</parameters>
</component>
<component name="Safari" type="Baseclass.Contrib.SpecFlow.Selenium.NUnit.RemoteWebDriver, Baseclass.Contrib.SpecFlow.Selenium.NUnit.SpecFlowPlugin" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency">
<parameters>
<parameter name="url" value=" http://localhost/wd/hub" />
<parameter name="desiredCapabilities" value="Chrome" />
</parameters>
</component>
I get an error when I try to run the script using the above Setup method.
Error:
System.Collections.Generic.KeyNotFoundException : The given key was not present in the dictionary
The blog I got this solution from doesn't seem to answer questions regarding to this so I'm a bit desperate. This will basically allow me to to the following on the feature file and get tests to run based on the tag
#Browser:Firefox
#Browser:Chrome
Hope this is enough information to give me advice.
The mistake you are making here is that you are annotating your entire feature file with the tag #Browser.
Baseclass.Contrib.Specflow allows you to annotate scenarios with scenario supporting Browsers. Therefore, you have to annotate each scenario.
If you don't do that, there is no Current Browser set for that test and trying to access Browser.Current will throw System.Collections.Generic.KeyNotFoundException.
You know you're doing it right when the generated Unit Tests will include the Browser name as part of the unit test name like
<Test Name> on <Browser> with: <parameters>
Example:
#Browser:IE
#Browser:Chrome
#Browser:Firefox
Scenario Outline: Add Two Numbers
>Given I navigated to / using
And I have entered <summandOne> into summandOne calculator
And I have entered <summandTwo> into summandTwo calculator
When I press add
Then the result should be <result> on the screen
Scenarios:
| summandOne| summandTwo|result|
| 10 | 20 | 30 |
| 3 | 4 | 7 |

MSBuild - XPath - XmlPeek can read but XmlPoke can not write

I'm using MSBuild to manipulate my Project (.csproj) file to update a reference to a static file. The static file will be built by my CI Server (TeamCity) and then the reference the Project uses will need to be updated before the Project itself is built.
Here is an example of the Xml from my csproj file (full version):
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
ToolsVersion="12.0">
<ItemGroup>
<Content Include="packages\pMixins.0.1.7.nupkg">
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
I have written an MSBuild Task:
<Target Name="ReplaceNugetPackageDependency" BeforeTargets="PrepareForBuild" >
<XmlPoke
XmlInputPath="$(MSBuildProjectFile)"
Query="//n:Project/n:ItemGroup/
n:Content[starts-with(#Include, 'packages')]/#Include"
Value="TEST-TEST"
Namespaces="<Namespace Prefix='n'
Uri='http://schemas.microsoft.com/developer/msbuild/2003'
Name='DoNotKnowWhatThisIsFor-ButItIsRequired' />" >
</XmlPoke>
</Target>
But when I run it I get the message 0 replacements.
So I added an XmlPeek task to test the query:
<XmlPeek
XmlInputPath="$(MSBuildProjectFile)"
Query="/n:Project/n:ItemGroup/
n:Content[starts-with(#Include, 'packages')]/#Include"
Namespaces="<Namespace Prefix='n'
Uri='http://schemas.microsoft.com/developer/msbuild/2003'
Name='DoNotKnowWhatThisIsFor-ButItIsRequired' />">
<Output TaskParameter="Result" ItemName="Peeked" />
</XmlPeek>
<Message Text="Text: #(Peeked)"/>
When I run MSBuild XmlPeek is able to read the Xml:
Text: packages\pMixins.0.1.7.nupkg
The queries are exactly the same! Why can't XmlPoke manipulate the Xml if XmlPeek can read it?
UPDATE
After hours of playing with this, I finally found an XPath query that will get XmlPoke to do what I want:
Query="//n:Project/n:ItemGroup/
n:Content[starts-with(#Include, 'packages')]/n:IncludeInVSIX/../#Include"
Why is it necessary to add /n:IncludeInVSIX/..? Is this a bug??
Just wanted to confirm for anyone else who encounters this, that this is how, in fact, you get around the issue of not being able to use the same exact XPath query in XmlPeek task and XmlPoke task.
Original query to replace "file" attribute value of AppSettings element in regular web.config:
<appSettings file="devsettings.config">
<add key="BuildVersion" value="" />
</appSettings>
To get at the "file" attribute in XmlPeek task I used following XPath query:
//appSettings[#file='devsettings.config']/#file
However this same query wouldn't work in XmlPoke task. Instead the following worked like what #philip-pittle discovered in his update to the question
//appSettings[#file='devsettings.config']/add/../#file
<XmlPeek XmlInputPath="$(_BuildPath)web.config"
Query="//appSettings[#file='devsettings.config']/#file">
<Output TaskParameter="Result" ItemName="ExistingPeeked" />
</XmlPeek>
<XmlPoke XmlInputPath="$(_BuildPath)web.config"
Query="//appSettings[#file='devsettings.config']/add/../#file"
Value="$(_EnvironmentConfig)" />
This was using following versions of MSBuild.
Microsoft (R) Build Engine version 12.0.31101.0
[Microsoft .NET Framework, version 4.0.30319.18444]
May be it's a bug? But definitely odd behavior.

How to mark obsolete classes/methods in the output with sandcastle

I'm building an API documentation with Sandcastle. The code has multiple classes and methods which are marked deprecated. Now I want that in the API-documentation output these methods are clearly marked (crossed-out or other marker). However the Sandcastle output doesn't mark obsolete methods/classes at all.
My question is. What do I need to do to have the obsolete methods/classes marked by Sandcastle.
Thanks for any advice/help.
Well I found the issue. The issue is a mix of the API and Attribute filters I had in place.
So I added the System-namespace to my API filters, so that it includes the Obsolete-Attribute:
<apiFilter>
<namespace name="System" expose="true">
<type name="ObsoleteAttribute" expose="true" />
<type name="SerializableAttribute" expose="false" />
</namespace>
<!-- rest of the stuff -->
</apiFilter>
And added it also to the list of Attribute-Filters:
<attributeFilter expose="true">
<namespace name="System" expose="false">
<type name="ObsoleteAttribute" expose="true" />
</namespace>
<!-- rest of the stuff -->
</attributeFilter>
I had the 'ObsoleteAttribute' in my attribute-filter, but not in the API-filter.
This thread was also helpful: http://docproject.codeplex.com/discussions/74716?ProjectName=docproject

Categories

Resources