public void TestSortedListOfStringsEnumerator()
        {
            var stringList = new SortedListCollection <string> {
                "string1", "string2"
            };

            stringList.Add("string3");
            stringList.Add("string4");

            var numerator = stringList.GetEnumerator();

            for (int i = 0; i < 10; i++)
            {
                numerator.MoveNext();
            }

            var current = numerator.Current;

            Assert.Equal("string4", current);

            Assert.Equal("string1", stringList[0]);
            Assert.Equal("string2", stringList[1]);
            Assert.Equal("string3", stringList[2]);
            Assert.Equal("string4", stringList[3]);
            Assert.Equal(4, stringList.Count);
        }
        public void TestSetElementEmptyListException()
        {
            var array = new SortedListCollection <byte>();

            ArgumentException ex = Assert.Throws <ArgumentException>(() => array[0] = 3);

            Assert.Equal("Invalid index; must be less than\r\nParameter name: Count = 0", ex.Message);

            Assert.Equal(0, array.Count);
        }
        public void TestGetElementForSimpleList()
        {
            var array = new SortedListCollection <double>
            {
                1,
                5,
                10
            };

            Assert.Equal(5, array[1]);
        }
        public void TestInsertElementWhenSortedListIsEmpty()
        {
            var array = new SortedListCollection <int>();

            array.Insert(0, 100);
            var checkGet = Assert.Throws <ArgumentException>(() => array.Insert(2, 111));

            Assert.Equal("Invalid Index; must be greater then 0 and less than \r\nParameter name: Count = 1", checkGet.Message);
            Assert.Equal(0, array.IndexOf(100));
            Assert.Equal(1, array.Count);
        }
        public void TestSetElementOneValueForWholeList()
        {
            var array = new SortedListCollection <byte>
            {
                2,
            };

            array[0] = 10;

            Assert.Equal(10, array[0]);
        }
        public void TestSetElementLowerValueShouldNotWork()
        {
            var array = new SortedListCollection <byte>
            {
                2,
                2,
                2
            };

            array[2] = 1;

            Assert.Equal(2, array[2]);
        }
        public void TestAddingListOfNumbersShouldBeInOrder()
        {
            var array = new SortedListCollection <int>();

            array.Add(3);
            array.Add(2);
            array.Add(1);

            Assert.Equal(3, array.Count);
            Assert.Equal(1, array[0]);
            Assert.Equal(2, array[1]);
            Assert.Equal(3, array[2]);
        }
        public void TestSetElementWhereIndexOutOfRange()
        {
            var array = new SortedListCollection <byte>
            {
                1,
                5,
                10
            };
            ArgumentException ex = Assert.Throws <ArgumentException>(() => array[10] = 100);

            Assert.Equal("Invalid index; must be less than\r\nParameter name: Count = 3", ex.Message);
            Assert.Equal(5, array[1]);
        }
        public void TestSetElementWhenResultingListNotSorted()
        {
            var array = new SortedListCollection <byte>
            {
                1,
                5,
                10
            };

            array[1] = 100;

            Assert.Equal(5, array[1]);
        }
        public void TestAddingListOfStringsShouldBeInOrder()
        {
            var array = new SortedListCollection <string>();

            array.Add("azz");
            array.Add("axc");
            array.Add("abc");

            Assert.Equal(3, array.Count);
            Assert.Equal("abc", array[0]);
            Assert.Equal("axc", array[1]);
            Assert.Equal("azz", array[2]);
        }
        public void TestSetLastElementSameValuesBefore()
        {
            var array = new SortedListCollection <byte>
            {
                2,
                2,
                2
            };

            array[2] = 3;

            Assert.Equal(3, array[2]);
        }
