public static async Task <TaskSessionsInfo> ExecuteTask(MazeTask mazeTask, ITaskComponentResolver componentResolver, IXmlSerializerCache xmlCache, IRestClient restClient) { using (var taskMemoryStream = new MemoryStream()) { var taskWriter = new MazeTaskWriter(taskMemoryStream, componentResolver, xmlCache); taskWriter.Write(mazeTask, TaskDetails.Client); taskMemoryStream.Position = 0; var stream = new StreamContent(taskMemoryStream); stream.Headers.ContentEncoding.Add("xml"); return(await CreateRequest(HttpVerb.Post, "execute", stream).Execute(restClient).Return <TaskSessionsInfo>()); } }
public static async Task Update(MazeTask mazeTask, ITaskComponentResolver componentResolver, IXmlSerializerCache xmlCache, IRestClient restClient) { using (var taskMemoryStream = new MemoryStream()) { var taskWriter = new MazeTaskWriter(taskMemoryStream, componentResolver, xmlCache); taskWriter.Write(mazeTask, TaskDetails.Server); taskMemoryStream.Position = 0; var stream = new StreamContent(taskMemoryStream); stream.Headers.ContentEncoding.Add("xml"); await CreateRequest(HttpVerb.Put, mazeTask.Id, stream).Execute(restClient); } }
private static void CompareWriteTask(MazeTask mazeTask, TaskDetails details, string expected) { var mock = new Mock <ITaskComponentResolver>(); mock.Setup(x => x.ResolveName(It.IsAny <Type>())).Returns <Type>(GetName); using (var memoryStream = new MemoryStream()) { var xmlWriter = XmlWriter.Create(memoryStream, new XmlWriterSettings { OmitXmlDeclaration = false, Indent = true, IndentChars = " ", Encoding = new UTF8Encoding(false) }); var writer = new MazeTaskWriter(xmlWriter, mock.Object, new XmlSerializerCache()); writer.Write(mazeTask, details); var result = Encoding.UTF8.GetString(memoryStream.ToArray()); Assert.Equal(expected, result); } }