public async Task HttpSendAndReceiveBytesShouldBeAbleToReturnBinary() { var testFileUriPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase), "TestFiles\\frends_favicon.png"); string localTestFilePath = new Uri(testFileUriPath).LocalPath; var requestBody = "some request data"; var requestBytes = Encoding.UTF8.GetBytes(requestBody); var input = new ByteInput { Method = SendMethod.POST, Url = "http://localhost:9191/endpoint", Headers = new[] { new Header { Name = "Content-Type", Value = "text/plain; charset=utf-8" }, new Header { Name ="Content-Length", Value = requestBytes.Length.ToString() } }, ContentBytes = Encoding.UTF8.GetBytes("some request data") }; var options = new Options { ConnectionTimeoutSeconds = 60 }; var actualFileBytes = File.ReadAllBytes(localTestFilePath); _mockHttpMessageHandler.When(input.Url) .Respond("image/png", new MemoryStream(actualFileBytes)); var result = (HttpByteResponse)await Web.HttpSendAndReceiveBytes(input, options, CancellationToken.None); Assert.NotEmpty(result.BodyBytes); Assert.Equal(actualFileBytes, result.BodyBytes); }
public async Task SendBytesShouldPassExactBytes() { var expectedString = "Tהה on se odotettu stringi!צײצצִ"; var bytes = Encoding.UTF8.GetBytes(expectedString); var input = new ByteInput { Method = SendMethod.POST, Url = "http://localhost:9191/data", Headers = new[] { new Header { Name = "Content-Type", Value = "text/plain; charset=utf-8" }, new Header() { Name = "Content-Length", Value = bytes.Length.ToString() } }, ContentBytes = bytes }; var options = new Options { ConnectionTimeoutSeconds = 60, Authentication = Authentication.OAuth, Token = "fooToken" }; _mockHttpMessageHandler.Expect(HttpMethod.Post, input.Url).WithHeaders("Content-Type", "text/plain; charset=utf-8").WithContent(expectedString) .Respond("text/plain", "foo והצ"); var result = (HttpResponse)await Web.HttpSendBytes(input, options, CancellationToken.None); _mockHttpMessageHandler.VerifyNoOutstandingExpectation(); }
public async Task <SimpleResult> UploadTimesheet(ByteInput input) { try { Attachment attachment = new Attachment(new MemoryStream(input.Bytes), input.Filename); ContentDisposition disposition = attachment.ContentDisposition; disposition.CreationDate = DateTime.Now; disposition.ModificationDate = DateTime.Now; disposition.ReadDate = DateTime.Now; disposition.Size = input.Bytes.Length; disposition.DispositionType = DispositionTypeNames.Attachment; var clients = _configuration["clients:plumbery:emails"]; var emails = clients.Split("::"); foreach (var email in emails) { await _emailSender.SendEmailAsync(email, "Timesheet: " + input.Filename.Split('.')[0], input.Message, attachment); } return(new SimpleResult { IsSuccess = true }); } catch (Exception ex) { return(new SimpleResult { IsSuccess = false, ErrorMessage = ex.Message }); } }
public void SetByte(byte i_Key, byte i_Value) { RemoveByte(i_Key); ByteInput byteInput = new ByteInput(i_Key, i_Value); m_Bytes.Add(byteInput); }
public byte GetByte(byte i_Key) { int index = GetByteInputIndex(i_Key); if (index >= 0) { ByteInput byteInput = m_Bytes[index]; return(byteInput.value); } return((byte)0); }
private int GetByteInputIndex(byte i_Key) { for (int index = 0; index < m_Bytes.Count; ++index) { ByteInput byteInput = m_Bytes[index]; if (byteInput.key == i_Key) { return(index); } } return(-1); }
public bool GetByteInput(int i_Index, out ByteInput o_ByteInput) { if (!IsValidByteIndex(i_Index)) { o_ByteInput = new ByteInput(0, 0); return(false); } ByteInput byteInput = m_Bytes[i_Index]; o_ByteInput = new ByteInput(byteInput); return(true); }
public bool HasByte(byte i_Key) { for (int index = 0; index < m_Bytes.Count; ++index) { ByteInput byteInput = m_Bytes[index]; if (byteInput.key == i_Key) { return(true); } } return(false); }
public async Task HttpSendAndReceiveBytesReturnShoulReturnEmpty() { var requestBody = "some request data"; var requestBytes = Encoding.UTF8.GetBytes(requestBody); var input = new ByteInput { Method = SendMethod.POST, Url = "http://localhost:9191/endpoint", Headers = new[] { new Header { Name = "Content-Type", Value = "text/plain; charset=utf-8" }, new Header { Name ="Content-Length", Value = requestBytes.Length.ToString() } }, ContentBytes = Encoding.UTF8.GetBytes("some request data") }; var options = new Options { ConnectionTimeoutSeconds = 60 }; _mockHttpMessageHandler.When(input.Url) .Respond("application/octet-stream", String.Empty); var result = (HttpByteResponse)await Web.HttpSendAndReceiveBytes(input, options, CancellationToken.None); Assert.Equal(0, result.BodySizeInMegaBytes); Assert.Empty(result.BodyBytes); }
public ByteInput(ByteInput i_Original) { m_Key = i_Original.key; m_Value = i_Original.value; }
public async Task <JsonResult> UploadTimesheet([FromBody] ByteInput input) { var result = await _timesheet.UploadTimesheet(input); return(await GenerateResult(result, _userSettings)); }