コード例 #1
0
ファイル: AccountTest.cs プロジェクト: akoesnan/PraLoup
        public void IsFriendGenerateOkSQL_Success()
        {
            using (var Scope = new SQLiteDatabaseScope <PraLoupAutoMappingConfiguration>())
            {
                using (ISession Session = Scope.OpenSession())
                {
                    IRepository r = new GenericRepository(Session);
                    EntityDataService <Account, AccountValidator> ads = new EntityDataService <Account, AccountValidator>(r, new AccountValidator());

                    Session.BeginTransaction();
                    Assert.IsTrue(ads.SaveOrUpdate(myself));
                    Assert.IsTrue(ads.SaveOrUpdate(friend));
                    Assert.IsTrue(ads.SaveOrUpdate(friend2));
                    Assert.IsTrue(ads.SaveOrUpdate(friend3));
                    Assert.IsTrue(ads.SaveOrUpdate(friend4));
                    Session.Transaction.Commit();
                }

                using (ISession Session = Scope.OpenSession())
                {
                    IRepository r = new GenericRepository(Session);
                    EntityDataService <Account, AccountValidator>       ads = new EntityDataService <Account, AccountValidator>(r, new AccountValidator());
                    EntityDataService <Connection, ConnectionValidator> cds = new EntityDataService <Connection, ConnectionValidator>(r, new ConnectionValidator());

                    var m  = ads.Find(myself.Id);
                    var f  = ads.Find(friend.Id);
                    var f3 = ads.Find(friend3.Id);
                    var f4 = ads.Find(friend4.Id);

                    // there should be 1 friend for f
                    Log.Debug("executing isfriend");
                    var spec = new AccountGetFriendQuery(f);
                    Assert.IsTrue(ads.ExecuteQuery(spec).RowCount() == 1);
                    spec = new AccountGetFriendQuery(m);
                    Assert.IsTrue(ads.ExecuteQuery(spec).RowCount() == 2);

                    // m should be friends of friend of f3
                    Log.Debug("executing isfriendoffriend");
                    var fof = new ConnectionIsFriendOfFriendQuery(m, f3);
                    Assert.IsTrue(cds.ExecuteQuery(fof).RowCount() > 0);

                    // negative case
                    fof = new ConnectionIsFriendOfFriendQuery(m, f4);
                    Assert.IsTrue(cds.ExecuteQuery(fof).RowCount() == 0);
                }
            }
        }
コード例 #2
0
ファイル: AccountExtensions.cs プロジェクト: akoesnan/PraLoup
 public static bool IsFriendOfFriend(this Account account, Account ab, IDataService ds)
 {
     var q = new ConnectionIsFriendOfFriendQuery(account, ab);
     return ds.Connection.ExecuteQuery(q).RowCount() > 0;
 }
コード例 #3
0
ファイル: AccountTest.cs プロジェクト: akoesnan/PraLoup
        public void IsFriendGenerateOkSQL_Success()
        {
            using (var Scope = new SQLiteDatabaseScope<PraLoupAutoMappingConfiguration>())
            {
                using (ISession Session = Scope.OpenSession())
                {
                    IRepository r = new GenericRepository(Session);
                    EntityDataService<Account, AccountValidator> ads = new EntityDataService<Account, AccountValidator>(r, new AccountValidator());

                    Session.BeginTransaction();
                    Assert.IsTrue(ads.SaveOrUpdate(myself));
                    Assert.IsTrue(ads.SaveOrUpdate(friend));
                    Assert.IsTrue(ads.SaveOrUpdate(friend2));
                    Assert.IsTrue(ads.SaveOrUpdate(friend3));
                    Assert.IsTrue(ads.SaveOrUpdate(friend4));
                    Session.Transaction.Commit();
                }

                using (ISession Session = Scope.OpenSession())
                {
                    IRepository r = new GenericRepository(Session);
                    EntityDataService<Account, AccountValidator> ads = new EntityDataService<Account, AccountValidator>(r, new AccountValidator());
                    EntityDataService<Connection, ConnectionValidator> cds = new EntityDataService<Connection, ConnectionValidator>(r, new ConnectionValidator());

                    var m = ads.Find(myself.Id);
                    var f = ads.Find(friend.Id);
                    var f3 = ads.Find(friend3.Id);
                    var f4 = ads.Find(friend4.Id);

                    // there should be 1 friend for f
                    Log.Debug("executing isfriend");
                    var spec = new AccountGetFriendQuery(f);
                    Assert.IsTrue(ads.ExecuteQuery(spec).RowCount() == 1);
                    spec = new AccountGetFriendQuery(m);
                    Assert.IsTrue(ads.ExecuteQuery(spec).RowCount() == 2);

                    // m should be friends of friend of f3
                    Log.Debug("executing isfriendoffriend");
                    var fof = new ConnectionIsFriendOfFriendQuery(m, f3);
                    Assert.IsTrue(cds.ExecuteQuery(fof).RowCount() > 0);

                    // negative case
                    fof = new ConnectionIsFriendOfFriendQuery(m, f4);
                    Assert.IsTrue(cds.ExecuteQuery(fof).RowCount() == 0);
                }
            }
        }
コード例 #4
0
        public static bool IsFriendOfFriend(this Account account, Account ab, IDataService ds)
        {
            var q = new ConnectionIsFriendOfFriendQuery(account, ab);

            return(ds.Connection.ExecuteQuery(q).RowCount() > 0);
        }