Ejemplo n.º 1
0
    static void Main()
    {
        //Vector v = new Vector();
        //Stack v = new Stack();
        //LinkedList v = new LinkedList();

        Queue v = new Queue();
        v.Print();

        v.Add(0);
        v.Add(1);
        v.Add(2);
        v.Print();

        v.Remove();
        v.Print();

        v.Remove();
        v.Print();

        Console.ReadKey();

        //v.RemoveFirst();
        //v.Print();

        //v.RemoveLast();
        //v.Print();

        //v.RemoveLast();
        //v.Add(123);
        //v.Print();

        //Console.ReadKey();
    }
Ejemplo n.º 2
0
 public void Add(ref keyType key, string text)
 {
     if (!string.IsNullOrEmpty(text))
     {
         queue.Add(ref key, text);
     }
 }
Ejemplo n.º 3
0
    public void RightView(TreeNode root)
    {
        //We will use the same approach as used in left view of binary tree.

        Queue <Node> queue = new Queue <Node>();

        queue.Enqueue(root);

        int n = queue.Count;

        while (queue.Count > 0)
        {
            for (int i = 1; i <= n; ++i)
            {
                Node d = queue.Dequeue();

                if (i == n) //means the node d is the last node in this level
                {
                    Console.WriteLine(d.data);
                }

                if (d.left != null)
                {
                    queue.Add(d.left);
                }

                if (d.right != null)
                {
                    queue.Add(d.right);
                }
            }
        }
    }
        public void Even()
        {
            Queue one = new Queue();

            one.Add(1);
            one.Add(2);
            one.Add(3);
            one.Add(4);
            Queue two = new Queue();

            two.Add("one");
            two.Add("two");
            two.Add("three");
            two.Add("four");

            Queue result = weaver.Weave(one, two);

            Assert.AreEqual(1, result.Remove());
            Assert.AreEqual("one", result.Remove());
            Assert.AreEqual(2, result.Remove());
            Assert.AreEqual("two", result.Remove());
            Assert.AreEqual(3, result.Remove());
            Assert.AreEqual("three", result.Remove());
            Assert.AreEqual(4, result.Remove());
            Assert.AreEqual("four", result.Remove());
            Assert.Throws <InvalidOperationException>(() => result.Remove());
        }
Ejemplo n.º 5
0
 public void GetBackwardItem()
 {
     var queue = new Queue();
     Assert.IsTrue(queue.GetBackwardItem().IsEmpty);
     queue.Add("filename0", 0, 1);
     queue.Add("filename1", 0, 1);
     Assert.IsTrue(queue.GetBackwardItem().Equals("filename0", 0, 1));
 }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            string      filePath = "/Users/elijah/БГТУ/2 Курс/ООП/Лабораторные работы/Лабораторная работа 1/C-/lab8/lab8.txt";
            Queue <int> intQueue = new Queue <int>();

            intQueue.Add(14);
            intQueue.Add(4124);
            intQueue.Add(12);
            intQueue.Add(24);
            intQueue.Add(256);
            intQueue.Add(128);
            intQueue.Remove();
            Console.WriteLine("intQueue: ");
            intQueue.QueuePrint();
            Console.WriteLine("\n----------------------\n");
            intQueue.ToFile(filePath);

            Queue <double> doubleQueue = new Queue <double>();

            doubleQueue.Add(2.33);
            doubleQueue.Add(55.1);
            doubleQueue.Add(46.12);
            doubleQueue.Add(4.21);
            doubleQueue.Add(3.14);
            Console.WriteLine("doubleQueue: ");
            doubleQueue.QueuePrint();
            Console.WriteLine("\n----------------------\n");
            doubleQueue.ToFile(filePath);

            Queue <bool> boolQueue = new Queue <bool>();

            boolQueue.Add(true);
            boolQueue.Add(false);
            boolQueue.Add(true);
            boolQueue.Add(false);
            boolQueue.Add(true);
            Console.WriteLine("boolQueue: ");
            boolQueue.QueuePrint();
            Console.WriteLine("\n----------------------\n");
            doubleQueue.ToFile(filePath);

            Queue <UserStruct> userStructQueue = new Queue <UserStruct>();
            UserStruct         userStruct1     = new UserStruct(12, 32.12, true);
            UserStruct         userStruct2     = new UserStruct(32, 4.12, true);
            UserStruct         userStruct3     = new UserStruct(412, 33.12, false);
            UserStruct         userStruct4     = new UserStruct(524, 332.1, true);
            UserStruct         userStruct5     = new UserStruct(24, 3.14, false);

            userStructQueue.Add(userStruct1);
            userStructQueue.Add(userStruct2);
            userStructQueue.Add(userStruct3);
            userStructQueue.Add(userStruct4);
            userStructQueue.Add(userStruct5);
            Console.WriteLine("userStructQueue: ");
            userStructQueue.QueuePrint();
            Console.WriteLine("\n----------------------\n");
            userStructQueue.ToFile(filePath);
        }
