示例#1
0
        public async Task Test_CreateNewIndex_Expect_NotEmptyJobId()
        {
            using var client = m_TestServer.CreateClient();
            var newPath        = WebTestHelper.GetPathToTestData("Meta");
            var configureModel = new { managementInformationPath = newPath };

            using (var requestPayload = new StringContent(JsonConvert.SerializeObject(configureModel), Encoding.UTF8, "application/json"))
                using (_ = await client.PutAsync(APIRoutes.ConfigurationRoute, requestPayload))
                {
                }

            var createIndexModel = new CreateIndexRequest()
            {
                SourcePath     = WebTestHelper.GetPathToTestData("01_ToIndex"),
                FileExtensions = new[] { ".txt" }
            };

            using (var requestPayload = new StringContent(JsonConvert.SerializeObject(createIndexModel), Encoding.UTF8, "application/json"))
                using (var response = await client.PostAsync(APIRoutes.CreateIndexRoute, requestPayload))
                {
                    response.EnsureSuccessStatusCode();
                    var responsePayload = await response.Content.ReadAsStringAsync();

                    var indexModel = JsonConvert.DeserializeObject <CreateIndexResponse>(responsePayload);
                    Assert.That(indexModel, Is.Not.Null);
                    Assert.That(indexModel.IndexingJobId, Is.Not.Null);
                    Assert.That(indexModel.IndexingJobId, Is.Not.Empty);
                }
        }
示例#2
0
        public async Task Test_ConfigureManagementPath_Expect_ConfigurationApplied()
        {
            var metaPath = WebTestHelper.GetPathToTestData("Meta");

            if (!Directory.Exists(metaPath))
            {
                Directory.CreateDirectory(metaPath);
            }
            using var client = m_TestServer.CreateClient();
            var model = new { managementInformationPath = metaPath };

            using var requestPayload = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
            using (_ = await client.PutAsync(APIRoutes.ConfigurationRoute, requestPayload))
            {
            }

            using var response = await client.GetAsync(APIRoutes.ConfigurationRoute);

            response.EnsureSuccessStatusCode();

            var responsePayload = await response.Content.ReadAsStringAsync();

            var configurationModel = JsonConvert.DeserializeObject <ConfigureResponse>(responsePayload);

            Assert.That(configurationModel, Is.Not.Null);
            Assert.That(configurationModel.ManagementInformationPath, Is.EqualTo(metaPath));
        }
示例#3
0
        public void TearDown()
        {
            m_TestServer.Dispose();

            // CleanUp ...
            var metaPath = WebTestHelper.GetPathToTestData("Meta");

            if (Directory.Exists(metaPath))
            {
                Directory.Delete(metaPath, true);
            }
        }
示例#4
0
        public async Task Test_ConfigureManagementPath_Expect_200OK()
        {
            var metaPath = WebTestHelper.GetPathToTestData("Meta");

            if (!Directory.Exists(metaPath))
            {
                Directory.CreateDirectory(metaPath);
            }
            using var client = m_TestServer.CreateClient();
            var model   = new { managementInformationPath = metaPath };
            var content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");

            using var response = await client.PutAsync(APIRoutes.ConfigurationRoute, content);

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
        }
示例#5
0
        public void TearDown()
        {
            m_TestServer.Dispose();
            // Cleanup, but not really  needed for the tests to work ...
            // if the metaPath is created between tests, the second test does not work for some reason ...
            var metaPath = WebTestHelper.GetPathToTestData("Meta");

            if (Directory.Exists(metaPath))
            {
                Directory.Delete(metaPath, true);
            }
            var managementInformationTestPath = Path.Combine(WebTestHelper.GetPathToTestData("AppData"), FolderNames.ManagementFolder);

            if (Directory.Exists(managementInformationTestPath))
            {
                Directory.Delete(managementInformationTestPath, true);
            }
        }
示例#6
0
        public void SetUp()
        {
            var manager = Factory.Get().GetCodeSearcherManager(new VoidLogger());
            var managementInformationTestPath = Path.Combine(WebTestHelper.GetPathToTestData("AppData"), FolderNames.ManagementFolder);

            if (!Directory.Exists(managementInformationTestPath))
            {
                Directory.CreateDirectory(managementInformationTestPath);
            }
            manager.ManagementInformationPath = managementInformationTestPath;

            var builder = new WebHostBuilder()
                          .UseEnvironment("Development")
                          .UseStartup <CodeSearcher.WebAPI.Startup>();

            m_TestServer = new TestServer(builder);

            var metaPath = WebTestHelper.GetPathToTestData("Meta");

            if (Directory.Exists(metaPath))
            {
                Directory.Delete(metaPath, true);
            }
        }
