Skip to content

Instantly share code, notes, and snippets.

@moodmosaic
Last active December 18, 2015 20:29
Show Gist options
  • Save moodmosaic/5840800 to your computer and use it in GitHub Desktop.
Save moodmosaic/5840800 to your computer and use it in GitHub Desktop.
Node.js sample adapter-module for AutoFixture via Edge.js
var create = require('edge').func(function () {/*
//#r "Ploeh.AutoFixture.dll"
using System;
using Ploeh.AutoFixture;
public class Startup
{
public async System.Threading.Tasks.Task<object> Invoke(object request)
{
var fixture = new Fixture();
var specimen = request.ToString();
if(specimen == "string")
return fixture.Create<string>();
if(specimen == "number")
return fixture.Create<double>();
if(specimen == "url")
return fixture.Create<Uri>().ToString();
if(specimen == "date")
return new TimeSpan(fixture.Create<DateTime>()
.ToUniversalTime().Ticks - new DateTime(1970, 1, 1).Ticks)
.TotalMilliseconds;
throw new ArgumentException(
"The request is not valid. It should be either a 'string' or a 'number'.");
}
}
*/});
var fixture = (function () {
function createSpecimen(type) {
var specimen;
create(type, function (error, result) {
if (error) {
throw error;
}
specimen = result;
});
return specimen;
}
function createString() {
return createSpecimen('string');
}
function createNumber() {
return createSpecimen('number');
}
function createDate() {
return new Date(createSpecimen('date'));
}
function createUrl() {
return createSpecimen('url');
}
return {
createString: createString,
createNumber: createNumber,
createDate: createDate,
createUrl: createUrl
};
})();
module.exports = fixture;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment