Exemplo n.º 1
0
        public void No_Match_Returns_Empty_Collection()
        {
            using (var database = new DbCodeReview())
            {
                database.Commits.AddRange(new Commit[]
                {
                    new Commit()
                    {
                        Author = "daffy", Message = "A message", Timestamp = new DateTime(2000, 1, 1),
                    },
                    new Commit()
                    {
                        Author = "bugs", Message = "Another message", Timestamp = new DateTime(2002, 1, 2)
                    },
                });
                database.SaveChanges();
            }

            using (var database = new DbCodeReview())
            {
                var sut = new CommitQuery(database.Commits)
                {
                    IncludeAuthor = "donald"
                };

                Assert.AreEqual(0, sut.Execute().Count <Commit>());

                var resultList = sut.Execute().ToList();

                for (int i = 1; i < resultList.Count; i++)
                {
                    Assert.IsTrue(resultList[i - 1].Timestamp < resultList[i].Timestamp);
                }
            }
        }
Exemplo n.º 2
0
        public void By_KeyWord()
        {
            using (var database = new DbCodeReview())
            {
                database.Commits.AddRange(new Commit[]
                {
                    new Commit()
                    {
                        Author = "daffy", Message = "A message", Timestamp = new DateTime(2000, 1, 1)
                    },
                    new Commit()
                    {
                        Author = "bugs", Message = "Another message", Timestamp = new DateTime(2002, 1, 2)
                    },
                    new Commit()
                    {
                        Author = "mickey", Message = "Yet another", Timestamp = new DateTime(2000, 2, 3)
                    },
                });
                database.SaveChanges();
            }

            using (var database = new DbCodeReview())
            {
                var sut = new CommitQuery(database.Commits)
                {
                    Keyword = "m"
                };

                var result = sut.Execute();

                Assert.AreEqual(2, result.Count <Commit>());
                Assert.AreEqual(2, result.Where(c => c.Author == "daffy" || c.Author == "bugs").Count <Commit>());
            }
        }
Exemplo n.º 3
0
        public static void Execute()
        {
            using (var database = new DbCodeReview())
            {
                int currentVersion = 0;

                try
                {
                    currentVersion = database.SchemaVersion.Max(v => v.Number);
                }
                catch
                {
                    // doesn't exist start from 0
                }

                int newVersion = Index.Migrations.Keys.Max();

                while (currentVersion < newVersion)
                {
                    ExecuteForVersion(database, ++currentVersion);

                    database.SchemaVersion.Add(
                        new SchemaVersion {
                        Number = currentVersion, Timestamp = DateTime.UtcNow
                    }
                        );

                    database.SaveChanges();
                }
            }
        }
Exemplo n.º 4
0
        public void By_All_Criteria()
        {
            using (var database = new DbCodeReview())
            {
                database.Commits.AddRange(new Commit[]
                {
                    new Commit()
                    {
                        Author = "daffy", Message = "A message", Timestamp = new DateTime(2000, 1, 1), ApprovedBy = "bugs"
                    },
                    new Commit()
                    {
                        Author = "bugs", Message = "Another message", Timestamp = new DateTime(2002, 1, 2)
                    },
                    new Commit()
                    {
                        Author = "mickey", Message = "Yet another", Timestamp = new DateTime(2000, 2, 3)
                    },
                    new Commit()
                    {
                        Author = "mickey", Message = "Yet another message", Timestamp = new DateTime(2000, 2, 3)
                    },
                    new Commit()
                    {
                        Author = "mickey", Message = "Mickey mouse message", Timestamp = new DateTime(2003, 2, 3)
                    }
                });
                database.SaveChanges();
            }

            using (var database = new DbCodeReview())
            {
                var sut = new CommitQuery(database.Commits)
                {
                    ExcludeApproved = true,
                    ExcludeAuthor   = "daffy",
                    IncludeAuthor   = "mickey",
                    Keyword         = "message",
                    Max             = 2
                };

                var result = sut.Execute();

                Assert.AreEqual(2, result.Count <Commit>());
                Assert.AreEqual(2, result.Where(c => c.Author == "mickey" && c.Message.Contains("message") && c.ApprovedBy == null).Count <Commit>());
            }
        }