Ejemplo n.º 7
0
 public void AddTest()
 {
     myQueue = new Queue(5);
     Assert.AreEqual(0, myQueue.Length());
     myQueue.Add("Arthur");
     Assert.AreEqual(1, myQueue.Length());
     myQueue.Add("William");
     Assert.AreEqual(2, myQueue.Length());
 }
Ejemplo n.º 8
0
        public void TestFindNonExistentValue()
        {
            AuxQueue = new Queue <int>();
            AuxQueue.Add(3);
            AuxQueue.Add(7);
            int value = 2;

            Assert.IsNull(AuxQueue.Find(value));
        }
Ejemplo n.º 9
0
 public void Clear()
 {
     var queue = new Queue();
     queue.Add("filename", 0, 1);
     queue.Add("filename", 10, 1);
     queue.Clear();
     Assert.AreEqual(0, queue.Count);
     Assert.IsTrue(queue.CurrentItem.IsEmpty);
 }
Ejemplo n.º 10
0
 public void CanBackward()
 {
     var queue = new Queue();
     Assert.IsFalse(queue.CanBackward);
     queue.Add("filename0", 0, 1);
     queue.Add("filename1", 0, 1);
     Assert.IsTrue(queue.CanBackward);
     queue.Backward();
     Assert.IsFalse(queue.CanBackward);
 }
    /// <summary>
    /// generates a platform piece starting from x,y for l length
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="l"></param>
    private void _generatePiece(float x, float y, float len, PLATFORM_TYPE pt, out List <GameObject> curObjects)
    {
        curObjects = new List <GameObject>();
        //case: we're generating a floor object
        if (pt == PLATFORM_TYPE.FLOOR_T)
        {
            var cur_length = x;
            while (cur_length < len)
            {
                //select random platform type
                PLATFORM_TYPE pt2;

                //debug stuff
                var rnum = _randomNum(0, 3);
                if (rnum == 1)
                {
                    pt2 = PLATFORM_TYPE.FLOOR_T;
                }
                else
                {
                    pt2 = PLATFORM_TYPE.SPIKE_T;
                }
                var num = _randomNum(1, 5);
                for (var i = 0; i < num; ++i)
                {
                    if (pt2 == PLATFORM_TYPE.FLOOR_T)
                    {
                        var obj = Instantiate(prefab_lowerPlatform, new Vector3(cur_length, y, 0), Quaternion.identity);
                        _currentFloorChunkObjects.Add(obj);
                        curObjects.Add(obj);
                    }
                    else
                    {
                        var obj = Instantiate(prefab_spikes, new Vector3(cur_length, y, 0), Quaternion.identity);
                        _currentFloorChunkObjects.Add(obj);
                        curObjects.Add(obj);
                    }
                    cur_length += BOX_WIDTH;
                }
            }
            _curFloorEnd = cur_length;
        }
        else if (pt == PLATFORM_TYPE.AIR_T)
        {
            var plen       = x + len;
            var cur_length = x;
            while (cur_length < plen)
            {
                curObjects.Add(Instantiate(prefab_lowerPlatform, new Vector3(cur_length, y), Quaternion.identity));
                cur_length += BOX_WIDTH;
            }
            _curPlatformEnd = cur_length;
        }
    }