示例#7
0
        public async Task Test_DeleteIndex_Expect_Success()
        {
            using var client = m_TestServer.CreateClient();
            var newPath        = WebTestHelper.GetPathToTestData("Meta");
            var configureModel = new { managementInformationPath = newPath };

            using (var requestPayload = new StringContent(JsonConvert.SerializeObject(configureModel), Encoding.UTF8, "application/json"))
                using (_ = await client.PutAsync(APIRoutes.ConfigurationRoute, requestPayload))
                {
                }

            var createIndexModel = new CreateIndexRequest()
            {
                SourcePath     = WebTestHelper.GetPathToTestData("01_ToIndex"),
                FileExtensions = new[] { ".txt" }
            };

            using (var requestPayload = new StringContent(JsonConvert.SerializeObject(createIndexModel), Encoding.UTF8, "application/json"))
                using (_ = await client.PostAsync(APIRoutes.CreateIndexRoute, requestPayload))
                {
                }

            //TODO can be optimized with API method to get information if background job still running
            ICodeSearcherIndex[] indexesModel;
            int count = 0;

            do
            {
                using (var response = await client.GetAsync(APIRoutes.IndexListRoute))
                {
                    var responsePayload = await response.Content.ReadAsStringAsync();

                    var settings = new JsonSerializerSettings();
                    settings.Converters.Add(Factory.Get().GetCodeSearcherIndexJsonConverter());
                    indexesModel = JsonConvert.DeserializeObject <ICodeSearcherIndex[]>(responsePayload, settings);
                    Assert.That(indexesModel, Is.Not.Null);
                }
                await Task.Delay(250);

                //timeout
                Assert.That(count++, Is.LessThan(100));
            } while (indexesModel.Length < 1);

            var deleteRequestModel = new DeleteIndexRequest
            {
                IndexID = indexesModel[0].ID
            };

            // simplified API client.DeleteAsync doesn't allow to set content
            var deleteRequest = new HttpRequestMessage
            {
                Method     = HttpMethod.Delete,
                RequestUri = new Uri(client.BaseAddress, APIRoutes.CreateIndexRoute),
                Content    = new StringContent(JsonConvert.SerializeObject(deleteRequestModel), Encoding.UTF8, "application/json")
            };

            using (var response = await client.SendAsync(deleteRequest))
            {
                response.EnsureSuccessStatusCode();
                var responsePayload = await response.Content.ReadAsStringAsync();

                var deleteModel = JsonConvert.DeserializeObject <DeleteIndexResponse>(responsePayload);
                Assert.That(deleteModel, Is.Not.Null);
                Assert.That(deleteModel.Succeeded, Is.True);
            }
        }
示例#8
0
        public async Task Test_SearchInIndex_Expect_Success()
        {
            using var client = m_TestServer.CreateClient();
            var newPath        = WebTestHelper.GetPathToTestData("Meta");
            var configureModel = new { managementInformationPath = newPath };

            using (var requestPayload = new StringContent(JsonConvert.SerializeObject(configureModel), Encoding.UTF8, "application/json"))
                using (_ = await client.PutAsync(APIRoutes.ConfigurationRoute, requestPayload))
                {
                }

            var createIndexModel = new CreateIndexRequest()
            {
                SourcePath     = WebTestHelper.GetPathToTestData("01_ToIndex"),
                FileExtensions = new[] { ".txt" }
            };

            using (var requestPayload = new StringContent(JsonConvert.SerializeObject(createIndexModel), Encoding.UTF8, "application/json"))
                using (_ = await client.PostAsync(APIRoutes.CreateIndexRoute, requestPayload))
                {
                }

            ICodeSearcherIndex[] indexesModel;
            int count = 0;

            do
            {
                using (var response = await client.GetAsync(APIRoutes.IndexListRoute))
                {
                    var responsePayload = await response.Content.ReadAsStringAsync();

                    var settings = new JsonSerializerSettings();
                    settings.Converters.Add(Factory.Get().GetCodeSearcherIndexJsonConverter());
                    indexesModel = JsonConvert.DeserializeObject <ICodeSearcherIndex[]>(responsePayload, settings);
                    Assert.That(indexesModel, Is.Not.Null);
                }
                await Task.Delay(250);

                //timeout
                Assert.That(count++, Is.LessThan(100));
            } while (indexesModel.Length < 1);

            var searchModel = new SearchIndexRequest()
            {
                IndexID    = indexesModel[0].ID,
                SearchWord = "erat"
            };

            using (var requestPayload = new StringContent(JsonConvert.SerializeObject(searchModel), Encoding.UTF8, "application/json"))
            {
                var request = new HttpRequestMessage
                {
                    Method     = HttpMethod.Post,
                    Content    = requestPayload,
                    RequestUri = new Uri(client.BaseAddress, APIRoutes.SearchInIndexRoute)
                };
                using (var response = await client.SendAsync(request))
                {
                    response.EnsureSuccessStatusCode();

                    var responsePayload = await response.Content.ReadAsStringAsync();

                    var settings = new JsonSerializerSettings();
                    settings.Converters.Add(Factory.Get().GetDetailedResultJsonConverter());
                    settings.Converters.Add(Factory.Get().GetFindingsInFileJsonConverter());
                    var searchIndex = JsonConvert.DeserializeObject <SearchIndexResponse>(responsePayload, settings);
                }
            }
        }