public void AddSingleFile() { dc.AddFile("test.txt", "Hello World!"); Assert.True(File.Exists(Path.Combine(dc.DirectoryName, "test.txt"))); Assert.Equal("Hello World!", File.ReadAllText(Path.Combine(dc.DirectoryName, "test.txt"))); }
public TestReloadWorks() { dc = new DirectoryCreator(); dc.AddFile( "endpoint1\\endpoint.json", JsonConvert.SerializeObject(DataUtils.CreateSimpleEndpoint("foobar", "myfile.txt")) ); dc.AddFile("endpoint1\\myfile.txt", "Hello world"); ecp = new EndpointCollectionProvider(dc.DirectoryName); CreateServerAndClient(); }
public async Task CanUseParamForFilename() { dc.AddFile("file.txt", "CONTENTS0"); dc.AddFile("otherfile.txt", "CONTENTS1"); var responseCreator = new FileResponse("$filename", endpoint); Assert.Equal(Path.Combine(endpoint.Directory, "file.txt"), responseCreator.Filename); Assert.Equal("CONTENTS0", (await GetResponseAsync(responseCreator)).WrittenContent); filenameParam.Value = "otherfile.txt"; Assert.Equal(Path.Combine(endpoint.Directory, "otherfile.txt"), responseCreator.Filename); Assert.Equal("CONTENTS1", (await GetResponseAsync(responseCreator)).WrittenContent); }
public TestTestCommand() { dc = new DirectoryCreator(); dc.AddFile("endpoint1\\endpoint.json", TESTCOMMAND_CONSTANTS.ENDPOINTJSON); dc.AddFile("endpoint1\\myscript.csscript", "return \"Hello world\";"); dc.AddFile("endpoint1\\content.txt", "FOOBARBOOBAR"); dc.AddFile("tests\\tests.json", TESTCOMMAND_CONSTANTS.TESTS); dc.AddFile("tests\\example.txt", "FOOBARBOOBAR"); dc.AddFile("tests\\response.txt", "Hello world"); dc.AddFile("tests\\now.txt", "2015-01-01 12:01:31"); dc.AddFile("getnow\\endpoint.json", "{'name': 'GetNow', 'pathregex': '/getnow/', 'responses': [{'match': {}, 'script':'getnow.csscript'}]}"); dc.AddFile("getnow\\getnow.csscript", "GetNow().ToString(\"yyyy-MM-dd HH:mm:ss\")"); }
public async Task NewEndpointIsAvailableAfterReload() { Assert.Equal(new[] { "foobar" }, await GetEndpointNames()); dc.AddFile( "endpoint2\\endpoint.json", JsonConvert.SerializeObject(DataUtils.CreateSimpleEndpoint("baz", "myfile.txt")) ); dc.AddFile("endpoint2\\myfile.txt", "Hello world"); Assert.Equal(new[] { "foobar" }, await GetEndpointNames()); var response = await client.GetAsync("/__netmockery/endpoints/reloadconfig"); Assert.Equal(System.Net.HttpStatusCode.Redirect, response.StatusCode); Assert.Equal(new[] { "foobar", "baz" }, await GetEndpointNames()); }
private void InitializeEndpointCollectionWithoutDefaults() { var jsonEndpoint1 = new JSONEndpoint { name = "foobar", pathregex = "foobar", responses = new[] { new JSONResponse { match = new JSONRequestMatcher(), file = "myfile.xml" } } }; directoryCreator.AddFile("endpoint1/endpoint.json", JsonConvert.SerializeObject(jsonEndpoint1)); endpointCollection = EndpointCollectionReader.ReadFromDirectory(directoryCreator.DirectoryName); }
public TestResponseHasCorrectEncoding() { dc = new DirectoryCreator(); dc.AddFile("endpoint1\\endpoint.json", JsonConvert.SerializeObject(DataUtils.CreateSimpleEndpoint("endpoint1", "myfile.txt", "/endpoint1"))); dc.AddFile("endpoint1\\myfile.txt", "æøå"); var endpoint2 = DataUtils.CreateSimpleEndpoint("endpoint2", "myfile.txt", "/endpoint2"); endpoint2.responses[0].charset = "latin1"; dc.AddFile("endpoint2\\endpoint.json", JsonConvert.SerializeObject(endpoint2)); dc.AddFile("endpoint2\\myfile.txt", "æøå"); var tests = new List <JSONTest>(new[] { new JSONTest { name = "Test endpoint1", requestpath = "/endpoint1", expectedresponsebody = "æøå" } }); dc.AddFile("tests\\tests.json", JsonConvert.SerializeObject(tests)); ecp = new EndpointCollectionProvider(dc.DirectoryName); CreateServerAndClient(); }
private EndpointCollection CreateEndpointWithScript() { dc.AddFile("endpoint/endpoint.json", JsonConvert.SerializeObject(DataUtils.CreateScriptEndpoint("endpoint", "script.csscript"))); dc.AddFile("endpoint/script.csscript", "return GetParam(\"greeting\") + \" \" + GetParam(\"subject\");"); dc.AddFile("endpoint/params.json", JsonConvert.SerializeObject(new[] { new JSONParam { name = "greeting", @default = "Hello", description = "foo" }, new JSONParam { name = "subject", @default = "World", description = "foo" }, })); return(EndpointCollectionReader.ReadFromDirectory(dc.DirectoryName)); }
public TestLoadScriptRelativePath() { dc.AddFile("a\\main.csscript", "#load \"..\\b\\lib.csscript\"\nreturn f;"); dc.AddFile("b\\lib.csscript", "var f = \"foo\";"); }
public TestCheckScriptModifications() { dc = new DirectoryCreator(); dc.AddFile("abc.txt", "abc"); }
public TestInitializeEndpointsWithNonEndpointDirectory() { dc.AddFile("endpoint1/endpoint.json", "{'name': 'Endpoint1', pathregex: '^/ep1/', responses: []}"); dc.AddFile("kith/file.txt", "Ignore me!"); }
public TestInitializeEndpointsFromDirectoryStructure() { dc.AddFile("endpoint1/endpoint.json", "{'name': 'Endpoint1', pathregex: '^/ep1/', responses: []}"); dc.AddFile("endpoint2/endpoint.json", TestInitFromJSON.ENDPOINTJSON); }
public TestLoadScript() { dc.AddFile("a/main.csscript", "#load \"../b/lib.csscript\"\nreturn f;"); dc.AddFile("b/lib.csscript", "var f = \"foo\";"); }
public void WorksIfEndpointNamedTest() { dc.AddFile("tests\\endpoint.json", TESTCOMMAND_CONSTANTS.ENDPOINTJSON); Assert.False(TestRunner.HasTestSuite(dc.DirectoryName)); }
public TestTestCommandWithoutTestsuite() { dc = new DirectoryCreator(); dc.AddFile("endpoint1\\endpoint.json", TESTCOMMAND_CONSTANTS.ENDPOINTJSON); }