public IHttpWebRequestAdapter Create(HttpRequest httpRequest, Uri uri, Version version) { var fullUri = string.Format("{0}{1}/{2}", uri, httpRequest.ResourceVersion, httpRequest.ResourcePath); uri = new Uri(fullUri); IHttpWebRequestAdapter httpWebRequest = new HttpWebRequestAdapter(uri); httpWebRequest.Method = httpRequest.HttpMethod.ToString(); httpWebRequest.UserAgent = string.Format("Esendex .NET SDK v{0}.{1}.{2}", version.Major, version.Minor, version.Build); return httpWebRequest; }
public void AddCredentials_WithHttpWebRequestAdapterAndBasicEsendexCredentials() { // Arrange EsendexCredentials credentials = new EsendexCredentials("username", "password"); IHttpWebRequestAdapter httpRequest = new HttpWebRequestAdapter(uri); // Act helper.AddCredentials(httpRequest, credentials); // Assert string username = httpRequest.Credentials.GetCredential(uri, "Basic").UserName; string password = httpRequest.Credentials.GetCredential(uri, "Basic").Password; Assert.AreEqual(credentials.Username, username); Assert.AreEqual(credentials.Password, password); }
public void AddCredentials_WithHttpWebRequestAdapterAndSessionEsendexCredentials() { // Arrange var sessionId = Guid.NewGuid(); var expectedHeaderValue = string.Format("Basic {0}", Convert.ToBase64String(new UTF8Encoding().GetBytes(sessionId.ToString()))); var credentials = new EsendexCredentials(sessionId); IHttpWebRequestAdapter httpRequest = new HttpWebRequestAdapter(_uri); // Act _helper.AddCredentials(httpRequest, credentials); // Assert var actualHeaderValue = httpRequest.Headers.Get("Authorization"); Assert.AreEqual(expectedHeaderValue, actualHeaderValue); }
public IHttpWebRequestAdapter Create(HttpRequest httpRequest, Uri uri) { Assembly assembly = Assembly.GetAssembly(typeof(IHttpRequestHelper)); Version version = assembly.GetName().Version; string fullUri = string.Format("{0}v{1}.{2}/{3}", uri, version.Major, version.Minor, httpRequest.ResourcePath); uri = new Uri(fullUri); IHttpWebRequestAdapter httpWebRequest = new HttpWebRequestAdapter(uri); httpWebRequest.Method = httpRequest.HttpMethod.ToString(); FileVersionInfo info = FileVersionInfo.GetVersionInfo(assembly.Location); httpWebRequest.UserAgent = string.Format("Esendex .NET SDK v{0}.{1}", info.FileMajorPart, info.FileMinorPart); return httpWebRequest; }
public void AddProxy_WithHttpWebRequestAdapterAndProxy() { // Arrange IHttpWebRequestAdapter httpRequest = new HttpWebRequestAdapter(uri); WebProxy proxy = new WebProxy(); // Act helper.AddProxy(httpRequest, proxy); // Assert Assert.AreEqual(proxy, httpRequest.Proxy); }