//LAYER_Class_NameOfTheMethod_TestedScenario_ExpectedBehaviour public void DAL_IFile_InsertFile_InsertFile_FileIsInserted() { //arrange int fileId = 5; File file_m1 = new File( fileId ); IFiles _DbFiles = new DbFiles(); //act int result = _DbFiles.insertFile(file_m1); //assert Assert.IsTrue(result >= (int)ENUM.CODE.TRANSLATO_DATABASE_SEED, "file not inserted into the database"); }
//returns [int >= TRANSLATO_DATABASE_SEED] if successful //returns [int < TRANSLATO_DATABASE_SEED] if not internal int insertFile(File file) { int returnCode = (int)CODE.ZERO; int result = (int)CODE.MINUS_ONE; //validate -> ToDo if ( result == (int)CODE.ZERO || returnCode != (int)CODE.ZERO ) { returnCode = (int)CODE.CTRTEXT_INSERTTEXT_INVALID_TEXTDATA; result = (int)CODE.ZERO; } if (returnCode == (int)CODE.ZERO && result != (int)CODE.ZERO)//safe to proceed { IFiles _DbFiles = new DbFiles(); try { using (var trScope = TransactionScopeBuilder.CreateSerializable()) { returnCode = _DbFiles.insertFile(file); trScope.Complete(); } } catch (TransactionAbortedException taEx) { returnCode = (int)CODE.CTRFILE_INSERTFILE_EXCEPTION; Log.Add(taEx.ToString()); } catch (ApplicationException aEx) { returnCode = (int)CODE.CTRFILE_INSERTFILE_EXCEPTION; Log.Add(aEx.ToString()); } catch (Exception ex) { returnCode = (int)CODE.CTRFILE_INSERTFILE_EXCEPTION; Log.Add(ex.ToString()); } } else { } return(returnCode); }
//returns [int >= TRANSLATO_DATABASE_SEED] if successful //returns [int < TRANSLATO_DATABASE_SEED] if not internal int insertFile(File file) { int returnCode = (int)CODE.ZERO; int result = (int)CODE.MINUS_ONE; //validate -> ToDo if ( result == (int)CODE.ZERO || returnCode != (int)CODE.ZERO ) { returnCode = (int)CODE.CTRTEXT_INSERTTEXT_INVALID_TEXTDATA; result = (int)CODE.ZERO; } if (returnCode == (int)CODE.ZERO && result != (int)CODE.ZERO)//safe to proceed { IFiles _DbFiles = new DbFiles(); try { using (var trScope = TransactionScopeBuilder.CreateSerializable()) { returnCode = _DbFiles.insertFile(file); trScope.Complete(); } } catch (TransactionAbortedException taEx) { returnCode = (int)CODE.CTRFILE_INSERTFILE_EXCEPTION; Log.Add(taEx.ToString()); } catch (ApplicationException aEx) { returnCode = (int)CODE.CTRFILE_INSERTFILE_EXCEPTION; Log.Add(aEx.ToString()); } catch (Exception ex) { returnCode = (int)CODE.CTRFILE_INSERTFILE_EXCEPTION; Log.Add(ex.ToString()); } } else { } return returnCode; }