public async Task D04_AddPersonTest() { //Arrange string dbName = Guid.NewGuid().ToString(); string expectedFirstName = "Max"; string expectedLastName = "Mustermann"; string expectedPhoneNumber = "066412345667"; Person person = new Person { FirstName = expectedFirstName, LastName = expectedLastName, PhoneNumber = expectedPhoneNumber, RecordTime = DateTime.Now }; //Act FunctionsCCT.AddPersonToDb(person, GetDbContext(dbName)); //Assert using (IUnitOfWork unitOfWork = new UnitOfWork(GetDbContext(dbName))) { Person[] personsInDb = await unitOfWork.PersonRepository.GetAllPersonAsync(); Assert.IsNotNull(personsInDb); Assert.AreEqual(1, personsInDb.Length); Assert.AreEqual(expectedFirstName, personsInDb[0].FirstName); Assert.AreEqual(expectedLastName, personsInDb[0].LastName); Assert.AreEqual(expectedPhoneNumber, personsInDb[0].PhoneNumber); Assert.AreEqual(DateTime.Now.Date, personsInDb[0].RecordTime.Date); Assert.AreEqual(DateTime.Now.Hour, personsInDb[0].RecordTime.Hour); } }
/// <summary> /// Read Nfc Tag from µFR Reader and transfer data to database /// </summary> static void ReadCycle_uFR(ref bool card_in_field) { //signaling const byte FRES_OK_LIGHT = 0x01, // long green FERR_LIGHT = 0x02, // long red FRES_OK_SOUND = 0x01, // short FERR_SOUND = 0x00; // none uFR.DL_STATUS dl_status; string nfcDataContent = string.Empty; (dl_status, nfcDataContent) = Functions_uFR.ReadLinear(); switch (dl_status) { case uFR.DL_STATUS.UFR_FT_STATUS_ERROR_2: case uFR.DL_STATUS.UFR_FT_STATUS_ERROR_5: Functions_uFR.reader_automaticOpen(); break; case uFR.DL_STATUS.UFR_OK: if (!card_in_field) { card_in_field = true; Person person = FunctionsCCT.ParseNfcDataToPerson(nfcDataContent); if (person != null) { bool dbSaveOk = false; try { dbSaveOk = FunctionsCCT.AddPersonToDb(person); } catch (Exception ex) { Console.WriteLine("Could not write to database"); uFCoder.ReaderUISignal(FERR_LIGHT, FERR_SOUND); WriteExceptions(ex); } Console.WriteLine(nfcDataContent); if (dbSaveOk) { uFCoder.ReaderUISignal(FRES_OK_LIGHT, FRES_OK_SOUND); } } else { uFCoder.ReaderUISignal(FERR_LIGHT, FERR_SOUND); } } break; case uFR.DL_STATUS.UFR_NO_CARD: card_in_field = false; break; default: break; } }
static void ReadCycle_RC522(string actEnvironment, ref int card_in_field) { if (actEnvironment == null || actEnvironment.StartsWith("RPI") == false) { return; } Functions_RC522.InvertLedSignal(); (bool cardDetected, bool readDone, string nfcDataContent) = Functions_RC522.ReadTagFromRC522(); // data from reader received ? if (string.IsNullOrEmpty(nfcDataContent) == false && readDone && card_in_field == 0) { card_in_field = 3; Person person = FunctionsCCT.ParseNfcDataToPerson(nfcDataContent); if (person != null) { bool dbSaveOk = false; try { dbSaveOk = FunctionsCCT.AddPersonToDb(person); } catch (Exception ex) { Console.WriteLine("Could not write to database"); // Signal not ok ??; WriteExceptions(ex); } Console.WriteLine(nfcDataContent); if (dbSaveOk) { Functions_RC522.BeepSignal(); } } } else if (card_in_field > 0) { if (cardDetected) { card_in_field = 3; } else { card_in_field--; } } else { card_in_field = 0; } }
public async Task D05_DeletePersonsOlderThenThen() { //Arrange string dbName = Guid.NewGuid().ToString(); string expectedFirstName = "Max"; string expectedLastName = "Mustermann"; string expectedPhoneNumber = "066412345667"; Person person1 = new Person { FirstName = expectedFirstName, LastName = expectedLastName, PhoneNumber = expectedPhoneNumber, RecordTime = DateTime.Now }; Person person2 = new Person { FirstName = "Max", LastName = "Mustermann", PhoneNumber = "0732332211", RecordTime = DateTime.Now.Subtract(TimeSpan.FromDays(31)) }; //Act FunctionsCCT.AddPersonToDb(person2, GetDbContext(dbName)); FunctionsCCT.AddPersonToDb(person1, GetDbContext(dbName)); await FunctionsCCT.DeletePersonsOlderThenInDbAsync(30, GetDbContext(dbName)); //Assert using (IUnitOfWork unitOfWork = new UnitOfWork(GetDbContext(dbName))) { Person[] personsInDb = await unitOfWork.PersonRepository.GetAllPersonAsync(); Assert.IsNotNull(personsInDb); Assert.AreEqual(1, personsInDb.Length); Assert.AreEqual(expectedFirstName, personsInDb[0].FirstName); Assert.AreEqual(expectedLastName, personsInDb[0].LastName); Assert.AreEqual(expectedPhoneNumber, personsInDb[0].PhoneNumber); Assert.AreEqual(DateTime.Now.Date, personsInDb[0].RecordTime.Date); Assert.AreEqual(DateTime.Now.Hour, personsInDb[0].RecordTime.Hour); } }