public async Task AddClassSection_StateUnderTest_ExpectedBehavior() { // Arrange var classesController = this.CreateClassesController(); ClassSectionDtoForAdd classSection = null; // Act var result = await classesController.AddClassSection( classSection); // Assert Assert.True(false); this.mockRepository.VerifyAll(); }
public async Task <IActionResult> AddClassSection(ClassSectionDtoForAdd classSection) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (await _repo.ClassSectionExists(classSection.SectionId, classSection.ClassId, classSection.SemesterId)) { return(BadRequest(new { message = "Class Section Already Exist" })); } _response = await _repo.AddClassSectionMapping(classSection); return(Ok(_response)); }
public async Task <ServiceResponse <object> > AddClassSectionMapping(ClassSectionDtoForAdd classSection) { try { var objToCreate = new ClassSection { ClassId = classSection.ClassId, SemesterId = classSection.SemesterId, SectionId = classSection.SectionId, SchoolBranchId = _LoggedIn_BranchID, NumberOfStudents = classSection.NumberOfStudents, Active = true, CreatedById = _LoggedIn_UserID, CreatedDatetime = DateTime.UtcNow }; await _context.ClassSections.AddAsync(objToCreate); await _context.SaveChangesAsync(); _serviceResponse.Success = true; _serviceResponse.Message = CustomMessage.Added; } catch (DbUpdateException ex) { if (ex.InnerException.Message.Contains("Cannot insert duplicate key row")) { _serviceResponse.Success = false; _serviceResponse.Message = CustomMessage.SqlDuplicateRecord; } else { throw ex; } } return(_serviceResponse); }