public void Contains()
        {
            var db = new TrackerDataContext { Log = Console.Out };

            var assignedId = new List<int?> { null, 1 };
            // null and int
            var q1 = db.Task.ByAssignedId(assignedId);

            var assignedList = q1.ToList();
            Assert.IsNotNull(assignedList);


            var details = new List<string> { null, "test" };
            // null and string
            var q2 = db.Task.ByDetails(details);
            var detailList = q2.ToList();
            Assert.IsNotNull(detailList);

            // null and int direct
            var q3 = db.Task.ByAssignedId(null, 1);

            var assignedList2 = q3.ToList();
            Assert.IsNotNull(assignedList2);

            // string, null direct
            var q4 = db.Task.ByDetails("test", null, "other");
            var detailList2 = q4.ToList();
            Assert.IsNotNull(detailList2);

            // should use IN operator
            var q5 = db.Task.ByCreatedId(1, 2);
            var createdList = q5.ToList();
            Assert.IsNotNull(createdList);
        }
        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to PLINQO!";

            if (User.Identity.IsAuthenticated)
            {

                var dashboard = new Dashboard();

                using (var db = new TrackerDataContext())
                {
                    dashboard.CurrentUser = db.User.GetByEmailAddress(User.Identity.Name);
                    if (dashboard.CurrentUser != null)
                    {
                        dashboard.TasksNotStarted = db.Task.ByAssignedId(dashboard.CurrentUser.Id).ByStatus(Status.NotStarted).Future();
                        dashboard.TasksInProgress = db.Task.ByAssignedId(dashboard.CurrentUser.Id).ByStatus(Status.InProgress).Future();
                        dashboard.TasksCompleted = db.Task.ByAssignedId(dashboard.CurrentUser.Id).ByStatus(Status.Completed).Future();
                        dashboard.TasksWaitingOnSomeone = db.Task.ByAssignedId(dashboard.CurrentUser.Id).ByStatus(Status.WaitingOnSomeoneElse).Future();
                        dashboard.TotalTasks = db.Task.FutureCount();
                        dashboard.TotalTasksCreatedByMe = db.Task.ByCreatedId(dashboard.CurrentUser.Id).FutureCount();
                        dashboard.TotalTasksAssignedToMe = db.Task.ByAssignedId(dashboard.CurrentUser.Id).FutureCount();
                        dashboard.TotalTasksCompleted = db.Task.ByStatus(Status.Completed).FutureCount();
                    }

                    db.ExecuteFutureQueries();
                }

                return View(dashboard);
            }
            else
            {
                return View();
            }
        }
        public void TestFixtureSetUp()
        {
            // setup memcached
            _memcached = Process.Start(
                @"..\..\..\..\Libraries\memcached.exe",
                "-vv -p 11200");

            using (var db = new TrackerDataContext())
            {
                var role1 = new Role
                {
                    Name = "Test Role"
                };
                var role2 = new Role
                {
                    Name = "Duck Roll"
                };

                db.Role.InsertOnSubmit(role1);
                db.Role.InsertOnSubmit(role2);
                db.SubmitChanges();

                _roleIds.Add(role1.Id);
                _roleIds.Add(role2.Id);
            }
        }
예제 #4
0
        public void ExecuteQueryLoadWith()
        {
            var db = new TrackerDataContext { Log = Console.Out };
            db.DeferredLoadingEnabled = false;
            db.ObjectTrackingEnabled = false;

            DataLoadOptions options = new DataLoadOptions();
            options.LoadWith<Task>(t => t.CreatedUser);

            db.LoadOptions = options;

            var q1 = db.User
                .ByEmailAddress("*****@*****.**");

            var q2 = db.Task
                .Where(t => t.LastModifiedBy == "*****@*****.**");

            var result = db.ExecuteQuery(q1, q2);

            Assert.IsNotNull(result);

            var userResult = result.GetResult<User>();
            Assert.IsNotNull(userResult);

            var users = userResult.ToList();
            Assert.IsNotNull(users);

            var taskResult = result.GetResult<Task>();
            Assert.IsNotNull(taskResult);

            var tasks = taskResult.ToList();
            Assert.IsNotNull(tasks);
        }
        public void FutureCountTest()
        {
            var db = new TrackerDataContext { Log = Console.Out };

            // build up queries

            var q1 = db.User
                .ByEmailAddress("*****@*****.**")
                .Future();

            var q2 = db.Task
                .Where(t => t.Summary == "Test")
                .FutureCount();

            // should be 2 queries 
            //Assert.AreEqual(2, db.FutureQueries.Count);

            // this triggers the loading of all the future queries
            var users = q1.ToList();
            Assert.IsNotNull(users);

            // should be cleared at this point
            //Assert.AreEqual(0, db.FutureQueries.Count);

            // this should already be loaded
            Assert.IsTrue(((IFutureQuery)q2).IsLoaded);

            int count = q2.Value;
            Assert.Greater(count, 0);
        }
        public void SlidingExpirationTest()
        {
            using (var db = new TrackerDataContext { Log = Console.Out })
            {
                var query = db.Role.Where(r => r.Name == "Test Role");
                var key = query.Take(1).GetHashKey();
                var role = query.FromCacheFirstOrDefault(new CacheSettings(TimeSpan.FromSeconds(2)));

                var cache = CacheManager.Get<ICollection<Role>>(key);
                Assert.IsNotNull(cache);
                Assert.AreEqual(role.Id, cache.FirstOrDefault().Id);

                System.Threading.Thread.Sleep(1500);

                cache = CacheManager.Get<ICollection<Role>>(key);
                Assert.IsNotNull(cache);
                Assert.AreEqual(role.Id, cache.FirstOrDefault().Id);

                System.Threading.Thread.Sleep(1500);

                cache = CacheManager.Get<ICollection<Role>>(key);
                Assert.IsNotNull(cache);
                Assert.AreEqual(role.Id, cache.FirstOrDefault().Id);

                System.Threading.Thread.Sleep(2500);

                cache = CacheManager.Get<ICollection<Role>>(key);
                Assert.IsNull(cache);
            }
        }
