-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57401a1
commit d1d49b0
Showing
5 changed files
with
89 additions
and
9 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using RichardSzalay.MockHttp; | ||
using Newtonsoft.Json; | ||
|
||
namespace ButterCMS.Tests | ||
{ | ||
public class ButterCMSClientWithMockedHttp : ButterCMSClient | ||
{ | ||
public static string MockedApiKey = "test-key"; | ||
|
||
public readonly MockHttpMessageHandler mockHttpMessageHandler; | ||
|
||
public ButterCMSClientWithMockedHttp(MockHttpMessageHandler mockHttpMessageHandler) : base(MockedApiKey, httpMessageHandler: mockHttpMessageHandler) | ||
{ | ||
this.mockHttpMessageHandler = mockHttpMessageHandler; | ||
} | ||
|
||
public void MockSuccessfullJSONResponse<T>(string url, T reponse) { | ||
mockHttpMessageHandler | ||
.When(url) | ||
.Respond("application/json", JsonConvert.SerializeObject(reponse)); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using ButterCMS.Tests.Models; | ||
using ButterCMS.Models; | ||
|
||
namespace ButterCMS.Tests | ||
{ | ||
public static class PagesMocks | ||
{ | ||
public static things Fields = new things() { thing1 = "Bike", thing2 = "MTB" }; | ||
|
||
public static Page<things> Page = new Page<things>() | ||
{ | ||
Name = "Bike page", | ||
Slug = "bikes", | ||
Updated = new System.DateTime(), | ||
PageType = "BikeList", | ||
Fields = Fields | ||
}; | ||
|
||
public static PagesResponse<things> PagesResponse = new PagesResponse<things>() | ||
{ | ||
Data = new[] { Page }, | ||
Meta = new PageMeta() | ||
{ | ||
Count = 1, | ||
NextPage = null, | ||
PreviousPage = null | ||
} | ||
}; | ||
|
||
public static void MockSuccessfullPagesResponse(this ButterCMSClientWithMockedHttp butterClient) | ||
{ | ||
butterClient.MockSuccessfullJSONResponse($"https://api.buttercms.com/v2/pages/things/?auth_token={ButterCMSClientWithMockedHttp.MockedApiKey}", PagesResponse); | ||
} | ||
} | ||
} |