Ejemplo n.º 12
0
    private void BuildRandomPath()
    {
        Queue pathQueue = new Queue();

        // copies essential path to the pathQueue
        foreach (KeyValuePair <Vector2, TileType> tile in gridPositions)
        {
            Vector2 tilePosition = new Vector2(tile.Key.x, tile.Key.y);
            pathQueue.Add(new PathTile(TileType.RANDOM, tilePosition, minBound, maxBound, gridPositions));
        }

        // starts processing
        while (pathQueue.hasNext)
        {
            PathTile tile = pathQueue.nextTile;

            int adjacentTileCount = tile.adjacentPathTiles.Count;

            if (adjacentTileCount == 0)
            {
                return;
            }

            // 1 in 5 chance to create a chamber
            if (Random.Range(0, 5) == 1)
            {
                BuildRandomChamber(tile);
            }

            // 1 in 3 chance whether a random path is created
            // or if tile is RANDOM and more than one direction to move, then creates random path
            else if (Random.Range(0, 3) == 1 || (tile.type == TileType.RANDOM && adjacentTileCount > 1))
            {
                int     randomIndex            = Random.Range(0, adjacentTileCount);
                Vector2 nextRandomPathPosition = tile.adjacentPathTiles[randomIndex];

                // if it isn't already part of dungeon
                if (!gridPositions.ContainsKey(nextRandomPathPosition))
                {
                    if (Random.Range(0, 20) == 1)
                    {
                        gridPositions.Add(nextRandomPathPosition, TileType.ENEMY);
                    }
                    else
                    {
                        gridPositions.Add(nextRandomPathPosition, TileType.EMPTY);
                    }

                    PathTile newRandomPath = new PathTile(TileType.RANDOM, nextRandomPathPosition, minBound, maxBound, gridPositions);
                    pathQueue.Add(newRandomPath);
                }
            }
        }
    }
Ejemplo n.º 13
0
        public void TestRemoveNonExistentItem()
        {
            AuxQueue = new Queue <int>();
            int value = 2;

            AuxQueue.Add(3);
            AuxQueue.Add(4);
            AuxQueue.Add(7);

            Assert.IsNull(AuxQueue.Remove(value));
        }
Ejemplo n.º 14
0
        public void TestRemove()
        {
            AuxQueue = new Queue <int>();
            int value = 2;

            AuxQueue.Add(3);
            AuxQueue.Add(value);
            AuxQueue.Add(7);

            Assert.AreEqual(value, AuxQueue.Remove(value));
        }
        public void should_peek_fifo()
        {
            // Arrange
            var queue = new Queue <int>();

            queue.Add(42);
            queue.Add(43);

            // Assert
            queue.Peek().Should().Be(42);
        }
Ejemplo n.º 16
0
        public static void Main()
        {
            //Create objects
            var parser = new Parser();
            var queue  = new Queue();
            var tasks  = new List <Task>();

            // Step 1 - Get Files by Directory
            var filesList = DirectoryUtils.GetDatFilesByDirectory(@"data\in");

            //Step 2 - Iterate and read files
            foreach (var file in filesList)
            {
                Dictionary <int, string> fileData = null;

                using (var fileReader = new FileReader(file))
                {
                    fileData = fileReader.ReadFile().Result;
                }

                //Run in parallel the data parse
                var t = Task.Run(() =>
                {
                    var customers = parser.ParseCustomerData(fileData);
                    var salesmen  = parser.ParseSalesmanData(fileData);
                    var sales     = parser.ParseSales(fileData);

                    queue.Add(customers);
                    queue.Add(salesmen);
                    queue.Add(sales);
                });

                tasks.Add(t);
            }

            Task.WaitAll(tasks.ToArray());

            //Step 3 - Get queue values and calculate values
            var customersList = queue.GetCustomers();
            var salesmenList  = queue.GetSalesMen();
            var salesList     = queue.GetSales();

            var numberOfCustomers      = DomainQueries.DomainQueries.NumberOfCustomers(customersList);
            var numberOfSalesMen       = DomainQueries.DomainQueries.NumberOfSalesman(salesmenList);
            var idTheMostExpensiveSale = DomainQueries.DomainQueries.TheMostExpensiveSale(salesList);
            var nameTheWorstSalesman   = DomainQueries.DomainQueries.TheWorstSalesman(salesList);

            //Step 4 - Write to output file the results of calculated values
            using (var writer = new FileWriter(@"data\out\flatfile.done.dat"))
            {
                writer.Write(numberOfCustomers, numberOfSalesMen, idTheMostExpensiveSale, nameTheWorstSalesman);
            }
        }
