private static void PutOrganization()
        {
            using (var request = new ApiWebRequest())
            {
                var organizationData = Helper.GetJsonObjectFromFile <Organization>("SampleData/Organization.json");

                RestApiCaller.CallAndHandleError
                (
                    () =>
                {
                    Console.WriteLine("-> Create data");
                    request.Post(RequestObject.Organizations, organizationData);

                    Console.WriteLine("-> Exercise Put");
                    organizationData.Description                    = "OrganizationDescriptionUpdated";
                    organizationData.DisplayName                    = "OrganizationDisplayNameUpdated";
                    organizationData.ExpiryDisallowLoginDays        = 99;
                    organizationData.ForceResetPasswordDefaultValue = true;
                    organizationData.PasswordExpiryDays             = 100;
                    var response = request.Put(RequestObject.Organizations, organizationData);
                    return(response);
                },
                    () =>
                {
                    request.Delete(string.Format(CultureInfo.CurrentCulture, "{0}/{1}", RequestObject.Organizations, organizationData.Name));
                }
                );
            }
        }
        private static void DeleteUser()
        {
            using (var request = new ApiWebRequest())
            {
                Console.WriteLine("Prepare data");
                var postData = Helper.GetJsonObjectFromFile <User>(PostDataFile01);
                RestApiCaller.CallAndHandleError
                (
                    () =>
                {
                    Console.WriteLine("Create new User");
                    request.Post(RequestObject.Users, postData);

                    Console.WriteLine("Delete User " + postData.Name);
                    var response =
                        request.Delete(string.Format(CultureInfo.InvariantCulture, "{0}/{1}",
                                                     RequestObject.Users, postData.Id));
                    return(response);
                },
                    () =>
                {
                    request.Delete(string.Format(CultureInfo.InvariantCulture, "{0}/{1}", RequestObject.Users,
                                                 postData.Name));
                }
                );
            }
        }
        private static void PutOneTimePasswordConnection()
        {
            using (var request = new ApiWebRequest())
            {
                var connection       = Helper.GetJsonObjectFromFile <Connection>("SampleData/OneTimePasswordConnection.json");
                var connectionUpdate = Helper.GetJsonObjectFromFile <Connection>("SampleData/OneTimePasswordConnectionUpdate.json");


                RestApiCaller.CallAndHandleError
                (
                    () =>
                {
                    Console.WriteLine("-> Create data");
                    request.Post(RequestObject.Connections, connection);

                    Console.WriteLine("-> Exercise PUT One Time Password Connection ");
                    var response = request.Put(RequestObject.Connections, connectionUpdate);
                    return(response);
                },
                    () =>
                {
                    request.Delete(string.Format(CultureInfo.CurrentCulture, "{0}/{1}", RequestObject.Connections, connection.Name));
                }
                );
            }
        }
        private static void PutMassUsers()
        {
            using (var request = new ApiWebRequest())
            {
                Console.WriteLine("Prepare data");
                var postData = Helper.GetJsonObjectFromFile <User[]>(PostMassDataFile);
                var putData  = Helper.GetJsonObjectFromFile <User[]>(PutMassDataFile);
                RestApiCaller.CallAndHandleError
                (
                    () =>
                {
                    request.Post(RequestObject.MassUsers, postData);

                    Console.WriteLine("Put Mass User");
                    HttpResponseMessage response = request.Put(RequestObject.MassUsers, putData);
                    return(response);
                },
                    () =>
                {
                    List <Guid> delData = (from user in putData select new Guid(user.Id)).ToList <Guid>();
                    request.Delete(RequestObject.MassUsers, delData);
                }
                );
            }
        }
