Skip to content

Commit a2ee819

Browse files
committed
updated was tested too
1 parent 3b5426b commit a2ee819

3 files changed

Lines changed: 39 additions & 4 deletions

File tree

Wissance.WebApiToolkit/Wissance.WebApiToolkit.TestApp/Factories/ProfileFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public static ProfileEntity Create(ProfileDto dto, ModelContext dbContext)
3535
public static void Update(ProfileDto dto, int id, ModelContext dbContext, ProfileEntity entity)
3636
{
3737
entity.Name = dto.Name;
38-
entity.Address = entity.Address;
39-
entity.Bio = entity.Bio;
40-
entity.Photo = entity.Photo;
38+
entity.Address = dto.Address;
39+
entity.Bio = dto.Bio;
40+
entity.Photo = dto.Photo;
4141
}
4242
}
4343
}

Wissance.WebApiToolkit/Wissance.WebApiToolkit.Tests/Controllers/TestConfiguredController.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,23 @@ public async Task TestCreateSuccessfullyAsync()
4242
[Fact]
4343
public async Task TestUpdateSuccessfullyAsync()
4444
{
45-
45+
using (HttpClient client = Application.CreateClient())
46+
{
47+
ProfileDto creatingProfile = new ProfileDto()
48+
{
49+
Address = "asylum on Syberian trakt 7 km",
50+
Bio = "Psycho",
51+
Name = "wtf",
52+
Photo = "axaxaxaxaxaxaxaxaxaxaxa"
53+
};
54+
OperationResultDto<ProfileDto> result = await TestBasicHttpInteraction.ExecCreateAndCheckAsync(client, "api/Profile", creatingProfile, HttpStatusCode.Created);
55+
Assert.NotNull(result);
56+
57+
ProfileDto createdProfile = result.Data;
58+
createdProfile.Photo = "look at me i am so handsome";
59+
result = await TestBasicHttpInteraction.ExecUpdateAndCheckAsync(client, $"api/Profile/{createdProfile.Id}", createdProfile, HttpStatusCode.OK);
60+
Assert.NotNull(result);
61+
}
4662
}
4763

4864
[Theory]

Wissance.WebApiToolkit/Wissance.WebApiToolkit.Tests/Utils/Operations/TestBasicHttpInteraction.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,24 @@ public static async Task<OperationResultDto<T>> ExecCreateAndCheckAsync<T>(HttpC
4747
return null;
4848
}
4949

50+
public static async Task<OperationResultDto<T>> ExecUpdateAndCheckAsync<T>(HttpClient client, string url, T dto,
51+
HttpStatusCode expectedStatusCode) where T : class
52+
{
53+
JsonContent content = JsonContent.Create(dto);
54+
HttpResponseMessage resp = await client.PutAsync(url, content);
55+
Assert.Equal(expectedStatusCode, resp.StatusCode);
56+
string createdDataStr = await resp.Content.ReadAsStringAsync();
57+
Assert.True(createdDataStr.Length > 0);
58+
if (expectedStatusCode == HttpStatusCode.OK)
59+
{
60+
OperationResultDto<T> result = JsonConvert.DeserializeObject<OperationResultDto<T>>(createdDataStr);
61+
Assert.NotNull(result);
62+
Assert.True(result.Success);
63+
return result;
64+
}
65+
66+
return null;
67+
}
68+
5069
}
5170
}

0 commit comments

Comments
 (0)