Overview
Adjust your PowerShell Profile
\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
Note that you can access your documents folder path from PowerShell like so:
$([environment]::getfolderpath("mydocuments")


\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
Note that you can access your documents folder path from PowerShell like so:
$([environment]::getfolderpath("mydocuments")


Get-WebConfigurationProperty
Add-WebConfigurationProperty
Set-WebConfigurationProperty
%windir%\system32\inetsrv\config\applicationHost.configAfter this rule has been applied, recycle the app pool or reset IIS and then when accessing http://localhost/simple-rewrite/1.html you’ll be taken to http://localhost/simple-rewrite/2.html.
Import-Module WebAdministrationTo create the above rule using Powershell, run the following script (see CreateRule1.ps1):
Add-WebConfigurationProperty `-pspath 'IIS:\Sites\Default Web Site\simple-rewrite' `-filter '/system.webserver/rewrite/rules' `-name "." `-value @{name='Rule 1'; patternSyntax='ECMAScript'; stopProcessing='True'}The pspath parameter is the website path in the format used by the WebAdministration module. The filter parameter is the XPath to select the element we’re interested in. Here it’s under rules/rule and has a name attribute with the value “Rule 1”.
Set-WebConfigurationProperty `-pspath 'IIS:\Sites\Default Web Site\simple-rewrite' `-filter '/system.webserver/rewrite/rules/rule[@name="Rule 1"]/match' `-name url `-value '1.html'
Set-WebConfigurationProperty `-pspath 'IIS:\Sites\Default Web Site\simple-rewrite' `-filter '/system.webserver/rewrite/rules/rule[@name="Rule 1"]/action' `-name . `-value @{ type="Redirect"; url='2.html'; redirectType="SeeOther" }
Clear-WebConfiguration `-pspath 'IIS:\Sites\Default Web Site\simple-rewrite' `-filter '/system.webserver/rewrite/rules/rule[@name="Rule 1"]'
$existing = Get-WebConfigurationProperty `-pspath 'IIS:\Sites\Default Web Site\simple-rewrite' `-filter '/system.webserver/rewrite/rules/rule[@name="Rule 1"]' -name *
if ($existing) {
Clear-WebConfiguration `-pspath 'IIS:\Sites\Default Web Site\simple-rewrite' `-filter '/system.webserver/rewrite/rules/rule[@name="Rule 1"]'
}
Add-WebConfigurationProperty `-pspath 'IIS:\Sites\Default Web Site\simple-rewrite' `
-filter '/system.webserver/rewrite/rules' `-name "." `-value @{name='Rule 1 Post Exception'; patternSyntax='ECMAScript'; stopProcessing='True'}
Set-WebConfigurationProperty `-pspath 'IIS:\Sites\Default Web Site\simple-rewrite' `
-filter '/system.webserver/rewrite/rules/rule[@name="Rule 1 Post Exception"]/match' `-name url `-value "b/2.html"
Add-WebConfigurationProperty `-pspath 'IIS:\Sites\Default Web Site\simple-rewrite' `
-filter '/system.webserver/rewrite/rules/rule[@name="Rule 1 Post Exception"]/conditions' `-name "." `-value @{input="{REQUEST_METHOD}"; pattern='POST'}
Add-WebConfigurationProperty `-pspath 'IIS:\Sites\Default Web Site\simple-rewrite' `
-filter '/system.webserver/rewrite/rules/rule[@name="Rule 1 Post Exception"]/conditions' `-name "." `-value @{input="{QUERY_STRING}"; pattern='paramA=(X|Y|Z)'}
Add-WebConfigurationProperty `-pspath 'IIS:\Sites\Default Web Site\simple-rewrite' `-filter '/system.webserver/rewrite/rules' `-name "." `-value @{name='Rule 1 Exception'; patternSyntax='ECMAScript'; stopProcessing='True'}The above script writes the following to the configuration file.
Set-WebConfigurationProperty `-pspath 'IIS:\Sites\Default Web Site\simple-rewrite' `-filter '/system.webserver/rewrite/rules/rule[@name="Rule 1 Exception"]/match' `-name url `-value 'b/c/1.html'
Set-WebConfigurationProperty `-pspath 'IIS:\Sites\Default Web Site\simple-rewrite' `-filter '/system.webserver/rewrite/rules/rule[@name="Rule 1 Exception"]/action' `-name . `-value @{ type="None" }
This post is about setting up testing for TypeScript with Jasmine in Visual Studio, but it should be pretty much the same using QUnit.
To set this up, start a new MVC project and let’s get Knockout and Jasmine installed into the project, along with their TypeScript definitions:
Install-Package knockoutjs
Install-Package knockout.typescript.DefinitelyTyped
Install-Package JasmineTest
Install-Package jasmine.typescript.DefinitelyTyped
We’re using the Jasmine Nuget package called JasmineTest. There is a similar one on Nuget called Jasmine-JS, the difference being that JasmineTest will add a controller and view to let you run your tests. We’ll be using that in a second to let us debug the tests. Now run and browse to ~/jasmine/run and you’ll see this:
This is the view added by the JasmineTest package. It is an HTML page (SpecRunner.cshtml) and has the references for the example Jasmine specs that ship with Jasmine. We are going to be using to let us debug out tests.
So, let’s write some tests. For simplicity we’re going to put the model and the tests into the same file. So we add a TypeScript file called Tests.ts to your /Scripts folder and add the following lines to that file, giving this:
If you have ReSharper installed, then the R# Test Runner will recognise the Jasmine test and allow you to run them. To set this up for a smooth experience, first install PhantomJS and set the path to phantomjs.exe in Resharper | Options | Tools | Unit Testing | JavaScript Tests.
R# will need to find the .JS files for the .TS references. R# will look for and use a file that is named the same as the Definitely Typed TS file, but ending with .JS. For us, this means copying knockout-3.1.0.js from /Scripts to /Scripts/typings/knockout and renaming it to knockout.d.js:
After that you can just run the tests as you would in C#:
You can also use the Chutzpah test runner to run Jasmine tests in Visual Studio. You can install that from Tools | Extensions and Updates here:
Once installed, you just right click the TypeScript file that contains the tests and select the item Run JS Tests. This puts the test results into the Visual Studio Output window by default, but there is a Visual Studio extension that gives integration with the Visual Studio Test Explorer.
If you go ahead and run the tests as shown above you’ll get an error. This is because Chutzpah resolves referenced JS files differently to R#. For this to run, we need to add a reference to the JS file in the TS test for Chutzpah to pick up. This is documented here and looks like this:
/// <chutzpah_reference path="knockout-3.1.0.js" />
As far as I can tell, there is currently no support from either R# or Chutzpah for debugging TS tests from either test runner in the IDE. However, we can do that by going back to our SpecRunner.cshtml that was installed with the JasmineTest Nuget package.
Just add the JS references along with a reference to our test file to the HTML shipped with the package:
Note that we are referencing Tests.js instead of the TS file. Then place a break point in the test in the TS file, run a browse to ~/Jasmine/Run:
Job done! Source code is here: https://bitbucket.org/seankearon/typescript-testing-in-studio
I ran into an issue today with using RavenDB from an obfuscated assembly. RavenDB started giving some nasty looking errors like:
System.InvalidOperationException: Could not understand query:
-- line 2 col 43: invalid NewExpression
After bashing my head against this for too long, I had run out of ideas and so I posted the problem on the RavenDB group. One of the really good things about RavenDB is the amazing support from both the Hibernating Rhinos team and the community on this group. So, pretty soon it was problem solved!
The problem: the obfuscation was renaming the anonymous types that are used when defining indexes from code in RavenDB.
The solution: either put your types into a non-obfuscated assembly or tell the obfuscator to stop renaming anonymous types. Let’s look at the second option a bit more.
Okay, so how do you detect an anonymous type? One way is to look at their names. The compiler gives anonymous types names and puts the text “AnonymousType” into the name. For example:
new { Name = "Sean"}.GetType().Name // Gives: <>f__AnonymousType0`1
Simple enough, but there is a caveat: the naming of anonymous types is an implementation detail and may vary with different compiler implementations. You cannot rely in this working with different compilers.
So, with that in mind, let’s look at a solution…
Different obfuscators allow you to add obfuscation rules in various ways. In this repo there is an example of using Eazfuscator with a RavenDB index. (Note that you will need to install Eazfuscator to be able to run the code.) All that is needed is to use an assembly scoped ObfuscationAttribute to prevent renaming of any type whose name contains the text “AnonymousType”:
[assembly: Obfuscation(Feature = "Apply to type *AnonymousType*: renaming", Exclude = true, ApplyToMembers = true)]
Bingo, everything works as it should again…happy days!