Esempio n. 1
0
        public void LoginTest_ShouldFalse()
        {
            // Setup the handler
            var mockHandler = GetHttpMessageHandlerMock("Invalid Username or Password.");

            // Use HttpClient with mocked HttpMessageHandler
            var httpClient = new HttpClient(mockHandler.Object);

            var objectToTest = new LoginApi(new Uri("https://test.com/"), ref httpClient);

            // Perform test
            var user = "******";
            var pass = "******";

            objectToTest.LoginAsync(user, pass).Result.Should().Be(false);
            objectToTest.IsLoggedIn.Should().Be(false);

            // Check the http call was as expected
            var expectedUri   = new Uri("https://test.com/cgi/session.pl");
            var formVariables = new List <KeyValuePair <string, string> >(3);

            formVariables.Add(new KeyValuePair <string, string>(".submit", "Sign+in"));
            formVariables.Add(new KeyValuePair <string, string>("user_id", user));
            formVariables.Add(new KeyValuePair <string, string>("password", pass));
            var expectedContent = new FormUrlEncodedContent(formVariables);

            VerifyMockCalls(mockHandler, HttpMethod.Post, expectedUri, expectedContent);
        }
Esempio n. 2
0
        private static async Task Main(string[] args)
        {
            if (args == null || args.Length == 0)
            {
                Console.WriteLine($"Usage: {nameof(SearcherWebClient)} \"query\" [\"Market1[,Market2[,...]]\" [size]] ");
                return;
            }

            // parse arguments
            var query          = args[0];
            var markets        = args.Length > 1 ? args[1].ParseMarkets().ToList() : null;
            var size           = args.Length > 2 ? ParseSize(args[2]) : (int?)null;
            var searchQueryDto = new SearchQueryDto(query, markets, size);

            // login
            var loginApi    = new LoginApi(BasePath);
            var loginResult = await loginApi.LoginAsync(new UserLoginDto("user", "qwerty"));

            if (!string.IsNullOrEmpty(loginResult.ErrorMessage))
            {
                Console.WriteLine($"Login error: {loginResult.ErrorMessage}");
                return;
            }

            Console.WriteLine($"Login as {loginResult.User.Login} (id={loginResult.User.Id}) is successful");

            // search
            var searchApi = new SearchApi(BasePath)
            {
                Configuration =
                {
                    DefaultHeader = new Dictionary <string, string> {
                        { "Authorization", "Bearer " + loginResult.Token }
                    }
                }
            };
            var foundItems = await searchApi.SearchAsync(searchQueryDto);

            // show results
            foreach (var item in foundItems)
            {
                var sb = new StringBuilder($"{item.Id} ({item.ItemType}): {item.Name}");
                if (!string.IsNullOrEmpty(item.FormerName))
                {
                    sb.Append($" ({item.FormerName})");
                }

                sb.Append($" {item.Address}");
                Console.WriteLine(sb.ToString());
            }
        }
Esempio n. 3
0
        private static async Task Main(string[] args)
        {
            var basePath = "http://localhost:5000/";

            if (args != null && args.Length > 0)
            {
                basePath = args[0];
            }

            Console.WriteLine($"Using base path: {basePath}");

            Console.WriteLine();
            Console.WriteLine("Login...");
            var loginApi    = new LoginApi(basePath);
            var loginResult = await loginApi.LoginAsync(new UserLoginDto("admin", "Qwerty"));

            if (!string.IsNullOrEmpty(loginResult.ErrorMessage))
            {
                Console.WriteLine($"Login error: {loginResult.ErrorMessage}");
                return;
            }

            Console.WriteLine($"Login as {loginResult.User.Login} ({loginResult.User.FullName}) is successful");
            var userApi = new UserApi(basePath)
            {
                Configuration =
                {
                    DefaultHeader = new Dictionary <string, string> {
                        { "Authorization", "Bearer " + loginResult.Token }
                    }
                }
            };

            var users = await userApi.GetUsersAsync(new UserFilterDto());

            Console.WriteLine("Users:");
            foreach (var u in users)
            {
                Console.WriteLine($"{u.Id}, {u.Login}, {u.FullName}, {u.IsAdmin}");
            }

            var vacancyApi = new VacancyApi(basePath)
            {
                Configuration =
                {
                    DefaultHeader = new Dictionary <string, string> {
                        { "Authorization", "Bearer " + loginResult.Token }
                    }
                }
            };

            Console.WriteLine();
            Console.WriteLine("Update vacancies...");
            var updateResult = await vacancyApi.UpdateVacanciesAsync();

            if (!string.IsNullOrEmpty(updateResult.ErrorMessage))
            {
                Console.WriteLine($"Update error: {updateResult.ErrorMessage}");
                return;
            }

            Console.WriteLine($"Adding {updateResult.AddedCount} new vacancies is successful");

            Console.WriteLine();
            Console.WriteLine("Getting vacancies...");
            var vacancies = await vacancyApi.FindVacanciesAsync(string.Empty);

            foreach (var v in vacancies)
            {
                Console.WriteLine($"Id: {v.Id}");
                Console.WriteLine($"SyncId: {v.SyncId}");
                Console.WriteLine($"Name: {v.Name}");
                Console.WriteLine($"EmployerName: {v.EmployerName}");
                Console.WriteLine($"Published: {v.Published}");
                Console.WriteLine($"Salary:{SalaryToString(v.Salary)}");
                Console.WriteLine($"Description: {v.Description}");
                Console.WriteLine();
            }
        }