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")); }
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); }
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>())); }
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)); }
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"); }
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"); } }
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); }
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(); } }
public void ListContainsTest() { var list = new List<char>(); list.Add('o'); Assert.IsTrue(list.Contains('o')); Assert.IsFalse(list.Contains('l')); }
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" ); }
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)); }
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"); }
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)); }
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"); }
public void AddRangeIf() { // Type var @this = new List<string> {"FizzExisting"}; // Examples @this.AddRangeIf(x => [email protected](x), "Fizz"); // Add "Fizz" value @this.AddRangeIf(x => [email protected](x), "FizzExisting", "Buzz"); // Add "Buzz" value but doesn't add "FizzExisting" // Unit Test Assert.AreEqual(3, @this.Count); }
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"); }
public void AddRange() { // Type var @this = new List<string>(); // Examples @this.AddRange("Fizz", "Buzz"); // Add "Fizz" and "Buzz" value // Unit Test Assert.IsTrue(@this.Contains("Fizz")); Assert.IsTrue(@this.Contains("Buzz")); }
public void CreateComparerTest() { var list1 = new List<TestInfo> { new TestInfo { Id = Guid.NewGuid(), Name = "a" }, new TestInfo { Id = Guid.NewGuid(), Name = "b" }, }; var info = new TestInfo { Id = Guid.NewGuid(), Name = "a" }; var comparer = Equality<TestInfo>.CreateComparer(m => m.Name); Assert.IsTrue(list1.Contains(info, comparer)); Assert.IsTrue(list1.Contains(info, r => r.Name)); }
public void AddIf() { // Type var @this = new List<string>(); // Examples @this.AddIf(s => true, "Fizz"); // Add "Fizz" value @this.AddIf(s => false, "Buzz"); // Doesn't add "Buzz" value // Unit Test Assert.IsTrue(@this.Contains("Fizz")); Assert.IsFalse(@this.Contains("Buzz")); }
public void MSOXCPERM_S01_TC01_GetFolderPermissionsList() { this.OxcpermAdapter.InitializePermissionList(); // Set the calendar folder type FolderTypeEnum folderType = FolderTypeEnum.CalendarFolderType; uint responseValue = 0; // Set IncludeFreeBusy flag RequestBufferFlags bufferflags = new RequestBufferFlags { IsIncludeFreeBusyFlagSet = true }; List<PermissionTypeEnum> permissionList = new List<PermissionTypeEnum> { PermissionTypeEnum.FreeBusyDetailed, PermissionTypeEnum.FreeBusySimple }; // Add the FreeBusyDetailed and FreeBusySimple to the calendar folder. responseValue = OxcpermAdapter.AddPermission(folderType, this.User1, bufferflags, permissionList); Site.Assert.AreEqual<uint>(TestSuiteBase.UINT32SUCCESS, responseValue, "0 indicates the server adds permission successfully."); // Get the permissions list on the folder permissionList.Clear(); responseValue = OxcpermAdapter.GetPermission(folderType, this.User1, bufferflags, out permissionList); // Add the debug information this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCPERM_R2014"); // Verify MS-OXCPERM requirement: MS-OXCPERM_R2014 this.Site.CaptureRequirementIfAreEqual<uint>( TestSuiteBase.UINT32SUCCESS, responseValue, 2014, @"[In Processing a RopGetPermissionsTable ROP Request] If the user has permission to view the permissions list of the folder, the server returns the permissions list in a RopQueryRows ROP response buffer ([MS-OXCROPS] section 2.2.5.4). "); // Verify MS-OXCPERM requirement: MS-OXCPERM_R19 bool isR19Verified = permissionList.Contains(PermissionTypeEnum.FreeBusyDetailed) && permissionList.Contains(PermissionTypeEnum.FreeBusySimple); string returnedPermission = this.ConvertFreeBusyStatusToString(permissionList); Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCPERM_R19: If the IncludeFreeBusy is set, the server should return {FreeBusyDetailed, FreeBusySimple}, actually " + returnedPermission); Site.CaptureRequirementIfIsTrue( isR19Verified, 19, @"[In RopGetPermissionsTable ROP Request Buffer] If this flag [IncludeFreeBusy] is set, the server MUST include the values of the FreeBusySimple and FreeBusyDetailed flags of the PidTagMemberRights property in the returned permissions list."); // Remove the user from the permissions list that added in this case responseValue = OxcpermAdapter.RemovePermission(folderType, this.User1, bufferflags); Site.Assert.AreEqual<uint>(TestSuiteBase.UINT32SUCCESS, responseValue, "0 indicates the server removes permission successfully."); }
public void Should_Increment_Counter_On_Operation() { var list = new List<int>(); 5.Times(x => { list.Add(x); }); Assert.IsTrue(list.Contains(0)); Assert.IsTrue(list.Contains(1)); Assert.IsTrue(list.Contains(2)); Assert.IsTrue(list.Contains(3)); Assert.IsTrue(list.Contains(4)); }
public void ObjectContainsListObject() { Employee emp1 = new Employee(); emp1.Id = 1; emp1.LastName = "Hoang"; Employee em2 = new Employee(); em2.Id = 2; em2.LastName = "Hung"; List<Employee> listEmp = new List<Employee>(); listEmp.Add(emp1); listEmp.Add(em2); bool test = listEmp.Contains(emp1); Assert.IsTrue(listEmp.Contains(emp1)); }
public void RandomElementTest() { List<int> a = new List<int>() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; int aRand = a.RandomElement(); Assert.AreEqual(true, a.Contains(aRand), $"Array: {a.CollectionToString()} | Element: {aRand}"); aRand = a.RandomElement(); int index = a.LastIndexOf(aRand); int length = a.Count - 1; Assert.AreEqual(true, index <= length, $"Array: {a.CollectionToString()} | Element: {aRand} | Index: {index} / {length}"); aRand = 11; Assert.AreEqual(false, a.Contains(aRand), $"Array: {a.CollectionToString()} | Element: {aRand}"); }
public void PropertyForwardingTest() { List<string> property_notifications = new List<string>(); Model m = new Model(); 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); m.Prop = 42; Assert.AreEqual(2, property_notifications.Count); Assert.IsTrue(property_notifications.Contains("Model:Prop")); Assert.IsTrue(property_notifications.Contains("ViewModel:Prop")); }
public void CanPutACardAndARabbit_ThenCanGetTheTwo() { IMagical aCard = new Card("Joker"); IMagical aRabbit = new Rabbit("Mr. Jumps"); _simpleHat.PutIn(aCard); _simpleHat.PutIn(aRabbit); List<IMagical> magicals = new List<IMagical>(); magicals.Add(_simpleHat.Shazaam()); magicals.Add(_simpleHat.Shazaam()); if (!(magicals.Contains(aCard) && magicals.Contains(aRabbit))) Assert.Fail(); }
public void CanSyncSetGetMailBoxContent() { const int N = 10; const int SecondsTimeout = 30; var list = new List<int>(); using (var mailBox = new ProcessMailBox("mailBox", TimeSpan.FromMilliseconds(-1))) { var setTask = Task.Factory.StartNew(() => { for (var i = 0; i < N; i++) { mailBox.Content = i; } }); var getTask = Task.Factory.StartNew(() => { for (var i = 0; i < N; i++) { list.Add((int)mailBox.Content); } }); setTask.Wait(TimeSpan.FromSeconds(SecondsTimeout)).Should().BeTrue(); getTask.Wait(TimeSpan.FromSeconds(SecondsTimeout)).Should().BeTrue(); } list.Count.Should().Be(N); for (var i = 0; i < N; i++) { list.Contains(i).Should().BeTrue(); } }
public void TestCourseStudentAdd() { Student student = new Student("Mitko Mitev",61614); List<Student> list = new List<Student>(); list.Add(student); Assert.IsTrue(list.Contains(student)); }
public void ShouldHave26RedCardsOnlyHeartsAndDiamonds() { var allowedSuites = new List<Card.Suites> { Card.Suites.Hearts, Card.Suites.Diamonds }; var result = this.deckBuilder.Build(); Assert.AreEqual(26, result.Cards.Count(x => x.Color == Card.Colors.Red && allowedSuites.Contains(x.Suite)), "There must be 26 red hearts and diamonds combined"); }
public void ShouldHave26BlackCardsOnlySpadesAndClubs() { var allowedSuites = new List<Card.Suites> { Card.Suites.Clubs, Card.Suites.Spades }; var result = this.deckBuilder.Build(); Assert.AreEqual(26, result.Cards.Count(x => x.Color == Card.Colors.Black && allowedSuites.Contains(x.Suite)), "There must be 26 black spades and clubs combined"); }
public void WeakEventManagerShouldSubscribeAndUnsubscribePropertyChangedEventSeveralSources() { const int count = 100; const string propertyName = "test"; var model = new BindingSourceModel(); var listeners = new List<EventListenerMock>(); var invokedItems = new List<EventListenerMock>(); IWeakEventManager weakEventManager = CreateWeakEventManager(); for (int i = 0; i < count; i++) { var listenerMock = new EventListenerMock(); var disposable = weakEventManager.Subscribe(model, propertyName, listenerMock); listeners.Add(listenerMock); listenerMock.Handle = (o, o1) => { invokedItems.Add(listenerMock); disposable.Dispose(); }; } model.OnPropertyChanged(propertyName + "1"); model.OnPropertyChanged(propertyName); model.OnPropertyChanged(propertyName); invokedItems.Count.ShouldEqual(count); foreach (var listener in listeners) invokedItems.Contains(listener).ShouldBeTrue(); }