Adding
This commit is contained in:
+92
@@ -0,0 +1,92 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using Moq;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using LCU.Library.Internal.CoreApiWrapperLib.CoreApiUtilities;
|
||||
using LCU.Library.Internal.CoreApiWrapperLib.Configuration;
|
||||
|
||||
namespace LCU.Api.Internal.CoreApiWrapperTest.CoreApiUtilities
|
||||
{
|
||||
public class CoreRequestTest
|
||||
{
|
||||
private readonly CoreRequest _coreRequest;
|
||||
private readonly Mock<IHttpClientFactory> _mockClientFactory;
|
||||
private readonly Mock<ICoreServiceConnection> _mockCoreServiceConnection;
|
||||
|
||||
public CoreRequestTest()
|
||||
{
|
||||
_mockClientFactory = new Mock<IHttpClientFactory>();
|
||||
_mockCoreServiceConnection = new Mock<ICoreServiceConnection>();
|
||||
var coreConfiguration = new CoreConfiguration()
|
||||
{
|
||||
CoreApiConfiguration = new CoreApiConfiguration()
|
||||
};
|
||||
|
||||
_coreRequest = new CoreRequest(_mockClientFactory.Object,
|
||||
_mockCoreServiceConnection.Object,
|
||||
coreConfiguration);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateHttpRequestMessage_NoBodyOrContent_CorrectUrl()
|
||||
{
|
||||
var testEndPoint = "endpoint/test";
|
||||
|
||||
var coreConfiguration = new CoreConfiguration()
|
||||
{
|
||||
CoreApiConfiguration = new CoreApiConfiguration()
|
||||
{
|
||||
HostUrl = "https://CoreTEST.com",
|
||||
HostPort = "1111",
|
||||
ApiChannelId = "TEST-afjksd9-0sakjf-klsdja-fpsjad"
|
||||
}
|
||||
};
|
||||
|
||||
var coreRequest = new CoreRequest(_mockClientFactory.Object,
|
||||
_mockCoreServiceConnection.Object,
|
||||
coreConfiguration);
|
||||
|
||||
_mockCoreServiceConnection.Setup(x => x.GetAccessToken()).Returns("TESTAafjp07087jfjas0d908qj324");
|
||||
|
||||
var result = coreRequest.CreateHttpRequestMessage(testEndPoint, HttpMethod.Post);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("//CoreTEST.com:1111endpoint/test", result.RequestUri.AbsolutePath);
|
||||
Assert.AreEqual("TESTAafjp07087jfjas0d908qj324", result.Headers.Authorization.Scheme);
|
||||
Assert.IsNull(result.Content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateHttpRequestMessage_BodyIsJson()
|
||||
{
|
||||
var testCompare = new Dictionary<string, string>();
|
||||
testCompare.Add("FirstName", "Test");
|
||||
var jsonTestCompare = JsonConvert.SerializeObject(testCompare);
|
||||
|
||||
var testEndPoint = "endpoint/test";
|
||||
|
||||
var coreConfiguration = new CoreConfiguration()
|
||||
{
|
||||
CoreApiConfiguration = new CoreApiConfiguration()
|
||||
{
|
||||
HostUrl = "https://CoreTEST.com",
|
||||
HostPort = "1111"
|
||||
}
|
||||
};
|
||||
|
||||
var coreRequest = new CoreRequest(_mockClientFactory.Object,
|
||||
_mockCoreServiceConnection.Object,
|
||||
coreConfiguration);
|
||||
|
||||
_mockCoreServiceConnection.Setup(x => x.GetAccessToken()).Returns("TESTAafjp07087jfjas0d908qj324");
|
||||
|
||||
var result = coreRequest.CreateHttpRequestMessage(testEndPoint, HttpMethod.Post, jsonTestCompare);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("//CoreTEST.com:1111endpoint/test", result.RequestUri.AbsolutePath);
|
||||
Assert.AreEqual("TESTAafjp07087jfjas0d908qj324", result.Headers.Authorization.Scheme);
|
||||
Assert.NotNull(result.Content);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user