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(); }
// 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)); }
/// <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"); }
//add public MyTodo Post(MyTodo myTodo) { //if (!ModelState.IsValid) return BadRequest(ModelState); _service.AddItem(myTodo); return(myTodo); }
// upd public IHttpActionResult Put(int id, MyTodo myTodo) { if (!ModelState.IsValid || id != myTodo.Id) { return(BadRequest(ModelState)); } _service.UpdateItem(myTodo); return(StatusCode(HttpStatusCode.OK)); }
public void Setup() { MyTodo.ResetGlobalId(); }
public void Run(RunDelegate d1, ExceptionDelegate d2) { MyTodo inst = new MyTodo(d1, d2); mgr.Add(inst); }