Exemplo n.º 1
0
        public void PickRemaining()
        {
            other.BitField.SetAll(true);
            other.IsChoking = false;
            List<Block> allBlocks = new List<Block>();
            pieces.ForEach(delegate(Piece p) { allBlocks.AddRange(p.Blocks); });
            allBlocks.RemoveAll(delegate(Block b){ return alreadyGot.Contains(b);});
            RequestMessage m;
            while ((m = picker.PickPiece(other, new List<PeerId>())) != null)
            {
                if(alreadyGot.Exists(delegate(Block b){
                    return b.PieceIndex == m.PieceIndex &&
                           b.StartOffset == m.StartOffset &&
                           b.RequestLength == m.RequestLength;}))
                {
                    Assert.AreEqual(0, allBlocks.Count, "#1");
                    break;
                }
                int ret = allBlocks.RemoveAll(delegate (Block b) {
                    return b.PieceIndex == m.PieceIndex &&
                           b.StartOffset == m.StartOffset &&
                           b.RequestLength == m.RequestLength;
                });
                Assert.AreEqual(1, ret, "#2");

            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calculates the nodes that should be visible in the main window tree view when the specified xen object is hidden.
        /// </summary>
        /// <param name="hiddenObject">The hidden object.</param>
        private ComparableList<IXenObject> CalculatePopulateWithHiddenObject(IXenObject hiddenObject)
        {
            VirtualTreeNode rootNode = MW(() => new MainWindowTreeBuilder(new FlickerFreeTreeView()).CreateNewRootNode(new NavigationPane().Search, NavigationPane.NavigationMode.Infrastructure));

            List<VirtualTreeNode> nodes = new List<VirtualTreeNode>(rootNode.Descendants);

            nodes.RemoveAll(n => hiddenObject.Equals(n.Tag));
            nodes.RemoveAll(n => new List<VirtualTreeNode>(n.Ancestors).Find(nn => hiddenObject.Equals(nn.Tag)) != null);
            return new ComparableList<IXenObject>(nodes.ConvertAll(n => (IXenObject)n.Tag));
        }
        public void RemoveAll()
        {
            ICollection<int> col = new List<int> { 1, 2, 3, 4, 5 };

            col.RemoveAll(x => x % 2 == 0);
            Assert.IsTrue(col.SequenceEqual(new [] { 1, 3, 5 }));
        }
        public void AttributeStatement_Element()
        {
            Predicate<StatementAbstract> findAttributeStatement =
                delegate(StatementAbstract stmnt) { return stmnt is AttributeStatement; };
            Assertion saml20Assertion = AssertionUtil.GetBasicAssertion();

            AttributeStatement attributeStatement =
                (AttributeStatement) Array.Find(saml20Assertion.Items, findAttributeStatement);

            // Add an encrypted attribute.
            EncryptedElement encAtt = new EncryptedElement();
            encAtt.encryptedData = new EncryptedData();
            encAtt.encryptedData.CipherData = new CipherData();
            encAtt.encryptedData.CipherData.Item = string.Empty;
            encAtt.encryptedKey = new EncryptedKey[0];
            attributeStatement.Items = new object[] { encAtt };
            TestAssertion(saml20Assertion, "The DK-SAML 2.0 profile does not allow encrypted attributes.");

            // Add an attribute with the wrong nameformat.
            //            Attribute att = DKSaml20EmailAttribute.create("*****@*****.**");
            //            att.NameFormat = "http://example.com";
            //            attributeStatement.Items = new object[] { att };
            //            testAssertion(saml20Assertion, "The DK-SAML 2.0 profile requires that an attribute's \"NameFormat\" element is urn:oasis:names:tc:SAML:2.0:attrname-format:uri.");

            // Clear all the attributes.
            attributeStatement.Items = new object[0];
            TestAssertion(saml20Assertion, "AttributeStatement MUST contain at least one Attribute or EncryptedAttribute");

            // Remove it.
            saml20Assertion = AssertionUtil.GetBasicAssertion();
            List<StatementAbstract> statements = new List<StatementAbstract>(saml20Assertion.Items);
            statements.RemoveAll(findAttributeStatement);
            saml20Assertion.Items = statements.ToArray();
            TestAssertion(saml20Assertion, "The DK-SAML 2.0 profile requires exactly one \"AuthnStatement\" element and one \"AttributeStatement\" element.");
        }
Exemplo n.º 5
0
		public void ShowLogosAndWait()
		{
			var screen = Resolve<ScreenSpace>();
			var factory = new LogoFactory(screen);
			var logos = new List<Logo>();
			var n = 10; // randomizer.Get(10, 100);
			for (int i = 0; i < n; i++)
			{
				var logo = factory.Create();
				if (logo != null)
					logos.Add(logo);
			}
			Assert.IsTrue(logos.Count == n);
			if (!IsMockResolver)
				return;
			while (GlobalTime.Current.Milliseconds < 10000)
			{
				var mouse = Resolve<MockMouse>();
				mouse.SetButtonState(MouseButton.Left, State.Releasing);
				AdvanceTimeAndUpdateEntities(1);
				if (Time.CheckEvery(1))
				{
					Resolve<Window>().Title = "Logo count: " + logos.Count;
					logos.RemoveAll(x => x.IsOutside(screen.Viewport));
				}
			}
			Assert.IsTrue(logos.Count == 0);	
		}
Exemplo n.º 6
0
        public void RemoveAll_List_NotFound()
        {
            IList<int> list = new List<int> { 1, 3 };
            Assert.IsFalse (list.RemoveAll (i => i == 2));

            Assert.AreEqual (2, list.Count);
        }
Exemplo n.º 7
0
        public void RemoveAll_MultipleList()
        {
            IList<int> list = new List<int> { 1, 2, 3, 4, 1, 2, 5 };
            list.RemoveAll (i => i == 2);

            Assert.AreEqual (5, list.Count);
            Assert.IsFalse (list.Contains (2), "List still contains removed items");
        }
 public void remove_all()
 {
     var list = new List<string> { "a", "c", "b" };
     list.ShouldHaveCount(3);
     Func<string, bool> whereEvaluator = item => item.CompareTo("c") < 0;
     list.RemoveAll(whereEvaluator);
     list.ShouldHaveCount(1).ShouldContain("c");
 }
Exemplo n.º 9
0
        public void RemoveAll()
        {
            IList<int> iList = new List<int> { 3, 3, 3, 3 };

            var iListRemovedCount = iList.RemoveAll(Match3);

            Assert.AreEqual(4, iListRemovedCount);
            Assert.AreEqual(0, iList.Count);
        }
Exemplo n.º 10
0
        public void RemoveFirst()
        {
            IList<int> iList = new List<int> { 3, 2, 4, 2 };

            var iListRemovedCount = iList.RemoveAll(Match3);

            Assert.AreEqual(1, iListRemovedCount);
            EnsureListsAreTheSame(new List<int> { 2, 4, 2 }, iList);
        }
Exemplo n.º 11
0
        public void RemoveMultiple()
        {
            IList<int> iList = new List<int> { 1, 2, 3, 4, 3 };

            var iListRemovedCount = iList.RemoveAll(Match3);

            Assert.AreEqual(2, iListRemovedCount);
            EnsureListsAreTheSame(new List<int> { 1, 2, 4 }, iList);
        }
Exemplo n.º 12
0
        public void RemoveNone()
        {
            IList<int> iList = new List<int> { 1, 1, 1, 1 };

            var iListRemovedCount = iList.RemoveAll(Match3);

            Assert.AreEqual(0, iListRemovedCount);
            EnsureListsAreTheSame(new List<int> { 1, 1, 1, 1 }, iList);
        }
        public void RemoveAll()
        {
            var list = new List<string>
            {
                "a1", "z1", "a2", "z2", "a3", "z3"
            };

            list.RemoveAll(x => x.StartsWith("a"));
            
            Assert.AreEqual(3, list.Count);
            Assert.IsTrue(list.TrueForAll(x => x.StartsWith("z")));
        }
Exemplo n.º 14
0
        public void NUGetProductListTestFailure()
        {
            //Arrange
            List<Products> productList = new List<Products>();

            //Act
            productList = Products.getGenericProductList(true);
            productList.RemoveAll(null);
            //Assert

            Assert.AreNotEqual(0, productList.Count);
        }
Exemplo n.º 15
0
        public void ShouldSomethingWithLambdasssss()
        {
            //User user = new User(new UserPrinciple());
            //System.Console.WriteLine( (User user) => user.EmailAddress.Length > 0 );

            List<string> strings = new List<string>();
            strings.Add("f**k you microsoft");
            strings.Add("f**k again");

            strings.RemoveAll((string s) => s.Contains("again"));
            Console.WriteLine(strings.Count);
        }
Exemplo n.º 16
0
        public void IfElseVarDefTest()
        {
            const string php = @"<?php
                                 if(true)
                                 {
                                     $var = 1;
                                 }
                                 else
                                 {
                                     $var = 2;
                                 }
                                 $var = 3;";

            var cfgCreator = ParseAndBuildCFG(php);
            var reachDef = new ReachingDefinitionAnalysis();
            var analysis = new CFGTraverser(new ForwardTraversal(), reachDef, new QueueWorklist());
            analysis.Analyze(cfgCreator.Graph);

            var inLineNumbers = new List<int>() { 4, 8 };
            var outLineNumbers = new List<int>() { 4, 8, 10 };

            foreach (var block in reachDef.ReachingSetDictionary)
            {
                if (block.Key.AstEntryNode != null && block.Key.AstEntryNode.Name == "node:Expr_Assign")
                {
                    if (block.Value.DefinedInVars.Any())
                    {
                        int ins = AstNode.GetStartLine(block.Value.DefinedInVars.Values.First().Info.Block.AstEntryNode);
                        inLineNumbers.RemoveAll(x => ins == x);
                    }
                    if (block.Value.DefinedOutVars.Any())
                    {
                        int outs = AstNode.GetStartLine(block.Value.DefinedOutVars.Values.First().Info.Block.AstEntryNode);
                        outLineNumbers.RemoveAll(x => x == outs);
                    }
                }
            }

            Assert.IsTrue(inLineNumbers.IsEmpty(), "The InLineNumbers are incorrect!");
            Assert.IsTrue(outLineNumbers.IsEmpty(), "The OutLineNumbers are incorrect!");
        }
        public IEnumerable<FactoryResult> GetDiscoverers(IReadOnlyCollection<string> sources, BoostTestAdapterSettings settings)
        {
            var tmpSources = new List<string>(sources);
            var discoverers = new List<FactoryResult>();

            // sources that can be run on the external runner
            if (settings.ExternalTestRunner != null)
            {
                var extSources = tmpSources
                    .Where(s => settings.ExternalTestRunner.ExtensionType.IsMatch(Path.GetExtension(s)))
                    .ToList();

                discoverers.Add(new FactoryResult()
                {
                    Discoverer = new ExternalDiscoverer(settings.ExternalTestRunner, _dummySolution.Provider),
                    Sources = extSources
                });

                tmpSources.RemoveAll(s => extSources.Contains(s));
            }

            // sources that support list-content parameter
            var listContentSources = tmpSources
                .Where(s => (s == ("ListContentSupport" + BoostTestDiscoverer.ExeExtension)))
                .ToList();

            if (listContentSources.Count > 0)
            {
                IBoostTestRunnerFactory factory = A.Fake<IBoostTestRunnerFactory>();
                A.CallTo(() => factory.GetRunner(A<string>._, A<BoostTestRunnerFactoryOptions>._)).ReturnsLazily((string source, BoostTestRunnerFactoryOptions options) => new StubListContentRunner(source));

                discoverers.Add(new FactoryResult()
                {
                    Discoverer = new ListContentDiscoverer(factory, _dummySolution.Provider),
                    Sources = listContentSources
                });

                tmpSources.RemoveAll(s => listContentSources.Contains(s));
            }

            return discoverers;
        }
Exemplo n.º 18
0
        private void AutoSelectPolicy()
        {
            List<PolicyType> possibleTypes = Provider.Instance.PolicyTypes.Values.ToList();
            List<Policy> policies = new List<Policy>();
            IEnumerable<string> pastEraNames = Eras.Select(b => b.Name);

            // remove all policy types which will become active in future eras only
            possibleTypes.RemoveAll(a => !pastEraNames.Contains(a.EraName));

            PropabilityMap<PolicyType> typeMap = new PropabilityMap<PolicyType>();

            foreach (PolicyType type in possibleTypes)
            {
                // add only to evaluation if not already adopted
                if (!_policyTypes.Contains(type))
                    typeMap.AddItem(type, 1f / Flavours.Distance(type.Flavours, Flavours));
                else
                    policies.AddRange(type.Policies);
            }

            policies.RemoveAll(a => _policies.Contains(a));

            PropabilityMap<Policy> policyMap = new PropabilityMap<Policy>();

            foreach (Policy p in policies)
                policyMap.AddItem(p, 1f / Flavours.Distance(p.Flavours, Flavours));

            if (typeMap.Items.Count > 0)
            {
                PolicyType bestPolicyType = typeMap.Best;

                if (policyMap.Items.Count == 0)
                {
                    if (!AdoptPolicyType(bestPolicyType))
                        throw new Exception("There was an error while adopting " + bestPolicyType);
                }
                else
                {
                    Policy bestPolicy = policyMap.RandomOfBest3;
                    if (Flavours.Distance(bestPolicyType.Flavours, Flavours) < Flavours.Distance(bestPolicy.Flavours, Flavours))
                    {
                        if (!AdoptPolicyType(bestPolicyType))
                            throw new Exception("There was an error while adopting " + bestPolicyType);
                    }
                    else
                    {
                        if (!AdoptPolicy(bestPolicy))
                            throw new Exception("There was an error while adopting " + bestPolicy);
                    }
                }
            }
            else
            {
                if (policyMap.Items.Count == 0 )
                    throw new Exception("There must be at least one policy to select!");

                AdoptPolicy(policyMap.RandomOfBest3);
            }
        }
        public void CheckManagedFilters()
        {
            List<string> filters = new List<string> (CIFilter.FilterNamesInCategories (null));
            var nspace = CIFilterType.Namespace;
            var types = CIFilterType.Assembly.GetTypes ();
            foreach (Type t in types) {
                if (t.Namespace != nspace)
                    continue;

                if (t.IsAbstract || !CIFilterType.IsAssignableFrom (t))
                    continue;

                // we need to skip the filters that are not supported by the executing version of iOS
                if (Skip (t))
                    continue;

                var ctor = t.GetConstructor (Type.EmptyTypes);
                if ((ctor == null) || ctor.IsAbstract)
                    continue;

                NSObject obj = ctor.Invoke (null) as NSObject;
                Assert.That (obj.Handle, Is.Not.EqualTo (IntPtr.Zero), t.Name + ".Handle");
            #if false
                // check base type - we might have our own base type or different names, so it's debug only (not failure)
                var super = new Class (obj.Class.SuperClass).Name;
                var bt = t.BaseType.Name;
                if ((super != bt) && (bt == "CIFilter")) // check if we should (like Apple) use a non-default base type for filters
                    Console.WriteLine ("[WARN] {0}.SuperClass == {1} (native) and {2} managed", t.Name, super, bt);
            #endif
                int result = filters.RemoveAll (s => StringComparer.OrdinalIgnoreCase.Compare (t.Name, s) == 0);
                Assert.That (result, Is.GreaterThan (0), t.Name);
            }
            // in case it's a buggy filter we need to try to remove it from the list too
            for (int i = filters.Count - 1; i >= 0; i--) {
                if (Skip (filters [i]))
                    filters.RemoveAt (i);
            }
            Assert.That (filters.Count, Is.EqualTo (0), "Managed filters not found for {0}", String.Join (", ", filters));
        }
 public void RemoveAllWithNullPredicate()
 {
     ICollection<int> col = new List<int> { 1, 2, 3 };
     Assert.Throws<ArgumentNullException>(() => col.RemoveAll(null));
 }
        public void TestSocketTransceiverWhenServerStops()
        {
            Responder responder = new SpecificResponder<Mail>(new MailImpl());
            var server = new SocketServer("localhost", 0, responder);

            server.Start();

            var transceiver = new SocketTransceiver("localhost", server.Port);
            var mail = SpecificRequestor.CreateClient<Mail>(transceiver);

            int[] successes = {0};
            int failures = 0;
            int[] quitOnFailure = {0};
            var threads = new List<Thread>();

            // Start a bunch of client threads that use the transceiver to send messages
            for (int i = 0; i < 100; i++)
            {
                var thread = new Thread(
                    () =>
                        {
                            while (true)
                            {
                                try
                                {
                                    mail.send(CreateMessage());
                                    Interlocked.Increment(ref successes[0]);
                                }
                                catch (Exception)
                                {
                                    Interlocked.Increment(ref failures);

                                    if (Interlocked.Add(ref quitOnFailure[0], 0) == 1)
                                    {
                                        return;
                                    }
                                }
                            }
                        });

                thread.Name = "Thread" + i;
                threads.Add(thread);
                thread.Start();
            }

            // Be sure the threads are running: wait until we get a good deal of successes
            while (Interlocked.Add(ref successes[0], 0) < 10000)
            {
                Thread.Sleep(50);
            }

            // Now stop the server
            server.Stop();

            // Server is stopped: successes should not increase anymore: wait until we're in that situation
            while (true)
            {
                int previousSuccesses = Interlocked.Add(ref successes[0], 0);
                Thread.Sleep(500);
                if (previousSuccesses == Interlocked.Add(ref successes[0], 0))
                {
                    break;
                }
            }

            server.Start();

            long now = CurrentTimeMillis();

            int previousSuccesses2 = successes[0];
            while (true)
            {
                Thread.Sleep(500);
                if (successes[0] > previousSuccesses2)
                {
                    break;
                }
                if (CurrentTimeMillis() - now > 5000)
                {
                    Console.WriteLine("FYI: requests don't continue immediately...");
                    break;
                }
            }

            // Stop our client, we would expect this to go on immediately
            Console.WriteLine("Stopping transceiver");

            Interlocked.Add(ref quitOnFailure[0], 1);
            now = CurrentTimeMillis();
            transceiver.Close();

            // Wait for all threads to quit
            while (true)
            {
                threads.RemoveAll(x => !x.IsAlive);

                if (threads.Count > 0)
                    Thread.Sleep(1000);
                else
                    break;
            }

            if (CurrentTimeMillis() - now > 10000)
            {
                Assert.Fail("Stopping NettyTransceiver and waiting for client threads to quit took too long.");
            }
            else
            {
                Console.WriteLine("Stopping NettyTransceiver and waiting for client threads to quit took "
                                  + (CurrentTimeMillis() - now) + " ms");
            }
        }
        public void AuthnStatement_Element()
        {
            Assertion saml20Assertion = AssertionUtil.GetBasicAssertion();
            AuthnStatement authnStmt =
                (AuthnStatement)Array.Find(saml20Assertion.Items, delegate(StatementAbstract stmnt) { return stmnt is AuthnStatement; });

            // Mess around with the AuthnStatement.
            {
                string oldSessionIndex = authnStmt.SessionIndex;
                authnStmt.SessionIndex = null;
                TestAssertion(saml20Assertion, "The DK-SAML 2.0 profile requires that the \"AuthnStatement\" element contains the \"SessionIndex\" attribute.");
                authnStmt.SessionIndex = oldSessionIndex;
            }

            {
                int index =
                    Array.FindIndex(authnStmt.AuthnContext.Items,
                                    delegate(object o) { return o is string && o.ToString() == "urn:oasis:names:tc:SAML:2.0:ac:classes:X509"; });
                object oldValue = authnStmt.AuthnContext.Items[index];
                authnStmt.AuthnContext.Items[index] = "Hallelujagobble!!";
                TestAssertion(saml20Assertion, "AuthnContextClassRef has a value which is not a wellformed absolute uri");
                authnStmt.AuthnContext.Items[index] = oldValue;
            }

            // Remove it.
            saml20Assertion = AssertionUtil.GetBasicAssertion();
            List<StatementAbstract> statements = new List<StatementAbstract>(saml20Assertion.Items);
            statements.RemoveAll(delegate(StatementAbstract stmnt) { return stmnt is AuthnStatement; });
            saml20Assertion.Items = statements.ToArray();
            TestAssertion(saml20Assertion, "The DK-SAML 2.0 profile requires exactly one \"AuthnStatement\" element and one \"AttributeStatement\" element.");
        }
Exemplo n.º 23
0
        public void RemoveSingular()
        {
            IList<int> iList = new List<int> { 1, 2, 3, 4 };

            var iListRemovedCount = iList.RemoveAll(Match3);

            Assert.AreEqual(1, iListRemovedCount);
            EnsureListsAreTheSame(new List<int> { 1, 2, 4 }, iList);
        }
        public IEnumerable<FactoryResult> GetDiscoverers(IReadOnlyCollection<string> sources, BoostTestAdapterSettings settings)
        {
            var tmpSources = new List<string>(sources);
            var discoverers = new List<FactoryResult>();

            // sources that can be run on the external runner
            if (settings.ExternalTestRunner != null)
            {
                var extSources = tmpSources
                    .Where(s => settings.ExternalTestRunner.ExtensionType == Path.GetExtension(s))
                    .ToList();

                discoverers.Add(new FactoryResult()
                {
                    Discoverer = new ExternalDiscoverer(settings.ExternalTestRunner),
                    Sources = extSources
                });

                tmpSources.RemoveAll(s => extSources.Contains(s));
            }

            // sources that support list-content parameter
            var listContentHelper = new StubListContentHelper();

            var listContentSources = tmpSources
                .Where(s => Path.GetExtension(s) == BoostTestDiscoverer.ExeExtension)
                .Where(listContentHelper.IsListContentSupported)
                .ToList();

            if (listContentSources.Count > 0)
            {
                discoverers.Add(new FactoryResult()
                {
                    Discoverer = new ListContentDiscoverer(listContentHelper),
                    Sources = listContentSources
                });

                tmpSources.RemoveAll(s => listContentSources.Contains(s));
            }


            // sources that NOT support the list-content parameter
            var sourceCodeSources = tmpSources
                .Where(s => Path.GetExtension(s) == BoostTestDiscoverer.ExeExtension)
                .ToList();

            if (sourceCodeSources.Count > 0)
            {
                discoverers.Add(new FactoryResult()
                {
                    Discoverer = new SourceCodeDiscoverer(_dummySolution.Provider),
                    Sources = sourceCodeSources
                });
            }
            return discoverers;

        }
Exemplo n.º 25
0
        private string[] getFiles(string path, string pattern)
        {
            // Cause an exception if the path is invalid
            Path.GetFileName(path);

            string pathWithoutTrailingSlash = path.EndsWith("\\") ? path.Substring(0, path.Length - 1) : path;
            //NOTE: the Replace calls below are a very minimal attempt to convert a basic, cmd.exe-style wildcard
            //into something Regex.IsMatch will know how to use.
            string finalPattern = "^" + pattern.Replace(".", "\\.").Replace("*", "[\\w\\W]*") + "$";

            List<string> matches = new List<string>(defaultTasksFileMap.Keys);
            matches.RemoveAll(
                delegate(string candidate)
                {
                    bool sameFolder = (0 == String.Compare(Path.GetDirectoryName(candidate),
                                                           pathWithoutTrailingSlash,
                                                           StringComparison.OrdinalIgnoreCase));
                    return !sameFolder || !Regex.IsMatch(Path.GetFileName(candidate), finalPattern);
                });
            return matches.ToArray();
        }
Exemplo n.º 26
0
        public void RemoveAll_SingleList()
        {
            IList<int> list = new List<int> { 1, 2, 3 };
            list.RemoveAll (i => i == 2);

            Assert.AreEqual (2, list.Count);
            Assert.IsFalse (list.Contains (2), "List still contains removed item");
        }
Exemplo n.º 27
0
 public void RemoveAllRemovesCorrectItemsFromCollection()
 {
     var data = new List<int> { 1, 3, 5, 4, 6, 8 };
     data.RemoveAll(x => x % 2 == 0);
     Assert.AreEqual(3, data.Count);
     Assert.Contains(1, data);
     Assert.Contains(3, data);
     Assert.Contains(5, data);
 }
Exemplo n.º 28
0
        public void FindUnmetDependencies()
        {
            var mods = new List<CkanModule>();
            var dlls = Enumerable.Empty<string>();
            Assert.IsEmpty(CKAN.SanityChecker.FindUnmetDependencies(mods, dlls), "Empty list");

            mods.Add(registry.LatestAvailable("DogeCoinFlag",null));
            Assert.IsEmpty(CKAN.SanityChecker.FindUnmetDependencies(mods, dlls), "DogeCoinFlag");

            mods.Add(registry.LatestAvailable("CustomBiomes",null));
            Assert.Contains("CustomBiomesData", CKAN.SanityChecker.FindUnmetDependencies(mods, dlls).Keys, "Missing CustomBiomesData");

            mods.Add(registry.LatestAvailable("CustomBiomesKerbal",null));
            Assert.IsEmpty(CKAN.SanityChecker.FindUnmetDependencies(mods, dlls), "CBD+CBK");

            mods.RemoveAll(x => x.identifier == "CustomBiomes");
            Assert.AreEqual(2, mods.Count, "Checking removed CustomBiomes");

            Assert.Contains("CustomBiomes", CKAN.SanityChecker.FindUnmetDependencies(mods, dlls).Keys, "Missing CustomBiomes");
        }
        private void AssertExpectedObjectsAreRegisteredWith(GenericApplicationContext context, int expectedDefinitionCount)
        {
            // only check names that are not part of configuration namespace test
            List<string> names = new List<string>(context.DefaultListableObjectFactory.GetObjectDefinitionNames());
            names.RemoveAll(x => x.StartsWith("ConfigurationNameSpace"));

            if (names.Count != expectedDefinitionCount)
            {
                Console.WriteLine("Actual types registered with the container:");
                foreach (var name in names)
                {
                    Console.WriteLine(name);
                }
            }

            Assert.That(names.Count, Is.EqualTo(expectedDefinitionCount));
        }
Exemplo n.º 30
0
        public void should_commit_when_writing_with_exp_ver_any_even_while_somene_is_writing_in_parallel()
        {
            const string stream = "should_commit_when_writing_with_exp_ver_any_even_while_somene_is_writing_in_parallel";

            var transWritesCompleted = new AutoResetEvent(false);
            var writesToSameStreamCompleted = new AutoResetEvent(false);

            var totalTranWrites = 500;
            var totalPlainWrites = 500;

            //excplicitly creating stream
            using (var store = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
                store.CreateStream(stream, new byte[0]);

            //500 events during transaction
            ThreadPool.QueueUserWorkItem(_ =>
            {
                using (var store = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
                {
                    var transaction = store.StartTransaction(stream, ExpectedVersion.Any);
                    var writes = new List<Task>();
                    for (int i = 0; i < totalTranWrites; i++)
                    {
                        if (i % 10 == 0)
                            writes.RemoveAll(write => write.IsCompleted);

                        writes.Add(store.TransactionalWriteAsync(transaction.TransactionId,
                                                                 transaction.Stream,
                                                                 new[] { new TestEvent((i + 1).ToString(), "trans write") }));
                    }

                    Task.WaitAll(writes.ToArray());
                    store.CommitTransaction(transaction.TransactionId, transaction.Stream);

                    transWritesCompleted.Set();
                }
            });

            //500 events to same stream in parallel
            ThreadPool.QueueUserWorkItem(_ =>
            {
                using (var store = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
                {
                    var writes = new List<Task>();
                    for (int i = 0; i < totalPlainWrites; i++)
                    {
                        if (i % 10 == 0)
                            writes.RemoveAll(write => write.IsCompleted);

                        writes.Add(store.AppendToStreamAsync(stream,
                                                             ExpectedVersion.Any,
                                                             new[] {new TestEvent((i + 1).ToString(), "plain write")}));
                    }

                    Task.WaitAll(writes.ToArray());

                    writesToSameStreamCompleted.Set();
                }
            });

            transWritesCompleted.WaitOne();
            writesToSameStreamCompleted.WaitOne();

            //check all written
            using (var store = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
            {
                var slice = store.ReadEventStreamForward(stream, 0, totalTranWrites + totalPlainWrites + 1);
                Assert.That(slice.Events.Length, Is.EqualTo(totalTranWrites + totalPlainWrites + 1));

                Assert.That(slice.Events.Count(ent => Encoding.UTF8.GetString(ent.Metadata) == "trans write"), Is.EqualTo(totalTranWrites));
                Assert.That(slice.Events.Count(ent => Encoding.UTF8.GetString(ent.Metadata) == "plain write"), Is.EqualTo(totalPlainWrites));
            }
        }