Example #5
0
        private static void PutGroup()
        {
            using (var request = new ApiWebRequest())
            {
                var groupData = Helper.GetJsonObjectFromFile <Group>("SampleData/Group.json");

                RestApiCaller.CallAndHandleError
                (
                    () =>
                {
                    Console.WriteLine("-> Create data");
                    request.Post(RequestObject.Groups, groupData);

                    Console.WriteLine("-> Exercise Put");
                    groupData.Description          = "GroupDescriptionUpdated";
                    groupData.ClaimValues[0].Value = "OrganizationAdmin";
                    groupData.ClaimValues[1].Value = "ClaimTransformationAdmin";
                    var response = request.Put(RequestObject.Groups, groupData);
                    return(response);
                },
                    () =>
                {
                    request.Delete(string.Format(CultureInfo.CurrentCulture, "{0}/{1}", RequestObject.Groups, groupData.Name));
                }
                );
            }
        }
Example #6
0
        private static void GetGroups()
        {
            using (var request = new ApiWebRequest())
            {
                var groupsData = Helper.GetJsonObjectFromFile <List <Group> >("SampleData/Groups.json");

                RestApiCaller.CallAndHandleError
                (
                    () =>
                {
                    Console.WriteLine("-> Create data");
                    request.Post(RequestObject.Groups, groupsData[0]);
                    request.Post(RequestObject.Groups, groupsData[1]);
                    request.Post(RequestObject.Groups, groupsData[2]);
                    request.Post(RequestObject.Groups, groupsData[3]);

                    Console.WriteLine("-> Exercise Get");
                    var response = request.Get(RequestObject.Groups);
                    return(response);
                },
                    () =>
                {
                    request.Delete(string.Format(CultureInfo.CurrentCulture, "{0}/{1}", RequestObject.Groups, groupsData[0].Name));
                    request.Delete(string.Format(CultureInfo.CurrentCulture, "{0}/{1}", RequestObject.Groups, groupsData[1].Name));
                    request.Delete(string.Format(CultureInfo.CurrentCulture, "{0}/{1}", RequestObject.Groups, groupsData[2].Name));
                    request.Delete(string.Format(CultureInfo.CurrentCulture, "{0}/{1}", RequestObject.Groups, groupsData[3].Name));
                }
                );
            }
        }
        private static void GetGenericConnection()
        {
            using (var request = new ApiWebRequest())
            {
                Console.WriteLine("Prepare data");
                var postData = Helper.GetJsonObjectFromFile <Connection>(PostDataFile01);

                RestApiCaller.CallAndHandleError
                (
                    () =>
                {
                    Console.WriteLine("Create new Generic connection");
                    request.Post(RequestObject.Connections, postData);

                    Console.WriteLine("Get Generic connection");
                    var response =
                        request.Get(string.Format(CultureInfo.InvariantCulture, "{0}/{1}",
                                                  RequestObject.Connections, postData.Name));
                    return(response);
                },
                    () =>
                    request.Delete(string.Format(CultureInfo.InvariantCulture, "{0}/{1}",
                                                 RequestObject.Connections, postData.Name))
                );
            }
        }
        private static void SearchUser()
        {
            using (var request = new ApiWebRequest())
            {
                Console.WriteLine("Prepare data");
                var postData   = Helper.GetJsonObjectFromFile <User[]>(PostMassDataFile);
                var searchData = Helper.GetJsonObjectFromFile <JObject>(SearchDataFile);
                RestApiCaller.CallAndHandleError
                (
                    () =>
                {
                    Console.WriteLine("Create new Users");
                    request.Post(RequestObject.MassUsers, postData);

                    Console.WriteLine("Search User");
                    var response = request.Post(RequestObject.UsersSearch, searchData);
                    return(response);
                },
                    () =>
                {
                    List <Guid> delData = (from user in postData select new Guid(user.Id)).ToList <Guid>();
                    request.Delete(RequestObject.MassUsers, delData);
                }
                );
            }
        }
        private static void PatchConnection(string connectionName, string postDataFilePath, string patchDataFilePath)
        {
            using (var request = new ApiWebRequest())
            {
                Console.WriteLine("-> Prepare data");
                var postData  = Helper.GetJsonObjectFromFile <Connection>(postDataFilePath);
                var patchData = Helper.GetJsonObjectFromFile <JArray>(patchDataFilePath);

                RestApiCaller.CallAndHandleError
                (
                    () =>
                {
                    Console.WriteLine("-> Create new {0}", connectionName);
                    var response = request.Post(RequestObject.Connections, postData);

                    Console.WriteLine("-> Put to update {0}", connectionName);
                    var path = string.Join("/", RequestObject.Connections, postData.Name);
                    response = request.Patch(path, patchData);
                    return(response);
                },
                    () =>
                {
                    request.Delete(string.Format(CultureInfo.InstalledUICulture, "{0}/{1}", RequestObject.Connections, postData.Name));
                }
                );
            }
        }
        private static void PutClaimDefinition()
        {
            using (var request = new ApiWebRequest())
            {
                Console.WriteLine("Prepare data");
                var postData = Helper.GetJsonObjectFromFile <ClaimDefinition>(PostOneDataFile);
                var putData  = Helper.GetJsonObjectFromFile <ClaimDefinition>(PutOneDataFile);
                RestApiCaller.CallAndHandleError
                (
                    () =>
                {
                    Console.WriteLine("Create new Claim Definition");
                    request.Post(RequestObject.ClaimDefinitions, postData);

                    Console.WriteLine("Put to update Claim Definition");
                    var response = request.Put(RequestObject.ClaimDefinitions, putData);
                    return(response);
                },
                    () =>
                {
                    request.Delete(string.Format(CultureInfo.InvariantCulture, "{0}/{1}",
                                                 RequestObject.ClaimDefinitions, postData.ClaimType));
                }
                );
            }
        }
 private static void DeleteClaimDefinitionsManyById()
 {
     using (var request = new ApiWebRequest())
     {
         Console.WriteLine("Prepare data");
         var postData = Helper.GetJsonObjectFromFile <ClaimDefinition[]>(PostManyDataFile);
         RestApiCaller.CallAndHandleError
         (
             () =>
         {
             var postResponse = request.Post(RequestObject.ClaimDefinitionsMany, postData);
             var guids        = ExtractArrayClaimIdsFromResult(postResponse);
             Console.WriteLine("Delete Claim Definitions");
             var response = request.Delete(
                 string.Format(CultureInfo.InvariantCulture, "{0}/{1}", RequestObject.ClaimDefinitions, RequestObject.Ids), guids);
             return(response);
         },
             () =>
         {
             var delData = Helper.GetJsonObjectFromFile <JArray>(DelDataFile);
             request.Delete(
                 string.Format(CultureInfo.InvariantCulture, "{0}/{1}", RequestObject.ClaimDefinitions,
                               RequestObject.ClaimTypes), delData);
         }
         );
     }
 }
        private static void GetCertificate(string resourceName, string postDataFilePath)
        {
            using (var request = new ApiWebRequest())
            {
                Console.WriteLine("-> Prepare data");
                var postData = Helper.GetJsonObjectFromFile <JObject>(postDataFilePath);
                var rawData  = (string)postData["RawData"];

                var cert = new X509Certificate2(Convert.FromBase64String(rawData));
                RestApiCaller.CallAndHandleError
                (
                    () =>
                {
                    Console.WriteLine("-> Create new {0}", resourceName);
                    var response = request.Post(RequestObject.Certificate, postData);

                    Console.WriteLine("-> Get {0}", resourceName);
                    response = request.Get(string.Join("/", RequestObject.Certificate, cert.Thumbprint));
                    return(response);
                },
                    () =>
                    request.Delete(string.Join("/", RequestObject.Certificate,
                                               string.Format(CultureInfo.InvariantCulture, "{0}?forceDeleteInUse=true", cert.Thumbprint)))
                );
            }
        }
        private static void DeleteClaimDefinitionById()
        {
            using (var request = new ApiWebRequest())
            {
                Console.WriteLine("Prepare data");
                var postData = Helper.GetJsonObjectFromFile <ClaimDefinition>(PostOneDataFile);
                RestApiCaller.CallAndHandleError
                (
                    () =>
                {
                    Console.WriteLine("Create new Claim Definition");
                    var postResponse = request.Post(RequestObject.ClaimDefinitions, postData);
                    string id        = ExtractClaimAttributeFromResult(postResponse, IdentifyJsonProperties.Id);

                    Console.WriteLine("Delete by Id Claim Definition " + postData.Name);
                    var response =
                        request.Delete(string.Format(CultureInfo.InvariantCulture, "{0}/{1}",
                                                     RequestObject.ClaimDefinitions, id));
                    return(response);
                },
                    () =>
                {
                    request.Delete(string.Format(CultureInfo.InvariantCulture, "{0}/{1}",
                                                 RequestObject.ClaimDefinitions, postData.ClaimType));
                }
                );
            }
        }
