public async Task CreateWithScript_RequiresScriptSet() { var mockHttp = new MockHttpMessageHandler(); mockHttp.When(HttpMethod.Post, $"{server}/fmi/data/v1/databases/{file}/layouts/{layout}/records*") .WithPartialContent("fieldData") .WithPartialContent("script") // ensure the body contains the script parameter we're sending .WithPartialContent("run_this_script") .Respond("application/json", DataApiResponses.SuccessfulCreate()); IFileMakerApiClient fdc = GetDataClientWithMockedHandler(mockHttp); var req = new CreateRequest <User>() { Layout = "layout", Data = new User { Name = "test name" }, Script = "run_this_script" }; var response = await fdc.SendAsync(req); Assert.NotNull(response); Assert.Contains(response.Messages, r => r.Message == "OK"); }
private static IFileMakerApiClient GetDataClientWithMockedHandler(MockHttpMessageHandler mockHttp = null) { if (mockHttp == null) { // new up a default set of responses (none were provided) mockHttp = new MockHttpMessageHandler(); mockHttp.When(HttpMethod.Post, $"{server}/fmi/data/v1/databases/{file}/layouts/{layout}/records*") .WithPartialContent("fieldData") // make sure that the body content contains the 'data' object expected by fms .Respond("application/json", DataApiResponses.SuccessfulCreate()); mockHttp.When(HttpMethod.Post, $"{server}/fmi/data/v1/databases/{file}/layouts/Somelayout/records*") .WithPartialContent("fieldData") // make sure that the body content contains the 'data' object expected by fms .Respond("application/json", DataApiResponses.SuccessfulCreate()); } // always add the authentication setup mockHttp.When($"{server}/fmi/data/v1/databases/{file}/sessions") .Respond("application/json", DataApiResponses.SuccessfulAuthentication()); var fdc = new FileMakerRestClient(mockHttp.ToHttpClient(), new ConnectionInfo { FmsUri = server, Database = file, Username = user, Password = pass }); return(fdc); }
public async Task CreateWithTableAttribute_ShouldReturnOK() { var mockHttp = new MockHttpMessageHandler(); // since we know 'ModelWithLayout' uses 'Somelayout' as its layout we need to ensure a response for that endpoint mockHttp.When(HttpMethod.Post, $"{s_server}/fmi/data/v1/databases/{s_file}/layouts/Somelayout/records*") .WithPartialContent("fieldData") // make sure that the body content contains the 'data' object expected by fms .Respond("application/json", DataApiResponses.SuccessfulCreate()); var fdc = GetDataClientWithMockedHandler(mockHttp); var newModel = new ModelWithLayout() { Name = "Fuzzzerd", AnotherField = "Different Value" }; var response = await fdc.CreateAsync(newModel); Assert.NotNull(response); Assert.Contains(response.Messages, r => r.Message == "OK"); }