//returns [int >= TRANSLATO_DATABASE_SEED] if successful //returns [int < TRANSLATO_DATABASE_SEED] if not internal int insertText(Text text) { int returnCode = (int)CODE.ZERO; int result = (int)CODE.MINUS_ONE; //validate textData if ( result == (int)CODE.ZERO || returnCode != (int)CODE.ZERO || string.IsNullOrWhiteSpace(text.textData) || !Validate.hasMinLength(text.textData, 1) || !Validate.hasMaxLength(text.textData, 40000) ) {returnCode = (int)CODE.CTRTEXT_INSERTTEXT_INVALID_TEXTDATA; result = (int)CODE.ZERO; } if (returnCode == (int)CODE.ZERO && result != (int)CODE.ZERO)//safe to proceed { text.textData = text.textData; ITexts _DbTexts = new DbTexts(); try { using (var trScope = TransactionScopeBuilder.CreateSerializable()) { returnCode = _DbTexts.insertText(text); trScope.Complete(); } } catch (TransactionAbortedException taEx) { returnCode = (int)CODE.CTRTEXT_INSERTTEXT_EXCEPTION; Log.Add(taEx.ToString()); } catch (ApplicationException aEx) { returnCode = (int)CODE.CTRTEXT_INSERTTEXT_EXCEPTION; Log.Add(aEx.ToString()); } catch (Exception ex) { returnCode = (int)CODE.CTRTEXT_INSERTTEXT_EXCEPTION; Log.Add(ex.ToString()); } } else { } return returnCode; }
//LAYER_Class_NameOfTheMethod_TestedScenario_ExpectedBehaviour public void DAL_IText_InsertText_InsertText_TextIsInserted() { //arrange int textId = 1; string textData = "some long text here to be translated"; Text text_m1 = new Text( textId, textData ); ITexts _DbTexts = new DbTexts(); //act int result = _DbTexts.insertText(text_m1); //assert Assert.IsTrue(result>=(int)ENUM.CODE.TRANSLATO_DATABASE_SEED, "text not inserted into the database"); }