Example #14
0
        private static void PutConnection(string connectionName, string postDataFilePath, string putDataFilePath)
        {
            using (var request = new ApiWebRequest())
            {
                Console.WriteLine("-> Prepare data");
                var postData = Helper.GetJsonObjectFromFile <Connection>(postDataFilePath);
                var putData  = Helper.GetJsonObjectFromFile <JObject>(putDataFilePath);

                RestApiCaller.CallAndHandleError
                (
                    () =>
                {
                    Console.WriteLine("-> Post {0}", connectionName);
                    var response = request.Post(RequestObject.Connections, postData);

                    Console.WriteLine("-> Put to update {0}", connectionName);
                    response = request.Put(RequestObject.Connections, putData);
                    return(response);
                },
                    () =>
                {
                    request.Delete(string.Format(CultureInfo.InvariantCulture, "{0}/{1}", RequestObject.Connections, postData.Name));
                }
                );
            }
        }
Example #15
0
        private static void PutClaimTransformationsNemIdConnection()
        {
            using (var request = new ApiWebRequest())
            {
                var connection              = Helper.GetJsonObjectFromFile <Connection>("SampleData/NemIdConnectionWithClaimTransformation.json");
                var claimTransformation     = Helper.GetJsonObjectFromFile <CreateExcludeTransformationRequest>("SampleData/ClaimTransformation.json");
                var claimTransformation1    = Helper.GetJsonObjectFromFile <CreateExcludeTransformationRequest>("SampleData/ClaimTransformation1.json");
                var putClaimTransformations = Helper.GetJsonObjectFromFile <object>("SampleData/PutClaimTransformations.json");

                RestApiCaller.CallAndHandleError
                (
                    () =>
                {
                    request.Post(RequestObject.ClaimTransformationExcludeIdentify, claimTransformation);
                    request.Post(RequestObject.ClaimTransformationExcludeIdentify, claimTransformation1);
                    request.Post(RequestObject.Connections, connection);


                    Console.WriteLine("-> Exercise Put many claim transformation NemId connection");
                    var response = request.Put(RequestObject.ConnectionsClaimTransformations, putClaimTransformations);
                    return(response);
                },
                    () =>
                {
                    request.Delete(string.Format(CultureInfo.CurrentCulture, "{0}/{1}", RequestObject.Connections, connection.Name));
                    request.Delete(string.Format(CultureInfo.CurrentCulture, "{0}/{1}", RequestObject.ClaimTransformationExcludeIdentify, claimTransformation.TransformationName));
                    request.Delete(string.Format(CultureInfo.CurrentCulture, "{0}/{1}", RequestObject.ClaimTransformationExcludeIdentify, claimTransformation.TransformationName));
                }
                );
            }
        }
        private static void PostManyCertificate(string resourceName, string postDataFilePath)
        {
            using (var request = new ApiWebRequest())
            {
                Console.WriteLine("-> Prepare data");
                var thumprints = new List <string>();
                var postData   = Helper.GetJsonObjectFromFile <JArray>(postDataFilePath);

                foreach (var data in postData)
                {
                    var rawData = (string)data["RawData"];
                    var cert    = new X509Certificate2(Convert.FromBase64String(rawData));
                    thumprints.Add(cert.Thumbprint);
                }

                RestApiCaller.CallAndHandleError
                (
                    () =>
                {
                    Console.WriteLine("-> Post {0}", resourceName);
                    var response = request.Post(string.Join("/", RequestObject.Certificate, "many"), postData);
                    return(response);
                },
                    () =>
                    request.Delete(string.Join("/", RequestObject.Certificate, "many?forceDeleteInUse=true"),
                                   thumprints)
                );
            }
        }
        private static void DeleteOrganizations()
        {
            using (var request = new ApiWebRequest())
            {
                var organizationsData = Helper.GetJsonObjectFromFile <List <Organization> >("SampleData/Organizations.json");

                RestApiCaller.CallAndHandleError
                (
                    () =>
                {
                    Console.WriteLine("-> Create data");
                    request.Post(RequestObject.Organizations, organizationsData[0]);
                    request.Post(RequestObject.Organizations, organizationsData[1]);
                    request.Post(RequestObject.Organizations, organizationsData[2]);
                    request.Post(RequestObject.Organizations, organizationsData[3]);

                    Console.WriteLine("-> Exercise Delete many");
                    var deletedGroups = new[]
                    {
                        organizationsData[1].Name, organizationsData[2].Name, organizationsData[3].Name, organizationsData[0].Name
                    };
                    var response = request.Delete(RequestObject.OrganizationsMany, deletedGroups);
                    return(response);
                },
                    () =>
                {
                    request.Delete(string.Format(CultureInfo.CurrentCulture, "{0}/{1}", RequestObject.Organizations, organizationsData[0].Name));
                    request.Delete(string.Format(CultureInfo.CurrentCulture, "{0}/{1}", RequestObject.Organizations, organizationsData[1].Name));
                    request.Delete(string.Format(CultureInfo.CurrentCulture, "{0}/{1}", RequestObject.Organizations, organizationsData[2].Name));
                    request.Delete(string.Format(CultureInfo.CurrentCulture, "{0}/{1}", RequestObject.Organizations, organizationsData[3].Name));
                }
                );
            }
        }
        private static void GetFilterClaimDefinition()
        {
            using (var request = new ApiWebRequest())
            {
                Console.WriteLine("Prepare data");
                var postData = Helper.GetJsonObjectFromFile <ClaimDefinition[]>(PostManyDataFile);
                RestApiCaller.CallAndHandleError
                (
                    () =>
                {
                    Console.WriteLine("Create new Claim Definitions");
                    request.Post(RequestObject.ClaimDefinitionsMany, postData);

                    Console.WriteLine("Get Filter Claim Definition with Filter string: {0}", FilterString);
                    var response = request.Get(RequestObject.ClaimDefinitionsFilter + FilterString);
                    return(response);
                },
                    () =>
                {
                    var delData = Helper.GetJsonObjectFromFile <JArray>(DelDataFile);
                    request.Delete(
                        string.Format(CultureInfo.InvariantCulture, "{0}/{1}", RequestObject.ClaimDefinitions,
                                      RequestObject.ClaimTypes), delData);
                }
                );
            }
        }