Ejemplo n.º 17
0
 public void Change_0()
 {
     const string fileName = "filename0";
     var queue = new Queue();
     queue.Add(fileName, position: 0, line: 1);
     queue.Add(fileName, position: 100, line: 2);
     queue.Add(fileName, position: 1000, line: 3);
     queue.Change(fileName, startPosition: 101, charsAdded: -999, linesAdded: -1);
     Assert.IsTrue(queue.CurrentItem.Equals(fileName, position: 100, line: 2));
     queue.Backward();
     Assert.IsTrue(queue.CurrentItem.Equals(fileName, position: 0, line: 1));
 }
Ejemplo n.º 18
0
 public void Change_2()
 {
     const string filename = "filename";
     var queue = new Queue();
     queue.Add(filename, position: 0, line: 1);
     queue.Add(filename, position: 6, line: 2);
     queue.Add(filename, position: 8, line: 3);
     Assert.IsTrue(queue.CurrentItem.Equals(filename, position: 8, line: 3));
     queue.Change(filename, startPosition: 7, charsAdded: -1, linesAdded: 0);
     Assert.IsTrue(queue.CurrentItem.Equals(filename, position: 7, line: 3));
     queue.Backward();
     Assert.IsTrue(queue.CurrentItem.Equals(filename, position: 6, line: 2));
 }
        public ServiceRequestsController()
        {
            // No session in WebApi without jumping through hoops
            //_serviceQueue = WebApiApplication["_serviceQueue"];

            _serviceQueue = new Queue<ServiceRequest>();
            _serviceQueue.Add(new ServiceRequest("222-222-2222", "Downtown 7-11"));
            _serviceQueue.Add(new ServiceRequest("555-222-5555", "Downtown Dry Cleaners"));
            _serviceQueue.Add(new ServiceRequest("888-222-8888", "Downtown Butcher Shop"));
            _serviceQueue.Add(new ServiceRequest("444-222-1111", "Downtown Bakery Shop"));

            //WebApiApplication["_serviceQueue"] = _serviceQueue;
        }
Ejemplo n.º 20
0
 public void Add()
 {
     var queue = new Queue();
     queue.Add("filename", 100, 1);
     Assert.AreEqual(0, queue.Count);
     Assert.IsTrue(queue.CurrentItem.Equals("filename", 100, 1));
     queue.Add("filename", 100, 1);
     Assert.AreEqual(0, queue.Count);
     Assert.IsTrue(queue.CurrentItem.Equals("filename", 100, 1));
     queue.Add("filename", 110, 1);
     Assert.AreEqual(1, queue.Count);
     Assert.IsTrue(queue.CurrentItem.Equals("filename", 110, 1));
 }
