Ejemplo n.º 1
0
        public void BecauseWithNArguments()
        {
            // ACT
            // ReSharper disable once HeapView.BoxingAllocation
            DesignByContractViolationException exception = Fail.Because("Always {0} {1} {2} {3}", "fails", 1, "times", "frequently");

            // ASSERT
            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.Message, Is.EqualTo("Always fails 1 times frequently"));
        }
Ejemplo n.º 2
0
        public void BecauseWith1Argument()
        {
            // ACT
            // ReSharper disable once HeapView.BoxingAllocation
            DesignByContractViolationException exception = Fail.Because("Always {0}", 1);

            // ASSERT
            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.Message, Is.EqualTo("Always 1"));
        }
        public Queue <T> Sort()
        {
            var sortedQueue = new Queue <T>(); // create, even if it stays empty

            var outputQueue = new Queue <T>(); // with predecessorCount == 0

            // (1) go through all the nodes
            //		if the node's predecessorCount == 0
            //			add it to the outputQueue
            foreach (KeyValuePair <T, NodeInfo> kvp in this.nodes)
            {
                if (kvp.Value.PredecessorCount == 0)
                {
                    outputQueue.Enqueue(kvp.Key);
                }
            }

            // (2) process the output Queue
            //	output the key
            //	delete the key from Nodes
            //	foreach successor
            //		decrement its predecessorCount
            //		if it becomes zero
            //			add it to the output Queue

            while (outputQueue.Count != 0)
            {
                T nodeKey = outputQueue.Dequeue();

                sortedQueue.Enqueue(nodeKey); // add it to sortedQueue

                NodeInfo nodeInfo = this.nodes[nodeKey];

                this.nodes.Remove(nodeKey); // remove it from Nodes

                foreach (T successor in nodeInfo.Successors)
                {
                    if (--this.nodes[successor].PredecessorCount == 0)
                    {
                        outputQueue.Enqueue(successor);
                    }
                }

                nodeInfo.Clear();
            }

            // outputQueue is empty here
            if (this.nodes.Count != 0)
            {
                //// there is at least one cycle
                throw Fail.Because("There is at least one cycle in the graph. It cannot be sorted topologically.");
            }

            return(sortedQueue);
        }
 private IContextStorage <SessionsContainer> GetContextStorage()
 {
     foreach (var storageType in preferredContextStorages)
     {
         var storageCandidates = this.sessionStorages.Where(s => storageType.IsInstanceOfType(s));
         var firstAvailable    = storageCandidates.FirstOrDefault(x => x.IsAvailable());
         if (firstAvailable != null)
         {
             return(firstAvailable);
         }
     }
     throw Fail.Because("There is no context storage available - are you missing declaration: using(new " + nameof(SessionThreadStaticScope) +
                        "()) {{ DATABASE ACCESS CODE; }}");
 }