当前位置: 首页>>代码示例>>C#>>正文


C# List.Contains方法代码示例

本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# List.Contains方法的具体用法?C# List.Contains怎么用?C# List.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.VisualStudio.TestTools.UnitTesting.List的用法示例。


在下文中一共展示了List.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CollectionPropertyDependencyTest

        public void CollectionPropertyDependencyTest()
        {
            List<string> property_notifications = new List<string>();
            Model m = new Model();
            m.Items.Add(new Item() { Prop = 42 });
            m.Items.Add(new Item() { Prop = 23 });
            m.Items.Add(new Item() { Prop = 17 });
            ViewModel vm = new ViewModel(m);

            m.PropertyChanged += (sender, args) => property_notifications.Add("Model:" + args.PropertyName);
            vm.PropertyChanged += (sender, args) => property_notifications.Add("ViewModel:" + args.PropertyName);

            var item = new Item() { Prop = 1 };
            item.PropertyChanged += (sender, args) => property_notifications.Add("Item:" + args.PropertyName);
            m.Items.Add(item);

            Assert.AreEqual(1, property_notifications.Count);
            Assert.IsTrue(property_notifications.Contains("ViewModel:Items"));
            property_notifications.Clear();

            item.Prop = 42;

            Assert.AreEqual(3, property_notifications.Count);
            Assert.IsTrue(property_notifications.Contains("Item:Prop"));
            Assert.IsTrue(property_notifications.Contains("ViewModel:Items")); // Called by Item.Prop changed
            Assert.IsTrue(property_notifications.Contains("ViewModel:Items")); // Called by ItemViewModel.PropSquared
            property_notifications.Clear();

            m.Items.Remove(item);

            Assert.AreEqual(1, property_notifications.Count);
            Assert.IsTrue(property_notifications.Contains("ViewModel:Items"));
        }
开发者ID:lycilph,项目名称:Projects,代码行数:33,代码来源:CollectionPropertyDependency.cs

示例2: MultipleModelsDependenciesTest

        public void MultipleModelsDependenciesTest()
        {
            List<string> property_notifications = new List<string>();
            ModelA ma = new ModelA() { PropA = 1 };
            ModelB mb = new ModelB() { PropB = 2 };
            ViewModel vm = new ViewModel(ma, mb);

            int current_total;

            ma.PropertyChanged += (sender, args) => property_notifications.Add("ModelA:" + args.PropertyName);
            mb.PropertyChanged += (sender, args) => property_notifications.Add("ModelB:" + args.PropertyName);
            vm.PropertyChanged += (sender, args) => property_notifications.Add("ViewModel:" + args.PropertyName);

            ma.PropA = 2;

            Assert.AreEqual(2, property_notifications.Count);
            Assert.IsTrue(property_notifications.Contains("ModelA:PropA"));
            Assert.IsTrue(property_notifications.Contains("ViewModel:Total"));
            property_notifications.Clear();

            mb.PropB = 40;

            Assert.AreEqual(2, property_notifications.Count);
            Assert.IsTrue(property_notifications.Contains("ModelB:PropB"));
            Assert.IsTrue(property_notifications.Contains("ViewModel:Total"));

            var total_property = TypeDescriptor.GetProperties(vm)["Total"];
            var total = total_property.GetValue(vm);
            Assert.AreEqual(42, total);
        }
开发者ID:lycilph,项目名称:Projects,代码行数:30,代码来源:MultipleModelsDependencies.cs

示例3: EqualsOneTest

 public void EqualsOneTest()
 {
     var res = new List<OnePrimary>
         {
             new OnePrimary
                 {
                     Id = 1,
                     Name = "awdwd"
                 },
             new OnePrimary
                 {
                     Id = 2,
                     Name = "aegaga"
                 }
         };
     var contains = new OnePrimary
         {
             Id = 1,
             Name = "akljegselgj",
         };
     var notContains = new OnePrimary
         {
             Id = 120,
             Name = "aegaga"
         };
     Assert.IsTrue(res.Contains(contains, new MapperComparer<OnePrimary>()));
     Assert.IsFalse(res.Contains(notContains, new MapperComparer<OnePrimary>()));
 }
开发者ID:riberk,项目名称:PersistenceBase,代码行数:28,代码来源:MapperComparerTests.cs

示例4: TestApiKeyQueryAll

        public void TestApiKeyQueryAll()
        {
            ApiKey key = new ApiKey();
            key.Save();
            Balanced.Balanced.configure(key.secret);
            Marketplace marketplace = new Marketplace();
            marketplace.Save();

            ApiKey key1 = new ApiKey();
            key1.SaveToMarketplace();
        
            ApiKey key2 = new ApiKey();
            key2.SaveToMarketplace();
        
            ApiKey key3 = new ApiKey();
            key3.SaveToMarketplace();
        
            List<ApiKey> keys = ApiKey.Query().All();
            Assert.AreEqual(4, keys.Count);
            List<String> key_guids = new List<String>();
            foreach (ApiKey k in keys) {
                key_guids.Add(k.id);
            }
            Assert.IsTrue(key_guids.Contains(key1.id));
            Assert.IsTrue(key_guids.Contains(key2.id));
            Assert.IsTrue(key_guids.Contains(key3.id));
        }
