Skip to content

Instantly share code, notes, and snippets.

@quexy
quexy / VerifyJsonContent.cs
Created June 19, 2017 11:11
WepAPI SpecFlow: checks if input string as JSON of given type matches input table
///<summary> Checks whether the JSON <paramref name="content"/> as <paramref name="resultType"/> contains the entities described in the given <paramref name="table"/> </summary>
private static string[] VerifyJsonContent(string content, string resultType, Table table)
{
var matchingTypes = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetExportedTypes())
.Where(t => (t.Namespace + "." + t.Name).EndsWith(resultType)).ToArray();
if (matchingTypes.Length != 1) return new[] { string.Format("Cannot determine matching type by the name {0}; candidates: [{1}]",
resultType, string.Join(", ", matchingTypes.Select(t => t.Namespace + "." + t.Name))) };
object message = null;
@quexy
quexy / MultipartFormDataMediaTypeFormatter.cs
Created June 19, 2017 11:16
WebAPI 'multipart/form-data' input formatter
using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Net.Http.Headers;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
namespace WebApi.Formatters