Exemplo n.º 1
0
        public void TestListOfStringObjects()
        {
            var stringList = new ListCollection <string> {
                "string1", "string2"
            };

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

            var numerator = stringList.GetEnumerator();

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

            var current = numerator.Current;

            Assert.Equal("1", current);

            Assert.Equal("string1", stringList[0]);
            Assert.Equal("string2", stringList[1]);
            Assert.Equal("string3", stringList[2]);
            Assert.Equal("1", stringList[3]);
            Assert.Equal(4, stringList.Count);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Route         route       = new Route("istanbul", "çanakkale", 500);
            BusExpedition bExpedition = new BusExpedition(route, new DateTime(2019, 5, 15));

            bExpedition.AddDriver(new Driver("özkan", "koç", LicenseType.HighLicense, new DateTime(1993, 5, 15)));
            ListCollection <string> myList = new ListCollection <string>();

            myList.Add("merhaba");
            myList.Add("özkan");
            myList.Add("nasılsın");
            var builder = new StringBuilder();;

            foreach (var item in myList)
            {
                builder.Append($"{item} ");
            }
            var strArr = new string[] { "erdem", "merve", "cevat" };

            myList.CopyTo(strArr);

            var myIntList = new ListCollection <int>()
            {
                1, 2, 3
            };
            var intArr = new int[3];

            myIntList.CopyTo(intArr);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="queryAction"></param>
        /// <param name="ignorePropertyDescriptors"></param>
        /// <returns></returns>
        public DbQueryPropertyDescriptors GetDescriptors(DbQueryActions queryAction, IgnoreChildPropertyDescriptors ignorePropertyDescriptors)
        {
            var _filteredProperties = GetDescriptorsByQueryAction(queryAction);

            if (!ignorePropertyDescriptors.IsEmpty)
            {
                var _propertyCollection = new ListCollection <DbQueryPropertyDescriptor>();

                foreach (var _filteredProperty in _filteredProperties)
                {
                    var _ignoreDescriptor = ignorePropertyDescriptors.GetDescriptor(_filteredProperty);

                    if (null != _ignoreDescriptor)
                    {
                        if (!_filteredProperty.PropertyDirection.Equals(DbQueryPropertyDirections.None))
                        {
                            var _propertyDirection = _filteredProperty.PropertyDirection & ~_ignoreDescriptor.PropertyDirection;

                            if (!((int)_propertyDirection).Equals(0))
                            {
                                _propertyCollection.Add(new DbQueryPropertyDescriptor(_filteredProperty, _propertyDirection));
                            }
                        }

                        continue;
                    }

                    _propertyCollection.Add(_filteredProperty);
                }

                return(new DbQueryPropertyDescriptors(_propertyCollection, _declaringDescriptor));
            }

            return(_filteredProperties);
        }
Exemplo n.º 4
0
        public void ListClearing()
        {
            var col = new ListCollection <int, int>();

            for (var i = 0; i < 5; ++i)
            {
                col.Add(1, 1000 + i);
            }

            for (var i = 0; i < 5; ++i)
            {
                col.Add(2, 2200 + i);
            }

            var l1 = col.Get(1);
            var l2 = col.Get(2);

            Assert.Equal(new int[] { 1000, 1001, 1002, 1003, 1004 }, l1.ToArray());
            Assert.Equal(new int[] { 2200, 2201, 2202, 2203, 2204 }, l2.ToArray());

            col.Clear(1);
            var l3 = col.Get(1);
            var l4 = col.Get(2);

            Assert.Equal(new int[] { }, l3.ToArray());
            Assert.Equal(new int[] { 2200, 2201, 2202, 2203, 2204 }, l4.ToArray());

            col.Clear(2);
            var l5 = col.Get(1);
            var l6 = col.Get(2);

            Assert.Equal(new int[] { }, l5.ToArray());
            Assert.Equal(new int[] { }, l6.ToArray());
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="attributeType"></param>
        /// <param name="inherit"></param>
        /// <returns></returns>
        public TCollection GetDescriptorsByAttributeType(Type attributeType, bool inherit = false)
        {
            var _dummy = new ListCollection <TDescriptor>();

            foreach (var _descriptor in this)
            {
                foreach (var _attribute in _descriptor.AttributeDescriptors)
                {
                    var _originType = _attribute.Member.GetType();

                    if (!inherit)
                    {
                        if (attributeType.Equals(_originType))
                        {
                            _dummy.Add(_descriptor);
                            break;
                        }
                    }
                    else
                    {
                        if (attributeType.IsAssignableFrom(_originType))
                        {
                            _dummy.Add(_descriptor);
                            break;
                        }
                    }
                }
            }

            return(ReadOnlyListCollection <TDescriptor> .Initializer.Initialize <TCollection>(_dummy));
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TAttribute"></typeparam>
        /// <param name="selector"></param>
        /// <returns></returns>
        public TCollection GetDescriptorsByAttribute <TAttribute>(Expression <Func <TAttribute, bool> > selector, bool inherit = false)
            where TAttribute : Attribute
        {
            var _type     = typeof(TAttribute);
            var _dummy    = new ListCollection <TDescriptor>();
            var _selector = selector.Compile();

            foreach (var _descriptor in this)
            {
                foreach (var _attribute in _descriptor.AttributeDescriptors)
                {
                    var _origin     = _attribute.Member;
                    var _originType = _origin.GetType();

                    if (!inherit)
                    {
                        if (_type.Equals(_originType) && _selector((TAttribute)_origin))
                        {
                            _dummy.Add(_descriptor);
                        }
                    }
                    else
                    {
                        if (_type.IsAssignableFrom(_originType) && _selector((TAttribute)_origin))
                        {
                            _dummy.Add(_descriptor);
                        }
                    }
                }
            }

            return(ReadOnlyListCollection <TDescriptor> .Initializer.Initialize <TCollection>(_dummy));
        }
Exemplo n.º 7
0
        public void AddValueAndResizeSortedArray()
        {
            var sut = new ListCollection <int>();

            sut.Add(0);
            sut.Add(2);
            sut.Add(3);
            sut.Add(4);
            sut.Add(1);
            sut.Add(6);
            sut.Add(7);
            sut.Add(8);
            sut.Add(9);
            sut.Add(10);       //- 0,2,3,4,1,6,7,8,9,10
            sut.Insert(5, 5);  //- 0,2,3,4,1,5,6,7,8,9,10
            sut.RemoveAt(10);  //- 0,2,3,4,5,6,7,8,9
            sut.Remove(8);     //- 0,2,3,4,5,6,7,9
            Assert.Equal(2, sut[1]);
            Assert.Equal(5, sut[5]);
            Assert.Equal(7, sut[7]);
            Assert.Equal(9, sut[8]);
            Assert.True(sut.Contains(5));
            Assert.False(sut.Contains(8));
            Assert.Equal(2, sut.IndexOf(3));
        }
Exemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="exception"></param>
        public void HandleThrownException(Exception exception)
        {
            if (!(exception is WebRequestException))
            {
                _innerErrorRepository.Add(new WebRequestException(exception));
                return;
            }

            _innerErrorRepository.Add(exception);
        }
        public void CountWhenAnyElementShouldReturnNumberOfElementsThatMatchesPredicate()
        {
            ListCollection <int> testList = new ListCollection <int>();

            testList.Add(1);
            testList.Add(2);
            testList.Add(3);
            testList.Add(4);

            Assert.Equal(2, testList.Count(x => x % 2 == 0));
        }
Exemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="item"></param>
        public void Add(TEntry item)
        {
            _innerRepository.Add(item);

            //RaisePropertyChanged("Count");
            //RaisePropertyChanged("Item[]");

            //RaiseCollectionChanged(NotifyCollectionChangedAction.Add, item, _innerRepository.Count);

            SetDirty();
        }
        public void LastWhenNoElementMatchesShouldThrowException()
        {
            ListCollection <string> testList = new ListCollection <string>();

            testList.Add("red");
            testList.Add("blue");

            string resultString;

            Assert.Throws <InvalidOperationException>(() => resultString = testList.Last(x => x.Length == 5));
        }
        public void LinqSingleWhenOnlyOneMatchingElementShouldReturnElement()
        {
            ListCollection <string> testList = new ListCollection <string>();

            testList.Add("red");
            testList.Add("green");
            testList.Add("blue");

            string resultString = testList.LinqSingle(x => x.Length == 5);

            Assert.Equal("green", resultString);
        }
Exemplo n.º 13
0
        public void TestContainsListOfIntegers()
        {
            var intList = new ListCollection <int>();

            intList.Add(123);
            intList.Add(int.MaxValue);
            intList.Add(int.MinValue);

            Assert.True(intList.Contains(123));
            Assert.True(intList.Contains(int.MinValue));
            Assert.Equal(3, intList.Count);
        }
        public void LinqSingleWhenMoreThanOneElementMatchShouldThrowException()
        {
            ListCollection <string> testList = new ListCollection <string>();

            testList.Add("red");
            testList.Add("green");
            testList.Add("blue");
            testList.Add("black");

            string resultString;

            Assert.Throws <InvalidOperationException>(() => resultString = testList.LinqSingle(x => x.Length == 5));
        }
        public void ConcatWhenNullSecondShouldThrowException()
        {
            ListCollection <string> firstTestList = new ListCollection <string>();

            firstTestList.Add("red");
            firstTestList.Add("green");

            ListCollection <string> secondTestList = null;

            IEnumerable <string> resultList;

            Assert.Throws <ArgumentNullException>(() => resultList = firstTestList.Concat(secondTestList));
        }
        public void LastWhenMatchingElementsShouldReturnLastMatchingElement()
        {
            ListCollection <string> testList = new ListCollection <string>();

            testList.Add("red");
            testList.Add("green");
            testList.Add("blue");
            testList.Add("black");

            string resultString = testList.Last(x => x.Length == 5);

            Assert.Equal("black", resultString);
        }
        public void CountWhenPredicateIsNullShouldThrowException()
        {
            ListCollection <int> testList = new ListCollection <int>();

            testList.Add(1);
            testList.Add(2);
            testList.Add(3);
            testList.Add(4);

            Func <int, bool> predicate = null;

            Assert.Throws <ArgumentNullException>(() => testList.Count(predicate));
        }
        public void LastWhenPredicateIsNullShouldThrowException()
        {
            ListCollection <string> testList = new ListCollection <string>();

            testList.Add("red");
            testList.Add("green");
            testList.Add("blue");

            Func <string, bool> predicate = null;

            string resultString;

            Assert.Throws <ArgumentNullException>(() => resultString = testList.Last(predicate));
        }
        public void ConcatWhenSecondEmptySequenceShouldReturnFirstSequence()
        {
            ListCollection <string> firstTestList = new ListCollection <string>();

            firstTestList.Add("red");
            firstTestList.Add("green");

            ListCollection <string> secondTestList = new ListCollection <string>();

            IEnumerable <string> resultList = firstTestList.Concat(secondTestList);

            Assert.Collection(resultList,
                              item => Assert.Equal("red", item),
                              item => Assert.Equal("green", item));
        }
Exemplo n.º 20
0
 public static void QueueWebChatMessage(WebChatMessage message)
 {
     lock (SyncRoot)
     {
         Messages.Add(message);
     }
 }
Exemplo n.º 21
0
        public void ListDocument()
        {
            //ExStart
            //ExFor:ListCollection.Document
            //ExFor:ListCollection.Count
            //ExFor:ListCollection.Item(Int32)
            //ExFor:ListCollection.GetListByListId
            //ExFor:List.Document
            //ExFor:List.ListId
            //ExSummary:Illustrates the owner document properties of lists.
            Document doc = new Document();

            ListCollection lists = doc.Lists;

            // All of these should be equal.
            Console.WriteLine("ListCollection document is doc: " + (doc == lists.Document));
            Console.WriteLine("Starting list count: " + lists.Count);

            Aspose.Words.Lists.List list = lists.Add(ListTemplate.BulletDefault);
            Console.WriteLine("List document is doc: " + (list.Document == doc));
            Console.WriteLine("List count after adding list: " + lists.Count);
            Console.WriteLine("Is the first document list: " + (lists[0] == list));
            Console.WriteLine("ListId: " + list.ListId);
            Console.WriteLine("List is the same by ListId: " + (lists.GetListByListId(1) == list));
            //ExEnd

            // Verify these properties
            Assert.AreEqual(doc, lists.Document);
            Assert.AreEqual(doc, list.Document);
            Assert.AreEqual(1, lists.Count);
            Assert.AreEqual(list, lists[0]);
            Assert.AreEqual(1, list.ListId);
            Assert.AreEqual(list, lists.GetListByListId(1));
        }
Exemplo n.º 22
0
        public void ListDocument()
        {
            //ExStart
            //ExFor:ListCollection.Document
            //ExFor:ListCollection.Count
            //ExFor:ListCollection.Item(Int32)
            //ExFor:ListCollection.GetListByListId
            //ExFor:List.Document
            //ExFor:List.ListId
            //ExSummary:Shows how to verify owner document properties of lists.
            Document doc = new Document();

            ListCollection lists = doc.Lists;

            Assert.AreEqual(doc, lists.Document);

            List list = lists.Add(ListTemplate.BulletDefault);

            Assert.AreEqual(doc, list.Document);

            Console.WriteLine("Current list count: " + lists.Count);
            Console.WriteLine("Is the first document list: " + (lists[0].Equals(list)));
            Console.WriteLine("ListId: " + list.ListId);
            Console.WriteLine("List is the same by ListId: " + (lists.GetListByListId(1).Equals(list)));
            //ExEnd

            doc   = DocumentHelper.SaveOpen(doc);
            lists = doc.Lists;

            Assert.AreEqual(doc, lists.Document);
            Assert.AreEqual(1, lists.Count);
            Assert.AreEqual(1, lists[0].ListId);
            Assert.AreEqual(lists[0], lists.GetListByListId(1));
        }
 public Uri BuildAppSite(string siteName)
 {
     try {
         // Load RootSite e.g. JusticeLeague
         Web rootSite = SharePointContext.Web;
         SharePointContext.Load(rootSite);
         //build new project site
         WebCreationInformation subsiteToCreationInfo = new WebCreationInformation()
         {
             Url         = siteName.Replace(" ", ""),
             Title       = siteName,
             Description = "For Justice!"
         };
         Web newSubsite = SharePointContext.Web.Webs.Add(subsiteToCreationInfo);
         SharePointContext.Load(newSubsite, site => site.Lists);
         ListCollection          lists            = newSubsite.Lists;
         ListCreationInformation listCreationInfo = new ListCreationInformation()
         {
             Title        = TASK_LIST_TITLE,
             TemplateType = 107, // ListTemplateType.Tasks,
             Description  = "Complete these quests to save the city!"
         };
         lists.Add(listCreationInfo);
         SharePointContext.ExecuteQuery();
         return(new Uri(ConstructFullUrl(siteName.Replace(" ", ""))));
     }
     catch (Exception ex) {
         return(new Uri(ConstructFullUrl(siteName.Replace(" ", ""))));
         //Debug.WriteLine(ex.Message);
         //throw ex;
     }
 }
Exemplo n.º 24
0
        //This method adds a list with the specified title.
        private void AddList(string accessToken, string newListName)
        {
            if (IsPostBack)
            {
                sharepointUrl = new Uri(Request.QueryString["SPHostUrl"]);
            }

            //Execute a request to add a list that has the user-supplied name.
            ClientContext           clientContext    = TokenHelper.GetClientContextWithAccessToken(sharepointUrl.ToString(), accessToken);
            Web                     web              = clientContext.Web;
            ListCollection          lists            = web.Lists;
            ListCreationInformation listCreationInfo = new ListCreationInformation();

            listCreationInfo.Title        = newListName;
            listCreationInfo.TemplateType = (int)ListTemplateType.GenericList;
            lists.Add(listCreationInfo);
            clientContext.Load <ListCollection>(lists);
            try
            {
                clientContext.ExecuteQuery();
            }
            catch (Exception e)
            {
                AddListNameBox.Text = e.Message;
            }
            RetrieveLists(accessToken);
        }
Exemplo n.º 25
0
 public void AddControlledItems(IEnumerable <ControlledItem> items)
 {
     foreach (var item in items)
     {
         ListCollection.Add(item);
     }
 }
        public void SkipWhileWhenNoEmptyShouldReturnElementsFromFalsePredicateToTheEnd()
        {
            ListCollection <int> testList = new ListCollection <int>();

            testList.Add(95);
            testList.Add(82);
            testList.Add(70);
            testList.Add(89);

            IEnumerable <int> resultList =
                testList.SkipWhile(grade => grade >= 80);

            Assert.Collection(resultList,
                              item => Assert.Equal(70, item),
                              item => Assert.Equal(89, item));
        }
        public void SkipWhileWhenNullPredicateShouldThrowException()
        {
            ListCollection <int> testList = new ListCollection <int>();

            testList.Add(95);
            testList.Add(82);
            testList.Add(70);
            testList.Add(89);

            IEnumerable <int> resultList;

            Func <int, bool> predicate = null;

            Assert.Throws <ArgumentNullException>(() => resultList =
                                                      testList.SkipWhile(predicate));
        }
Exemplo n.º 28
0
        public ListCollection <ArenaPlayer> FindArenaPlayers(String token)
        {
            token = token.ToLower();

            ListCollection <ArenaPlayer> playerList = new ListCollection <ArenaPlayer>();

            for (Int32 i = Count - 1; i >= 0; i--)
            {
                ArenaPlayer arenaPlayer = this[i];
                if (arenaPlayer == null)
                {
                    continue;
                }

                if (token == arenaPlayer.ActiveCharacter.Name.ToLower() ||
                    (token == "@chaos" && arenaPlayer.ActiveTeam == Team.Chaos) ||
                    (token == "@balance" && arenaPlayer.ActiveTeam == Team.Balance) ||
                    (token == "@order" && arenaPlayer.ActiveTeam == Team.Order) ||
                    (token == "@neutral" && arenaPlayer.ActiveTeam == Team.Neutral && arenaPlayer.ActiveCharacter.OpLevel == 0) ||
                    (token == "@all" && arenaPlayer.ActiveCharacter.OpLevel == 0))
                {
                    playerList.Add(arenaPlayer);
                }
            }

            return(playerList);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Adds a list to a site
        /// </summary>
        /// <param name="properties">Site to operate on</param>
        /// <param name="listType">Type of the list</param>
        /// <param name="featureID">Feature guid that brings this list type</param>
        /// <param name="listName">Name of the list</param>
        /// <param name="enableVersioning">Enable versioning on the list</param>
        public bool AddList(int listType, Guid featureID, string listName, bool enableVersioning)
        {
            bool created = false;

            UsingContext(ctx =>
            {
                Site site = ctx.Site;
                Web web   = site.RootWeb;

                ListCollection listCollection = web.Lists;
                ctx.Load(listCollection, lists => lists.Include(list => list.Title).Where(list => list.Title == listName));
                ctx.ExecuteQuery();

                if (listCollection.Count == 0)
                {
                    ListCollection listCol      = web.Lists;
                    ListCreationInformation lci = new ListCreationInformation();
                    lci.Title             = listName;
                    lci.TemplateFeatureId = featureID;
                    lci.TemplateType      = listType;
                    List newList          = listCol.Add(lci);
                    if (enableVersioning)
                    {
                        newList.EnableVersioning    = true;
                        newList.EnableMinorVersions = true;
                    }
                    newList.Update();
                    ctx.Load(listCol);
                    ctx.ExecuteQuery();
                    created = true;
                }
            });

            return(created);
        }
Exemplo n.º 30
0
        private void CreateListInternal(Web web, ListTemplateType listType, string listName, bool enableVersioning, bool updateAndExecuteQuery = true, string urlPath = "")
        {
            ListCollection          listCol = web.Lists;
            ListCreationInformation lci     = new ListCreationInformation();

            lci.Title        = listName;
            lci.TemplateType = (int)listType;

            if (!string.IsNullOrEmpty(urlPath))
            {
                lci.Url = urlPath;
            }

            List newList = listCol.Add(lci);

            if (enableVersioning)
            {
                newList.EnableVersioning    = true;
                newList.EnableMinorVersions = true;
            }

            if (updateAndExecuteQuery)
            {
                newList.Update();
                web.Context.Load(listCol);
                web.Context.ExecuteQuery();
            }
        }
        public void TestAdd()
        {
            var rand = new Random(3);

            ListCollection<string> list1 = new ListCollection<string>();
            Collection<string> list2 = new Collection<string>();

            //Check Add
            for (int x = 0; x < 100; x++)
            {
                var str = x.ToString();
                list1.Add(str);
                list2.Add(str);

                CheckEquals1(list1, list2);
            }

            //Check Remove
            for (int x = 100; x < 200; x++)
            {
                var str = x.ToString();
                var removeItem = list1[rand.Next(list1.Count)];
                list1.Remove(removeItem);
                list2.Remove(removeItem);

                CheckEquals1(list1, list2);

                list1.Add(str);
                list2.Add(str);

                CheckEquals1(list1, list2);
            }

            //Check RemoveAt
            for (int x = 0; x < 100; x++)
            {
                int index = rand.Next(list1.Count);
                list1.RemoveAt(index);
                list2.RemoveAt(index);

                CheckEquals1(list1, list2);
            }

            //Check Insert
            for (int x = 0; x < 100; x++)
            {
                int index = rand.Next(list1.Count);
                list1.Insert(index, x.ToString());
                list2.Insert(index, x.ToString());

                CheckEquals1(list1, list2);
            }

            //Check set
            for (int x = 0; x < 100; x++)
            {
                int index = rand.Next(list1.Count);
                list1[index] = x.ToString();
                list2[index] = x.ToString();

                CheckEquals1(list1, list2);
            }

            list1.Clear();
            list2.Clear();
            CheckEquals1(list1, list2);

            //Check Add
            for (int x = 0; x < 100; x++)
            {
                var str = x.ToString();
                list1.Add(str);
                list2.Add(str);

                CheckEquals1(list1, list2);
            }

            //Check indexOf
            for (int x = 0; x < 100; x++)
            {
                int index = rand.Next(list1.Count * 2);

                if (list1.IndexOf(index.ToString()) != list2.IndexOf(index.ToString()))
                    throw new Exception();

                CheckEquals1(list1, list2);
            }

            string[] lst1 = new string[list1.Count];
            string[] lst2 = new string[list2.Count];

            list1.CopyTo(lst1, 0);
            list2.CopyTo(lst2, 0);

            CheckEquals3(list1, list2);

            for (int x = 0; x < 100; x++)
            {
                int index = rand.Next(list1.Count * 2);

                if (list1.Contains(index.ToString()) != list2.Contains(index.ToString()))
                    throw new Exception();

                CheckEquals1(list1, list2);
            }


        }