예제 #7
0
        public void Reflection()
        {
            var db = new TrackerDataContext { Log = Console.Out };
            IQueryable source = db.Task.Where(t => t.LastModifiedBy == "*****@*****.**").OrderBy(t => t.CreatedId);


            // can be static
            Type queryableType = typeof(Queryable);
            // can be static
            MethodInfo countMethod = (from m in queryableType.GetMethods(BindingFlags.Static | BindingFlags.Public)
                                      where m.Name == "Count"
                                        && m.IsGenericMethod
                                        && m.GetParameters().Length == 1
                                      select m).FirstOrDefault();


            Assert.IsNotNull(countMethod);

            var genericMethod = countMethod.MakeGenericMethod(new[] { source.ElementType });
            var expression = Expression.Call(null, genericMethod, source.Expression);

            Assert.IsNotNull(expression);

            Type dataContextType = db.GetType();
            PropertyInfo providerProperty = dataContextType.GetProperty("Provider", BindingFlags.Instance | BindingFlags.NonPublic);

            object provider = providerProperty.GetValue(db, null);

            Type providerType = provider.GetType().GetInterface("IProvider");
            MethodInfo getCommandMethod = providerType.GetMethod("GetCommand", BindingFlags.Instance | BindingFlags.Public);

            object commandObject = getCommandMethod.Invoke(provider, new object[] { expression });

            Assert.IsNotNull(commandObject);
        }
        public void ContainmentTest()
        {
            var db = new TrackerDataContext { Log = Console.Out };

            var q1 = db.Task.BySummary(ContainmentOperator.Contains, "Earth");
            var list = q1.ToList();
            Assert.IsNotNull(list);

            var q2 = db.Task.BySummary(ContainmentOperator.StartsWith, "Make");
            list = q2.ToList();
            Assert.IsNotNull(list);

            var q3 = db.Task.BySummary(ContainmentOperator.EndsWith, "Earth");
            list = q3.ToList();
            Assert.IsNotNull(list);

            var q4 = db.Task.BySummary(ContainmentOperator.NotContains, "test");
            list = q4.ToList();
            Assert.IsNotNull(list);

            var q5 = db.Task.ByDetails(ContainmentOperator.Equals, null);
            list = q5.ToList();
            Assert.IsNotNull(list);

            var q6 = db.Task.ByDetails(ContainmentOperator.NotEquals, null);
            list = q6.ToList();
            Assert.IsNotNull(list);
        }
        public void ContainmentStartsWith()
        {
            var db = new TrackerDataContext { Log = Console.Out };

            var q5 = db.Task.ByDetails(ContainmentOperator.StartsWith, null);
            var list = q5.ToList();
            Assert.IsNotNull(list);          
        }
 public void TestFixtureTearDown()
 {
     using (var db = new TrackerDataContext { Log = Console.Out })
     {
         db.Guid.Delete(_guid1Id);
         db.Guid.Delete(_guid2Id);
         db.Guid.Delete(_guid3Id);
     }
 }
 public ActionResult Delete(int id)
 {
     using (var db = new TrackerDataContext())
     {
         db.Audit.Delete(a => a.TaskId == id);
         db.Task.Delete(id);
     }
     return RedirectToAction("Index");
 }
        public void Run(RuleContext context)
        {
            var currentUser = (User)context.TrackedObject.Current;

            using (var db = new TrackerDataContext())
            {
                db.ObjectTrackingEnabled = false;
                var user = db.User.GetByEmailAddress(currentUser.EmailAddress);
                context.Success = (null == user || user.Id == currentUser.Id);
            }
        }
        public void ByTest()
        {
            using (var db = new TrackerDataContext { Log = Console.Out })
            {
                var a = db.Task.ByCreatedDate(CreateDates[0]).ToList();
                var b = db.Task.ByCreatedDate(CreateDates[1]).ToList();

                var c = db.Task.ByCreatedDate(CreateDates[0], null).ToList();
                Assert.AreEqual(a.Count, c.Count);
            }
        }
