public async Task ShouldGetAllStudentGuardiansAsync() { // given var randomStudentGuardians = new List <StudentGuardian>(); for (var i = 0; i <= GetRandomNumber(); i++) { StudentGuardian randomStudentGuardian = await PostStudentGuardianAsync(); randomStudentGuardians.Add(randomStudentGuardian); } List <StudentGuardian> inputStudentGuardians = randomStudentGuardians; List <StudentGuardian> expectedStudentGuardians = inputStudentGuardians; // when List <StudentGuardian> actualStudentGuardians = await this.otripleSApiBroker.GetAllStudentGuardiansAsync(); // then foreach (StudentGuardian expectedStudentGuardian in expectedStudentGuardians) { StudentGuardian actualStudentGuardian = actualStudentGuardians.Single(studentGuardian => studentGuardian.StudentId == expectedStudentGuardian.StudentId); actualStudentGuardian.Should().BeEquivalentTo(expectedStudentGuardian); await DeleteStudentGuardianAsync(actualStudentGuardian); } }
public static bool InsertStudentGuardian(StudentGuardian model) { using (SqlConnection conn = new SqlConnection(Connection.StringConnection)) { conn.Open(); using (SqlCommand comm = new SqlCommand("INSERT INTO student.information_guardian VALUES (@StudentID,@MotherName,@MotherMobile,@FatherName,@FatherMobile,@GuardianName,@GuardianMobile,@GuardianRelation)", conn)) { comm.Parameters.AddWithValue("@StudentID", model.StudentID); comm.Parameters.AddWithValue("@MotherName", model.MotherName); comm.Parameters.AddWithValue("@MotherMobile", model.MotherMobile); comm.Parameters.AddWithValue("@FatherName", model.FatherName); comm.Parameters.AddWithValue("@FatherMobile", model.FatherMobile); comm.Parameters.AddWithValue("@GuardianName", model.GuardianName); comm.Parameters.AddWithValue("@GuardianMobile", model.GuardianMobile); comm.Parameters.AddWithValue("@GuardianRelation", model.GuardianRelation); if (comm.ExecuteNonQuery() > 0) { return(true); } else { return(false); } } } }
public async Task ShouldThrowValidationExceptionOnModifyWhenStudentIdIsInvalidAndLogItAsync() { //given Guid invalidStudentId = Guid.Empty; DateTimeOffset dateTime = GetRandomDateTime(); StudentGuardian randomStudentGuardian = CreateRandomStudentGuardian(dateTime); StudentGuardian invalidStudentGuardian = randomStudentGuardian; invalidStudentGuardian.StudentId = invalidStudentId; var invalidStudentGuardianInputException = new InvalidStudentGuardianInputException( parameterName: nameof(StudentGuardian.StudentId), parameterValue: invalidStudentGuardian.StudentId); var expectedStudentGuardianValidationException = new StudentGuardianValidationException(invalidStudentGuardianInputException); //when ValueTask <StudentGuardian> modifyStudentGuardianTask = this.studentGuardianService.ModifyStudentGuardianAsync(invalidStudentGuardian); //then await Assert.ThrowsAsync <StudentGuardianValidationException>(() => modifyStudentGuardianTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedStudentGuardianValidationException))), Times.Once); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldPutStudentGuardianAsync() { // given Student inputStudent = await PostStudentAsync(); Guardian inputGuardian = await PostGuardianAsync(); StudentGuardian randomStudentGuardian = CreateRandomStudentGuardian(inputStudent.Id, inputGuardian.Id); StudentGuardian inputStudentGuardian = randomStudentGuardian; await this.otripleSApiBroker.PostStudentGuardianAsync(inputStudentGuardian); StudentGuardian modifiedStudentGuardian = randomStudentGuardian.DeepClone(); modifiedStudentGuardian.UpdatedDate = DateTimeOffset.UtcNow; // when await this.otripleSApiBroker.PutStudentGuardianAsync(modifiedStudentGuardian); StudentGuardian actualStudentGuardian = await this.otripleSApiBroker.GetStudentGuardianAsync( randomStudentGuardian.StudentId, randomStudentGuardian.GuardianId); // then actualStudentGuardian.Should().BeEquivalentTo(modifiedStudentGuardian); await this.otripleSApiBroker.DeleteStudentGuardianAsync(actualStudentGuardian.StudentId, actualStudentGuardian.GuardianId); await this.otripleSApiBroker.DeleteGuardianByIdAsync(actualStudentGuardian.GuardianId); await this.otripleSApiBroker.DeleteStudentByIdAsync(actualStudentGuardian.StudentId); }
public async Task ShouldRetrieveStudentGuardianById() { // given DateTimeOffset inputDateTime = GetRandomDateTime(); StudentGuardian randomStudentGuardian = CreateRandomStudentGuardian(inputDateTime); StudentGuardian storageStudentGuardian = randomStudentGuardian; StudentGuardian expectedStudentGuardian = storageStudentGuardian; this.storageBrokerMock.Setup(broker => broker.SelectStudentGuardianByIdAsync(randomStudentGuardian.StudentId, randomStudentGuardian.GuardianId)) .Returns(new ValueTask <StudentGuardian>(randomStudentGuardian)); // when StudentGuardian actualStudentGuardian = await this.studentGuardianService.RetrieveStudentGuardianByIdAsync(randomStudentGuardian.StudentId, randomStudentGuardian.GuardianId); // then actualStudentGuardian.Should().BeEquivalentTo(expectedStudentGuardian); this.storageBrokerMock.Verify(broker => broker.SelectStudentGuardianByIdAsync(randomStudentGuardian.StudentId, randomStudentGuardian.GuardianId), Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldPostStudentGuardianAsync() { // given Student persistedStudent = await PostStudentAsync(); Guardian persistedGuardian = await PostGuardianAsync(); StudentGuardian randomStudentGuardian = CreateRandomStudentGuardian( persistedStudent.Id, persistedGuardian.Id); StudentGuardian inputStudentGuardian = randomStudentGuardian; StudentGuardian expectedStudentGuardian = inputStudentGuardian; // when StudentGuardian persistedStudentGuardian = await this.otripleSApiBroker.PostStudentGuardianAsync(inputStudentGuardian); StudentGuardian actualStudentGuardian = await this.otripleSApiBroker.GetStudentGuardianAsync(persistedStudentGuardian.StudentId, persistedStudentGuardian.GuardianId); // then actualStudentGuardian.Should().BeEquivalentTo(expectedStudentGuardian); await this.otripleSApiBroker.DeleteStudentGuardianAsync(actualStudentGuardian.StudentId, actualStudentGuardian.GuardianId); await this.otripleSApiBroker.DeleteGuardianByIdAsync(actualStudentGuardian.GuardianId); await this.otripleSApiBroker.DeleteStudentByIdAsync(actualStudentGuardian.StudentId); }
public static bool UpdateStudentGuardian(StudentGuardian model) { using (SqlConnection conn = new SqlConnection(Connection.StringConnection)) { conn.Open(); using (SqlCommand comm = new SqlCommand("UPDATE student.information_guardian SET MotherName = @MotherName, MotherMobile = @MotherMobile, FatherName = @FatherName, FatherMobile = @FatherMobile, GuardianName = @GuardianName, GuardianMobile = @GuardianMobile, GuardianRelation = @GuardianRelation WHERE StudentGuardianID = @StudentGuardianID", conn)) { comm.Parameters.AddWithValue("@StudentGuardianID", model.StudentGuardianID); comm.Parameters.AddWithValue("@MotherName", model.MotherName); comm.Parameters.AddWithValue("@MotherMobile", model.MotherMobile); comm.Parameters.AddWithValue("@FatherName", model.FatherName); comm.Parameters.AddWithValue("@FatherMobile", model.FatherMobile); comm.Parameters.AddWithValue("@GuardianName", model.GuardianName); comm.Parameters.AddWithValue("@GuardianMobile", model.GuardianMobile); comm.Parameters.AddWithValue("@GuardianRelation", model.GuardianRelation); if (comm.ExecuteNonQuery() > 0) { return(true); } else { return(false); } } } }
public IHttpActionResult PostStudentGuardian(StudentGuardian studentGuardian) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.StudentGuardian.Add(studentGuardian); try { db.SaveChanges(); } catch (DbUpdateException) { if (StudentGuardianExists(studentGuardian.studentId)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = studentGuardian.studentId }, studentGuardian)); }
public ValueTask <StudentGuardian> AddStudentGuardianAsync(StudentGuardian studentGuardian) => TryCatch(async() => { ValidateStudentGuardianOnCreate(studentGuardian); return(await this.storageBroker.InsertStudentGuardianAsync(studentGuardian)); });
private void ValidateInvalidAuditFields(StudentGuardian studentGuardian) { switch (studentGuardian) { case { } when IsInvalid(studentGuardian.CreatedBy): throw new InvalidStudentGuardianInputException( parameterName: nameof(StudentGuardian.CreatedBy), parameterValue: studentGuardian.CreatedBy); case { } when IsInvalid(studentGuardian.UpdatedBy): throw new InvalidStudentGuardianInputException( parameterName: nameof(StudentGuardian.UpdatedBy), parameterValue: studentGuardian.UpdatedBy); case { } when IsInvalid(studentGuardian.CreatedDate): throw new InvalidStudentGuardianInputException( parameterName: nameof(StudentGuardian.CreatedDate), parameterValue: studentGuardian.CreatedDate); case { } when IsInvalid(studentGuardian.UpdatedDate): throw new InvalidStudentGuardianInputException( parameterName: nameof(StudentGuardian.UpdatedDate), parameterValue: studentGuardian.UpdatedDate); } }
public SaveResult ClientSave(JObject saveBundle) { var guardian = new StudentGuardian(ctxManager, StudentPerson); ctxManager.BeforeSaveEntitiesDelegate += guardian.BeforeSaveEntities; return(ctxManager.SaveChanges(saveBundle)); }
private void ValidateStudentGuardianIsNull(StudentGuardian studentGuardian) { if (studentGuardian is null) { throw new NullStudentGuardianException(); } }
public IHttpActionResult PutStudentGuardian(int id, StudentGuardian studentGuardian) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != studentGuardian.studentId) { return(BadRequest()); } db.Entry(studentGuardian).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!StudentGuardianExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async void ShouldThrowValidationExceptionOnModifyWhenStudentGuardianIsNullAndLogItAsync() { //given StudentGuardian invalidStudentGuardian = null; var nullStudentGuardianException = new NullStudentGuardianException(); var expectedStudentGuardianValidationException = new StudentGuardianValidationException(nullStudentGuardianException); //when ValueTask <StudentGuardian> modifyStudentGuardianTask = this.studentGuardianService.ModifyStudentGuardianAsync(invalidStudentGuardian); //then await Assert.ThrowsAsync <StudentGuardianValidationException>(() => modifyStudentGuardianTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedStudentGuardianValidationException))), Times.Once); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
public static List <StudentGuardian> GetGuardians() { List <StudentGuardian> guardians = new List <StudentGuardian>(); using (SqlConnection conn = new SqlConnection(Connection.StringConnection)) { conn.Open(); using (SqlCommand comm = new SqlCommand("SELECT * FROM student.information_guardian ORDER BY StudentID ASC", conn)) { using (SqlDataReader reader = comm.ExecuteReader()) { while (reader.Read()) { StudentGuardian guardian = new StudentGuardian() { StudentGuardianID = Convert.ToInt32(reader["StudentGuardianID"]), MotherName = Convert.ToString(reader["MotherName"]), MotherMobile = Convert.ToString(reader["MotherMobile"]), FatherName = Convert.ToString(reader["FatherName"]), FatherMobile = Convert.ToString(reader["FatherMobile"]), GuardianName = Convert.ToString(reader["GuardianName"]), GuardianMobile = Convert.ToString(reader["GuardianMobile"]), GuardianRelation = Convert.ToString(reader["GuardianRelation"]) }; guardians.Add(guardian); } } } } return(guardians); }
public static StudentGuardian GetStudentGuardian(int StudentID) { StudentGuardian guardian = new StudentGuardian(); using (SqlConnection conn = new SqlConnection(Connection.StringConnection)) { conn.Open(); using (SqlCommand comm = new SqlCommand("SELECT * FROM student.information_guardian WHERE StudentID = @StudentID", conn)) { comm.Parameters.AddWithValue("@StudentID", StudentID); using (SqlDataReader reader = comm.ExecuteReader()) { while (reader.Read()) { guardian = new StudentGuardian() { StudentGuardianID = Convert.ToInt32(reader["StudentGuardianID"]), MotherName = Convert.ToString(reader["MotherName"]), MotherMobile = Convert.ToString(reader["MotherMobile"]), FatherName = Convert.ToString(reader["FatherName"]), FatherMobile = Convert.ToString(reader["FatherMobile"]), GuardianName = Convert.ToString(reader["GuardianName"]), GuardianMobile = Convert.ToString(reader["GuardianMobile"]), GuardianRelation = Convert.ToString(reader["GuardianRelation"]) }; } } } } return(guardian); }
public async void ShouldThrowValidationExceptionOnAddWhenStudentGuardianIsNullAndLogItAsync() { // given StudentGuardian randomStudentGuardian = default; StudentGuardian nullStudentGuardian = randomStudentGuardian; var nullStudentGuardianException = new NullStudentGuardianException(); var expectedStudentGuardianValidationException = new StudentGuardianValidationException(nullStudentGuardianException); // when ValueTask <StudentGuardian> addStudentGuardianTask = this.studentGuardianService.AddStudentGuardianAsync(nullStudentGuardian); // then await Assert.ThrowsAsync <StudentGuardianValidationException>(() => addStudentGuardianTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedStudentGuardianValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertStudentGuardianAsync(It.IsAny <StudentGuardian>()), Times.Never); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }
private void button1_Click(object sender, EventArgs e) { StudentGuardian guardian = new StudentGuardian() { StudentGuardianID = _guardian.StudentGuardianID, StudentID = _StudentID, MotherName = txtMotherName.Text, MotherMobile = txtMotherMobile.Text, FatherName = txtFatherName.Text, FatherMobile = txtFatherMobile.Text, GuardianName = txtGuardianName.Text, GuardianMobile = txtGuardianMobile.Text, GuardianRelation = txtGuardianRelation.Text }; if (saving == SavingOptions.INSERT) { StudentInfo.SaveStudentGuardian(guardian); } else { StudentInfo.UpdateStudentGuardian(guardian); } MessageBox.Show("Guardian information has been successfully saved!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); Dispose(); }
public async void ShouldThrowValidationExceptionOnModifyWhenUpdatedDateIsSameAsCreatedDateAndLogItAsync() { // given DateTimeOffset dateTime = GetRandomDateTime(); StudentGuardian randomStudentGuardian = CreateRandomStudentGuardian(dateTime); StudentGuardian inputStudentGuardian = randomStudentGuardian; var invalidStudentGuardianInputException = new InvalidStudentGuardianInputException( parameterName: nameof(StudentGuardian.UpdatedDate), parameterValue: inputStudentGuardian.UpdatedDate); var expectedStudentGuardianValidationException = new StudentGuardianValidationException(invalidStudentGuardianInputException); // when ValueTask <StudentGuardian> modifyStudentGuardianTask = this.studentGuardianService.ModifyStudentGuardianAsync(inputStudentGuardian); // then await Assert.ThrowsAsync <StudentGuardianValidationException>(() => modifyStudentGuardianTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedStudentGuardianValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectStudentGuardianByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Never); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }
private void ValidateStudentGuardianOnCreate(StudentGuardian studentGuardian) { ValidateStudentGuardianIsNull(studentGuardian); ValidateStudentGuardianRequiredFields(studentGuardian); ValidateInvalidAuditFields(studentGuardian); ValidateInvalidAuditFieldsOnCreate(studentGuardian); }
private void ValidateStudentGuardianOnModify(StudentGuardian studentGuardian) { ValidateStudentGuardianIsNull(studentGuardian); ValidateStudentGuardianRequiredFields(studentGuardian); ValidateInvalidAuditFields(studentGuardian); ValidateDatesAreNotSame(studentGuardian); ValidateUpdatedDateIsRecent(studentGuardian); }
public ActionResult DeleteConfirmed(int id) { StudentGuardian studentGuardian = db.StudentGuardians.Find(id); db.StudentGuardians.Remove(studentGuardian); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task ShouldThrowValidationExceptionOnModifyIfStorageCreatedDateNotSameAsCreateDateAndLogItAsync() { // given int randomNumber = GetRandomNumber(); int randomMinutes = randomNumber; DateTimeOffset randomDate = GetRandomDateTime(); StudentGuardian randomStudentGuardian = CreateRandomStudentGuardian(randomDate); StudentGuardian invalidStudentGuardian = randomStudentGuardian; invalidStudentGuardian.UpdatedDate = randomDate; StudentGuardian storageStudentGuardian = randomStudentGuardian.DeepClone(); Guid studentId = invalidStudentGuardian.StudentId; Guid semesterCourseId = invalidStudentGuardian.GuardianId; invalidStudentGuardian.CreatedDate = storageStudentGuardian.CreatedDate.AddMinutes(randomNumber); var invalidStudentGuardianInputException = new InvalidStudentGuardiantException( parameterName: nameof(StudentGuardian.CreatedDate), parameterValue: invalidStudentGuardian.CreatedDate); var expectedStudentGuardianValidationException = new StudentGuardianValidationException(invalidStudentGuardianInputException); this.storageBrokerMock.Setup(broker => broker.SelectStudentGuardianByIdAsync(studentId, semesterCourseId)) .ReturnsAsync(storageStudentGuardian); this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTime()) .Returns(randomDate); // when ValueTask <StudentGuardian> modifyStudentGuardianTask = this.studentGuardianService.ModifyStudentGuardianAsync(invalidStudentGuardian); // then await Assert.ThrowsAsync <StudentGuardianValidationException>(() => modifyStudentGuardianTask.AsTask()); this.dateTimeBrokerMock.Verify(broker => broker.GetCurrentDateTime(), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectStudentGuardianByIdAsync( invalidStudentGuardian.StudentId, invalidStudentGuardian.GuardianId), Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedStudentGuardianValidationException))), Times.Once); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
public async ValueTask <StudentGuardian> DeleteStudentGuardianAsync(StudentGuardian studentGuardian) { EntityEntry <StudentGuardian> studentGuardianEntityEntry = this.StudentGuardians.Remove(studentGuardian); await this.SaveChangesAsync(); return(studentGuardianEntityEntry.Entity); }
public ValueTask <StudentGuardian> RetrieveStudentGuardianByIdAsync(Guid studentId, Guid guardianId) => TryCatch(async() => { ValidateStudentGuardianIdIsNull(studentId, guardianId); StudentGuardian storageStudentGuardian = await this.storageBroker.SelectStudentGuardianByIdAsync(studentId, guardianId); ValidateStorageStudentGuardian(storageStudentGuardian, studentId, guardianId); return(storageStudentGuardian); });
public async ValueTask <StudentGuardian> InsertStudentGuardianAsync(StudentGuardian studentGuardian) { EntityEntry <StudentGuardian> studentGuardianEntityEntry = await this.StudentGuardians.AddAsync(studentGuardian); await this.SaveChangesAsync(); return(studentGuardianEntityEntry.Entity); }
private void ValidateDatesAreNotSame(StudentGuardian studentGuardian) { if (studentGuardian.CreatedDate == studentGuardian.UpdatedDate) { throw new InvalidStudentGuardianInputException( parameterName: nameof(StudentGuardian.UpdatedDate), parameterValue: studentGuardian.UpdatedDate); } }
private void ValidateUpdatedDateIsRecent(StudentGuardian studentGuardian) { if (IsDateNotRecent(studentGuardian.UpdatedDate)) { throw new InvalidStudentGuardianInputException( parameterName: nameof(StudentGuardian.UpdatedDate), parameterValue: studentGuardian.UpdatedDate); } }
// GET: StudentGuardians/Create public ActionResult Create(int?studentId, int?guardianId) { StudentGuardian studentGuardian = new StudentGuardian(); var studentID = Convert.ToInt32(studentId); var guardianID = Convert.ToInt32(guardianId); studentGuardian.Student_User_ID = studentID; studentGuardian.Guardian_User_ID = guardianID; return(View(studentGuardian)); }
private static void ValidateStorageStudentGuardian( StudentGuardian storageStudentGuardian, Guid semesterCourseId, Guid studentId) { if (storageStudentGuardian == null) { throw new NotFoundStudentGuardianException(semesterCourseId, studentId); } }