public bool ContainsGroupName(GroupModel groupModel) { using (var uow = _unitOfWorkFactory.GetUnitOfWork()) { var group = uow.GroupRepository.GetAll().FirstOrDefault(g => g.Name == groupModel.Name); return group != null; } }
public bool CheckIfGroupNameExists(GroupModel groupModel) { using (var context = new WorldOfWordsDatabaseContext()) { var group = context.Groups.FirstOrDefault(g => g.Name == groupModel.Name); return group != null; } }
public Group Map(GroupModel groupModel) { Group newGroup = new Group() { Name = groupModel.Name, CourseId = groupModel.CourseId, OwnerId = groupModel.OwnerId }; return newGroup; }
public bool Add(GroupModel groupModel) { using (var context = new WorldOfWordsDatabaseContext()) { var newGroup = _mapper.MapToGroup(groupModel); context.Groups.Add(newGroup); context.SaveChanges(); return true; } }
public void ContainsGroupNameTestPositive() { // Arrange groupRepository.Setup(x => x.GetAll()).Returns(groups); var groupModel = new GroupModel { Name = "Name1" }; // Act bool result1 = groupService.ContainsGroupName(groupModel); // Assert Assert.IsTrue(result1, "Should return true if a group exists with a such name"); }
public IHttpActionResult Post(GroupModel newGroup) { if (newGroup == null) { throw new ArgumentNullException("Parameter could not be null", "newGroup"); } if (!_groupService.ContainsGroupName(newGroup)) { var groupToAdd = _groupMapper.Map(newGroup); _groupService.Add(groupToAdd); return Ok(); } return BadRequest(string.Format("Group {0} already exist!", newGroup.Name)); }
public void ContainsGroupNameTestNegative() { // Arrange groupRepository.Setup(x => x.GetAll()).Returns(groups); var groupModel = new GroupModel { Name = "Name that doesn't exist" }; // Act bool result1 = groupService.ContainsGroupName(groupModel); // Assert Assert.IsFalse(result1, "Should return false if a group doesn't exist with a such name"); }
public IHttpActionResult Post(GroupModel newGroup) { if (newGroup == null) { throw new ArgumentNullException("Parameter could not be null", "newGroup"); } if (!_groupService.CheckIfGroupNameExists(newGroup)) { if (_groupService.Add(newGroup)) { return Ok(); } } return BadRequest(string.Format("Group {0} already exist!", newGroup.Name)); }
public void Post_NewGroup_ReturnsOkResult_Positive() { var initial = new GroupModel { Name = "Some Group Name", OwnerId = 1, CourseId = 1 }; GenerateData("1", new[] { "NoRoles" }); Mock<IGroupForListingMapper> groupForListingMapper = new Mock<IGroupForListingMapper>(); Mock<IGroupService> groupService = new Mock<IGroupService>(); Mock<IEnrollmentService> enrollmentService = new Mock<IEnrollmentService>(); Mock<IWordProgressService> wordProgressService = new Mock<IWordProgressService>(); Mock<IWordSuiteService> wordsuiteService = new Mock<IWordSuiteService>(); Mock<ICourseService> courseService = new Mock<ICourseService>(); Mock<ICourseForGroupMapper> courseMapper = new Mock<ICourseForGroupMapper>(); Mock<IGroupMapper> groupMapper = new Mock<IGroupMapper>(); GroupController groupController = new GroupController(groupService.Object, groupForListingMapper.Object, enrollmentService.Object, wordProgressService.Object, wordsuiteService.Object, courseService.Object, courseMapper.Object, groupMapper.Object); groupService.Setup(x => x.CheckIfGroupNameExists(initial)).Returns(false); groupService.Setup(x => x.Add(initial)).Returns(true); var actual = groupController.Post(initial); Assert.IsInstanceOf(typeof(OkResult), actual); }