예제 #14
0
 public void TearDown()
 {
     using (var db = new TrackerDataContext { Log = Console.Out })
     {
         db.Audit.Delete(a => a.User.EmailAddress.EndsWith("startrek.com"));
         db.UserRole.Delete(ur => ur.User.EmailAddress.EndsWith("startrek.com"));
         db.Task.Delete(t =>
             t.AssignedUser.EmailAddress.EndsWith("startrek.com") ||
             t.CreatedUser.EmailAddress.EndsWith("startrek.com"));
         db.User.Delete(u => u.EmailAddress.EndsWith("startrek.com"));
     }
 }
        public void TestFixtureTearDown()
        {
            using (var db = new TrackerDataContext())
                db.Role.Delete(r => _roleIds.Contains(r.Id));


            if (_memcached != null)
            {
                _memcached.Kill();
                _memcached.Dispose();
            }
        }
 public ActionResult Details(int id)
 {
     Task task = null;
     using (var db = new TrackerDataContext())
     {
         var options = new DataLoadOptions();
         options.LoadWith<Task>(t => t.AssignedUser);
         options.LoadWith<Task>(t => t.CreatedUser);
         db.LoadOptions = options;
         task = db.Task.GetByKey(id);
     }
     return View(task);
 }
        public void LongProfile()
        {
            using (var db = new TrackerDataContext())
            {
                var query = db.Role.Where(r => r.Name == "Duck Roll");
                var key = query.GetHashKey();
                var roles = query.FromCache("Long").ToList();

                var cache = CacheManager.Get<ICollection<Role>>(key);
                Assert.IsNotNull(cache);
                Assert.AreEqual(roles.Count, cache.Count);
            }
        }
        public void SimpleTest()
        {
            using (var db = new TrackerDataContext())
            {
                var query = db.Role.Where(r => r.Name == "Test Role");
                var key = query.Take(1).GetHashKey();
                var role = query.FromCacheFirstOrDefault();

                var cache = CacheManager.Get<ICollection<Role>>(key);
                Assert.IsNotNull(cache);
                Assert.AreEqual(role.Id, cache.FirstOrDefault().Id);
            }
        }
        public ActionResult AddRole(int userId, int roleId)
        {
            using (var db = new TrackerDataContext())
            {
                var options = new DataLoadOptions();
                options.LoadWith<User>(u => u.UserRoleList);

                var user = db.User.GetByKey(userId);
                var role = db.Role.GetByKey(roleId);
                user.RoleList.Add(role);
                db.SubmitChanges();
            }
            return RedirectToAction("Edit", new { id = userId });
        }
        public ActionResult CopyTask(int id)
        {
            Task copiedTask = null;
            using (var db = new TrackerDataContext())
            {
                Task task = db.Task.GetByKey(id);
                copiedTask = task.Clone();
                copiedTask.Id = 0;
                copiedTask.CreatedUser = db.User.GetByEmailAddress(System.Web.HttpContext.Current.User.Identity.Name);
                db.Task.InsertOnSubmit(copiedTask);
                db.SubmitChanges();
            }

            return RedirectToAction("Edit", new {id = copiedTask.Id});
        }
        public void IncludeFirstOrDefault()
        {
            var db = new TrackerDataContext { Log = Console.Out };
            
            var tasks = db.Task
                .Where(t => t.CreatedId != null)
                .Include(t => t.CreatedUser);

            // loads all, then does first
            var task = tasks.FirstOrDefault();


            Assert.IsNotNull(task);
            Assert.IsNotNull(task.CreatedUser);
        }
        public void NoCacheEmptyResultTest()
        {
            using (var db = new TrackerDataContext())
            {
                var guid = System.Guid.NewGuid().ToString();
                var query = db.Role.Where(r => r.Name == guid);
                var key = query.Take(1).GetHashKey();
                var role = query.FromCacheFirstOrDefault(new CacheSettings(2) { CacheEmptyResult = false });

                Assert.IsNull(role);

                var cache = CacheManager.Get<ICollection<Role>>(key);
                Assert.IsNull(cache);
            }
        }
        public void ByTest()
        {
                using (var db = new TrackerDataContext {Log = Console.Out})
                {
                    var a = db.Task.ByStatus(Status.InProgress).ToList();
                    var b = db.Task.ByStatus(Status.NotStarted).ToList();

                    var c = db.Task.ByStatus(Status.InProgress, null).ToList();
                    Assert.AreEqual(a.Count, c.Count);

                    var d = db.Task.ByStatus(Status.InProgress, Status.NotStarted).ToList();
                    Assert.AreEqual(a.Count + b.Count, d.Count);
                }

        }
