public async Task Controller_GET_APIKey() { var controller = new ApiKeyController(User, Manager); await PostTestAPIKey(); var res = controller.Get() as JsonResult; var obj = res.Value as IEnumerable <Models.Output.Admin.ApiKey>; Assert.AreEqual(1, obj.Count()); Assert.AreEqual("TEST_API_KEY", obj.First().Description); Assert.AreEqual(DateTime.MaxValue, obj.First().ExpirationDate); Assert.AreEqual(AuthorizeApiKey.Authentication | AuthorizeApiKey.Registration | AuthorizeApiKey.Standard, obj.First().Flags); Assert.AreEqual(2, obj.First().UseNum); User.SetPermissions(new string[] { }); Assert.Throws <Shared.Exceptions.InsuficientPermission>(() => controller.Get()); }
public async void Get_Not_Exists() { ApiKeyControllerMockFacade mock = new ApiKeyControllerMockFacade(); mock.ServiceMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <ApiApiKeyResponseModel>(null)); ApiKeyController controller = new ApiKeyController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Get(default(string)); response.Should().BeOfType <StatusCodeResult>(); (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound); mock.ServiceMock.Verify(x => x.Get(It.IsAny <string>())); }