Skip to content

Instantly share code, notes, and snippets.

View darrelmiller's full-sized avatar

Darrel darrelmiller

View GitHub Profile
using System;
using System.Net.Http;
using System.Threading.Tasks;
namespace SimpleHttpClient
{
class Program
{
private static Uri url = new Uri("http://bing.com/");
public class StringExtensionsSpecifications
{
[Scenario]
[Example("Given", StepType.Given)]
[Example("When", StepType.When)]
[Example("Then", StepType.Then)]
[Example("But", StepType.But)]
[Example("And", StepType.And)]
public void GetStepType(string clause, StepType expected, StepType actual)
{
[Scenario]
public void RetrievingIssues(IEnumerable<Issue> issues, Mock<IIssueStore> issueStore )
{
var mockIssueStore = new Mock<IIssueStore>();
var fakeIssues = GetFakeIssues();
var controller = new IssueController(mockIssueStore.Object);
"Given existing issues".
f(() => mockIssueStore.Setup(i => i.FindAsync()).Returns(Task.FromResult(fakeIssues)));
"When a GET request is made for all issues".
var client = new HttpClient();
var runscopeLink = new RunScopeLink() {
Target = new Uri("https://api.github.com"),
BucketKey = "bucket_key"
};
var response = client.SendAsync(runscopeLink.CreateRequest()).Response;
var runscopeHandler = new RunscopeMessageHandler("bucketKey", new HttpClientHandler());
var httpClient = new HttpClient(runscopeHandler);
var response = await httpClient.GetAsync("https://api.github.com");
// Ask the server for a password challenge string
var requestId = CryptographicBuffer.EncodeToHexString(CryptographicBuffer.GenerateRandom(4));
var challengeResponse = await _httpClient.GetAsync(_clientBaseUrl + "GetPasswordChallenge?requestId=" + requestId);
challengeResponse.EnsureSuccessStatusCode();
var challengeEncoded = await challengeResponse.Content.ReadAsAsync<string>();
var challengeBuffer = CryptographicBuffer.DecodeFromHexString(challengeEncoded);
// Use HMAC_SHA512 hash to encode the challenge string using the password being authenticated as the key.
var provider = MacAlgorithmProvider.OpenAlgorithm(MacAlgorithmNames.HmacSha512);
@darrelmiller
darrelmiller / gist:6213002
Created August 12, 2013 17:18
ApiRouter side by side with standard route.
config.Routes.MapHttpRoute(
name: "TreeApi",
routeTemplate: "tree/{*path}",
defaults: null,
constraints: null,
handler: new ApiRouter("", new Uri("http://localhost:64921/tree")).To<FooController>());
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
<FORM method="POST" action="http://example.com/whatever-I-dont-care">
<INPUT type="text" name="value1" value="default1"/>
<INPUT type="text" name="value2" value="default2"/>
<FORM>
<LINK rel="http://tavis.ca/rels/form" method="POST" href="http://example.com/whatever-I-dont-care">
<INPUT type="text" name="value1" value="default1"/>
<INPUT type="text" name="value2" value="default2"/>
<LINK>
public class CollectionJsonContent : HttpContent
{
private readonly MemoryStream _memoryStream = new MemoryStream();
public CollectionJsonContent(Collection collection)
{
var serializerSettings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
Formatting = Newtonsoft.Json.Formatting.Indented,
ContractResolver = new CamelCasePropertyNamesContractResolver()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Owin;
using Microsoft.Owin;
using Microsoft.Owin.BuilderProperties;
using Microsoft.Owin.Host.HttpListener;