Ejemplo n.º 21
0
        public ServiceRequestsController()
        {
            // No session in WebApi without jumping through hoops
            //_serviceQueue = WebApiApplication["_serviceQueue"];

            _serviceQueue = new Queue <ServiceRequest>();
            _serviceQueue.Add(new ServiceRequest("222-222-2222", "Downtown 7-11"));
            _serviceQueue.Add(new ServiceRequest("555-222-5555", "Downtown Dry Cleaners"));
            _serviceQueue.Add(new ServiceRequest("888-222-8888", "Downtown Butcher Shop"));
            _serviceQueue.Add(new ServiceRequest("444-222-1111", "Downtown Bakery Shop"));

            //WebApiApplication["_serviceQueue"] = _serviceQueue;
        }
Ejemplo n.º 22
0
        public void Test()
        {
            var queue = new Queue <int>(0);

            queue.Add(1);
            queue.Add(2);
            queue.Add(3);
            queue.Add(4);

            for (int i = 0; i < queue.Count; i++)
            {
                Assert.AreEqual(i, queue.DeQueue().Data);
            }
        }
Ejemplo n.º 23
0
        public void QueueOperations()
        {
            Queue <int> subject = new Queue <int>();

            Assert.AreEqual(0, subject.First);
            Assert.AreEqual(0, subject.Last);
            subject.Add(1);
            Assert.AreEqual(1, subject.Count);
            Assert.AreEqual(1, subject.First);
            Assert.AreEqual(1, subject.Last);
            Assert.IsTrue(subject.Contains(1));
            Assert.IsFalse(subject.Contains(2));
            Assert.IsFalse(subject.Contains(3));

            subject.Add(2);
            Assert.AreEqual(2, subject.Count);
            Assert.AreEqual(1, subject.First);
            Assert.AreEqual(2, subject.Last);
            Assert.IsTrue(subject.Contains(1));
            Assert.IsTrue(subject.Contains(2));
            Assert.IsFalse(subject.Contains(3));

            subject.Add(3);
            Assert.AreEqual(3, subject.Count);
            Assert.AreEqual(1, subject.First);
            Assert.AreEqual(3, subject.Last);
            Assert.IsTrue(subject.Contains(1));
            Assert.IsTrue(subject.Contains(2));
            Assert.IsTrue(subject.Contains(3));

            Assert.IsTrue(subject.Remove(2));
            Assert.AreEqual(2, subject.Count);
            Assert.AreEqual(1, subject.First);
            Assert.AreEqual(3, subject.Last);

            Assert.IsFalse(subject.Remove(9));
            Assert.AreEqual(2, subject.Count);
            Assert.AreEqual(1, subject.First);
            Assert.AreEqual(3, subject.Last);

            Assert.AreEqual(1, subject.Dequeue());
            Assert.AreEqual(1, subject.Count);
            Assert.AreEqual(3, subject.First);
            Assert.AreEqual(3, subject.Last);

            Assert.AreEqual(3, subject.Dequeue());
            Assert.AreEqual(0, subject.Count);

            Assert.AreEqual(0, subject.Dequeue());
        }
Ejemplo n.º 24
0
    public static void Main(string[] args)
    {
        var queue = new Queue();

        queue.Add(3);
        queue.Add(2);
        queue.Add(1);

        Console.WriteLine(queue.Remove().Data);
        Console.WriteLine(queue.Remove().Data);
        Console.WriteLine(queue.Remove().Data);


        Console.ReadLine();
    }
Ejemplo n.º 25
0
 /// <summary>加入队列</summary>
 /// <param name="context"></param>
 /// <param name="msg"></param>
 /// <returns></returns>
 protected virtual void AddToQueue(IHandlerContext context, T msg)
 {
     if (msg != null && context["TaskSource"] is TaskCompletionSource <Object> source)
     {
         Queue.Add(context.Owner, msg, Timeout, source);
     }
 }
