Skip to content

Commit

Permalink
Added unit test for process container data.
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzzerd committed Sep 5, 2018
1 parent dad2e9a commit af90a73
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/FMData.Rest.Tests/FindRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,42 @@ public async Task GetByRecordId_ShouldReturnMatchingRecordId()
Assert.Equal(recordId, response.FileMakerRecordId);
}

[Fact]
public async Task GetByRecordId_ShouldHaveContainerWithContainerDataFor()
{
// arrange
object FMrecordIdMapper(ContainerFieldTestModel o, int id) => o.FileMakerRecordId = id;
var mockHttp = new MockHttpMessageHandler();

var server = "http://localhost";
var file = "test-file";
var user = "unit";
var pass = "test";
var layout = "Users";
var recordId = 26;

mockHttp.When(HttpMethod.Post, $"{server}/fmi/data/v1/databases/{file}/sessions")
.Respond("application/json", DataApiResponses.SuccessfulAuthentication());

var b64String = System.IO.File.ReadAllText("ResponseData\\b64-string.dat");
var bytes = Convert.FromBase64String(b64String);
var b64= new ByteArrayContent(bytes);

mockHttp.When(HttpMethod.Get, $"{server}/some-data-path")
.Respond(b64);

mockHttp.When(HttpMethod.Get, $"{server}/fmi/data/v1/databases/{file}/layouts/{layout}/records/{recordId}")
.Respond("application/json", DataApiResponses.SuccessfulGetByIdWithContainer(recordId, $"{server}/some-data-path"));

var fdc = new FileMakerRestClient(mockHttp.ToHttpClient(), server, file, user, pass);

// act
var response = await fdc.GetByFileMakerIdAsync<ContainerFieldTestModel>(recordId, FMrecordIdMapper);

// assert
Assert.Equal(bytes, response.SomeContainerFieldData);
}


[Fact]
public async Task SendAsync_Dictionary_WithPortals_ShouldHaveData()
Expand Down
21 changes: 21 additions & 0 deletions tests/FMData.Rest.Tests/ResponseData/Responses.Record.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,27 @@ public static string SuccessfulGetById(int id) => $@"{{
""messages"":[{{""code"":""0"",""message"":""OK""}}]
}}";

public static string SuccessfulGetByIdWithContainer(int id, string containerPath) => $@"{{
""response"": {{
""data"": [
{{
""fieldData"": {{
""Id"": ""4"",
""Name"": ""fuzzzerd"",
""Created"": ""03/29/2018 15:22:09"",
""Modified"": ""03/29/2018 15:22:12"",
""SomeContainerField"": ""{containerPath}""
}},
""portalData"": {{}},
""recordId"": ""{id}"",
""modId"": ""0""
}}
]
}},
""messages"":[{{""code"":""0"",""message"":""OK""}}]
}}";


public static string LayoutNotFound() => @"{
""response"": {},
""messages"":[{""code"":""105"",""message"":""Layout is missing""}]
Expand Down

0 comments on commit af90a73

Please sign in to comment.