Ejemplo n.º 1
0
 public void Two_Levels()
 {
     var root = "test";
     var friend = "friend";
     var otherFriend = "otherfriend";
     var graph = new UserGraph();
     graph.Add(root, friend);
     graph.Add(friend, otherFriend);
     Assert.That(graph.Users, Has.Count(3));
     Assert.That(graph.Edges.Count(), Is.EqualTo(2));
 }
Ejemplo n.º 2
0
        public UserGraph BuildGraph(string rootUser)
        {
            var graph = new UserGraph();

            // HACK!
            using (var conn = ConnectionFactory.Create())
            {
                conn.Open();
                // force things to only 2 levels...
                // trasa has 193 friends (1st degree)
                // those friends have 248,634 friends (2nd degree contacts)
                // those friends have well over 12 million friends (3rd degree, and the query times out before it can finish)
                #region sql = "Select..";
                const string sql = @"select UserName, IsFriendOf, 1 as Degree from userfriends where UserName = @user
            UNION
            select UserName, IsFriendOf, 2 as Degree
            from userfriends
            where UserName in (select IsFriendOf from userfriends where UserName = @user)";
                #endregion

                using (var cmd = new SqlCommand(sql, conn))
                {
                    cmd.Parameters.AddWithValue("@user", rootUser);
                    using (var dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                    {
                        while (dr.Read())
                        {
                            graph.Add(dr.GetString(0), dr.GetString(1));
                        }
                    }
                }
                return graph;
            }
        }
Ejemplo n.º 3
0
 public void Build_Simplest_Graph()
 {
     var graph = new UserGraph();
     graph.Add("root", "root");
     string result = ServiceUnderTest.BuildGraphML(graph);
     Console.WriteLine(result);
 }
Ejemplo n.º 4
0
        public void Simple_Graph()
        {
            var graph = new UserGraph();
            graph.Add("test", "test");

            Assert.That(graph.Users, Has.Count(1));
            Assert.That(graph.Edges.Count(), Is.EqualTo(1));
        }
Ejemplo n.º 5
0
 public void Build_Simplest_Graph_With_Edges()
 {
     const string root = "test";
     const string friend = "friend";
     var graph = new UserGraph();
     graph.Add(root, friend);
     string result = ServiceUnderTest.BuildGraphML(graph);
     Console.WriteLine(result);
 }
Ejemplo n.º 6
0
 public void One_Edge()
 {
     var root = "test";
     var friend = "friend";
     var graph = new UserGraph();
     graph.Add(root, friend);
     Assert.That(graph.Users, Has.Count(2));
     Assert.That(graph.Users.Contains(root));
     Assert.That(graph.Users.Contains(friend));
     Assert.That(graph.Edges.Count(), Is.EqualTo(1));
     Assert.That(graph.Edges.First().Source, Is.EqualTo(root));
     Assert.That(graph.Edges.First().Target, Is.EqualTo(friend));
 }