Ejemplo n.º 26
0
        public void AddToQueue(Mobile m, EncounterType encounter)
        {
            if (Queue.ContainsKey(m))
            {
                if (encounter == EncounterType.Roof)
                {
                    m.SendLocalizedMessage(1156245);
                    // You are currently already in the queue for the finale. You cannot join this queue unless you leave the other queue. Use the context menu option on the crystal ball to exit that queue.
                }
                else
                {
                    m.SendLocalizedMessage(1156246);
                    // You are currently already in the queue for one of the tower encounters. You cannot join this queue unless you leave the other queue. Use the context menu option on the crystal ball to exit that queue.
                }

                return;
            }

            Queue.Add(m, encounter);

            int order = Array.IndexOf <Mobile>(Queue.Keys.ToArray(), m) + 1;

            m.SendLocalizedMessage(1156182, order > 1 ? order.ToString() : "next");

            /* The fortress is currently full right now. You are currently ~1_NUM~ in the queue.
             * You will be messaged when an encounter is available.  You must remain in the lobby in
             * order to be able to join.*/
        }
Ejemplo n.º 27
0
        public virtual void Enqueue(PlayerMobile pm, PvPTeam team = null, bool party = true)
        {
            if (pm == null || pm.Deleted)
            {
                return;
            }

            if (!CanQueue(pm))
            {
                OnQueueReject(pm);
                return;
            }

            if (team != null && team.Deleted)
            {
                team = null;
            }

            if (!IsQueued(pm))
            {
                Queue.Add(pm, team);
                OnQueueJoin(pm, team);
            }
            else
            {
                Queue[pm] = team;
                OnQueueUpdate(pm, team);
            }

            if (party)
            {
                EnqueueParty(pm, Party.Get(pm), team);
            }
        }
Ejemplo n.º 28
0
        public void AddApp(NApp app)
        {
            app.State = NApp.StateTypes.Waiting;
            NAppDownloader svn = new NAppDownloader(app, BaseUrl, Branch);

            Queue.Add(svn);
        }
Ejemplo n.º 29
0
        //szélesség
        public Graf(int kezdopont)
        {
            HashSet <int> bejart = new HashSet <int>();

            Queue <int> kovetkezok = new Queue <int>();

            kovetkezok.Add(kezdopont);
            bejart.Add(kezdopont);

            foreach (var k in kovetkezok)
            {
                k = kovetkezok.Dequeue();

                Console.WriteLine(this.csucsok[k]);

                foreach (El el in this.elek)
                {
                    if ((el.Csucs1 == k) && (!bejart.Contains(el.Csucs2)))
                    {
                        kovetkezok.Enqueue(el.Csucs2);
                        bejart.Add(el.Csucs2);
                    }
                }
            }
        }
