public async Task CreatePlacementDescription_returns_id_of_created()
        {
            var description = new CreatePlacementDescriptionDTO
            {
                Degree          = Degree.Other,
                MinSalary       = 10,
                KeywordNames    = new [] { "Java", "Testing" },
                MinWorkingHours = 1,
                MaxWorkingHours = 100,
                Agreement       = false,
                Location        = "Copenhagen",
                LastApplyDate   = new DateTime(2020, 12, 3),
                Email           = "*****@*****.**",
                Thumbnail       = new Uri("https://starwarsblog.starwars.com/wp-content/uploads/2020/04/best-friend-in-galaxy-chewbacca_TALL.jpg"),
                Title           = "UML designer",
                Description     = "You should be able to do UML diagrams correctly",
                CompanyName     = "Spotify"
            };

            var descriptionList = await Context.PlacementDescriptions.ToListAsync();

            var lastId = descriptionList.OrderByDescending(d => d.Id)
                         .FirstOrDefault()
                         .Id;

            var actual = await repository.CreatePlacementDescriptionAsync(description);

            Assert.Equal(lastId + 1, actual);

            var created = await Context.PlacementDescriptions.FindAsync(actual);

            Assert.Equal(description.KeywordNames, created.Keywords.Select(k => k.Keyword.Name).ToList());
            Assert.Equal(description.CompanyName, created.Company.Name);
        }
Example #2
0
        public async Task <ActionResult <int> > Create([FromBody] CreatePlacementDescriptionDTO description, bool isTest = false)
        {
            try
            {
                var id = await repository.CreatePlacementDescriptionAsync(description);

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