public void Get_NonSupportedIdentifier_Returns400BadRequest() { const string BadRequestMessage = "The specified DID method is not supported. Only ION (https://github.com/decentralized-identity/ion) based identifiers can be resolved."; IdentifiersController identifiersController = GetMockedIdentifiersController(HttpStatusCode.BadRequest, "ignored_for_test"); BadRequestObjectResult badRequestResult = identifiersController.Get("did:notsupported").Result as BadRequestObjectResult; // Check that action result is returned // and as expected Assert.IsNotNull(badRequestResult); Assert.AreEqual(400, badRequestResult.StatusCode); Assert.IsNotNull(badRequestResult.Value); // Check that an an error object is returned // and correct Error error = badRequestResult.Value as Error; Assert.IsNotNull(error); Assert.AreEqual(BadRequestMessage, error.Message); Assert.AreEqual(Error.Types.RequestResolveIdentifier, error.Type); Assert.AreEqual(Error.Codes.UnsupportedDidMethod, error.Code); Assert.IsNotNull(error.CorrelationId); Guid guidResult; Assert.IsTrue(Guid.TryParse(error.CorrelationId, out guidResult)); }
public void Get_ConnectionErrors_Returns400BadRequest() { IdentifiersController identifiersController = GetMockedIdentifiersController(HttpStatusCode.BadRequest, "Bad Request"); ObjectResult objectResult = identifiersController.Get("did:ion:test").Result as ObjectResult; // Check that action result is returned // and as expected Assert.IsNotNull(objectResult); Assert.AreEqual(400, objectResult.StatusCode); Assert.IsNotNull(objectResult.Value); // Check that an an error object is returned // and correct Error error = objectResult.Value as Error; Assert.IsNotNull(error); Assert.AreEqual("Bad Request", error.Message); Assert.AreEqual(Error.Types.RequestResolveIdentifier, error.Type); Assert.AreEqual(Error.Codes.RemoteServiceError, error.Code); Assert.IsNotNull(error.CorrelationId); Guid guidResult; Assert.IsTrue(Guid.TryParse(error.CorrelationId, out guidResult)); }
public void Get_ConnectionReturns404_Returns404NotFound() { IdentifiersController identifiersController = GetMockedIdentifiersController(HttpStatusCode.NotFound, "ignored_for_test"); NotFoundResult notFoundResult = identifiersController.Get("did:ion:test").Result as NotFoundResult; // Check that action result is returned // and as expected Assert.IsNotNull(notFoundResult); Assert.AreEqual(404, notFoundResult.StatusCode); }
public void Get_SupportedIdentifier_ReturnsJson() { string responseContent = "{\"document\":{}}"; IdentifiersController identifiersController = GetMockedIdentifiersController(HttpStatusCode.OK, responseContent); JsonResult jsonResult = identifiersController.Get("did:ion:test").Result as JsonResult; // Check that action result is returned // and as expected Assert.IsNotNull(jsonResult); Assert.IsNotNull(jsonResult.Value); // Check that an an json object is // as expected JObject json = jsonResult.Value as JObject; Assert.IsNotNull(json); Assert.AreEqual(responseContent, json.ToString(Formatting.None)); }
public void PrepareIdentifier_InitialStateIncluded_ReturnsIdentifierAndInitialState() { Assert.AreEqual("testIdentifier?-ion-initial-state=testState", IdentifiersController.PrepareIdentifier("testIdentifier", "testState")); }
public void PrepareIdentifier_InitialStateWhiteSpace_ReturnsIdentifier() { Assert.AreEqual("testIdentifier", IdentifiersController.PrepareIdentifier("testIdentifier", " ")); }
public void PrepareIdentifier_InvalidInput_ThrowsArgumentException() { Assert.ThrowsException <ArgumentException>(() => IdentifiersController.PrepareIdentifier(string.Empty)); Assert.ThrowsException <ArgumentException>(() => IdentifiersController.PrepareIdentifier(" ")); //whitespace }
public void PrepareIdentifier_InvalidInput_ThrowsArgumentNullException() { Assert.ThrowsException <ArgumentNullException>(() => IdentifiersController.PrepareIdentifier(null)); }