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); }
public async Task <int> CreatePlacementDescriptionAsync(CreatePlacementDescriptionDTO description) { var entity = new PlacementDescription { Degree = description.Degree, Keywords = GetKeywords(description.KeywordNames).ToList(), MinSalary = description.MinSalary, MinWorkingHours = description.MinWorkingHours, MaxWorkingHours = description.MaxWorkingHours, Agreement = description.Agreement, Location = description.Location, LastApplyDate = description.LastApplyDate, Email = description.Email, Thumbnail = description.Thumbnail, Title = description.Title, Description = description.Description, Company = await GetCompany(description.CompanyName) }; await context.PlacementDescriptions.AddAsync(entity); await context.SaveChangesAsync(); return(entity.Id); }
public async Task Create_returns_500_on_internal_error() { var description = new CreatePlacementDescriptionDTO(); repository.Setup(r => r.CreatePlacementDescriptionAsync(description)).ThrowsAsync(new Exception()); var controller = new PlacementDescriptionRepositoryController(repository.Object); var actual = await controller.Create(description, true); var actionResult = Assert.IsType <ActionResult <int> >(actual); var code = Assert.IsType <StatusCodeResult>(actionResult.Result); Assert.Equal(500, code.StatusCode); }
public async Task Create_returns_200_and_id_of_created_student() { var nextMockedId = 10; var description = new CreatePlacementDescriptionDTO(); repository.Setup(r => r.CreatePlacementDescriptionAsync(description)).ReturnsAsync(nextMockedId); var controller = new PlacementDescriptionRepositoryController(repository.Object); var actual = await controller.Create(description, true); var actionResult = Assert.IsType <ActionResult <int> >(actual); var okResult = Assert.IsType <OkObjectResult>(actionResult.Result); var actualId = Assert.IsType <int>(okResult.Value); Assert.Equal(200, okResult.StatusCode); Assert.Equal(nextMockedId, actualId); }
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)); } }