Ejemplo n.º 1
0
        public async void TestCreateAndDeleteDataset()
        {
            string datasetName        = "TestDatasetName";
            string datasetDescription = "TestDatasetDescription";
            string datasetData        = "0 1\n0 2\n0 3\n1 2\n1 3\n2 3\n2\t3";

            var datasetInput = new DatasetInput()
            {
                Name        = datasetName,
                Description = datasetDescription,
                Data        = datasetData
            };


            CreateTestDataset(datasetInput);
            var datasets = dbContext.Datasets.Where(d => d.Name == datasetName).ToList();

            Assert.Single(datasets);

            Dataset dataset = datasets[0];

            //Description
            Assert.Equal(datasetDescription, dataset.Description);

            //Links
            var expectedLinks = datasetService.OrderLinksAndRemoveDublicates(parser.Parse(new DatasetInput()
            {
                Data = datasetData
            }));
            var actualLinks = dbContext.Links.Where(l => l.DatasetId == dataset.Id).ToList();

            Assert.Equal(expectedLinks.Count, dataset.LinksCount);
            Assert.Equal(expectedLinks.Count, actualLinks.Count);

            for (int i = 0; i < expectedLinks.Count; i++)
            {
                Assert.Equal(expectedLinks[i].User1Id, actualLinks[i].User1Id);
                Assert.Equal(expectedLinks[i].User2Id, actualLinks[i].User2Id);
            }

            //Users
            var users = await datasetService.GetOrderedUsers(expectedLinks);

            Assert.Equal(users.Count, dataset.UsersCount);


            //Delete dataset
            await datasetService.RemoveDataset(dataset.Id);

            datasets = dbContext.Datasets.Where(d => d.Id == dataset.Id).ToList();
            Assert.Empty(datasets);

            actualLinks = dbContext.Links.Where(l => l.DatasetId == dataset.Id).ToList();
            Assert.Empty(actualLinks);
        }
Ejemplo n.º 2
0
 public async Task <ActionResult <Dataset> > UploadDataset([FromForm] DatasetInput datasetInput)
 {
     try
     {
         using (var stream = datasetInput.File.OpenReadStream())
         {
             datasetInput.Data = new StreamReader(stream).ReadToEnd();
         }
         int result = await datasetService.CreateNewDataset(datasetInput.Name, datasetInput.Description, parser.Parse(datasetInput));
     }
     catch (DatasetParserException ex)
     {
         _logger.LogError(ex, $"{ex.Message}\n{ex.StackTrace}");
         return(BadRequest(new { errorMessage = "Invalid data format. Input file should contain rows with two space separated numbers" }));
     }
     return(StatusCode(201));
 }
Ejemplo n.º 3
0
 public async Task <ActionResult <Dataset> > Post([FromBody] DatasetInput datasetInput)
 {
     if (datasetInput.Data == null || datasetInput.Data.Length == 0)
     {
         return(BadRequest(new { errorMessage = "Input does not contain any data" }));
     }
     else
     {
         try
         {
             int result = await datasetService.CreateNewDataset(datasetInput.Name, datasetInput.Description, parser.Parse(datasetInput));
         } catch (DatasetParserException ex) {
             _logger.LogError(ex, $"{ex.Message}\n{ex.StackTrace}");
             return(BadRequest(new { errorMessage = "Invalid data format. Input file should contain rows with two space separated numbers" }));
         }
     }
     return(StatusCode(201));
 }
Ejemplo n.º 4
0
 private void CreateTestDataset(DatasetInput datasetInput)
 {
     dbContext.Database.EnsureDeleted();
     dbContext.Database.EnsureCreated();
     datasetService.CreateNewDataset(datasetInput.Name, datasetInput.Description, parser.Parse(datasetInput));
 }