Exemplo n.º 12
0
        public static void Main(string[] args)
        {
            DictionaryCollection dictionaryCollection = new DictionaryCollection();
            ListCollection       listCollection       = new ListCollection();
            QueueCollection      queueCollection      = new QueueCollection();
            SortedListCollection sortedListCollection = new SortedListCollection();
            StackCollection      stackCollection      = new StackCollection();

            dictionaryCollection.FillCollection("dictionary");
            listCollection.FillCollection();
            queueCollection.FillCollection();
            sortedListCollection.FillCollection("sorted list");
            stackCollection.FillCollection();
            Console.WriteLine();

            dictionaryCollection.FindValueByKey(6, "dictionary");
            listCollection.FindValueByPosition(600);
            queueCollection.FindFirstElement();
            sortedListCollection.FindValueByKey(300, "sorted list");
            stackCollection.FindTopElement();
            Console.WriteLine();

            dictionaryCollection.RemoveElementByKey(100, "dictionary");
            listCollection.RemoveElementByPosition(250);
            queueCollection.RemoveBeginningElement();
            sortedListCollection.RemoveElementByKey(1000, "sorted list");
            stackCollection.RemoveTopElement();
            Console.WriteLine();

            /*List<Vegetable> springSaladIngredients = new List<Vegetable>()
             * {
             *  new Tomato(200),
             *  new Cucumber(200),
             *  new Onion(50)
             * };
             * Salad springSalad = new Salad (springSaladIngredients, "Spring Salad");
             * List<Vegetable> tangySaladIngredients = new List<Vegetable>()
             * {
             *  new Cucumber(200),
             *  new Avocado(200),
             *  new Lime(50),
             *  new GreenOnion(50)
             * };
             * Salad tangySalad = new Salad(tangySaladIngredients, "Tangy Salad");
             * springSalad.getSaladCaloricity();
             * tangySalad.getSaladCaloricity();
             * springSalad.sortByCalories();
             * springSalad.sortByWeigth();
             * tangySalad.selectVegetablesByWeigth(40, 150) ; */
        }
        public void TestAddingListOfFloatsShouldBeInOrder()
        {
            var array = new SortedListCollection <float>();

            array.Add(float.MaxValue);
            array.Add(float.MinValue);
            array.Add(int.MaxValue);
            array.Add(long.MinValue);
            array.Add(1);

            Assert.Equal(2, array.Count);
            Assert.Equal(float.MinValue, array[0]);
            Assert.Equal(float.MaxValue, array[1]);
        }
        public void TestInsertElementWhenResultingIntListIsSorted()
        {
            var array = new SortedListCollection <int>
            {
                1,
                4,
                6,
                8
            };

            array.Insert(2, 5);

            Assert.Equal(2, array.IndexOf(5));
            Assert.Equal(5, array.Count);
        }
        public void TestInsertElementWhenResultingIntListIsNotSorted()
        {
            var array = new SortedListCollection <int>
            {
                1,
                4,
                6,
                8
            };

            array.Insert(2, 100);

            Assert.Equal(-1, array.IndexOf(100));
            Assert.Equal(4, array.Count);
        }
        public void TestAddingListOfBooleansShouldBeInOrder()
        {
            var array = new SortedListCollection <bool>();

            array.Add(true);
            array.Add(false);
            array.Add(true);
            array.Add(false);
            array.Add(true);

            Assert.Equal(5, array.Count);
            Assert.Equal(false, array[0]);
            Assert.Equal(false, array[1]);
            Assert.Equal(true, array[2]);
            Assert.Equal(true, array[3]);
            Assert.Equal(true, array[4]);
        }
        public void TestAddingListOfRepetedCharsShouldBeInOrder()
        {
            var array = new SortedListCollection <char>
            {
                'e',
                'd',
                'a',
                'a',
                'a'
            };


            Assert.Equal(5, array.Count);
            Assert.Equal('a', array[0]);
            Assert.Equal('a', array[1]);
            Assert.Equal('a', array[2]);
            Assert.Equal('d', array[3]);
            Assert.Equal('e', array[4]);
        }
