public void UpdateUsergeneratedSystemKey_IfNoPermissionIsAssigned_InvalidOperationExceptionWillBeThrown() { UserValidationEssentials essentials = AccessControlUtility.RegisterAndLogin("user", "*****@*****.**", "123", _applicationContext); SecurityKeyPairController securityKeyPairController = _applicationContext["SecurityKeyPairController"] as SecurityKeyPairController; IPermissionRepository permissionRepository = _applicationContext["PermissionRespository"] as IPermissionRepository; IList <Permission> permissions = permissionRepository.GetAllPermissions(); List <string> securityKeyPermissions = new List <string>(); for (int i = 0; i < permissions.Count; i++) { securityKeyPermissions.Add(permissions[i].PermissionId); } securityKeyPairController.Request = new HttpRequestMessage(HttpMethod.Post, ""); securityKeyPairController.Request.Headers.Add("Auth", essentials.ApiKey); CreateUserGeneratedSecurityKeyPair command = new CreateUserGeneratedSecurityKeyPair(securityKeyPermissions, "", "", "", false, false, false, "#1"); IHttpActionResult httpActionResult = securityKeyPairController.CreateSecurityKey(command); OkNegotiatedContentResult <SecurityKeyPair> result = (OkNegotiatedContentResult <SecurityKeyPair>)httpActionResult; Assert.IsNotNullOrEmpty(result.Content.ApiKey); Assert.IsNotNullOrEmpty(result.Content.SecretKey); httpActionResult = securityKeyPairController.GetUserSecurityKeys(); OkNegotiatedContentResult <object> result1 = (OkNegotiatedContentResult <object>)httpActionResult; List <object> objectPairs = result1.Content as List <object>; Assert.IsNotNull(objectPairs); List <SecurityKeyPairList> pairs = new List <SecurityKeyPairList>(); foreach (object objectPair in objectPairs) { pairs.Add(objectPair as SecurityKeyPairList); } Assert.AreEqual(pairs.Count, 1); Assert.AreEqual(pairs[0].KeyDescription, "#1"); Assert.IsNull(pairs[0].ExpirationDate); httpActionResult = securityKeyPairController.GetSecurityKeyDetail("#1"); OkNegotiatedContentResult <SecurityKeyRepresentation> securityKey = (OkNegotiatedContentResult <SecurityKeyRepresentation>)httpActionResult; Assert.AreEqual(securityKey.Content.KeyDescritpion, "#1"); Assert.AreEqual(securityKey.Content.EnableEndDate, false); Assert.AreEqual(securityKey.Content.EnableExpirationDate, false); Assert.AreEqual(securityKey.Content.EnableStartDate, false); List <SecurityKeyPermissionsRepresentation> permissionsRepresentations = new List <SecurityKeyPermissionsRepresentation>(); for (int i = 0; i < securityKeyPermissions.Count; i++) { permissionsRepresentations.Add(new SecurityKeyPermissionsRepresentation(false, new Permission(securityKeyPermissions[i], ""))); } UpdateUserGeneratedSecurityKeyPair updateKeyPair = new UpdateUserGeneratedSecurityKeyPair(securityKey.Content.ApiKey, "#2", true, false, false, "", DateTime.Today.AddDays(-2).ToString(), permissionsRepresentations.ToArray(), ""); httpActionResult = securityKeyPairController.UpdateSecurityKey(updateKeyPair); BadRequestErrorMessageResult errorMessage = (BadRequestErrorMessageResult)httpActionResult; Assert.AreEqual(errorMessage.Message, "Please assign atleast one permission."); }
public void CreateUsergeneratedSystemKey_ProvideAllParameters_TheKeysShouldBeReturned() { UserValidationEssentials essentials = AccessControlUtility.RegisterAndLogin("user", "*****@*****.**", "123", _applicationContext); SecurityKeyPairController securityKeyPairController = _applicationContext["SecurityKeyPairController"] as SecurityKeyPairController; IPermissionRepository permissionRepository = _applicationContext["PermissionRespository"] as IPermissionRepository; IList <Permission> permissions = permissionRepository.GetAllPermissions(); List <string> securityKeyPermissions = new List <string>(); for (int i = 0; i < permissions.Count; i++) { securityKeyPermissions.Add(permissions[i].PermissionId); } securityKeyPairController.Request = new HttpRequestMessage(HttpMethod.Post, ""); securityKeyPairController.Request.Headers.Add("Auth", essentials.ApiKey); CreateUserGeneratedSecurityKeyPair command = new CreateUserGeneratedSecurityKeyPair(securityKeyPermissions, "", "", "", false, false, false, "#1"); IHttpActionResult httpActionResult = securityKeyPairController.CreateSecurityKey(command); OkNegotiatedContentResult <SecurityKeyPair> result = (OkNegotiatedContentResult <SecurityKeyPair>)httpActionResult; Assert.IsNotNullOrEmpty(result.Content.ApiKey); Assert.IsNotNullOrEmpty(result.Content.SecretKey); CreateUserGeneratedSecurityKeyPair command2 = new CreateUserGeneratedSecurityKeyPair(securityKeyPermissions, "", "", "", false, false, false, "#2"); httpActionResult = securityKeyPairController.CreateSecurityKey(command2); result = (OkNegotiatedContentResult <SecurityKeyPair>)httpActionResult; Assert.IsNotNullOrEmpty(result.Content.ApiKey); Assert.IsNotNullOrEmpty(result.Content.SecretKey); httpActionResult = securityKeyPairController.GetUserSecurityKeys(); OkNegotiatedContentResult <object> result1 = (OkNegotiatedContentResult <object>)httpActionResult; List <object> objectPairs = result1.Content as List <object>; List <SecurityKeyPairList> pairs = new List <SecurityKeyPairList>(); foreach (object objectPair in objectPairs) { pairs.Add(objectPair as SecurityKeyPairList); } Assert.AreEqual(pairs.Count, 2); Assert.AreEqual(pairs[1].KeyDescription, "#1"); Assert.IsNull(pairs[1].ExpirationDate); httpActionResult = securityKeyPairController.GetSecurityKeyDetail("#1"); OkNegotiatedContentResult <SecurityKeyRepresentation> securityKey = (OkNegotiatedContentResult <SecurityKeyRepresentation>)httpActionResult; Assert.AreEqual(securityKey.Content.KeyDescritpion, "#1"); Assert.AreEqual(securityKey.Content.EnableEndDate, false); Assert.AreEqual(securityKey.Content.EnableExpirationDate, false); Assert.AreEqual(securityKey.Content.EnableStartDate, false); Assert.AreEqual(pairs[0].KeyDescription, "#2"); Assert.IsNull(pairs[0].ExpirationDate); httpActionResult = securityKeyPairController.GetSecurityKeyDetail("#2"); securityKey = (OkNegotiatedContentResult <SecurityKeyRepresentation>)httpActionResult; Assert.AreEqual(securityKey.Content.KeyDescritpion, "#2"); Assert.AreEqual(securityKey.Content.EnableEndDate, false); Assert.AreEqual(securityKey.Content.EnableExpirationDate, false); Assert.AreEqual(securityKey.Content.EnableStartDate, false); }
public void UpdateUsergeneratedSystemKey_ProvideAllParameters_TheKeysDetailsShouldGetUpdated() { UserValidationEssentials essentials = AccessControlUtility.RegisterAndLogin("user", "*****@*****.**", "123", _applicationContext); SecurityKeyPairController securityKeyPairController = _applicationContext["SecurityKeyPairController"] as SecurityKeyPairController; IPermissionRepository permissionRepository = _applicationContext["PermissionRespository"] as IPermissionRepository; IList <Permission> permissions = permissionRepository.GetAllPermissions(); List <string> securityKeyPermissions = new List <string>(); for (int i = 0; i < permissions.Count; i++) { securityKeyPermissions.Add(permissions[i].PermissionId); } securityKeyPairController.Request = new HttpRequestMessage(HttpMethod.Post, ""); securityKeyPairController.Request.Headers.Add("Auth", essentials.ApiKey); CreateUserGeneratedSecurityKeyPair command = new CreateUserGeneratedSecurityKeyPair(securityKeyPermissions, "", "", "", false, false, false, "#1"); IHttpActionResult httpActionResult = securityKeyPairController.CreateSecurityKey(command); OkNegotiatedContentResult <SecurityKeyPair> result = (OkNegotiatedContentResult <SecurityKeyPair>)httpActionResult; Assert.IsNotNullOrEmpty(result.Content.ApiKey); Assert.IsNotNullOrEmpty(result.Content.SecretKey); httpActionResult = securityKeyPairController.GetUserSecurityKeys(); OkNegotiatedContentResult <object> result1 = (OkNegotiatedContentResult <object>)httpActionResult; List <object> objectPairs = result1.Content as List <object>; Assert.IsNotNull(objectPairs); List <SecurityKeyPairList> pairs = new List <SecurityKeyPairList>(); foreach (object objectPair in objectPairs) { pairs.Add(objectPair as SecurityKeyPairList); } Assert.AreEqual(pairs.Count, 1); Assert.AreEqual(pairs[0].KeyDescription, "#1"); Assert.IsNull(pairs[0].ExpirationDate); httpActionResult = securityKeyPairController.GetSecurityKeyDetail("#1"); OkNegotiatedContentResult <SecurityKeyRepresentation> securityKey = (OkNegotiatedContentResult <SecurityKeyRepresentation>)httpActionResult; Assert.AreEqual(securityKey.Content.KeyDescritpion, "#1"); Assert.AreEqual(securityKey.Content.EnableEndDate, false); Assert.AreEqual(securityKey.Content.EnableExpirationDate, false); Assert.AreEqual(securityKey.Content.EnableStartDate, false); List <SecurityKeyPermissionsRepresentation> permissionsRepresentations = new List <SecurityKeyPermissionsRepresentation>(); for (int i = 0; i < securityKeyPermissions.Count; i++) { if (securityKeyPermissions[i] == PermissionsConstant.Cancel_Order) { permissionsRepresentations.Add(new SecurityKeyPermissionsRepresentation(false, new Permission(securityKeyPermissions[i], "Cancel Order"))); } else if (securityKeyPermissions[i] == PermissionsConstant.Query_Open_Orders) { permissionsRepresentations.Add(new SecurityKeyPermissionsRepresentation(false, new Permission(securityKeyPermissions[i], "Query Open Orders"))); } else if (securityKeyPermissions[i] == PermissionsConstant.Place_Order) { permissionsRepresentations.Add(new SecurityKeyPermissionsRepresentation(false, new Permission(securityKeyPermissions[i], "Place Order"))); } else if (securityKeyPermissions[i] == PermissionsConstant.Withdraw_Funds) { permissionsRepresentations.Add(new SecurityKeyPermissionsRepresentation(false, new Permission(securityKeyPermissions[i], "Withdraw Funds"))); } else { permissionsRepresentations.Add(new SecurityKeyPermissionsRepresentation(true, new Permission(securityKeyPermissions[i], securityKeyPermissions[i]))); } } UpdateUserGeneratedSecurityKeyPair updateKeyPair = new UpdateUserGeneratedSecurityKeyPair(securityKey.Content.ApiKey, "#2", true, false, false, "", DateTime.Today.AddDays(-2).ToString(), permissionsRepresentations.ToArray(), ""); httpActionResult = securityKeyPairController.UpdateSecurityKey(updateKeyPair); httpActionResult = securityKeyPairController.GetSecurityKeyDetail("#2"); securityKey = (OkNegotiatedContentResult <SecurityKeyRepresentation>)httpActionResult; Assert.AreEqual(securityKey.Content.KeyDescritpion, "#2"); Assert.AreEqual(securityKey.Content.EnableEndDate, false); Assert.AreEqual(securityKey.Content.EnableExpirationDate, false); Assert.AreEqual(securityKey.Content.EnableStartDate, true); ValidatePermissions(securityKey.Content.SecurityKeyPermissions); }