Exemplo n.º 5
0
        public void Take_Max()
        {
            using (var database = new DbCodeReview())
            {
                database.Commits.AddRange(new Commit[]
                {
                    new Commit()
                    {
                        Author = "daffy", Message = "A message", Timestamp = new DateTime(2000, 1, 1)
                    },
                    new Commit()
                    {
                        Author = "bugs", Message = "Another message", Timestamp = new DateTime(2002, 1, 2)
                    },
                    new Commit()
                    {
                        Author = "mickey", Message = "Yet another", Timestamp = new DateTime(2000, 2, 3)
                    },
                    new Commit()
                    {
                        Author = "mickey", Message = "Yet another mickey message", Timestamp = new DateTime(2000, 2, 1)
                    },
                    new Commit()
                    {
                        Author = "mickey", Message = "Yet another mickey mouse message", Timestamp = new DateTime(2000, 2, 4)
                    },
                });
                database.SaveChanges();
            }

            using (var database = new DbCodeReview())
            {
                var sut = new CommitQuery(database.Commits)
                {
                    Max = 2
                };

                var result = sut.Execute();

                Assert.AreEqual(2, result.Count <Commit>());

                var resultList = result.ToList();
                Assert.IsTrue(resultList[0].Timestamp <= resultList[1].Timestamp);
            }
        }
Exemplo n.º 6
0
        public void By_ExcludeApproved()
        {
            using (var database = new DbCodeReview())
            {
                database.Commits.AddRange(new Commit[]
                {
                    new Commit()
                    {
                        Author = "daffy", Message = "A message", Timestamp = new DateTime(2000, 1, 1), ApprovedBy = "bugs"
                    },
                    new Commit()
                    {
                        Author = "bugs", Message = "Another message", Timestamp = new DateTime(2002, 1, 2)
                    },
                    new Commit()
                    {
                        Author = "mickey", Message = "Yet another", Timestamp = new DateTime(2000, 2, 3)
                    },
                });
                database.SaveChanges();
            }

            using (var database = new DbCodeReview())
            {
                var sut = new CommitQuery(database.Commits)
                {
                    ExcludeApproved = true
                };

                var result = sut.Execute();

                Assert.AreEqual(2, result.Count <Commit>());
                Assert.AreEqual(0, result.Where(c => c.Author == "daffy").Count <Commit>());

                sut = new CommitQuery(database.Commits)
                {
                    ExcludeApproved = false
                };

                result = sut.Execute();

                Assert.AreEqual(3, result.Count <Commit>());
            }
        }
Exemplo n.º 7
0
        public void Ordered_By_Timestamp_Ascending()
        {
            using (var database = new DbCodeReview())
            {
                database.Commits.AddRange(new Commit[]
                {
                    new Commit()
                    {
                        Author = "daffy", Message = "A message", Timestamp = new DateTime(2000, 1, 1), ApprovedBy = "bugs"
                    },
                    new Commit()
                    {
                        Author = "bugs", Message = "Another message", Timestamp = new DateTime(2002, 1, 2)
                    },
                    new Commit()
                    {
                        Author = "mickey", Message = "Yet another", Timestamp = new DateTime(2000, 2, 3)
                    },
                    new Commit()
                    {
                        Author = "mickey", Message = "Yet another message", Timestamp = new DateTime(2000, 2, 3)
                    },
                    new Commit()
                    {
                        Author = "mickey", Message = "Mickey mouse message", Timestamp = new DateTime(2003, 2, 3)
                    }
                });
                database.SaveChanges();
            }

            using (var database = new DbCodeReview())
            {
                var sut = new CommitQuery(database.Commits);

                var resultList = sut.Execute().ToList();

                for (int i = 1; i < resultList.Count; i++)
                {
                    Assert.IsTrue(resultList[i - 1].Timestamp <= resultList[i].Timestamp);
                }
            }
        }
Exemplo n.º 8
0
        public void By_Revision()
        {
            using (var database = new DbCodeReview())
            {
                database.Comments.AddRange(new Comment[]
                {
                    new Comment()
                    {
                        Revision = 1111, LineId = "1212", User = "******", Text = "1111Comment1"
                    },
                    new Comment()
                    {
                        Revision = 1111, LineId = "1212", User = "******", Text = "1111Comment2"
                    },
                    new Comment()
                    {
                        Revision = 3333, LineId = "1212", User = "******", Text = "333Comment1"
                    },
                    new Comment()
                    {
                        Revision = 11111, LineId = "1212", User = "******", Text = "1111Comment1"
                    },
                });
                database.SaveChanges();
            }

            using (var database = new DbCodeReview())
            {
                var sut = new CommentQuery(database.Comments)
                {
                    Revision = 1111
                };

                var result = sut.Execute();

                Assert.AreEqual(2, result.Count <Comment>());
                Assert.AreEqual(2, result.Where(c => c.Revision == 1111).Count <Comment>());
            }
        }