public async void ShouldThrowValidationExceptionOnAddWhenContactIdIsInvalidAndLogItAsync() { // given StudentContact randomStudentContact = CreateRandomStudentContact(); StudentContact inputStudentContact = randomStudentContact; inputStudentContact.ContactId = default; var invalidStudentContactInputException = new InvalidStudentContactInputException( parameterName: nameof(StudentContact.ContactId), parameterValue: inputStudentContact.ContactId); var expectedStudentContactValidationException = new StudentContactValidationException(invalidStudentContactInputException); // when ValueTask <StudentContact> addStudentContactTask = this.studentContactService.AddStudentContactAsync(inputStudentContact); // then await Assert.ThrowsAsync <StudentContactValidationException>(() => addStudentContactTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedStudentContactValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertStudentContactAsync(It.IsAny <StudentContact>()), Times.Never); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }
public ContactDetailsViewModel(StudentContact contact) { this.Contact = contact; if (string.IsNullOrWhiteSpace(Contact.Phone)) { Contact.Phone = "xxx-xxx-xxxx"; } if (string.IsNullOrWhiteSpace(Contact.Mobile)) { Contact.Mobile = "xxx-xxx-xxxx"; } if (string.IsNullOrWhiteSpace(Contact.PickUpSched)) { Contact.PickUpSched = "Pickup allowed. Schedule not set"; } if (string.IsNullOrWhiteSpace(Contact.CustodyNote)) { Contact.CustodyNote = "Custody Issue. Reason not listed."; } ValidateAddress(); }
public async void ShouldThrowValidationExceptionOnAddWhenStudentContactIsNullAndLogItAsync() { // given StudentContact randomStudentContact = default; StudentContact nullStudentContact = randomStudentContact; var nullStudentContactException = new NullStudentContactException(); var expectedStudentContactValidationException = new StudentContactValidationException(nullStudentContactException); // when ValueTask <StudentContact> addStudentContactTask = this.studentContactService.AddStudentContactAsync(nullStudentContact); // then await Assert.ThrowsAsync <StudentContactValidationException>(() => addStudentContactTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedStudentContactValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertStudentContactAsync(It.IsAny <StudentContact>()), Times.Never); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }
private void ValidateStudentContactIsNull(StudentContact studentContact) { if (studentContact is null) { throw new NullStudentContactException(); } }
public async Task ShouldThrowDependencyExceptionOnAddWhenDbExceptionOccursAndLogItAsync() { // given StudentContact randomStudentContact = CreateRandomStudentContact(); StudentContact inputStudentContact = randomStudentContact; var databaseUpdateException = new DbUpdateException(); var expectedStudentContactDependencyException = new StudentContactDependencyException(databaseUpdateException); this.storageBrokerMock.Setup(broker => broker.InsertStudentContactAsync(inputStudentContact)) .ThrowsAsync(databaseUpdateException); // when ValueTask <StudentContact> addStudentContactTask = this.studentContactService.AddStudentContactAsync(inputStudentContact); // then await Assert.ThrowsAsync <StudentContactDependencyException>(() => addStudentContactTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedStudentContactDependencyException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertStudentContactAsync(inputStudentContact), Times.Once); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldGetAllStudentContactAsync() { // given IEnumerable <StudentContact> randomStudentContacts = CreateRandomStudentContacts(); List <StudentContact> inputStudentContacts = randomStudentContacts.ToList(); foreach (StudentContact studentContact in inputStudentContacts) { await this.otripleSApiBroker.PostStudentContactAsync(studentContact); } List <StudentContact> expectedStudentContacts = inputStudentContacts; // when List <StudentContact> actualStudentContacts = await this.otripleSApiBroker.GetAllStudentContactsAsync(); // then foreach (StudentContact expectedStudentContact in expectedStudentContacts) { StudentContact actualStudentContact = actualStudentContacts.Single( studentContact => studentContact.StudentId == expectedStudentContact.StudentId && studentContact.ContactId == expectedStudentContact.ContactId ); StudentContact expectedReturnedStudentContact = CreateExpectedStudentContact(expectedStudentContact); actualStudentContact.Should().BeEquivalentTo(expectedReturnedStudentContact); await this.otripleSApiBroker.DeleteStudentContactAsync(actualStudentContact.StudentId, actualStudentContact.ContactId); } }
public async Task ShouldPostStudentContactAsync() { // given StudentContact randomStudentContact = CreateRandomStudentContact(); StudentContact inputStudentContact = randomStudentContact; StudentContact expectedStudentContact = inputStudentContact; // when await this.otripleSApiBroker.PostStudentContactAsync(inputStudentContact); StudentContact actualStudentContact = await this.otripleSApiBroker.GetStudentContactAsync( inputStudentContact.StudentId, inputStudentContact.ContactId); // then actualStudentContact.Should().BeEquivalentTo(expectedStudentContact, options => options .Excluding(StudentContact => StudentContact.Student) .Excluding(StudentContact => StudentContact.Contact)); await this.otripleSApiBroker.DeleteStudentContactAsync( actualStudentContact.StudentId, actualStudentContact.ContactId); }
public async Task ShouldAddStudentStudentContactAsync() { // given StudentContact randomStudentContact = CreateRandomStudentContact(); StudentContact inputStudentContact = randomStudentContact; StudentContact storageStudentContact = randomStudentContact; StudentContact expectedStudentContact = storageStudentContact; this.storageBrokerMock.Setup(broker => broker.InsertStudentContactAsync(inputStudentContact)) .ReturnsAsync(storageStudentContact); // when StudentContact actualStudentContact = await this.studentContactService.AddStudentContactAsync(inputStudentContact); // then actualStudentContact.Should().BeEquivalentTo(expectedStudentContact); this.storageBrokerMock.Verify(broker => broker.InsertStudentContactAsync(inputStudentContact), Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldRetrieveStudentContactById() { // given DateTimeOffset inputDateTime = GetRandomDateTime(); StudentContact randomStudentContact = CreateRandomStudentContact(inputDateTime); StudentContact storageStudentContact = randomStudentContact; StudentContact expectedStudentContact = storageStudentContact; this.storageBrokerMock.Setup(broker => broker.SelectStudentContactByIdAsync(randomStudentContact.StudentId, randomStudentContact.ContactId)) .Returns(new ValueTask <StudentContact>(randomStudentContact)); // when StudentContact actualStudentContact = await this.studentContactService.RetrieveStudentContactByIdAsync(randomStudentContact.StudentId, randomStudentContact.ContactId); // then actualStudentContact.Should().BeEquivalentTo(expectedStudentContact); this.storageBrokerMock.Verify(broker => broker.SelectStudentContactByIdAsync(randomStudentContact.StudentId, randomStudentContact.ContactId), Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); }
public ValueTask <StudentContact> AddStudentContactAsync(StudentContact studentContact) => TryCatch(async() => { ValidateStudentContactOnCreate(studentContact); return(await this.storageBroker.InsertStudentContactAsync(studentContact)); });
private static void ValidateStorageStudentContact( StudentContact storageStudentContact, Guid studentId, Guid contactId) { if (storageStudentContact == null) { throw new NotFoundStudentContactException(studentId, contactId); } }
public async ValueTask <StudentContact> InsertStudentContactAsync( StudentContact StudentContact) { EntityEntry <StudentContact> StudentContactEntityEntry = await this.StudentContacts.AddAsync(StudentContact); await this.SaveChangesAsync(); return(StudentContactEntityEntry.Entity); }
public async ValueTask <StudentContact> DeleteStudentContactAsync( StudentContact StudentContact) { EntityEntry <StudentContact> StudentContactEntityEntry = this.StudentContacts.Remove(StudentContact); await this.SaveChangesAsync(); return(StudentContactEntityEntry.Entity); }
public ValueTask <StudentContact> RetrieveStudentContactByIdAsync(Guid studentId, Guid contactId) => TryCatch(async() => { ValidateStudentContactIdIsNull(studentId, contactId); StudentContact storageStudentContact = await this.storageBroker.SelectStudentContactByIdAsync(studentId, contactId); ValidateStorageStudentContact(storageStudentContact, studentId, contactId); return(storageStudentContact); });
public void testStudentContactSIF20() { Adk.SifVersion = SifVersion.SIF20r1; StringMapAdaptor sma = createStudentContactFields(); StudentContact sc = new StudentContact(); sc.Type = "E4"; Mappings m = fCfg.Mappings.GetMappings("Default").Select(null, null, null); m.MapOutbound(sma, sc, SifVersion.SIF20r1); String value = sc.ToXml(); Console.WriteLine(value); // Verify that the phone number is properly escaped int loc = value.IndexOf("<Number>M&W</Number>"); Assertion.Assert("Phone number should be escaped", loc > -1); // Verify that the @Type attribute is not rendered in SIF 2.0 loc = value.IndexOf("Type=\"E4\""); Assertion.AssertEquals("Type Attribute should not be rendered", -1, loc); sc.SifVersion = SifVersion.SIF20r1; Element e = sc .GetElementOrAttribute("//PhoneNumber[@Type='0096']/Number"); Assertion.AssertNotNull("School PhoneNumber should be mapped", e); Assertion.AssertEquals("School phone", "8014504555", e.TextValue); e = sc.GetElementOrAttribute("//PhoneNumber[@Type='0350'][1]/Number"); Assertion.AssertNotNull("School PhoneNumber should be mapped", e); // Note the " " Space at the end of the value. This should be there, // according to the mapping Assertion.AssertEquals("School phone", "8014505555 ", e.TextValue); e = sc.GetElementOrAttribute("//PhoneNumber[@Type='0350'][2]/Number"); Assertion.AssertNull("School PhoneNumber should not be mapped", e); AddressList al = sc.AddressList; if (al != null) { foreach (Address addr in al) { Assertion.AssertNull("Country should be null", addr.Country); if (addr.Type.Equals("1075")) { Assertion.AssertNull("State should be null", addr.StateProvince); } } } }
public async ValueTask <StudentContact> DeleteStudentContactAsync( StudentContact studentContact) { using var broker = new StorageBroker(this.configuration); EntityEntry <StudentContact> studentContactEntityEntry = broker.StudentContacts.Remove(entity: studentContact); await broker.SaveChangesAsync(); return(studentContactEntityEntry.Entity); }
public static int AddStudentContact(StudentContact studentContact) { //create DBContext object using (var smsDB = new SMSEntities()) { //Add Student object into Students DBset smsDB.StudentContacts.Add(studentContact); // call SaveChanges method to save student into database return(smsDB.SaveChanges()); } }
public void testStudentContactMapping010() { StudentContact sc = new StudentContact(); Mappings mappings = fCfg.Mappings.GetMappings("Default"); IFieldAdaptor adaptor = createStudentContactFields(); mappings.MapOutbound(adaptor, sc); SifWriter writer = new SifWriter(Console.Out); writer.Write(sc); writer.Flush(); Assertion.AssertEquals("Testing Pickup Rights", "Yes", sc.ContactFlags.PickupRights); }
private void ValidateStudentContactRequiredFields(StudentContact studentContact) { switch (studentContact) { case { } when IsInvalid(studentContact.StudentId): throw new InvalidStudentContactInputException( parameterName: nameof(StudentContact.StudentId), parameterValue: studentContact.StudentId); case { } when IsInvalid(studentContact.ContactId): throw new InvalidStudentContactInputException( parameterName: nameof(StudentContact.ContactId), parameterValue: studentContact.ContactId); } }
public void testStudentContactSIF15r1() { StringMapAdaptor sma = createStudentContactFields(); StudentContact sc = new StudentContact(); Mappings m = fCfg.Mappings.GetMappings("Default").Select(null, null, null); m.MapOutbound(sma, sc, SifVersion.SIF15r1); String value = sc.ToXml(); Console.WriteLine(value); // Verify that the phone number is properly escaped int loc = value.IndexOf("<PhoneNumber Format=\"NA\" Type=\"EX\">M&W</PhoneNumber>"); Assertion.Assert("Phone number should be escaped", loc > -1); Element e = sc .GetElementOrAttribute("PhoneNumber[@Format='NA' and @Type='HP']"); Assertion.AssertNotNull("School PhoneNumber should be mapped", e); Assertion.AssertEquals("School phone", "8014504555", e.TextValue); e = sc .GetElementOrAttribute("PhoneNumber[@Format='NA' and @Type='AP']"); Assertion.AssertNotNull("School PhoneNumber should be mapped", e); // Note the " " Space at the end of the value. This should be there, // according to the mapping Assertion.AssertEquals("School phone", "8014505555 ", e.TextValue); e = sc .GetElementOrAttribute("PhoneNumber[@Format='NA' and @Type='WP']"); Assertion.AssertNull("School PhoneNumber should not be mapped", e); AddressList al = sc.AddressList; if (al != null) { foreach (Address addr in al) { Assertion.AssertNull("Country should be null", addr.Country); if (addr.Type.Equals("O")) { Assertion.AssertNull("State should be null", addr.StateProvince); } } } }
public async Task ShouldThrowValidationExceptionOnRemoveWhenStorageStudentContactIsInvalidAndLogItAsync() { // given DateTimeOffset randomDateTime = GetRandomDateTime(); StudentContact randomStudentContact = CreateRandomStudentContact(randomDateTime); Guid inputContactId = randomStudentContact.ContactId; Guid inputStudentId = randomStudentContact.StudentId; StudentContact nullStorageStudentContact = null; var notFoundStudentContactException = new NotFoundStudentContactException(inputStudentId, inputContactId); var expectedSemesterCourseValidationException = new StudentContactValidationException(notFoundStudentContactException); this.storageBrokerMock.Setup(broker => broker.SelectStudentContactByIdAsync(inputStudentId, inputContactId)) .ReturnsAsync(nullStorageStudentContact); // when ValueTask <StudentContact> removeStudentContactTask = this.studentContactService.RemoveStudentContactByIdAsync(inputStudentId, inputContactId); // then await Assert.ThrowsAsync <StudentContactValidationException>(() => removeStudentContactTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedSemesterCourseValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectStudentContactByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Once); this.storageBrokerMock.Verify(broker => broker.DeleteStudentContactAsync(It.IsAny <StudentContact>()), Times.Never); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldRemoveStudentContactAsync() { // given var randomStudentId = Guid.NewGuid(); var randomContactId = Guid.NewGuid(); Guid inputStudentId = randomStudentId; Guid inputContactId = randomContactId; DateTimeOffset inputDateTime = GetRandomDateTime(); StudentContact randomStudentContact = CreateRandomStudentContact(inputDateTime); randomStudentContact.StudentId = inputStudentId; randomStudentContact.ContactId = inputContactId; StudentContact storageStudentContact = randomStudentContact; StudentContact expectedStudentContact = storageStudentContact; this.storageBrokerMock.Setup(broker => broker.SelectStudentContactByIdAsync(inputStudentId, inputContactId)) .ReturnsAsync(storageStudentContact); this.storageBrokerMock.Setup(broker => broker.DeleteStudentContactAsync(storageStudentContact)) .ReturnsAsync(expectedStudentContact); // when StudentContact actualStudentContact = await this.studentContactService.RemoveStudentContactByIdAsync(inputStudentId, inputContactId); // then actualStudentContact.Should().BeEquivalentTo(expectedStudentContact); this.storageBrokerMock.Verify(broker => broker.SelectStudentContactByIdAsync(inputStudentId, inputContactId), Times.Once); this.storageBrokerMock.Verify(broker => broker.DeleteStudentContactAsync(storageStudentContact), Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldPostStudentContactAsync() { // given StudentContact randomStudentContact = await CreateRandomStudentContactAsync(); StudentContact inputStudentContact = randomStudentContact; StudentContact expectedStudentContact = inputStudentContact; // when await this.otripleSApiBroker.PostStudentContactAsync(inputStudentContact); StudentContact actualStudentContact = await this.otripleSApiBroker.GetStudentContactByIdsAsync( inputStudentContact.StudentId, inputStudentContact.ContactId); // then actualStudentContact.Should().BeEquivalentTo(expectedStudentContact); await DeleteStudentContactAsync(actualStudentContact); }
public IEnumerable <StudentContact> GetContacts() { IEnumerable <Student> students = Get(); using (var connection = GetConnection()) { List <StudentContact> studentContacts = new List <StudentContact>(); foreach (Student i in students) { StudentContact contact = new StudentContact(); contact.Id = i.student_id; contact.Admin = i.admin_number; contact.FullName = i.full_name; contact.Email = i.email_address; contact.Mobile = i.mobile_number; contact.Semester = i.semester; contact.Year = i.year; studentContacts.Add(contact); } return(studentContacts); } }
public async void ShouldThrowValidationExceptionOnAddWhenStudentContactAlreadyExistsAndLogItAsync() { // given StudentContact randomStudentContact = CreateRandomStudentContact(); StudentContact alreadyExistsStudentContact = randomStudentContact; string randomMessage = GetRandomMessage(); string exceptionMessage = randomMessage; var duplicateKeyException = new DuplicateKeyException(exceptionMessage); var alreadyExistsStudentContactException = new AlreadyExistsStudentContactException(duplicateKeyException); var expectedStudentContactValidationException = new StudentContactValidationException(alreadyExistsStudentContactException); this.storageBrokerMock.Setup(broker => broker.InsertStudentContactAsync(alreadyExistsStudentContact)) .ThrowsAsync(duplicateKeyException); // when ValueTask <StudentContact> addStudentContactTask = this.studentContactService.AddStudentContactAsync(alreadyExistsStudentContact); // then await Assert.ThrowsAsync <StudentContactValidationException>(() => addStudentContactTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedStudentContactValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertStudentContactAsync(alreadyExistsStudentContact), Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); }
public async void ShouldThrowValidationExceptionOnAddWhenReferneceExceptionAndLogItAsync() { // given StudentContact randomStudentContact = CreateRandomStudentContact(); StudentContact invalidStudentContact = randomStudentContact; string randomMessage = GetRandomMessage(); string exceptionMessage = randomMessage; var foreignKeyConstraintConflictException = new ForeignKeyConstraintConflictException(exceptionMessage); var invalidStudentContactReferenceException = new InvalidStudentContactReferenceException(foreignKeyConstraintConflictException); var expectedStudentContactValidationException = new StudentContactValidationException(invalidStudentContactReferenceException); this.storageBrokerMock.Setup(broker => broker.InsertStudentContactAsync(invalidStudentContact)) .ThrowsAsync(foreignKeyConstraintConflictException); // when ValueTask <StudentContact> addStudentContactTask = this.studentContactService.AddStudentContactAsync(invalidStudentContact); // then await Assert.ThrowsAsync <StudentContactValidationException>(() => addStudentContactTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedStudentContactValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertStudentContactAsync(invalidStudentContact), Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); }
public void testCountryCodeStudentContact() { String customMappings = "<agent id='Repro' sifVersion='2.0'>" + " <mappings id='Default'>" + " <object object='StudentContact'>" + " <field name='APRN.COUNTRY' sifVersion='+2.0'>AddressList/Address[@Type='0123']/Country=US</field>" + " <field name='APRN.COUNTRY' sifVersion='-1.5r1'>Address[@Type='M']/Country[@Code='US']</field>" + "</object></mappings></agent>"; Adk.SifVersion = SifVersion.SIF15r1; IDictionary map = new Hashtable(); map.Add("APRN.COUNTRY", null); StringMapAdaptor sma = new StringMapAdaptor(map); StudentContact obj = new StudentContact(); doOutboundMapping(sma, obj, customMappings, null); Assertion.AssertNull("AddressList should be null", obj.AddressList); }
public async Task ShouldDeleteStudentContactAsync() { // given StudentContact randomStudentContact = await PostStudentContactAsync(); StudentContact inputStudentContact = randomStudentContact; StudentContact expectedStudentContact = inputStudentContact; // when StudentContact deletedStudentContact = await DeleteStudentContactAsync(inputStudentContact); ValueTask <StudentContact> getStudentContactByIdTask = this.otripleSApiBroker.GetStudentContactByIdsAsync( inputStudentContact.StudentId, inputStudentContact.ContactId); // then deletedStudentContact.Should().BeEquivalentTo(expectedStudentContact); await Assert.ThrowsAsync <HttpResponseNotFoundException>(() => getStudentContactByIdTask.AsTask()); }
public async Task ShouldGetAllStudentContactAsync() { // given Student randomStudent = await PostRandomStudentAsync(); List <StudentContact> randomStudentContacts = new List <StudentContact>(); for (int i = 0; i < GetRandomNumber(); i++) { randomStudentContacts.Add(await CreateRandomStudentContactAsync(randomStudent)); } List <StudentContact> inputStudentContacts = randomStudentContacts.ToList(); List <StudentContact> expectedStudentContacts = inputStudentContacts; // when List <StudentContact> actualStudentContacts = await this.otripleSApiBroker.GetAllStudentContactsAsync(); // then foreach (StudentContact expectedStudentContact in expectedStudentContacts) { StudentContact actualStudentContact = actualStudentContacts.Single( studentContact => studentContact.StudentId == expectedStudentContact.StudentId && studentContact.ContactId == expectedStudentContact.ContactId ); actualStudentContact.Should().BeEquivalentTo(expectedStudentContact); await this.otripleSApiBroker.DeleteStudentContactAsync( actualStudentContact.StudentId, actualStudentContact.ContactId); await this.otripleSApiBroker.DeleteContactByIdAsync(actualStudentContact.ContactId); } await this.otripleSApiBroker.DeleteStudentByIdAsync(randomStudent.Id); }
public bool SetContactUDF(Int32 personid, string udfvalue) { try { using (EditContact process = new EditContact()) { // Load Contact record process.Populate(new PersonID(personid)); foreach (UDFValue udfVal in process.Contact.UDFValues) { if (simsudf == udfVal.TypedValueAttribute.Description) { if (Core.SetUdf(udfVal, udfvalue)) { // Get a NullReferenceException if there isn't a contact relation. So set a 'null' one so it can save, but doesn't update any relationships. StudentContact relation = new StudentContact(0); relation.RelationType = new RelationType(); process.Contact.ContactRelation = relation; return(process.Save()); } else { return(false); } } } logger.Error("UDF {0} not found.", simsudf); return(false); } } catch (Exception e) { logger.Log(LogLevel.Error, "SetContactUDF " + e); return(false); } }