예제 #24
0
        public void ByTest()
        {

            using (var db = new TrackerDataContext { Log = Console.Out })
            {
                var a = db.Task.ByCreatedId(UserIds[1]).ToList();
                var b = db.Task.ByCreatedId(UserIds[2]).ToList();

                var c = db.Task.ByCreatedId(UserIds[1], null).ToList();
                Assert.AreEqual(a.Count, c.Count);

                var d = db.Task.ByCreatedId(UserIds[1], UserIds[2]).ToList();
                Assert.AreEqual(a.Count + b.Count, d.Count);
            }

        }
        public void SimpleTest()
        {
            using (var db = new TrackerDataContext())
            {
                var query = db.Role.Where(r => r.Name == "Duck Roll");
                var roles = query.FromCache().ToList();

                Assert.IsInstanceOf(typeof(MemcachedProvider), CacheManager.GetProvider());

                var key = query.GetHashKey();

                var cache = CacheManager.Get<ICollection<Role>>(key);
                Assert.IsNotNull(cache);
                Assert.AreEqual(roles.Count, cache.Count);
            }
        }
        public void ByTest()
        {

            using (var db = new TrackerDataContext { Log = Console.Out })
            {
                var a = db.Guid.ById(_guid1Id).ToList();
                var b = db.Guid.ById(_guid2Id).ToList();

                var c = db.Guid.ById(_guid1Id, null).ToList();
                Assert.AreEqual(a.Count, c.Count);

                var d = db.Guid.ById(_guid1Id, _guid2Id).ToList();
                Assert.AreEqual(a.Count + b.Count, d.Count);
            }

        }
        public ActionResult RemoveRole(int userId, int roleId)
        {
            using (var db = new TrackerDataContext())
            {
                var options = new DataLoadOptions();
                options.LoadWith<User>(u => u.UserRoleList);
                options.LoadWith<UserRole>(r => r.Role);
                db.LoadOptions = options;

                var user = db.User.GetByKey(userId);
                var role = user.RoleList.FirstOrDefault(r => r.Id == roleId);

                user.RoleList.Remove(role);
                db.SubmitChanges();
            }
            return RedirectToAction("Edit", new { id = userId });
        }
예제 #28
0
 private void CreateTask(int userId)
 {
     var task = new Task()
     {
         AssignedId = userId,
         Status = Status.InProgress,
         Summary = "Explain the visions that inspire you",
         Priority = Priority.High,
         CreatedId = userId,
     };
     using (var db = new TrackerDataContext { Log = Console.Out })
     {
         db.Task.InsertOnSubmit(task);
         db.SubmitChanges();
         TaskId = task.Id;
     }
 }
        public void AbsoluteExpirationTest()
        {
            using (var db = new TrackerDataContext())
            {
                var query = db.Role.Where(r => r.Name == "Test Role");
                var key = query.GetHashKey();
                var roles = query.FromCache(new CacheSettings(DateTime.Now.AddSeconds(2))).ToList();

                var cache = CacheManager.Get<ICollection<Role>>(key);
                Assert.IsNotNull(cache);
                Assert.AreEqual(roles.Count, cache.Count);

                System.Threading.Thread.Sleep(3000);

                cache = CacheManager.Get<ICollection<Role>>(key);
                Assert.IsNull(cache);
            }
        }
        public void AbsoluteExpirationTest()
        {
            using (var db = new TrackerDataContext())
            {
                var query = db.Role.Where(r => r.Name == "Test Role");
                var key = query.Take(1).GetHashKey();
                var role = query.FromCacheFirstOrDefault(CacheSettings.FromAbsolute(DateTime.Now.AddSeconds(2)));

                var cache1 = CacheManager.Get<ICollection<Role>>(key);
                Assert.IsNotNull(cache1);
                Assert.AreEqual(role.Id, cache1.FirstOrDefault().Id);

                System.Threading.Thread.Sleep(2500);

                var cache2 = CacheManager.Get<ICollection<Role>>(key);
                Assert.IsNull(cache2);
            }
        }