Example #19
0
 private static void GetSystemSetup()
 {
     using (var request = new ApiWebRequest())
     {
         var response = request.Get(RequestObject.SystemSetup);
         Console.WriteLine("-> Response:");
         Console.WriteLine("Status code: {0}, Content {1}", response.StatusCode, Helper.ReadResponseContentAsString(response));
     }
 }
 private static void PostGroup()
 {
     using (var request = new ApiWebRequest())
     {
         var postData = Helper.GetJsonObjectFromFile <Group>(GroupDataFile);
         RestApiCaller.CallAndHandleError
         (
             () =>
         {
             HttpResponseMessage message = request.Post(RequestObject.Groups, postData);
             return(message);
         },
             () => { }
         );
     }
 }
Example #21
0
        private static void PostLinkedInConnection()
        {
            using (var request = new ApiWebRequest())
            {
                var connection = Helper.GetJsonObjectFromFile <Connection>("SampleData/PostLinkedInConnectionSample.json");

                RestApiCaller.CallAndHandleError
                (
                    () =>
                {
                    Console.WriteLine("-> Exercise POST LinkedIn connection");
                    return(request.Post(RequestObject.Connections, connection));
                },
                    () =>
                    request.Delete(string.Format(CultureInfo.InvariantCulture, "{0}/{1}", RequestObject.Connections,
                                                 connection.Name))
                );
            }
        }
