Exemple #1
0
        public static void AssemblyInitialize(TestContext testContent)
        {
            // Setup server with defaults that prevent us from accessing external resources.
            napackServerTask = Task.Factory.StartNew(() =>
            {
                Global.SystemConfig = new SystemConfig()
                {
                    AdministratorEmail        = "*****@*****.**",
                    AdministratorName         = "test",
                    EmailHost                 = "unused",
                    EmailPort                 = 1234,
                    NameValidationFilePath    = @"..\..\..\server\Resources\NameValidation.json",
                    PackageValidationFilePath = @"..\..\..\server\Resources\PackageValidation.json",
                    RequireEmailValidation    = false
                };

                Global.EmailManager = new EmailManager(new InMemoryEmailSender());

                AdminModule.DefaultAdminUserName = "******";
                AdminModule.DefaultAdminPassword = "******";

                Global.Main(new[] { SystemSetup.LocalServer, "true" });
            }, TaskCreationOptions.LongRunning);

            // Setup the REST client for that server.
            SystemSetup.RestClient = new RestClient(new Uri(SystemSetup.LocalServer));

            while (!Global.Initialized)
            {
                Thread.Sleep(100);
            }

            // Create a user to perform authenticated requests.
            using (NapackServerClient client = new NapackServerClient(new Uri(SystemSetup.LocalServer)))
            {
                SystemSetup.AuthorizedUser = client.RegisterUserAsync("*****@*****.**").GetAwaiter().GetResult();
            }
        }
Exemple #2
0
        public async Task <TResponse> PostAsync <TResponse, TBody>(string uriSuffix, TBody body, UserSecret userSecret, Dictionary <HttpStatusCode, Exception> exceptionMap = null)
            where TResponse : class
        {
            string serializedContent = typeof(TBody) == typeof(string) ? body as string : Serializer.Serialize(body);

            using (StringContent content = new StringContent(serializedContent, Encoding.UTF8, RestClient.JsonMediaType))
            {
                content.Headers.Add(CommonHeaders.UserId, userSecret.UserId);
                content.Headers.Add(CommonHeaders.UserKeys, Convert.ToBase64String(Encoding.UTF8.GetBytes(Serializer.Serialize(userSecret.Secrets))));
                return(await this.SendWithExceptionHandlingAndSerialization <TResponse>(() => client.PostAsync(uriSuffix, content), exceptionMap));
            }
        }
Exemple #3
0
        public async Task <TResponse> PutAsync <TResponse, TBody>(string uriSuffix, TBody body, UserSecret userSecret)
            where TResponse : class
        {
            string serializedContent = typeof(TBody) == typeof(string) ? body as string : Serializer.Serialize(body);

            using (StringContent content = new StringContent(serializedContent, Encoding.UTF8, RestClient.JsonMediaType))
            {
                content.Headers.Add(CommonHeaders.UserId, userSecret.UserId);
                content.Headers.Add(CommonHeaders.UserKeys, Convert.ToBase64String(Encoding.UTF8.GetBytes(Serializer.Serialize(userSecret.Secrets)))); content.Headers.Add(CommonHeaders.UserId, userSecret.UserId);
                content.Headers.Add(CommonHeaders.UserKeys, Convert.ToBase64String(Encoding.UTF8.GetBytes(Serializer.Serialize(userSecret.Secrets))));
                using (HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Put, uriSuffix)
                {
                    Content = content
                })
                {
                    return(await this.SendWithExceptionHandlingAndSerialization <TResponse>(() => client.SendAsync(requestMessage)));
                }
            }
        }