public Job(Owner jobOwner, int cpus, double expectedRuntime, Func<string[], int> process) { Id = globalId++; JobOwner = jobOwner; //Limit the number of cpus to 1-10 CPUs = cpus < 1 ? 1 : 10 < cpus ? 10 : cpus; //Limit the expected runtime to 0.1 - 5.0 ExpectedRuntime = expectedRuntime < 0.1 ? 0.1 : 5.0 < expectedRuntime ? 5.0 : expectedRuntime; State = JobState.Unknown; this.process = process; Delayed = 0; }
/// <summary> /// Add a user to the database /// </summary> /// <param name="owner">The user to add</param> public static bool AddUser(Owner owner) { try { using (var context = new OOADEntities()) { user u = new user(); u.name = owner.Name; context.users.AddObject(u); context.SaveChanges(); return true; } } catch (Exception) { return false; } }
private static Job CreateRandomJob() { Func<String[], int> process = (x) => { int i = (int)double.Parse(x[0]); Thread.Sleep(i*1000); return i; }; Random rnd = new Random(); //Sets cpus to a number between 1-10 both inclusive int cpus = rnd.Next(1, 11); //Sets the expectedRuntime to a number between 0.0 and 5.0 both inclusive double expectedRuntime = rnd.NextDouble() * 5.0; Owner jobOwner = new Owner("Christian", 4); Job job = new Job(jobOwner, cpus, expectedRuntime, process); return job; }
public void AddUserTest() { Owner owner = new Owner("Bob", 0); Assert.IsTrue(DAO.AddUser(owner)); }