public void GetLearnerCompletedCourses_LearnerHasLearningPath_ReturnLearnerCompletedCourses() { // Arrange var learner = new User("email", "organizationId"); var learningPath = new LearningPath("learning path", "organizationId"); learner.UpdateLearningPath(learningPath); var course1 = new LearningPathCourseDto("courseId1", "title", 1); var course2 = new LearningPathCourseDto("courseId2", "title", 1); var publishedCourses = new List <LearningPathCourseDto> { course1, course2 }; _repo.Setup(x => x.GetLearningPathPublishedCourses(learningPath.Id, _publishedStatus, default)) .ReturnsAsync(publishedCourses); _repo.Setup(x => x.GetLearnerCompletedLectures(learner.Id, "courseId1", _publishedStatus, default)) .ReturnsAsync(1); _repo.Setup(x => x.GetLearnerCompletedLectures(learner.Id, "courseId2", _publishedStatus, default)) .ReturnsAsync(0); // Act var result = _sut.GetLearnerCompletedCourses(learner, default).Result; // Assert Assert.That(result.CompletedCourses.Count, Is.EqualTo(1)); Assert.That(result.LearningPathCourseCount, Is.EqualTo(2)); }
public void CheckIfDeletable(LearningPath learningPath) { if (!learningPath.IsDeletable) { throw new NonDeletableLearningPathException(); } }
public async Task <LearningPath> Update(Guid Id, [FromBody] LearningPathDTO learningPathDTO) { var learningPath = new LearningPath(learningPathDTO); var result = await _repository.Update(Id, learningPath); return(result); }
public async Task <LearningPath> Insert([FromBody] LearningPathDTO learningPathDTO) { var learningPath = new LearningPath(learningPathDTO); var result = await _repository.Insert(learningPath); return(result); }
public void AddGeneralLearningPathToRepo_WhenCalled_AddGeneralLearningPathToRepo() { var generalLearningPath = new LearningPath("General", "organizationId"); _sut.AddGeneralLearningPathToRepo(generalLearningPath); _repo.Verify(x => x.AddLearningPath(generalLearningPath)); }
public void ConstructorWithNameOrganizationId_WhenCalled_SetPropertiesCorrectly() { _sut = new LearningPath("learning path", "organizationId"); Assert.That(_sut.Id, Is.Not.Null); Assert.That(_sut.Name, Is.EqualTo("learning path")); Assert.That(_sut.OrganizationId, Is.EqualTo("organizationId")); }
public LearningPath CreateGeneralLearningPath(string organizationId) { var generalLearningPath = new LearningPath("General", organizationId, isDeletable: false); generalLearningPath.UpdateDescription("The user default learning path when the user account is created"); return(generalLearningPath); }
public void AddLearningPathToRepo_WhenCalled_AddLearningPathToRepo() { var learningPath = new LearningPath("name", "organizationId"); _sut.AddLearningPathToRepo(learningPath, default).Wait(); _repo.Verify(x => x.AddLearningPath(learningPath, default)); }
public void UpdateLearningPathRepo_WhenCalled_UpdateLearningPathRepo() { var learningPath = new LearningPath("name", "organizationId"); _sut.UpdateLearningPathRepo(learningPath); _repo.Verify(x => x.UpdateLearningPath(learningPath)); }
public void UpdateAdminUserLearningPath_WhenCalled_UpdateAdminUserLearningPath() { var adminUser = new Mock <User>("email", "organizationId"); var generalLearningPath = new LearningPath("General", "organizationId"); _sut.UpdateAdminUserLearningPath(adminUser.Object, generalLearningPath); adminUser.Verify(x => x.UpdateLearningPath(generalLearningPath)); }
public void UpdateUserLearningPath_WhenCalled_UpdateTheUserLearningPath() { var learningPath = new LearningPath("name", "organizationId"); var user = new Mock <User>("email", "organizationId"); _sut.UpdateUserLearningPath(user.Object, learningPath); user.Verify(x => x.UpdateLearningPath(learningPath)); }
public void UpdateLearningPath_WhenCalled_UpdateUserLearningPath() { var learningPath = new LearningPath("learning Path", "organizationId"); _sut.UpdateLearningPath(learningPath); Assert.That(_sut.LearningPath, Is.EqualTo(learningPath)); Assert.That(_sut.LearningPathId, Is.EqualTo(learningPath.Id)); }
public async Task <LearningPathDomainModel> Handle(CreateLearningPathCommand request, CancellationToken cancellationToken) { LearningPath newLearningPath = _mapper.Map <LearningPath>(request.Model); _unitOfWork.LearningPaths.Add(newLearningPath); await _unitOfWork.Complete(); return(_mapper.Map <LearningPathDomainModel>(newLearningPath)); }
public void GetUser_TheUserDoesExist_ReturnLearningPathId() { var learningPath = new LearningPath("name", "organizationId"); _userToReturn.UpdateLearningPath(learningPath); var result = _sut.GetUser("userId", default).Result; Assert.That(result.LearningPathId, Is.EqualTo(_userToReturn.LearningPathId)); }
public async Task <LearningPathDomainModel> Handle(GetLearningPathByIdQuery request, CancellationToken cancellationToken) { LearningPath source = await _unitOfWork.LearningPaths.Get(request.LearningPathId); if (source == null) { throw new LearningPathNotFoundException($"{nameof(GetLearningPathByIdQuery)}, {request.LearningPathId}"); } return(_mapper.Map <LearningPathDomainModel>(source)); }
public void GetLearningPath_LearningPathDoesExist_ReturnTheCorrectLearningPath() { var learningPath = new LearningPath("name", "organizationId"); _repo.Setup(x => x.GetLearningPath("learningPathId", "organizationId", default)) .ReturnsAsync(learningPath); var result = _sut.GetLearningPath("learningPathId", default).Result; Assert.That(result, Is.EqualTo(learningPath)); }
public void GivenTheFollowingLearningPaths(Table table) { var developer = new LearningPath("developer", _organizationId); _factory.AddLearningPath(developer); var businessAnalyst = new LearningPath("Business Analyst", _organizationId); _factory.AddLearningPath(businessAnalyst); _learningPathsIds = new[] { developer.Id, businessAnalyst.Id }; }
public void WhenCalled_ForEachInvitedUser_UpdateTheLearningPath() { var learningPath = new LearningPath("name", "organizationId"); _service.Setup(x => x.GetLearningPathFromRepo(_command.LearningPathId, default)) .ReturnsAsync(learningPath); _sut.Handle(_command, default).Wait(); _service.Verify(x => x.UpdateUserLearningPath(It.IsIn <User>(_usersToInvite), learningPath), Times.Exactly(_usersToInvite.Count)); }
public async Task <IActionResult> Post([FromBody] LearningPath learningPath) { if (learningPath == null) { return(StatusCode(400, false)); } var result = await _unitOfWork.LearningPathService.Inset(learningPath); var status = ControllerService.GetIActionResult(result);// A switch statment that creates a status objected based on the result from the previous method. return(StatusCode(status.StatusCode, status.Response)); }
public void LearningPathIsDeletableAndItHasUsers_ChangeLearningPathCurrentUsersToGeneral() { // Arrange var learningPathUsers = new List <User> { new User("email", "organizationId") }; _service.Setup(x => x.GetLearningPathUsers(_learningPathToDelete.Id, default)) .ReturnsAsync(learningPathUsers); var generalLearningPath = new LearningPath("General", "organizationId", isDeletable: false); _service.Setup(x => x.GetGeneralLearningPath(default))
public void WhenCalled_CreateTheCorrectLearningPathIdClaim() { var user = new User("email", "organizationId"); var learningPath = new LearningPath("name", "organizationId"); user.UpdateLearningPath(learningPath); var result = _sut.CreateUserClaims(user); var learningPathValue = result.FirstOrDefault(x => x.Type == "learningPathId")?.Value; Assert.That(learningPathValue, Is.EqualTo(user.LearningPath.Id)); }
public void CreateLoggedUser_WhenCalled_CreateLoggedUser() { var learningPath = new LearningPath("learning path", "organizationId"); var user = new User("email", "organizationId"); user.UpdateLearningPath(learningPath); var result = _sut.CreateLoggedUser(user); Assert.That(result.Id, Is.EqualTo(user.Id)); Assert.That(result.UserName, Is.EqualTo(user.UserName)); Assert.That(result.LearningPath, Is.EqualTo(user.LearningPath.Name)); }
public void SetUp() { _service = new Mock <ICreateLearningPathService>(); _unitOfWork = new Mock <IUnitOfWork>(); _sut = new CreateLearningPathCommandHandler(_service.Object, _unitOfWork.Object); _command = new CreateLearningPathCommand { Name = "name" }; _learningPathToCreate = new LearningPath(_command.Name, "organizationId"); _service.Setup(x => x.CreateLearningPath(_command.Name)) .Returns(_learningPathToCreate); }
public void SetUp() { _service = new Mock <IDeleteLearningPathService>(); _unitOfWork = new Mock <IUnitOfWork>(); _sut = new DeleteLearningPathCommandHandler(_service.Object, _unitOfWork.Object); _command = new DeleteLearningPathCommand { LearningPathId = "learningPathId" }; _learningPathToDelete = new LearningPath("name", "organizationId"); _service.Setup(x => x.GetLearningPath(_command.LearningPathId, default)) .ReturnsAsync(_learningPathToDelete); }
public async Task <Unit> Handle(DeleteLearningPathCommand request, CancellationToken cancellationToken) { LearningPath source = await _unitOfWork.LearningPaths.Get(request.LearningPathId); if (source == null) { return(Unit.Value); } _unitOfWork.LearningPaths.Remove(source); await _unitOfWork.Complete(); return(Unit.Value); }
public async Task <LearningPathDomainModel> Handle(UpdateLearningPathCommand request, CancellationToken cancellationToken) { LearningPath existingLearningPath = await _unitOfWork.LearningPaths.Get(request.LearningPathId); if (existingLearningPath == null) { throw new LearningPathNotFoundException($"{nameof(UpdateLearningPathCommand)}, {request.LearningPathId}"); } _mapper.Map(request.Model, existingLearningPath); await _unitOfWork.Complete(); return(_mapper.Map <LearningPathDomainModel>(existingLearningPath)); }
public void SetUp() { _service = new Mock <IAddCoursesToLearningPathService>(); _unitOfWork = new Mock <IUnitOfWork>(); _sut = new AddCoursesToLearningPathCommandHandler(_service.Object, _unitOfWork.Object); _command = new AddCoursesToLearningPathCommand { CoursesIds = new List <string> { "courseId" } }; _learningPathToUpdate = new LearningPath("name", "organizationId"); _service.Setup(x => x.GetLearningPathFromRepo(_command.LearningPathId, default)) .ReturnsAsync(_learningPathToUpdate); }
public async Task <LearningPath> Update(Guid Id, LearningPath learningPath) { var filter = Builders <LearningPath> .Filter.Eq(lp => lp.Id, Id); var update = Builders <LearningPath> .Update.Set(lp => lp.Name, learningPath.Name) .Set(lp => lp.Description, learningPath.Description) .Set(lp => lp.Courses, learningPath.Courses) .Set(lp => lp.EmployeeRoles, learningPath.EmployeeRoles) .Set(lp => lp.DateUpdated, DateTime.Now); await _collection.UpdateOneAsync(filter, update); var result = await LoadById(Id); return(result); }
public async Task <int> Insert(LearningPath model) { var parameters = new { model.Name, model.Slug, model.TotalCourses, model.PathIcon, model.LearningPathDescription, @CreateDate = DateTime.Now, @ModifiedDate = DateTime.Now }; var result = await _dapperBaseRepository.Excute("sp_AddLearningPath", parameters); Elastic.LogInformation(model, EnumHelper.GetEnumValue(EnumHelper.SystemEnums.Status, result), MethodBase.GetCurrentMethod().DeclaringType.FullName, "UserIDHERE"); return(result); }
public async Task WhenIUpdateTheLearningPathsOfAPublishedCourse() { var course = new Course("course", _instructorId, DateTime.Now); course.ChangeCourseStatus(PublishedStatus.Instance); _factory.CreateCourse(course); var learningPath = new LearningPath("developer", _organizationId); _factory.AddLearningPath(learningPath); _command = new UpdateCourseLearningPathsCommand { CourseId = course.Id, LearningPathsIds = new[] { learningPath.Id } }; _response = await _client.PutAsync(BaseUrl, Utilities.GetRequestContent(_command)); }