Ejemplo n.º 30
0
        //összefüggőség
        public Graf(bool e)
        {
            HashSet <int> bejart = new HashSet <int>();

            Queue <int> kovetkezok = new Queue <int>();

            kovetkezok.Add(0);
            bejart.Add(0);

            foreach (var k in kovetkezok)
            {
                k = kovetkezok.Enqueue();

                foreach (El el in elek)
                {
                    if ((el.Csucs1 == k) && (!bejart.Contains(el.Csucs2)))
                    {
                        kovetkezok.Enqueue(el.Csucs2);
                        bejart.Add(el.Csucs2);
                    }
                }
            }

            if (bejart.Count == this.csucsokSzama)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
 internal void ProcessDirectoryEntry(DirectoryEntry dir)
 {
     if (dir.Type == DirectoryEntryType.DIRECTORY)
     {
         if (AclLog.IsDebugEnabled)
         {
             AclLog.Debug($"Enumerate job submitted for: {dir.FullName}");
         }
         Queue.Add(new EnumerateDirectoryChangeAclJob(this, dir.FullName));
         Interlocked.Increment(ref _directoryEnumerated);
     }
     else
     {
         // If the input only contains default acl then the FileAclEntries willl be empty
         if (FileAclEntries.Count == 0)
         {
             return;
         }
         Interlocked.Increment(ref _filesEnumerated);
     }
     if (_isVerify)
     {
         Queue.Add(new VerifyChangeAclJob(this, dir.FullName, dir.Type));
     }
     else
     {
         if (AclLog.IsDebugEnabled)
         {
             AclLog.Debug($"ChangeAcl job submitted for: {dir.FullName}");
         }
         Queue.Add(new ChangeAclJob(this, dir.FullName, dir.Type));
     }
 }
Ejemplo n.º 32
0
        //feszítőfa
        public Graf Feszitofa()
        {
            Graf fa = new Graf(this.csucsokSzama);

            HashSet <int> bejart     = new HashSet <int>();
            Queue <int>   kovetkezok = new Queue <int>();

            kovetkezok.Add(0);
            bejart.Add(0);

            foreach (var k in kovetkezok)
            {
                k = kovetkezok.Enqueue();

                foreach (El el in elek)
                {
                    if (el.Csucs1 == el)
                    {
                        if (!bejart.Contains(el.Csucs2))
                        {
                            bejart.Add(el.Csucs2);
                            kovetkezok.Enqueue(el.Csucs1);
                            fa.Add(el.Csucs1, el.Csucs2);
                        }
                    }
                }
            }
            return(fa);
        }
Ejemplo n.º 33
0
 public static void Main()
 {
     try {
       Queue q1 = new Queue();
       Queue q2 = new Queue(3);
       q2.Add(4);
       q2.Add(5);
       Console.WriteLine("The front is now {0}", q2.Head());
       q2.Add(6);
       Console.WriteLine
             ("Removing from q2 returns {0}", q2.Remove());
       Console.WriteLine("Queue 1 has size {0}", q1.size);
       Console.WriteLine("Queue 1 empty? {0}", q1.IsEmpty());
       q1.Remove();
       Console.WriteLine("Throws exception before we get here");
     }catch(Exception e) {
     Console.WriteLine(e);
     }
 }
        public async Task ShouldBeAbleToAddAJobFromCSharpWithEase()
        {
            // Given
            // Transaction mock for adding the job to the wait list and sending a pubsub message
            var transactionMock = new Mock<ITransaction>();
            transactionMock
                .Setup(t => t.ListLeftPushAsync(It.IsAny<RedisKey>(), It.IsAny<RedisValue>(), It.IsAny<When>(), It.IsAny<CommandFlags>()))
                .Returns(Task.FromResult(1L));
            transactionMock
                .Setup(t => t.PublishAsync(It.IsAny<RedisChannel>(), It.IsAny<RedisValue>(), It.IsAny<CommandFlags>()))
                .Returns(Task.FromResult(1L));
            transactionMock
                .Setup(t => t.ExecuteAsync(It.IsAny<CommandFlags>()))
                .Returns(Task.FromResult(true));
           
            // Database mock so you can add a job
            var databaseMock = new Mock<IDatabase>();
            databaseMock
                .Setup(d => d.HashSetAsync(It.IsAny<RedisKey>(), It.IsAny<HashEntry[]>(), It.IsAny<CommandFlags>()))
                .Returns(Task.Run(() => { }));
            databaseMock
                .Setup(d => d.StringIncrementAsync(It.IsAny<RedisKey>(), 1L, It.IsAny<CommandFlags>()))
                .Returns(Task.FromResult(1L));
            databaseMock
                .Setup(d => d.CreateTransaction(null))
                .Returns(transactionMock.Object);

            // So oxen can verify the internal subscription was successful
            var subscriberMock = new Mock<ISubscriber>();
            subscriberMock
                .Setup(s => s.PublishAsync(It.IsAny<RedisChannel>(), It.IsAny<RedisValue>(), It.IsAny<CommandFlags>()))
                .Returns(Task.FromResult(1L));

            IOxenQueue<Message> queue = new Queue<Message>("test-queue", () => databaseMock.Object, () => subscriberMock.Object);

            // When
            var job = await queue.Add(new Message()
            {
                OtherThing = false,
                Thing = "yes"
            });

            // Then
            job.data.Thing.ShouldEqual("yes");
            job.data.OtherThing.ShouldBeFalse();
            job.jobId.ShouldEqual(1L);

            databaseMock.Verify(db => db.HashSetAsync(It.IsAny<RedisKey>(), It.IsAny<HashEntry[]>(), It.IsAny<CommandFlags>()), Times.Once);
            databaseMock.Verify(db => db.StringIncrementAsync(It.IsAny<RedisKey>(), 1L, It.IsAny<CommandFlags>()), Times.Once);

            transactionMock.Verify(t => t.ListLeftPushAsync(It.IsAny<RedisKey>(), It.IsAny<RedisValue>(), It.IsAny<When>(), It.IsAny<CommandFlags>()), Times.Once);
            transactionMock.Verify(t => t.PublishAsync(It.IsAny<RedisChannel>(), It.IsAny<RedisValue>(), It.IsAny<CommandFlags>()), Times.Once);
        }
Ejemplo n.º 35
0
 public void Backward()
 {
     var queue = new Queue();
     queue.Add("filename0", 0, 1);
     queue.Add("filename1", 0, 1);
     queue.Add("filename2", 0, 1);
     queue.Add("filename3", 0, 1);
     queue.Add("filename4", 0, 1);
     queue.Backward();
     Assert.IsTrue(queue.CurrentItem.Equals("filename3", 0, 1));
     queue.Backward();
     Assert.IsTrue(queue.CurrentItem.Equals("filename2", 0, 1));
     queue.Backward();
     Assert.IsTrue(queue.CurrentItem.Equals("filename1", 0, 1));
     queue.Backward();
     Assert.IsTrue(queue.CurrentItem.Equals("filename0", 0, 1));
     queue.Backward();
     queue.Backward();
     queue.Backward();
     Assert.IsTrue(queue.CurrentItem.Equals("filename0", 0, 1));
 }
Ejemplo n.º 36
0
 public void CanForward()
 {
     var queue = new Queue();
     Assert.IsFalse(queue.CanForward);
     queue.Add("filename0", 0, 1);
     queue.Add("filename1", 0, 1);
     Assert.IsFalse(queue.CanForward);
     queue.Backward();
     Assert.IsTrue(queue.CanForward);
     queue.Forward();
     Assert.IsFalse(queue.CanForward);
     queue.Backward();
     queue.Add("filename3", 0, 1);
     Assert.IsFalse(queue.CanForward);
 }
Ejemplo n.º 37
0
 public void Change()
 {
     var queue = new Queue();
     const string filename0 = "filename0";
     queue.Add(filename0, position: 0, line: 1);
     queue.Add("filename1", 1, 1);
     queue.Add(filename0, position: 100, line: 2);
     queue.Add("filename3", 1, 1);
     queue.Add(filename0, position: 1000, line: 3);
     queue.Change(filename0, startPosition: 150, charsAdded: 1, linesAdded: 1);
     Assert.IsTrue(queue.CurrentItem.Equals(filename0, position: 1001, line: 4));
     queue.Change(filename0, 0, 10, 1);
     Assert.IsTrue(queue.CurrentItem.Equals(filename0, position: 1011, line: 5));
     queue.Backward();
     queue.Backward();//skip filename3
     Assert.IsTrue(queue.CurrentItem.Equals(filename0, position: 110, line: 3));
     queue.Backward();
     queue.Backward();//skip filename1
     Assert.IsTrue(queue.CurrentItem.Equals(filename0, position: 10, line: 2));
 }
Ejemplo n.º 38
0
 public void Change_3()
 {
     const string filename = "filename";
     var queue = new Queue();
     queue.Add(filename, position: 0, line: 1);
     queue.Add(filename, position: 6, line: 2);
     queue.Add(filename, position: 8, line: 3);
     Assert.IsTrue(queue.CurrentItem.Equals(filename, position: 8, line: 3));
     queue.Change(filename, startPosition: 4, charsAdded: -4, linesAdded: -1);
     Assert.IsTrue(queue.CurrentItem.Equals(filename, position: 4, line: 2));
     queue.Backward();
     Assert.IsTrue(queue.CurrentItem.Equals(filename, position: 0, line: 1));
 }