开发者ID:NSAKHAN,项目名称:balanced-csharp,代码行数:27,代码来源:ApiKeyTest.cs

示例5: ExternalCollectionDependencyTest

        public void ExternalCollectionDependencyTest()
        {
            var changed_properties = new List<string>();
            var base_obj = new ExternalCollectionDependencyBaseObject();
            var obj = new ExternalCollectionDependencyObject(base_obj);
            obj.PropertyChanged += (sender, args) => changed_properties.Add(args.PropertyName);

            base_obj.BaseProp1.Add(42);

            Assert.AreEqual(1, changed_properties.Count, "1 property changed event expected");
            Assert.IsTrue(changed_properties.Contains("Prop1"), "Prop1 property changed event expected");
            changed_properties.Clear();

            base_obj = new ExternalCollectionDependencyBaseObject();
            obj.BaseObject = base_obj;
            base_obj.BaseProp1.Add(42);

            Assert.AreEqual(2, changed_properties.Count, "2 property changed events expected");
            Assert.IsTrue(changed_properties.Contains("BaseObject"), "BaseObject property changed event expected");
            Assert.IsTrue(changed_properties.Contains("Prop1"), "Prop1 property changed event expected");
            changed_properties.Clear();

            base_obj.BaseProp1 = new ObservableCollection<int>();
            base_obj.BaseProp1.Add(42);

            Assert.AreEqual(1, changed_properties.Count, "1 property changed event expected");
            Assert.IsTrue(changed_properties.Contains("Prop1"), "Prop1 property changed event expected");
        }
开发者ID:lycilph,项目名称:Projects,代码行数:28,代码来源:ExternalCollectionDependency.cs

示例6: InvokeWebActionListAction

        public void InvokeWebActionListAction()
        {
            using (var scope = new PSTestScope(true))
            {
                List<string> listNames = new List<string>();

                Action<List> listAction = list =>
                {
                    listNames.Add(list.Title);
                };

                var results = scope.ExecuteCommand("Invoke-SPOWebAction",
                    new CommandParameter("ListAction", listAction),
                    new CommandParameter("ListProperties", new[] { "Title" })
                );

                Assert.IsTrue(listNames.Count > 3, "Wrong count on lists");

                Assert.IsTrue(listNames.Contains("PnPTestList1"), "PnPTestList1 is missing");
                Assert.IsTrue(listNames.Contains("PnPTestList2"), "PnPTestList2 is missing");
                Assert.IsTrue(listNames.Contains("PnPTestList3"), "PnPTestList3 is missing");

                InvokeWebActionResult result = results.Last().BaseObject as InvokeWebActionResult;

                AssertInvokeActionResult(result,
                    processedWebCount: 1
                );

                Assert.IsTrue(result.ProcessedListCount > 3, "Wrong count on proccessed list");
            }
        }
开发者ID:russgove,项目名称:PnP-PowerShell,代码行数:31,代码来源:InvokeWebActionTest.cs

示例7: TestTemplateOneOf

 public void TestTemplateOneOf()
 {
     Random random = new Random();
     var document = new SimpleDocument("The letter is {OneOf(\"a\", \"b\", \"c\", \"d\", null)}.");
     var store = new BuiltinStore();
     store["OneOf"] = new NativeFunction((values) =>
     {
         return values[random.Next(values.Count)];
     });
     store["system"] = "Alrai";
     List<string> results = new List<string>();
     for (int i = 0; i < 1000; i++)
     {
         results.Add(document.Render(store));
     }
     Assert.IsTrue(results.Contains(@"The letter is a."));
     results.RemoveAll(result => result == @"The letter is a.");
     Assert.IsTrue(results.Contains(@"The letter is b."));
     results.RemoveAll(result => result == @"The letter is b.");
     Assert.IsTrue(results.Contains(@"The letter is c."));
     results.RemoveAll(result => result == @"The letter is c.");
     Assert.IsTrue(results.Contains(@"The letter is d."));
     results.RemoveAll(result => result == @"The letter is d.");
     Assert.IsTrue(results.Contains(@"The letter is ."));
     results.RemoveAll(result => result == @"The letter is .");
     Assert.IsTrue(results.Count == 0);
 }
开发者ID:cmdrmcdonald,项目名称:EliteDangerousDataProvider,代码行数:27,代码来源:ScriptResolverTest.cs

