-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request tokens endpoint #3
base: master
Are you sure you want to change the base?
Changes from all commits
e0de193
b187fbc
0540f0f
3dddcbc
684c9d2
29ace45
409bdda
3a372d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,14 +183,15 @@ public void Should_Client_Get_Requests_Return_Multiple() | |
Assert.AreEqual(resp.Requests.Count, 5); | ||
} | ||
} | ||
[Test] | ||
public void Should_Client_Delete_Post_Correct_Data() | ||
{ | ||
string id = Guid.NewGuid().ToString(); | ||
string token = Guid.NewGuid().ToString(); | ||
string requestContent = ""; | ||
var requestHandlers = new List<MockHttpHandler>() | ||
{ | ||
new MockHttpHandler("/requests/", "DELETE", (req, rsp, prm) => | ||
new MockHttpHandler("/requests/" + id, "DELETE", (req, rsp, prm) => | ||
{ | ||
requestContent = req.Content(); | ||
}) | ||
|
@@ -204,6 +205,233 @@ public void Should_Client_Delete_Post_Correct_Data() | |
Assert.GreaterOrEqual(requestContent.IndexOf("Steve"), 0); | ||
} | ||
} | ||
} | ||
} | ||
|
||
[Test] | ||
public void Should_Client_Search_Drug_Use_Correct_Data() | ||
{ | ||
string drug_name = Guid.NewGuid().ToString(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a bit nitty, but should the drug name match the drug(s) that is in the fixture? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I moved removed this test from this branch and added it to the form and drug search PR. |
||
Dictionary<string, string> requestContent = new Dictionary<string, string>(); | ||
var requestHandlers = new List<MockHttpHandler>() | ||
{ | ||
new MockHttpHandler("/drugs", "GET", (req, rsp, prm) => | ||
{ | ||
requestContent = prm; | ||
}) | ||
}; | ||
using(new MockServer(DEFAULT_MOCK_PORT, requestHandlers)) | ||
{ | ||
_client.SearchDrugs(drug_name); | ||
Assert.That(requestContent.Any(p => p.Key == "q")); | ||
Assert.That(requestContent.Any(p => p.Value == drug_name)); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Should_Client_Search_Drug_Parse_Data() | ||
{ | ||
string drug_name = Guid.NewGuid().ToString(); | ||
Dictionary<string, string> requestContent = new Dictionary<string, string>(); | ||
var requestHandlers = new List<MockHttpHandler>() | ||
{ | ||
new MockHttpHandler("/drugs", "GET", (req, rsp, prm) => | ||
{ | ||
return File.ReadAllText("Fixtures/Drugs.json"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't find this (or other) fixture files. Was in included in another PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh nice catch. I didn't push any of the fixtures because they were in the Debug folder. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay I added them in this commit ec41011 |
||
}) | ||
}; | ||
using(new MockServer(DEFAULT_MOCK_PORT, requestHandlers, (req, rsp, prm) => rsp.Header("Content-Type", "application/json"))) | ||
{ | ||
var drugs = _client.SearchDrugs(drug_name); | ||
Assert.AreEqual(drugs.Drugs.Count, 3); | ||
Assert.AreEqual(drugs.Drugs.First().FullName, "Boniva 150MG tablets"); | ||
Assert.AreEqual(drugs.Drugs.First().Strength, "150"); | ||
Assert.AreEqual(drugs.Drugs[1].Href, "https://staging.api.covermymeds.com/drugs/094563"); | ||
Assert.AreEqual(drugs.Drugs[2].GPI, "30042048102030"); | ||
} | ||
} | ||
|
||
|
||
[Test] | ||
public void Should_Client_Get_Drug_Use_Correct_Data() | ||
{ | ||
string drug_id = Guid.NewGuid().ToString(); | ||
bool called = false; | ||
var requestHandlers = new List<MockHttpHandler>() | ||
{ | ||
new MockHttpHandler(string.Format("/drugs/{0}", drug_id), "GET", (req, rsp, prm) => | ||
{ | ||
called = true; | ||
}) | ||
}; | ||
using(new MockServer(DEFAULT_MOCK_PORT, requestHandlers)) | ||
{ | ||
_client.GetDrug(drug_id); | ||
Assert.That(called); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know anything about MockHttpHandler, only conceptually what it is doing here, but I'd expect it to have some kind of method to assert that a request was made. (In lieu of using a local variable for this.) Is there anything like that in the usage documentation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought so as well, but because it uses lambdas for handling the responses, NUnit does not see them as tests, so the asserts don't work There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are spoiled by rspec/webmock |
||
} | ||
} | ||
|
||
[Test] | ||
public void Should_Client_Get_Form_Parse_Data() | ||
{ | ||
string form_id = Guid.NewGuid().ToString(); | ||
var requestHandlers = new List<MockHttpHandler>() | ||
{ | ||
new MockHttpHandler(string.Format("/forms/{0}", form_id), "GET", (req, rsp, prm) => | ||
{ | ||
return File.ReadAllText("Fixtures/Form.json"); | ||
}) | ||
}; | ||
using(new MockServer(DEFAULT_MOCK_PORT, requestHandlers, (req, rsp, prm)=> rsp.Header("Content-Type", "application/json"))) | ||
{ | ||
var form = _client.GetForm(form_id); | ||
Assert.AreEqual(form.Id, 4); | ||
Assert.AreEqual(form.Name, "humana_tracleer"); | ||
Assert.AreEqual(form.IsEPA, false); | ||
Assert.AreEqual(form.ContactFax, "(877) 486-2621"); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Should_Client_Get_Form_Use_Correct_URL() | ||
{ | ||
string form_id = Guid.NewGuid().ToString(); | ||
bool called = false; | ||
var requestHandlers = new List<MockHttpHandler>() | ||
{ | ||
new MockHttpHandler(string.Format("/forms/{0}", form_id), "GET", (req, rsp, prm) => | ||
{ | ||
called = true; | ||
}) | ||
}; | ||
using(new MockServer(DEFAULT_MOCK_PORT, requestHandlers, (req, rsp, prm) => rsp.Header("Content-Type", "application/json"))) | ||
{ | ||
_client.GetForm(form_id); | ||
Assert.That(called); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Should_Client_Search_Forms_Parse_Data() | ||
{ | ||
var requestHandlers = new List<MockHttpHandler>() | ||
{ | ||
new MockHttpHandler("/forms/", "GET", (req, rsp, prm) => | ||
{ | ||
return File.ReadAllText("Fixtures/Forms.Json"); | ||
}) | ||
}; | ||
using(new MockServer(DEFAULT_MOCK_PORT, requestHandlers, (req, rsp, prm) => rsp.Header("Content-Type", "application/json"))) | ||
{ | ||
var forms = _client.SearchForms("1234", "OH", "12345"); | ||
Assert.AreEqual(forms.Forms.Count, 5); | ||
Assert.AreEqual(forms.Forms.First().Id, 15257); | ||
Assert.AreEqual(forms.Forms[2].Name, "express_scripts_medicare_part_d_quantity_limit_exceptions"); | ||
Assert.AreEqual(forms.Forms[1].Directions, "Prior Authorization of Benefits (PAB) Form for Multi-Source Brand Medications"); | ||
Assert.AreEqual(forms.Forms.Last().RequestFormId, "anthem_general_3876"); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Should_Client_Search_Forms_Use_Correct_Data() | ||
{ | ||
var requestContent = new Dictionary<string, string>(); | ||
var requestHandlers = new List<MockHttpHandler>() | ||
{ | ||
new MockHttpHandler("/forms", "GET", (req, rsp, prm) => | ||
{ | ||
requestContent = prm; | ||
}) | ||
}; | ||
using(new MockServer(DEFAULT_MOCK_PORT, requestHandlers, (req, rsp, prm) => rsp.Header("Content-Type", "application/json"))) | ||
{ | ||
_client.SearchForms("1234", "OH", "12345"); | ||
Assert.AreEqual(requestContent["drug_id"], "1234"); | ||
Assert.AreEqual(requestContent["state"], "OH"); | ||
Assert.AreEqual(requestContent["q"], "12345"); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Should_Client_Search_Forms_Use_Correct_Data2() | ||
{ | ||
var requestContent = new Dictionary<string, string>(); | ||
var requestHandlers = new List<MockHttpHandler>() | ||
{ | ||
new MockHttpHandler("/forms", "GET", (req, rsp, prm) => | ||
{ | ||
requestContent = prm; | ||
}) | ||
}; | ||
using(new MockServer(DEFAULT_MOCK_PORT, requestHandlers, (req, rsp, prm) => rsp.Header("Content-Type", "application/json"))) | ||
{ | ||
_client.SearchForms("1234", "OH", "30", "binsample", "223142", "group-567"); | ||
Assert.AreEqual(requestContent["drug_id"], "1234"); | ||
Assert.AreEqual(requestContent["state"], "OH"); | ||
Assert.AreEqual(requestContent["threshold"], "30"); | ||
Assert.AreEqual(requestContent["bin"], "binsample"); | ||
Assert.AreEqual(requestContent["pcn"], "223142"); | ||
Assert.AreEqual(requestContent["group_id"], "group-567"); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Should_Client_Post_Tokens() | ||
{ | ||
var tokenIds = new List<string>(); | ||
string requestContent = ""; | ||
for(int i = 0;i<5;i++) | ||
tokenIds.Add(Guid.NewGuid().ToString()); | ||
var requestHandlers = new List<MockHttpHandler>() | ||
{ | ||
new MockHttpHandler("/requests/tokens", "POST", (req, rsp, prm) => | ||
{ | ||
requestContent = req.Content(); | ||
}) | ||
}; | ||
using(new MockServer(DEFAULT_MOCK_PORT, requestHandlers)) | ||
{ | ||
_client.PostTokens(tokenIds.ToArray()); | ||
for(int i = 0;i<5;i++) | ||
Assert.GreaterOrEqual(requestContent.IndexOf(tokenIds[i]), 0); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Should_Client_Parse_Token_Data() | ||
{ | ||
var requestHandlers = new List<MockHttpHandler>() | ||
{ | ||
new MockHttpHandler("/requests/tokens", "POST", (req, rsp, prm) => | ||
{ | ||
return File.ReadAllText("Fixtures/PostToken.json"); | ||
}) | ||
}; | ||
using(new MockServer(DEFAULT_MOCK_PORT, requestHandlers, (req, rsp, prm) => rsp.Header("Content-Type", "application/json"))) | ||
{ | ||
var resp = _client.PostTokens(new string []{"blah", "test", "Test2"}); | ||
Assert.AreEqual(resp.Tokens.Count, 1); | ||
Assert.AreEqual(resp.Tokens.First().Id, "nhe44fu4g22upqqgstea"); | ||
Assert.AreEqual(resp.Tokens.First().RequestId, "NT4HJ4"); | ||
|
||
} | ||
} | ||
|
||
[Test] | ||
public void Should_Client_Delete_Token() | ||
{ | ||
string _tokenId = Guid.NewGuid().ToString(); | ||
bool called = false; | ||
var requestHandlers = new List<MockHttpHandler>() | ||
{ | ||
new MockHttpHandler("/requests/tokens/" + _tokenId, "DELETE", (req, rsp, prm) => | ||
{ | ||
called = true; | ||
}) | ||
}; | ||
using(new MockServer(DEFAULT_MOCK_PORT, requestHandlers)) | ||
{ | ||
_client.DeleteToken(_tokenId); | ||
Assert.That(called); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System.Net.Http; | ||
using System; | ||
using NUnit.Framework; | ||
using Moq; | ||
using RestSharp; | ||
using System.Linq; | ||
using CoverMyDotNet.Requests; | ||
|
||
namespace CoverMyDotNet.Tests | ||
{ | ||
[TestFixture] | ||
public class GetDrugTests | ||
{ | ||
private string _apiId; | ||
private string _drugId; | ||
private GetDrug _getDrug; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
_apiId = Guid.NewGuid().ToString(); | ||
_drugId = Guid.NewGuid().ToString(); | ||
_getDrug = new GetDrug(_apiId, _drugId); | ||
} | ||
|
||
[Test] | ||
public void Should_Use_Correct_Method() | ||
{ | ||
Assert.AreEqual(_getDrug.Method, Method.GET); | ||
} | ||
|
||
[Test] | ||
public void Should_Use_Correct_Resource() | ||
{ | ||
Assert.AreEqual(_getDrug.Resource, string.Format("drugs/{0}", _drugId)); | ||
} | ||
|
||
[Test] | ||
public void Should_Use_Correct_RootElement() | ||
{ | ||
Assert.AreEqual(_getDrug.RootElement, "drug"); | ||
} | ||
|
||
[Test] | ||
public void Should_Have_Version_Parameter() | ||
{ | ||
Assert.That(_getDrug.Parameters.Any(p => p.Name == "v" && p.Value.ToString() == "1")); | ||
} | ||
|
||
[Test] | ||
public void Should_Have_Authorization_Parameter() | ||
{ | ||
Assert.That(_getDrug.Parameters.Any(p => p.Name == "Authorization" && | ||
p.Value.ToString() == string.Format("Bearer {0}+x-no-pass", _apiId))); | ||
} | ||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are your thoughts on combining the drug-related examples into one class, and ditto for form ones? Then perhaps extracting each into their own files so that Program.cs just has the Main class in it?? I haven't done any .NET programming in awhile, but IIRC correctly that's a common practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be a good idea. I was mainly using the CoverMyDotNet.Samples to make sure the client class was working correctly with the api. Ill make those changes though.