Skip to content

Instantly share code, notes, and snippets.

View mauricedb's full-sized avatar

Maurice de Beijer mauricedb

View GitHub Profile
@mauricedb
mauricedb / gist:11350476
Created April 27, 2014 17:04
Validating data using ClearScript/V8 and JavaScript in the WebAPI
using (var engine = new V8ScriptEngine())
{
var settings = GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings;
var jsonBook = JsonConvert.SerializeObject(newBook, settings);
engine.Execute("var book = " + jsonBook);
var path = HttpContext.Current.Server.MapPath(@"~\App\ValidateBook.js");
engine.Execute(File.ReadAllText(path));
var result = engine.Evaluate("validateBook(book)") as string;
@mauricedb
mauricedb / Script1.js
Last active August 29, 2015 14:02
X things every JavaScript developer should know: scoping - Wrong
var text = "Hello from script 1";
setTimeout(function () {
console.log(text);
}, 1000);
@mauricedb
mauricedb / Script1.js
Last active August 29, 2015 14:02
X things every JavaScript developer should know: scoping - Right
(function() {
var text = "Hello from script 1";
setTimeout(function () {
console.log(text);
}, 1000);
}());
@mauricedb
mauricedb / CodedUIWithPageObjectModel.cs
Created May 6, 2015 19:58
CodedUIWithPageObjectModel
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace CodedUITestProject1
{
[CodedUITest]
public class CodedUIWithPageObjectModel
{
public class HomeController : Controller
{
private readonly IRuntimeEnvironment _runtimeEnvironment;
public HomeController(IRuntimeEnvironment runtimeEnvironment)
{
_runtimeEnvironment = runtimeEnvironment;
}
public IActionResult About()
@{
ViewData["Title"] = "About";
}
<h2>@ViewData["Title"].</h2>
<h3>@ViewData["Message"]</h3>
<h4>OperatingSystem: @ViewData["OperatingSystem"]</h4>
<h4>OperatingSystemVersion: @ViewData["OperatingSystemVersion"]</h4>
<h4>RuntimeType: @ViewData["RuntimeType"]</h4>
<h4>RuntimeArchitecture: @ViewData["RuntimeArchitecture"]</h4>
FROM microsoft/aspnet:1.0.0-beta8-coreclr
COPY./src/WebApplication3./app
WORKDIR./app
RUN dnu restore
ENTRYPOINT dnx web --server.urls http://*:80
@mauricedb
mauricedb / gist:5280482
Last active December 15, 2015 15:19
AngularJS controller using TypeScript
/// <reference path="../Scripts/typings/angularjs/angular.d.ts" />
module App {
export class TestCtrl {
private startTime: string;
constructor(private $scope: ITestCtrlScope) {
this.startTime = new Date().toLocaleString();
$scope.message = "Hello there at " + this.startTime;
@mauricedb
mauricedb / gist:5290642
Last active December 15, 2015 16:39
Unit testing a WebAPI controller using the HttpClient and server config
[TestMethod]
public void PutViaServer()
{
// Arrange
var config = new HttpConfiguration();
WebApiConfig.Register(config);
var server = new HttpServer(config);
var client = new HttpClient(server);
var book = new Book();
@mauricedb
mauricedb / gist:5562976
Created May 12, 2013 09:30
Unit test an ASP.NET ApiController that uses the ApiController.Request property
[TestMethod]
public void GetWithAnUnknownIdShouldReturnNotFound()
{
// Arrange
var controller = new BooksController()
{
Request = new HttpRequestMessage()
{
Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } }
}