public void Add() { var criteria = new List<IIterationStopCriterium> { new FailureStopCriterium(), new DivergenceStopCriterium(), new IterationCountStopCriterium(), new ResidualStopCriterium() }; var iterator = new Iterator(); Assert.AreEqual(0, iterator.NumberOfCriteria, "Incorrect criterium count"); foreach (var criterium in criteria) { iterator.Add(criterium); Assert.IsTrue(iterator.Contains(criterium), "Missing criterium"); } // Check that we have all the criteria Assert.AreEqual(criteria.Count, iterator.NumberOfCriteria, "Incorrect criterium count"); var enumerator = iterator.StoredStopCriteria; while (enumerator.MoveNext()) { var criterium = enumerator.Current; Assert.IsTrue(criteria.Exists(c => ReferenceEquals(c, criterium)), "Criterium missing"); } }
public void AfterAPostIsAdded_ItsTagsShouldBeRetrievable() { var post = GetTestPost(); Metaweblog.AddPost(string.Empty, string.Empty, string.Empty, post, true); var tags = new List<CategoryInfo>(Metaweblog.GetCategories(string.Empty, string.Empty, string.Empty)); foreach (string c in post.categories) { Assert.IsTrue(tags.Exists(t => t.title == c)); } }
public void Deal_FromStart_All52CardsDifferent() { Deck deck = new Deck(); List<Card> cards = new List<Card>(); for (int i = 0; i < 52; i++) { Card next = deck.Deal(); Assert.IsFalse(cards.Exists(c => next == c)); cards.Add(next); } }
public void CheckRelationshipData () { AddThreeRelationShips (); PackagePart part = package.GetPart (new Uri ("/_rels/.rels", UriKind.Relative)); Assert.IsNotNull (package.GetPart (new Uri ("/_RELS/.RELS", UriKind.Relative)), "#0"); package.Flush (); Assert.IsNotNull (part, "#1"); Stream stream = part.GetStream (); Assert.IsTrue (stream.Length > 0, "#2a"); XmlDocument doc = new XmlDocument (); XmlNamespaceManager manager = new XmlNamespaceManager (doc.NameTable); manager.AddNamespace("rel", "http://schemas.openxmlformats.org/package/2006/relationships"); doc.Load (new StreamReader (stream)); Assert.IsNotNull (doc.SelectSingleNode ("/rel:Relationships", manager), "#2b"); XmlNodeList list = doc.SelectNodes ("/rel:Relationships/*", manager); Assert.AreEqual (3, list.Count); List<PackageRelationship> relationships = new List<PackageRelationship>(package.GetRelationships ()); foreach (XmlNode node in list) { Assert.AreEqual (3, node.Attributes.Count, "#3"); Assert.IsNotNull (node.Attributes ["Id"], "#4"); Assert.IsNotNull (node.Attributes ["Target"], "#5"); Assert.IsNotNull (node.Attributes ["Type"], "#6"); Assert.IsTrue(relationships.Exists(d => d.Id == node.Attributes["Id"].InnerText && d.TargetUri == new Uri (node.Attributes["Target"].InnerText, UriKind.Relative) && d.RelationshipType == node.Attributes["Type"].InnerText)); } }
public void GetNotificationMessagesValidBusinessIsSuccessful() { // Arrange var notificationManagerMock = MockRepository.GenerateMock<INotificationManager>(); PropertyManagementSystemService.NotificationManager = notificationManagerMock; //Make sure business is present CacheHelper.StubBusinessCacheSingleBusiness(BUSINESS_ID); // invalidate the cache so we make sure our business is loaded into the cache Cache.Business.Invalidate(); var stubMessages = new List<Message> { MessageBuilder.BuildSimple(), MessageBuilder.BuildSimple(messageId: 2), MessageBuilder.BuildSimple(messageId: 3, messageStatusEnum: MessageStatusEnum.Read) }; notificationManagerMock.Expect(manager => manager.GetNotificationMessages(BUSINESS_ID)) .Return(stubMessages); // Act List<MessageDto> messagesFound = PropertyManagementSystemService.GetNotificationMessages(BUSINESS_ID); // Assert notificationManagerMock.VerifyAllExpectations(); Assert.AreEqual(stubMessages.Count, messagesFound.Count, "Number of messages returned wasn't correct"); Assert.IsTrue(stubMessages.Exists(msg => msg.Id == 2) && messagesFound.Exists(msg => msg.Id == 2), "Message with Id was not returned correctly"); CacheHelper.ReAssignBusinessDaoToBusinessCache(); }
public void TestReturnedPeers() { rig.Tracker.AllowNonCompact = true; rig.Tracker.Add(rig.Trackables[0]); List<PeerDetails> peers = new List<PeerDetails>(); for (int i = 0; i < 25; i++) peers.Add(rig.Peers[i]); for (int i = 0; i < peers.Count; i++) rig.Listener.Handle(peers[i], rig.Trackables[0]); BEncodedDictionary dict = (BEncodedDictionary)rig.Listener.Handle(rig.Peers[24], rig.Trackables[0]); BEncodedList list = (BEncodedList)dict["peers"]; Assert.AreEqual(25, list.Count, "#1"); foreach (BEncodedDictionary d in list) { IPAddress up = IPAddress.Parse(d["ip"].ToString()); int port = (int)((BEncodedNumber)d["port"]).Number; string peerId = ((BEncodedString)d["peer id"]).Text; Assert.IsTrue(peers.Exists(delegate(PeerDetails pd) { return pd.ClientAddress.Equals(up) && pd.Port == port && pd.PeerId == peerId; }), "#2"); } }
public void story_log_is_observed_during_invocation() { var log = new List<KeyValuePair<LogSeverity, string>> { new KeyValuePair<LogSeverity, string>( LogSeverity.Info, "test_info"), new KeyValuePair<LogSeverity, string>( LogSeverity.Warning, "test_warning"), new KeyValuePair<LogSeverity, string>( LogSeverity.Error, "test_error"), }; var handlerRules = new Ruleset<IStory, IStoryHandler>() { Rules = { new PredicateRule( _ => true, // always run for story _ => new ActionHandler( (story) => Assert.AreEqual(0, story.Log.Count()), // make sure OnStart() is invoked with zero log items. (story, task) => Assert.IsTrue(story.Log.All( entry => log.Exists( l => l.Key == entry.Severity && l.Value == entry.Text)))) ), }, }; new Story("testStory", handlerRules).Run(story => { foreach (var kvp in log) { story.Log.Add(kvp.Key, kvp.Value); } }); }
private void contains(List<HistoryItem> items, HistoryItem item) { Assert.That(items.Exists(h => h.Id == item.Id)); }
public void Clone() { var criteria = new List<IIterationStopCriterium> { new FailureStopCriterium(), new DivergenceStopCriterium(), new IterationCountStopCriterium(), new ResidualStopCriterium() }; var iterator = new Iterator(criteria); var clonedIterator = iterator.Clone(); Assert.IsInstanceOf(typeof (Iterator), clonedIterator, "Incorrect type"); var clone = clonedIterator as Iterator; Assert.IsNotNull(clone); // ReSharper disable PossibleNullReferenceException Assert.AreEqual(iterator.NumberOfCriteria, clone.NumberOfCriteria, "Incorrect criterium count"); // ReSharper restore PossibleNullReferenceException foreach (var criterium in clone.StoredStopCriteria) { Assert.IsTrue(criteria.Exists(c => c.GetType() == criterium.GetType()), "Criterium missing"); } }
public void SearchTest() { DynamicRTree<int> rTree = new DynamicRTree<int>(new GuttmanQuadraticInsert<int>(), new GuttmanQuadraticSplit<int>(), new DynamicRTreeBalanceHeuristic()); addEntries(rTree); List<RTreeIndexEntry<int>> resultsList = new List<RTreeIndexEntry<int>>(); resultsList.AddRange(rTree.Search(new BoundingBox(-100, -100, 5928.57523425, 3252.50803582))); Assert.AreEqual(8, resultsList.Count); resultsList.Clear(); resultsList.AddRange(rTree.Search(new BoundingBox(0, 0, 100, 100))); Assert.AreEqual(6, resultsList.Count); Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 1; })); Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 2; })); Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 3; })); Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 6; })); Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 7; })); Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 8; })); resultsList.Clear(); resultsList.AddRange(rTree.Search(new BoundingBox(1500, 1500, 1500, 1500))); Assert.AreEqual(2, resultsList.Count); Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 4; })); Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 5; })); resultsList.Clear(); resultsList.AddRange(rTree.Search(new BoundingBox(100, 100, 100, 100))); Assert.AreEqual(4, resultsList.Count); Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 1; })); Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 2; })); Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 7; })); Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 8; })); resultsList.Clear(); addRandomEntries(rTree); resultsList.AddRange(rTree.Search(new BoundingBox(100, 100, 100, 100))); Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 1; })); Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 2; })); Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 7; })); Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 8; })); resultsList.Clear(); rTree.Dispose(); }
private void AssertPhrasesEqual(List<List<string>> expected, List<List<string>> actual) { foreach (var phrase in expected) { Assert.IsTrue(actual.Exists(x => AreEquivalent(phrase, x))); } }
private static int Main(string[] args) { AppArguments parsedArgs = new AppArguments(); if (!Parser.ParseArgumentsWithUsage(args, parsedArgs)) { return 1; } List<string> referencedAssemblies = new List<string>(parsedArgs.ReferencedAssemblies); if ( !referencedAssemblies.Exists( delegate(string asm) { return asm.Contains("ProtocolGenerator.exe"); })) { referencedAssemblies.Add("ProtocolGenerator.exe"); } Assembly templateAssembly; if (!CompileLibraryInMemory(parsedArgs.EventTemplatePath, referencedAssemblies.ToArray(), out templateAssembly)) { Console.WriteLine("ERROR: TemplateFile compile error."); return 2; } uint minorVersion = GetMinorVersion(parsedArgs.EventTemplatePath); IGenerator rootGenerator; try { // TODO - Ctor throws exception. Is it OK? rootGenerator = new RootGenerator(templateAssembly.GetTypes(), minorVersion); } catch (SyntaxErrorException e) { Console.WriteLine(e); return 3; } string generatedFilePath = GetGeneratedFilePath(parsedArgs.EventTemplatePath); using (StreamWriter sw = File.CreateText(generatedFilePath)) { rootGenerator.Write(new CodeWriter(sw)); } return 0; }
public void TestBoxF2DLineEnumeration() { var rect1 = new BoxF2D(0, 0, 2, 2); List<LineF2D> lines = new List<LineF2D>(rect1 as IEnumerable<LineF2D>); Assert.AreEqual(4, lines.Count); Assert.IsTrue(lines[0].IsSegment); Assert.IsTrue(lines[1].IsSegment); Assert.IsTrue(lines[2].IsSegment); Assert.IsTrue(lines[3].IsSegment); Assert.IsTrue(lines.Exists(x => (x.Point1 == rect1.Corners[0] && x.Point2 == rect1.Corners[1]) || (x.Point2 == rect1.Corners[0] && x.Point1 == rect1.Corners[1]))); Assert.IsTrue(lines.Exists(x => (x.Point1 == rect1.Corners[1] && x.Point2 == rect1.Corners[2]) || (x.Point2 == rect1.Corners[2] && x.Point1 == rect1.Corners[1]))); Assert.IsTrue(lines.Exists(x => (x.Point1 == rect1.Corners[2] && x.Point2 == rect1.Corners[3]) || (x.Point2 == rect1.Corners[3] && x.Point1 == rect1.Corners[2]))); Assert.IsTrue(lines.Exists(x => (x.Point1 == rect1.Corners[3] && x.Point2 == rect1.Corners[0]) || (x.Point2 == rect1.Corners[0] && x.Point1 == rect1.Corners[3]))); }
private static void CleanUpFoldersOrig(List<string> uniqueFolders) { uniqueFolders.RemoveAll( delegate(string curFolder) { // remove empty if (string.IsNullOrEmpty(curFolder)) { return true; } // remove sub paths if (uniqueFolders.Exists( delegate(string s) { if (!string.IsNullOrEmpty(s) && curFolder.StartsWith(s) && string.Compare(s, curFolder) != 0) { return true; } return false; })) { return true; } return false; } ); }
void VerifyAttachments(List<Attachment> before, List<Attachment> after) { Assert.AreEqual(before.Count, after.Count); foreach (Attachment x in before) { Assert.IsTrue(after.Exists(delegate(Attachment inAfter) { return inAfter.Id == x.Id && inAfter.Name == x.Name && inAfter.Content.Length == x.Content.Length && !string.IsNullOrEmpty(inAfter.Id); }), "Attachment name {0} and id {1} doesnt exist in modified list", x.Name, x.Id); } }
public void ExistsTest() { IEnumerable<int> lst = new List<int>() {2, 12, 12, 34, 43, 22}; Console.WriteLine(lst.Exists(a => a == 2)); }
public void FourtyOnePatchToBeInstalledForCurrentVersion() { // Arrange var serverVersions = GetAVersionWithGivenNumberOfPatches(100); RemoveANumberOfPatchesPseudoRandomly(serverVersions.First().MinimalPatches, 49); var pool_patches = new List<Pool_patch>(); for (int ii = 0; ii < 10; ii++) { pool_patches.Add(new Pool_patch() { uuid = serverVersions.First().MinimalPatches[ii].Uuid }); } var notMinimalPatchesInVersion = serverVersions.First().Patches.Where(p => !serverVersions.First().MinimalPatches.Exists(mp => mp.Uuid == p.Uuid)).ToList(); for (int ii = 0; ii < 5; ii++) { pool_patches.Add(new Pool_patch() { uuid = notMinimalPatchesInVersion[ii].Uuid }); } var master = GetAMockHost(serverVersions.First().Oem, serverVersions.First().BuildNumber, pool_patches); SetXenServerVersionsInUpdates(serverVersions); // Act var upgradeSequence = XenAdmin.Core.Updates.GetUpgradeSequence(master.Object.Connection); // Assert Assert.NotNull(upgradeSequence); Assert.AreEqual(1, upgradeSequence.Count); var seqToCheck = upgradeSequence.First(); Assert.NotNull(seqToCheck.Key); Assert.AreEqual(seqToCheck.Key.uuid, master.Object.uuid); Assert.NotNull(seqToCheck.Value); Assert.AreEqual(seqToCheck.Value.Count, 41); foreach (var patch in seqToCheck.Value) Assert.IsTrue(serverVersions.First().MinimalPatches.Contains(patch) && !pool_patches.Exists(p => p.uuid == patch.Uuid)); Assert.False(seqToCheck.Value.Exists(seqpatch => !serverVersions.First().MinimalPatches.Contains(seqpatch))); Assert.True(seqToCheck.Value.Exists(seqpatch => !pool_patches.Exists(pp => pp.uuid == seqpatch.Uuid))); }
public void CreateWithCollection() { var criteria = new List<IIterationStopCriterium> { new FailureStopCriterium(), new DivergenceStopCriterium(), new IterationCountStopCriterium(), new ResidualStopCriterium() }; var iterator = new Iterator(criteria); Assert.IsNotNull(iterator, "Should have an iterator"); // Check that we have all the criteria Assert.AreEqual(criteria.Count, iterator.NumberOfCriteria, "Incorrect criterium count"); foreach (var criterium in iterator.StoredStopCriteria) { Assert.IsTrue(criteria.Exists(c => ReferenceEquals(c, criterium)), "Criterium missing"); } }
public void Advertise5() { List<PeerId> peers = new List<PeerId>(new PeerId[] { rig.CreatePeer(true), rig.CreatePeer(true), rig.CreatePeer(true) }); peers.ForEach(unchoker.PeerConnected); peers.Add(this.peer); peers[0].BitField.SetTrue(0).SetTrue(7).SetTrue(14); peers[1].BitField.SetTrue(2).SetTrue(6).SetTrue(10); peers[2].BitField.SetTrue(5).SetTrue(9).SetTrue(12); unchoker.UnchokeReview(); foreach (PeerId peer in peers) { while (peer.QueueLength > 0) { int index = ((HaveMessage)peer.Dequeue()).PieceIndex; Assert.IsFalse(peers.Exists(delegate(PeerId p) { return p.BitField[index]; })); } } }