Flurl is a modern, fluent, asynchronous, testable, portable, buzzword-laden URL builder and HTTP client library.
tmenier.github.io/Flurl/
Powershell Generic Invoke-RestMethod / WebRequest error handler
From: https://stackoverflow.com/questions/39319680/onelogin-rest-api-with-powershells-invoke-restmethod
#generic Invoke-RestMethod / WebRequest error handler #https://stackoverflow.com/questions/39319680/onelogin-rest-api-with-powershells-invoke-restmethod function Failure { $global:helpme = $body $global:helpmoref = $moref $global:result = $_.Exception.Response.GetResponseStream() $global:reader = New-Object System.IO.StreamReader($global:result) $global:responseBody = $global:reader.ReadToEnd(); Write-Host -BackgroundColor:Black -ForegroundColor:Red "Status: A system exception was caught." Write-Host -BackgroundColor:Black -ForegroundColor:Red $global:responsebody Write-Host -BackgroundColor:Black -ForegroundColor:Red "The request body has been saved to `$global:helpme" break }
Then, wrap all of your Invoke-RestMethod calls in a try Catch block like this.
try {
$e = Invoke-WebRequest 'https://api.us.onelogin.com/api/1/users/$id' `
-Headers @{ Authorization = "bearer:$token" } `
-Body ( @{ phone = "7709746046" } | ConvertTo-Json ) `
-Method Put -ErrorAction:Stop -ContentType 'application/json'
}
catch {Failure}
Now when you run into an error, you can see the actual message, like this
> Status: A system exception was caught.
{"status":{"error":true,"code":400,"type":"bad request","message":{"description":"notes is not a valid attribute for user model","attribute":"notes"}}}
The request body has been saved to $global:helpme
Windows PowerShell concatenate and escape multi-line string
$x = @"
"Curiouser and curiouser!" cried Alice (she was so much surprised, that for the moment she quite forgot how to speak good English); "now I'm opening out like the largest telescope that ever was! Good-bye, feet!"
"@
$x
Source: Windows PowerShell Tip: Using Windows PowerShell “Here-Strings”
Report tools for NUnit xml test report file
I have recently been doing custom Powershell script steps for Octopus deploy to trigger Selenium based UI tests and needed a good way to present the test outcome.
This command line tool creates a nice html dashboard page of the xml:
ReportUnit
https://github.com/reportunit/reportunit
Support for both NUnit 2.x, 3.x and MSTest
Interesting alternatives:
NUnit HTML Report Generator
https://github.com/SongArc/NUnit-HTML-Report-Generator/blob/master/README.md
NUnit Test Results Viewer
‘NUnit Test Results Viewer’ is a free open source project that allows to view NUnit resulted *xml file.
https://sourceforge.net/projects/nunittrviewer/
If tests are triggered from TeamCity or VSTS (Visual Studio Team Services) they have test report tools built-in.
Generate C# API Documentation with Wyam – CodeOpinion
Setting up your project and TeamCity/OctoPack to include certain files in deploy package.
From: Setting up your project and TeamCity/OctoPack for front-end builds
Octopus Deploy has a nice NuGet package, called OctoPack, for generating Octopus Deploy-compatible NuGet packages out of .NET projects.
However, OctoPack will only pack files that are included in the CSPROJ file, and in the case of static files, have Build Action set to Content. This is a problem, because this means that all files generated by your task runners, be it Gulp or Grunt, will have to be included in the project and pushed out to source control.
This introduces an unnecessary problem – conflicts in generated code. So, if developer A was working on a SCSS file which was referenced in the main stylesheet, and developer B was working on a separate SCSS file, also referenced in the same main stylesheet, why should either one have to resolve a conflict caused in the file generated by the task runner?
This makes no sense. It’s like building your .NET project, and pushing the generated DLL files to source control, and then having to resolve conflicts within the DLL files generated by the build. Why would you do that?
So, in order for you to never have to resolve another conflict in generated files again, here’s my guide on how to set up your project so they play nice with TeamCity and OctoPack.
Create a NUSPEC file for your project, and include the folders that are not currently included in the project.
What this does is it informs OctoPack about the files that you want to include in the deployment package. Here’s an example.
<?xml version="1.0"?> <package > <metadata> <id>MyProject.Web</id> <version>$version$</version> <authors>Geta AS</authors> <owners>Geta AS</owners> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>MyProject.Web deployment package</description> <copyright>Copyright 2016</copyright> </metadata> <files> <file src="public\**\*.*" target="public" /> </files> </package>
As you can probably already tell, this will cause OctoPack to only include files stored in the specified folder in the generated deployment package. That’s no good.
On to the next step.
Update the project CSPROJ file to include all other files.
<?xml version="1.0" encoding="utf-8"?> ... <PropertyGroup> <OctoPackEnforceAddingFiles>True</OctoPackEnforceAddingFiles> </PropertyGroup> ...
This tells OctoPack to include all the files it would normally include in addition to the files specified in the NUSPEC file.
Once we have all this set up, we can commit the files, and push them to source control.
Source: Setting up your project and TeamCity/OctoPack for front-end builds
Basic Git Command Line Reference for Windows Users – CodeProject
.net – NUnit 3.2.1 + TeamCity: Could not load file or assembly ‘nunit.framework’ – Stack Overflow
21 down vote I had the same problem with TeamCity 10.0.1 (build 42078) and NUnit 3.4.1. And it turned out to be completely my fault. I’m posting it here as someone else can stumble into the same problem and this can save them some time. It turned out that the problem was in the “Run tests from: ” setting in my build configuration. I had **\*.Test.dll. That was accidentally picking up dlls for \obj\**\ directories (where there is no nunit.framework.dll present). Once I changed the setting to **\bin\%Bui
Source: .net – NUnit 3.2.1 + TeamCity: Could not load file or assembly ‘nunit.framework’ – Stack Overflow
NuGetPackageExplorer: Create, update and deploy Nuget Packages with a GUI
choco install nugetpackageexplorer
Source: NuGetPackageExplorer/NuGetPackageExplorer: Create, update and deploy Nuget Packages with a GUI
Cashew: A simple and elegant yet powerful HTTP client cache for .NET
A simple and elegant yet powerful HTTP client cache for .NET
Cashew
Cashew is a .NET library for caching responses easily with an HttpClient through an API that is simple and elegant yet powerful. There’s support out of the box for the awesome CacheManager via the
Cashew.Adapters.CacheManager
package. Its aim is to focus on the HTTP part of caching and not worrying about how stuff is stored, meaning no half-arsed cache implementations!Cashew targets .NET 4.5 and .NET Standard 1.1 (.NET Core, Mono, Xamarin.iOS, Xamarin.Android, UWP and more) meaning it can be used on all sorts of devices.
Source: joakimskoog/Cashew: A simple and elegant yet powerful HTTP client cache for .NET