Exemplo n.º 18
0
        //main() is the entry point for project execuition
        static void Main(string[] args)
        {
            //To keep breakpoint use F9 (key) keyboard

            //#region <tab> (code segment for region will be automatically created)
            #region "Understanding ADO.Net"

            //DataSet Operations
            LearnADO.TableOperation.RetrieveRecordsDataSet retrieveRecordsDataSet = new LearnADO.TableOperation.RetrieveRecordsDataSet();
            DataSet dataSet = retrieveRecordsDataSet.DataSetOperations();
            Console.WriteLine(dataSet.GetXml());

            //understanding reader object in detail
            LearnADO.TableOperation.RetrieveRecord retrieveRec = new LearnADO.TableOperation.RetrieveRecord();
            retrieveRec.RetrieveRecordSelect();

            //get records from table based on search condition
            string serachProduct = "Monitor 15";
            LearnADO.TableOperation.SelectTableRecordProc selectTableRecordProc = new LearnADO.TableOperation.SelectTableRecordProc();
            selectTableRecordProc.SearchProduct(serachProduct);

            //get data from the system table (list all procedures of the database)
            LearnADO.TableOperation.SelectInformationSchemaProc selectInformationSchemaProc = new LearnADO.TableOperation.SelectInformationSchemaProc();
            selectInformationSchemaProc.ListAllStoredProceduresInDatabase();

            //copy all data from a table to another table
            LearnADO.TableOperation.InsertIntoTable insertIntoTable = new LearnADO.TableOperation.InsertIntoTable();
            insertIntoTable.CopyTableDataToAnotherTable();

            //insert record to table using stored procedure
            LearnADO.TableOperation.InsertRecordStoredProcedure insertRecordStoredProcedure = new LearnADO.TableOperation.InsertRecordStoredProcedure();
            insertRecordStoredProcedure.InsertNewRecordToTable();

            //database manupulations
            string sqlQueryCreateDatabase = "CREATE DATABASE [LEARNDBMP02]";
            string sqlQueryRenameDatabase = "ALTER DATABASE LEARNDBMP02 MODIFY NAME = LEARNDBMP04";
            string sqlQueryDeleteDatabase = "DROP DATABASE [LEARNDBMP04]";
            string message = "Action Completed Successfully";

            //table manipulations
            string sqlQueryCreateTable  = @"
            CREATE TABLE LEARNDBMP01.dbo.Products(
                  ID     INT            IDENTITY(1, 1) NOT NULL
                , [Name] NVARCHAR(50)   NULL
                , Price  NVARCHAR(50)   NULL
                , [Date] DATETIME       NULL

                CONSTRAINT pk_id PRIMARY KEY(ID)
            )";
            string sqlQueryRenameTable  = "Exec sp_rename 'Products', 'Accessories'";
            string sqlQueryAddColumn    = "ALTER TABLE Accessories ADD Stock NVARCHAR(50)";
            string sqlQueryModifyColumn = "ALTER TABLE Accessories ALTER COLUMN Stock INT";
            string sqlQueryRemoveColumn = "ALTER TABLE Accessories DROP COLUMN Stock";
            string sqlQueryRemoveTable  = "DROP TABLE Accessories";

            string sqlQueryInsertRecord = "INSERT INTO dbo.Products (NAME, Price, [Date]) VALUES ('LED TV', '$ 120.00', '27-January-2019')";

            LearnADO.DatabaseManipulation databaseManipulation = new LearnADO.DatabaseManipulation();

            //adding record to table
            databaseManipulation.DatabaseAction(sqlQueryInsertRecord, message);

            //table manipulation
            databaseManipulation.DatabaseAction(sqlQueryRemoveTable, message);
            databaseManipulation.DatabaseAction(sqlQueryRemoveColumn, message);
            databaseManipulation.DatabaseAction(sqlQueryModifyColumn, message);
            databaseManipulation.DatabaseAction(sqlQueryAddColumn, message);
            databaseManipulation.DatabaseAction(sqlQueryRenameTable, message);
            databaseManipulation.DatabaseAction(sqlQueryCreateTable, message);

            //database manupulation
            databaseManipulation.DatabaseAction(sqlQueryCreateDatabase, message);
            databaseManipulation.DatabaseAction(sqlQueryRenameDatabase, message);
            databaseManipulation.DatabaseAction(sqlQueryDeleteDatabase, message);

            //adding record to table
            LearnADO.TableOperation.InsertTableRecord insertTableRecord = new LearnADO.TableOperation.InsertTableRecord();
            insertTableRecord.InsertNewRecordToTable();

            LearnADO.TableOperation.InsertTableRecordParameterized insertTableRecordParameterized = new LearnADO.TableOperation.InsertTableRecordParameterized();
            insertTableRecordParameterized.InsertNewRecordToTable();

            //table manipulation
            LearnADO.TableOperation.RenameTable renameTable = new LearnADO.TableOperation.RenameTable();
            renameTable.RenameExistingTable();

            LearnADO.TableOperation.CreateTable createTable = new LearnADO.TableOperation.CreateTable();
            createTable.CreateNewTable();

            //...

            //database manipulation
            LearnADO.DatabaseOperation.DeleteDatabase deleteDatabase = new LearnADO.DatabaseOperation.DeleteDatabase();
            deleteDatabase.RemoveDatabase();

            LearnADO.DatabaseOperation.RenameDatabase renameDatabase = new LearnADO.DatabaseOperation.RenameDatabase();
            renameDatabase.RenameTheDatabase();

            LearnADO.DatabaseOperation.CreateDatabase createDatabase = new LearnADO.DatabaseOperation.CreateDatabase();
            createDatabase.CreateNewDatabase();

            //table reading
            LearnADO.TableOperation.RetrieveRecord retrieveRecord = new LearnADO.TableOperation.RetrieveRecord();
            retrieveRecord.RetrieveRecordSelect();

            #endregion

            #region     "Collections"

            SortedDictionaryCollection sortedDictionaryCollection = new SortedDictionaryCollection();
            sortedDictionaryCollection.GenericSortedDictionary();

            HashSetCollection hashSetCollection = new HashSetCollection();
            hashSetCollection.StoreElementsToHashSet();

            StackCollection stackCollection = new StackCollection();
            stackCollection.StackManipulations();

            QueueCollection queueCollection = new QueueCollection();
            queueCollection.QueueManipulation();

            DictionaryCollection dictionaryCollections = new DictionaryCollection();
            dictionaryCollections.DictionaryOperations();

            SortedListCollection sortedListCollection = new SortedListCollection();
            sortedListCollection.SortedList();

            ArrayListCollection arrayListCollections = new ArrayListCollection();
            arrayListCollections.AddArrayListElement();

            ListCollection listCollection = new ListCollection();

            Console.ReadLine();

            #endregion

            #region "File Handing in C#"

            FileIO fileIO = new FileIO();

            fileIO.StreamWriterInFiles();
            fileIO.StreamReaderInFiles();

            fileIO.UnderstandFileDelete();
            fileIO.UnderstandFileCopy();
            fileIO.UnderstandFileReadAllText();
            fileIO.UnderstandFileReadAllLines();
            fileIO.UnderstandFileExists();

            #endregion

            #region "Understanding Arrays"

            Arrays objArrays = new Arrays();
            objArrays.MultiDiamentionalArray();

            objArrays.AccessingValuesFromArray();
            objArrays.AcceptValuesFromUserAndDisplayOutput();
            objArrays.ArrayDeclarationAndInitilization();

            #endregion

            #region "StringBuilder and their methods"

            StringBuilders objStringBuilders = new StringBuilders();
            objStringBuilders.StringBuilderFunctions();

            #endregion

            #region "Data types: Value and Reference type"

            ValueTypeReferenceType objValueTypeReferenceType = new ValueTypeReferenceType();
            objValueTypeReferenceType.UnderstandingReferenceType();
            //objValueTypeReferenceType.UnderstandingValueType();

            #endregion

            #region "Understanding Loop Statements"

            LoopStatements objLoopStatements = new LoopStatements();
            objLoopStatements.UnderstandingForLoop();
            objLoopStatements.UnderstandingForLoopCondStmt();
            objLoopStatements.UnderstandingWhileLoop();
            objLoopStatements.WhileLoopWithBreakStmt();
            objLoopStatements.UnderstandingDoWhileLoop();
            objLoopStatements.UnderstandingDoWhileLoopFalseCondition();
            objLoopStatements.DoWhileLoopWithBreakStmt();

            #endregion

            #region "Understanding Conditional Statements"

            //switch statement
            ConditionalStatements objConditionalStatements = new ConditionalStatements();
            objConditionalStatements.SwitchStatement();

            objConditionalStatements.GoToInSwitchStatement();

            #endregion

            #region "How to call a Class"

            //<name of class> <object of the class> <new - allocating memory> <name of the class>
            //MyClass: is class --> Blue Print --> car
            //myClass: is object --> Benz, BMW, Audi, Ford, etc..
            //MyClass myClass = new MyClass();
            MyClass objMyClass = new MyClass();
            //Lets set the value to a property and they get the value from the property
            int valueFromProperty = 0;
            //Set the value to the property
            objMyClass.Counter = 4;
            //Get the value from the property
            valueFromProperty = objMyClass.Counter;
            Console.WriteLine(valueFromProperty);

            objMyClass.PropVariable = 6;                //(setter)
            Console.WriteLine(objMyClass.PropVariable); //(getter) the return value of the private class variable _propVariable

            //try to see if we are able to access 'Count' and private in scope
            //objMyClass.Count; (error since its scope is private)

            //Create an object of newly created class (AnotherClass)
            //Any new class created will have default methods available
            AnotherClass objAnotherClass = new AnotherClass();
            //objAnotherClass.

            //Properties with only getter
            //objMyClass.MarkSheetGrade = "India"; (not possible since it is getter only property)

            //Properties with only setter
            objMyClass.CollegeName = "National Engineering College";
            //Console.WriteLine(objMyClass.CollegeName); get accessor is not exposed for this propery hence data can not be viewed

            #endregion

            #region "Call - Understanding Variables"

            //Understand C# variables and their declarations
            UnderstandVariables();

            //Understanding C# datatypes in detail
            UnderstandDataTypes();

            #endregion

            //Purpose of command: to display the output visiable to user until user selects any key in the keyboard
            Console.ReadKey();
        }