//LAYER_Class_NameOfTheMethod_TestedScenario_ExpectedBehaviour public void BLL_CtrFile_InsertFile_InsertFile_FileIsInserted() { //arrange int fileId = 1; File file_m1 = new File( fileId ); CtrFile _CtrFile = new CtrFile(); //act int result = _CtrFile.insertFile(file_m1); //assert Assert.IsTrue(result >= (int)ENUM.CODE.TRANSLATO_DATABASE_SEED, "file not inserted"); }
//returns [int >= TRANSLATO_DATABASE_SEED] if successful //returns [int < TRANSLATO_DATABASE_SEED] if not internal int insertUploadFile(Upload upload) { int returnCode = (int)CODE.ZERO; int result = (int)CODE.MINUS_ONE; //validate only file if ( result == (int)CODE.ZERO || returnCode != (int)CODE.ZERO || upload.text != null || upload.file == null ) { returnCode = (int)CODE.CTRUPLOAD_INSERTUPLOADFILE_FAILED_ONLYFILE; result = (int)CODE.ZERO; } if (returnCode == (int)CODE.ZERO && result != (int)CODE.ZERO)//safe to proceed { upload.text = null; upload.file = upload.file; CtrFile _CtrFile = new CtrFile(); IUploads _DbUploads = new DbUploads(); try { using (var trScope = TransactionScopeBuilder.CreateSerializable()) { returnCode = _CtrFile.insertFile(upload.file); if (returnCode >= (int)CODE.TRANSLATO_DATABASE_SEED)//means file was inserted successfully { upload.file.fileId = returnCode; returnCode = _DbUploads.insertUploadFile(upload); } else {//means file failed to be inserted trScope.Dispose(); } trScope.Complete(); } } catch (TransactionAbortedException taEx) { returnCode = (int)CODE.CTRUPLOAD_INSERTUPLOADFILE_EXCEPTION; Log.Add(taEx.ToString()); } catch (ApplicationException aEx) { returnCode = (int)CODE.CTRUPLOAD_INSERTUPLOADFILE_EXCEPTION; Log.Add(aEx.ToString()); } catch (Exception ex) { returnCode = (int)CODE.CTRUPLOAD_INSERTUPLOADFILE_EXCEPTION; Log.Add(ex.ToString()); } } else { } return returnCode; }
//returns [int >= TRANSLATO_DATABASE_SEED] if successful //returns [int < TRANSLATO_DATABASE_SEED] if not internal int insertUploadFile(Upload upload) { int returnCode = (int)CODE.ZERO; int result = (int)CODE.MINUS_ONE; //validate only file if ( result == (int)CODE.ZERO || returnCode != (int)CODE.ZERO || upload.text != null || upload.file == null ) { returnCode = (int)CODE.CTRUPLOAD_INSERTUPLOADFILE_FAILED_ONLYFILE; result = (int)CODE.ZERO; } if (returnCode == (int)CODE.ZERO && result != (int)CODE.ZERO)//safe to proceed { upload.text = null; upload.file = upload.file; CtrFile _CtrFile = new CtrFile(); IUploads _DbUploads = new DbUploads(); try { using (var trScope = TransactionScopeBuilder.CreateSerializable()) { returnCode = _CtrFile.insertFile(upload.file); if (returnCode >= (int)CODE.TRANSLATO_DATABASE_SEED)//means file was inserted successfully { upload.file.fileId = returnCode; returnCode = _DbUploads.insertUploadFile(upload); } else {//means file failed to be inserted trScope.Dispose(); } trScope.Complete(); } } catch (TransactionAbortedException taEx) { returnCode = (int)CODE.CTRUPLOAD_INSERTUPLOADFILE_EXCEPTION; Log.Add(taEx.ToString()); } catch (ApplicationException aEx) { returnCode = (int)CODE.CTRUPLOAD_INSERTUPLOADFILE_EXCEPTION; Log.Add(aEx.ToString()); } catch (Exception ex) { returnCode = (int)CODE.CTRUPLOAD_INSERTUPLOADFILE_EXCEPTION; Log.Add(ex.ToString()); } } else { } return(returnCode); }