Last active
December 18, 2015 20:29
-
-
Save moodmosaic/5840800 to your computer and use it in GitHub Desktop.
Node.js sample adapter-module for AutoFixture via Edge.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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