Example #22
0
        private static void PutSystemSetup()
        {
            using (var request = new ApiWebRequest())
            {
                var rollbackSystemSetup = JsonConvert.DeserializeObject <SystemSetup>(
                    Helper.ReadResponseContentAsString(request.Get(RequestObject.SystemSetup)));

                var systemSetup = Helper.GetJsonObjectFromFile <SystemSetup>("SystemSetup.json");
                var response    = request.Put(RequestObject.SystemSetup, systemSetup);
                Console.WriteLine("-> Response:");
                Console.WriteLine("Status code: {0}, Content {1}", response.StatusCode, Helper.ReadResponseContentAsString(response));

                Console.WriteLine("-> Rollback System Setup Settings");
                response = request.Put(RequestObject.SystemSetup, rollbackSystemSetup);
                var isRollbackSuccess = response.StatusCode == HttpStatusCode.OK ?
                                        "Success" : "Failed";
                Console.WriteLine("Rollback is {0}", isRollbackSuccess);
            }
        }
 private static void DeleteOrganization()
 {
     using (var request = new ApiWebRequest())
     {
         var postData = Helper.GetJsonObjectFromFile <Organization>(OrganizationDataFile);
         RestApiCaller.CallAndHandleError
         (
             () =>
         {
             Console.WriteLine("Clean up organizations");
             HttpResponseMessage message =
                 request.Delete(string.Format(CultureInfo.InvariantCulture,
                                              "{0}/{1}", RequestObject.Organizations, postData.Name));
             return(message);
         },
             () => { }
         );
     }
 }
        private static void PostOrganization()
        {
            using (var request = new ApiWebRequest())
            {
                var organizationData = Helper.GetJsonObjectFromFile <Organization>("SampleData/Organization.json");

                RestApiCaller.CallAndHandleError
                (
                    () =>
                {
                    Console.WriteLine("-> Create data");

                    Console.WriteLine("-> Exercise Post");
                    var response = request.Post(RequestObject.Organizations, organizationData);
                    return(response);
                },
                    () =>
                {
                    request.Delete(string.Format(CultureInfo.CurrentCulture, "{0}/{1}", RequestObject.Organizations, organizationData.Name));
                }
                );
            }
        }
Example #25
0
        private static void GetCertificateNemIdConnection()
        {
            using (var request = new ApiWebRequest())
            {
                var connection = Helper.GetJsonObjectFromFile <Connection>("SampleData/NemIdConnection.json");

                RestApiCaller.CallAndHandleError
                (
                    () =>
                {
                    Console.WriteLine("-> Create data");
                    request.Post(RequestObject.Connections, connection);

                    Console.WriteLine("-> Exercise GET certificate for NemId connection");
                    var response = request.Get(string.Format(CultureInfo.CurrentCulture, "{0}/{1}", RequestObject.ConnectionsCertificate, connection.Name));
                    return(response);
                },
                    () =>
                {
                    request.Delete(string.Format(CultureInfo.CurrentCulture, "{0}/{1}", RequestObject.Connections, connection.Name));
                }
                );
            }
        }