//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");
        }
Beispiel #2
0
        //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);
        }
Beispiel #3
0
        static int Main(string[] args)
        {
            DbFiles db = new DbFiles();

            if (args.Any())
            {
                switch (args[0].ToLower())
                {
                case "--reset":
                    Reset(db);
                    break;
                }
            }

            Pharmacy pharmacy = new Pharmacy(db);


            return(pharmacy.Start());
        }
Beispiel #4
0
        //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;
        }
Beispiel #5
0
        static void Reset(DbFiles db)
        {
            File.Delete(db.MainDbFile);
            File.Delete(db.UserDbFile);

            List <string> mainDbFileDefault = new List <string>
            {
                "1,Auriga Flavo-C Forte Serum,15,ml,Auriga,false,0,30.95",
                "2,VITA BUER D3,120,kaps,VITA,false,0,40.30",
                "4,PALMERS Krem łagodzący do twarzy,100,ml,Palmers,false,0,40.34",
                "5,BEROTEC aerozol inhalacyjny,200,dawka,BEROTEC,true,20,60.45",
                "6,CORONAL 10 mg,30,tabl,CORONAL,true,20,10.20"
            };

            List <string> userDbFileDefault = new List <string>
            {
                "1,Jan,janek,Kowalski,kowalski1",
                "2,Piotr,piotr3,Dąb,piotrek",
                "3,Anna,ania,Najdek,aneta"
            };

            File.WriteAllLines(db.MainDbFile, mainDbFileDefault);
            File.WriteAllLines(db.UserDbFile, userDbFileDefault);
        }
Beispiel #6
0
 public Pharmacy(DbFiles dbFiles)
 {
     _dbFiles = dbFiles;
     _userDb  = new UserDb(File.ReadAllLines(_dbFiles.UserDbFile).ToList());
     _mainDb  = new MedicineDb(File.ReadAllLines(_dbFiles.MainDbFile).ToList());
 }