Exemple #1
0
        private PlacementDescriptionMatch CalculateScore(StudentDetailsDTO student, PlacementDescriptionDetailsDTO description)
        {
            float score = 0;

            score += (float)student.KeywordNames.Where(k => description.KeywordNames.Contains(k)).Count() / 2f;
            score += student.MinSalary >= description.MinSalary ? 1 : 0;
            score += student.MinWorkingHours >= description.MinWorkingHours ? 1 : 0;
            score += student.MaxWorkingHours <= description.MaxWorkingHours ? 1 : 0;
            score += student.Agreement == description.Agreement ? 1 : 0;
            score += student.Location.Equals(description.Location) ? 1 : 0; // Primitive location matching

            return(new PlacementDescriptionMatch
            {
                MatchScore = score,
                Id = description.Id,
                Degree = description.Degree,
                KeywordNames = description.KeywordNames,
                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,
                CompanyName = description.CompanyName
            });
        }
Exemple #2
0
        public ICollection <PlacementDescriptionMatch> CalculateMatches(
            StudentDetailsDTO student,
            ICollection <PlacementDescriptionDetailsDTO> descriptions)
        {
            var sameDegree = descriptions.Where(d => d.Degree == student.Degree);

            var matches = new List <PlacementDescriptionMatch>();

            foreach (var description in sameDegree)
            {
                matches.Add(CalculateScore(student, description));
            }

            var sorted = matches.OrderByDescending(m => m.MatchScore);

            return(sorted.ToList());
        }
Exemple #3
0
        public async Task Get_given_id_returns_200_and_student()
        {
            var student = new StudentDetailsDTO {
                Id = Guid.NewGuid(), Degree = Degree.Bachelor, MinSalary = 100, MinWorkingHours = 5, MaxWorkingHours = 20, Agreement = false, Location = "Nowhere"
            };

            repository.Setup(r => r.GetStudentAsync(student.Id)).ReturnsAsync(student);
            var controller = new StudentRepositoryController(repository.Object);

            var actual = await controller.Get(student.Id, true);

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

            Assert.Equal(200, okResult.StatusCode);
            Assert.Equal(student, actualStudent);
        }
        public void Matches_returns_list_of_placement_descriptions()
        {
            var student = new StudentDetailsDTO
            {
                Id              = Guid.NewGuid(),
                Degree          = Degree.Bachelor,
                KeywordNames    = new [] { "Java", "C#" },
                MinSalary       = 10,
                MinWorkingHours = 10,
                MaxWorkingHours = 20,
                Agreement       = true,
                Location        = "Nørreport"
            };

            var placementDescriptions = new []
            {
                new PlacementDescriptionDetailsDTO {
                    Id = 1, Degree = Degree.Other, KeywordNames = new [] { "Java", "C#" }, MinSalary = 10, MinWorkingHours = 1, MaxWorkingHours = 100, Agreement = false, Location = "Aalborg", 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 = "Test Company"
                },
                new PlacementDescriptionDetailsDTO {
                    Id = 2, Degree = Degree.Bachelor, KeywordNames = new [] { "UML", "C#" }, MinSalary = 100, MinWorkingHours = 10, MaxWorkingHours = 100, Agreement = true, Location = "Copenhagen", 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 = "C# developer", Description = "Join our team in of skilled developers", CompanyName = "Another Test Company"
                }
            };

            var actual = service.CalculateMatches(student, placementDescriptions);

            var expected = new []
            {
                new PlacementDescriptionMatch {
                    Id = 2, MatchScore = 3.5f, Degree = Degree.Bachelor, KeywordNames = new [] { "UML", "C#" }, MinSalary = 100, MinWorkingHours = 10, MaxWorkingHours = 100, Agreement = true, Location = "Copenhagen", 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 = "C# developer", Description = "Join our team in of skilled developers", CompanyName = "Another Test Company"
                }
            };

            Assert.Equal(expected.Count(), actual.Count);

            var actualArray = actual.ToArray();

            for (var i = 0; i < actualArray.Length; i++)
            {
                Assert.Equal(expected[i].MatchScore, actualArray[i].MatchScore);
            }
        }
        public async Task GetStudent_returns_the_requested_student()
        {
            var id     = id1;
            var actual = await repository.GetStudentAsync(id);

            var expected = new StudentDetailsDTO
            {
                Id                      = id,
                Degree                  = Degree.Bachelor,
                KeywordNames            = new [] { "Testing", "C#" },
                MinSalary               = 100,
                MinWorkingHours         = 5,
                MaxWorkingHours         = 20,
                Agreement               = false,
                Location                = "Nowhere",
                PlacementDescriptionIds = new [] { 1, 2 }
            };

            Assert.Equal(expected.Id, actual.Id);
            Assert.Equal(expected.Degree, actual.Degree);
            Assert.Equal(expected.PlacementDescriptionIds, actual.PlacementDescriptionIds);
            Assert.Equal(expected.KeywordNames, actual.KeywordNames);
        }