示例8: SqliteInitializationTest

        public void SqliteInitializationTest()
        {          
            using (SQLiteLocalStorage storage = new SQLiteLocalStorage())
            { }

            using (SQLiteConnection connection = new SQLiteConnection(string.Format("Data Source={0};Version=3;", DB_FILE_PATH)))
            {
                connection.Open();

                var cmd = connection.CreateCommand();
                cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table'";
                var reader = cmd.ExecuteReader();

                var tableName = new List<string>();

                while (reader.Read())
                {
                    tableName.Add(reader.GetString(0));
                }

                Assert.IsTrue(tableName.Count == 3);
                Assert.IsTrue(tableName.Contains("datasets"));
                Assert.IsTrue(tableName.Contains("records"));
                Assert.IsTrue(tableName.Contains("kvstore"));
                connection.Close();
            }
        }
开发者ID:lawandeneel,项目名称:Fashion,代码行数:27,代码来源:SQLiteTests.cs

示例9: ListContainsTest

 public void ListContainsTest()
 {
     var list = new List<char>();
     list.Add('o');
     Assert.IsTrue(list.Contains('o'));
     Assert.IsFalse(list.Contains('l'));
 }
开发者ID:Kirill-Andreev,项目名称:University,代码行数:7,代码来源:GenericsTest.cs

示例10: TestGenerateBool

 public void TestGenerateBool() {
     var result = new List<bool>();
     for( int i = 0; i < 100; i++ ) {
         result.Add( _builder.GenerateBool() );
     }
     Assert.IsTrue( result.Contains( true ), "true" );
     Assert.IsTrue( result.Contains( false ), "false" );
 }
开发者ID:NetUtil,项目名称:Util,代码行数:8,代码来源:RandomBuilderTest.cs

示例11: AddRange

        public void AddRange()
        {
            List<int> stuff = new List<int>();
            stuff.AddRange(5, 6, 7, 8);

            Assert.IsTrue(stuff.Contains(5));
            Assert.IsTrue(stuff.Contains(6));
            Assert.IsTrue(stuff.Contains(7));
            Assert.IsTrue(stuff.Contains(8));
        }
开发者ID:einsteinsci,项目名称:ultimate-util,代码行数:10,代码来源:CollectionUtil_Test.cs

示例12: GivenTwoAnagramsAndOneOther_ShouldPrintOnlyAnagrams

        public void GivenTwoAnagramsAndOneOther_ShouldPrintOnlyAnagrams()
        {
            var word = new[] { "word", "drow", "crow" };
            var printedLines = new List<string>();

            RunFinder(word, printedLines);

            Assert.IsTrue(printedLines.Contains("word drow"), "Should have printed the words in same line");
            Assert.IsFalse(printedLines.Contains("crow"), "Should skip word not anagram");
        }
开发者ID:runerys,项目名称:Anagram-kata,代码行数:10,代码来源:AnagramTests.cs

示例13: CreateRandomBoolTest

 public void CreateRandomBoolTest()
 {
     RandomValue target = new RandomValue(); // TODO: 初始化為適當值
     List<bool> temp = new List<bool>();
     for (int i = 0; i < 200; i++)
     {
         temp.Add(target.CreateRandomBool());
     }
     Assert.AreEqual(true, temp.Contains(true)&&temp.Contains(false));
 }
开发者ID:ko255128,项目名称:VocabularyTest,代码行数:10,代码来源:RandomValueTest.cs

示例14: GivenTwoAnagrams_ShouldPrintBothInTwoLines

        public void GivenTwoAnagrams_ShouldPrintBothInTwoLines()
        {
            var word = new[] { "word", "drow", "blue", "lueb" };
            var printedLines = new List<string>();

            RunFinder(word, printedLines);

            Assert.AreEqual(2, printedLines.Count);
            Assert.IsTrue(printedLines.Contains("word drow"), "Should have printed the words in same line");
            Assert.IsTrue(printedLines.Contains("blue lueb"), "Should have printed the words in same line");
        }
开发者ID:runerys,项目名称:Anagram-kata,代码行数:11,代码来源:AnagramTests.cs

示例15: DerivedSimpleDependencyTest

        public void DerivedSimpleDependencyTest()
        {
            var changed_properties = new List<string>();
            var obj = new DerivedSimpleDependencyObject();
            obj.PropertyChanged += (sender, args) => changed_properties.Add(args.PropertyName);

            obj.BaseProp1 = 42;

            Assert.AreEqual(2, changed_properties.Count, "2 property changed events expected");
            Assert.IsTrue(changed_properties.Contains("BaseProp1"), "BaseProp1 property changed event expected");
            Assert.IsTrue(changed_properties.Contains("Prop1"), "Prop1 property changed event expected");
        }
开发者ID:lycilph,项目名称:Projects,代码行数:12,代码来源:DerivedSimpleDependency.cs


注:本文中的Microsoft.VisualStudio.TestTools.UnitTesting.List.Contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。