Exemplo n.º 1
0
        public async Task <bool> UpdatePlacementDescriptionAsync(UpdatePlacementDescriptionDTO description)
        {
            var entity = await context.PlacementDescriptions.FindAsync(description.Id);

            if (entity == null)
            {
                throw new ArgumentException($"Could not remove placement description with id {description.Id}, because it does not exist.");
            }

            // Remove the previous keywords, as they are a primary key
            var keywordsForDescription = from k in context.PlacementDescriptionKeywords
                                         where k.PlacementDescriptionId == entity.Id
                                         select k;

            context.PlacementDescriptionKeywords.RemoveRange(keywordsForDescription);

            entity.Agreement       = description.Agreement;
            entity.Degree          = description.Degree;
            entity.Keywords        = GetKeywords(description.KeywordNames).ToList();
            entity.Location        = description.Location;
            entity.MaxWorkingHours = description.MaxWorkingHours;
            entity.MinWorkingHours = description.MinWorkingHours;
            entity.MinSalary       = description.MinSalary;
            entity.Company         = await GetCompany(description.CompanyName);

            entity.Description   = description.Description;
            entity.Email         = description.Email;
            entity.LastApplyDate = description.LastApplyDate;
            entity.Title         = description.Title;
            entity.Thumbnail     = description.Thumbnail;

            await context.SaveChangesAsync();

            return(true);
        }
        public async Task UpdatePlacementDescription_returns_true_on_updated()
        {
            var descriptionToUpdate = new UpdatePlacementDescriptionDTO
            {
                Id              = 1,
                KeywordNames    = new [] { "UML" },
                Degree          = Degree.Bachelor,
                MinSalary       = 10,
                MinWorkingHours = 1,
                MaxWorkingHours = 100,
                Agreement       = true,
                Location        = "Nørreport",
                LastApplyDate   = new DateTime(2020, 12, 10),
                Email           = "*****@*****.**",
                Thumbnail       = new Uri("https://starwarsblog.starwars.com/wp-content/uploads/2020/04/best-friend-in-galaxy-chewbacca_TALL.jpg"),
                Title           = "UML Tester",
                Description     = "You should be able to do UML diagrams correctly",
                CompanyName     = "Spotify"
            };

            var actual = await repository.UpdatePlacementDescriptionAsync(descriptionToUpdate);

            Assert.True(actual);

            var updated = await Context.PlacementDescriptions.FindAsync(descriptionToUpdate.Id);

            Assert.Equal(descriptionToUpdate.KeywordNames, updated.Keywords.Select(k => k.Keyword.Name).ToList());
            Assert.Equal(descriptionToUpdate.CompanyName, updated.Company.Name);
        }
 public async Task UpdatePlacementDescription_returns_ArgumentException_on_not_found()
 {
     var descriptionToUpdate = new UpdatePlacementDescriptionDTO {
         Id = 100
     };
     await Assert.ThrowsAsync <ArgumentException>(() => repository.UpdatePlacementDescriptionAsync(descriptionToUpdate));
 }
        public async Task Update_returns_500_on_internal_error()
        {
            var description = new UpdatePlacementDescriptionDTO {
                Degree = Degree.Bachelor
            };

            repository.Setup(r => r.UpdatePlacementDescriptionAsync(description)).ThrowsAsync(new Exception());
            var controller = new PlacementDescriptionRepositoryController(repository.Object);

            var actual = await controller.Update(description, true);

            var actionResult = Assert.IsType <ActionResult <bool> >(actual);
            var code         = Assert.IsType <StatusCodeResult>(actionResult.Result);

            Assert.Equal(500, code.StatusCode);
        }
        public async Task Update_returns_200_and_true()
        {
            var description = new UpdatePlacementDescriptionDTO {
                Degree = Degree.Bachelor
            };

            repository.Setup(r => r.UpdatePlacementDescriptionAsync(description)).ReturnsAsync(true);
            var controller = new PlacementDescriptionRepositoryController(repository.Object);

            var actual = await controller.Update(description, true);

            var actionResult   = Assert.IsType <ActionResult <bool> >(actual);
            var okResult       = Assert.IsType <OkObjectResult>(actionResult.Result);
            var hasBeenUpdated = Assert.IsType <bool>(okResult.Value);

            Assert.Equal(200, okResult.StatusCode);
            Assert.True(hasBeenUpdated);
        }
Exemplo n.º 6
0
        public async Task <ActionResult <bool> > Update([FromBody] UpdatePlacementDescriptionDTO description, bool isTest = false)
        {
            try
            {
                var isUpdated = await repository.UpdatePlacementDescriptionAsync(description);

                return(Ok(isUpdated));
            }
            catch (ArgumentException e)
            {
                Util.LogError(e, isTest);
                return(StatusCode(StatusCodes.Status404NotFound));
            }
            catch (Exception e)
            {
                Util.LogError(e, isTest);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }