Ejemplo n.º 1
0
        public void TestWorkersAndEntries()
        {
            TodoManager mgr = new TodoManager(50, 10, 1, 5, 5000, 1);

            mgr.Start();

            Assert.AreEqual(0, mgr.NumEntries());
            Assert.AreEqual(0, mgr.NumWorkers());

            mgr.Add(new MyTodo());

            Assert.AreEqual(1, mgr.NumEntries());
            Assert.AreEqual(1, mgr.NumWorkers());

            // experiment with a total of 50 entries.
            for (int i = 0; i < 49; i++)
            {
                mgr.Add(new MyTodo());
            }

            Assert.AreEqual(50, MyTodo.LastIdGenerated());

            WaitTillComplete(4000);
            //Assert.AreEqual( 5, mgr.NumWorkers() );


            // test if all todo's were executed.
            Assert.AreEqual(0, mgr.NumEntries());

            TodoManager.ShutDown();
        }
Ejemplo n.º 2
0
        // GET: Todos/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var todo = await _context.Todo
                       .SingleOrDefaultAsync(m => m.Id == id);

            TodoDTO _tdDto = new TodoDTO();
            MyTodo  _td    = new MyTodo();

            DatabaseManager.TodoId = (int)id;
            _td.Id    = DatabaseManager.TodoId;
            _td.Title = todo.Title;

            if (todo == null)
            {
                return(NotFound());
            }

            _tdDto.AllItems = _context.Item.ToList();

            _tdDto.MyTodos = _td;
            return(View(_tdDto));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Wait until all Todos are run.
        /// </summary>
        /// <param name="maxWait">Max time in milliseconds
        /// to wait</param>
        private void WaitTillComplete(long maxWait)
        {
            DateTime now = DateTime.Now;

            long nowTime = 0;
            long endTime = nowTime + maxWait;

            TimeSpan span;
            long     spanTime = 0;

            while (true && (nowTime < endTime))
            {
                if (MyTodo.TodosRemaining() == 0)
                {
                    return;
                }

                span     = DateTime.Now - now;
                now      = DateTime.Now;
                spanTime = (long)span.TotalMilliseconds;
                nowTime += spanTime;
            }

            throw new Exception("Time exceeded");
        }
Ejemplo n.º 4
0
        //add
        public MyTodo Post(MyTodo myTodo)
        {
            //if (!ModelState.IsValid) return BadRequest(ModelState);

            _service.AddItem(myTodo);

            return(myTodo);
        }
Ejemplo n.º 5
0
        // upd
        public IHttpActionResult Put(int id, MyTodo myTodo)
        {
            if (!ModelState.IsValid || id != myTodo.Id)
            {
                return(BadRequest(ModelState));
            }

            _service.UpdateItem(myTodo);

            return(StatusCode(HttpStatusCode.OK));
        }
Ejemplo n.º 6
0
 public void Setup()
 {
     MyTodo.ResetGlobalId();
 }
Ejemplo n.º 7
0
        public void Run(RunDelegate d1, ExceptionDelegate d2)
        {
            MyTodo inst = new MyTodo(d1, d2);

            mgr.Add(inst);
        }