Beispiel #1
0
        public void UpdateFamilyInRepository()
        {
            // arrange - Insert a record so that it can be updated.
            // note connection string is in app.config
            FamilyPointsContext db = new FamilyPointsContext();
            Family obj             = new Family();

            obj.Name     = "New Family 1";
            obj.Children = (from d in db.Children select d).ToList();
            obj.Parents  = (from d in db.Parents select d).ToList();
            db.Familys.Add(obj);
            db.SaveChanges();


            // act - retrieve the saved record and update it.
            Family savedObj = (from d in db.Familys where d.FamilyID == obj.FamilyID select d).Single();

            savedObj.Name = "An updated Family 2";
            db.SaveChanges();

            // Assert -- see if the record retreived from the database matches the one i just updated
            Family updatedObj = (from d in db.Familys where d.FamilyID == obj.FamilyID select d).Single();

            Assert.AreEqual(updatedObj.Name, savedObj.Name);
            Assert.AreEqual(savedObj.Children, obj.Children);
            Assert.AreEqual(savedObj.Parents, obj.Parents);

            // cleanup
            db.Familys.Remove(updatedObj);
            db.SaveChanges();
        }
Beispiel #2
0
        public void SaveNewBehaviorToRepository()
        {
            // arrange

            // note connection string is in app.config
            FamilyPointsContext db  = new FamilyPointsContext();
            Behavior            obj = new Behavior();

            obj.Description = "New Behavior 1";
            obj.Points      = 1;
            db.Behaviors.Add(obj);

            // act
            db.SaveChanges();

            // Assert -- see if the record retreived from the database matches the one i just added
            Behavior savedObj = (from d in db.Behaviors where d.BehaviorID == obj.BehaviorID select d).Single();

            Assert.AreEqual(savedObj.Description, obj.Description);
            Assert.AreEqual(savedObj.Points, obj.Points);

            // cleanup
            db.Behaviors.Remove(savedObj);
            db.SaveChanges();
        }
Beispiel #3
0
        public void UpdateRewardInRepository()
        {
            // arrange - Insert a record so that it can be updated.
            // note connection string is in app.config
            FamilyPointsContext db = new FamilyPointsContext();
            Reward obj             = new Reward();

            obj.Description = "New Reward 2";
            obj.Points      = 0;
            db.Rewards.Add(obj);
            db.SaveChanges();


            // act - retrieve the saved record and update it.
            Reward savedObj = (from d in db.Rewards where d.RewardID == obj.RewardID select d).Single();

            savedObj.Description = "An updated Reward 2";
            savedObj.Points      = 2;
            db.SaveChanges();

            // Assert -- see if the record retreived from the database matches the one i just updated
            Reward updatedObj = (from d in db.Rewards where d.RewardID == obj.RewardID select d).Single();

            Assert.AreEqual(updatedObj.Description, savedObj.Description);
            Assert.AreEqual(updatedObj.Points, savedObj.Points);

            // cleanup
            db.Rewards.Remove(updatedObj);
            db.SaveChanges();
        }
Beispiel #4
0
        public void SaveNewChildToRepository()
        {
            // arrange

            // note connection string is in app.config
            FamilyPointsContext db = new FamilyPointsContext();
            Child obj = new Child();

            obj.Name     = "New Child 1";
            obj.Password = "******";
            db.Children.Add(obj);

            // act
            db.SaveChanges();

            // Assert -- see if the record retreived from the database matches the one i just added
            Child savedObj = (from d in db.Children where d.ChildID == obj.ChildID select d).Single();

            Assert.AreEqual(savedObj.Name, obj.Name);
            Assert.AreEqual(savedObj.Password, obj.Password);

            // cleanup
            db.Children.Remove(savedObj);
            db.SaveChanges();
        }
Beispiel #5
0
        public void SaveNewFamilyToRepository()
        {
            // arrange
            // note connection string is in app.config
            FamilyPointsContext db = new FamilyPointsContext();
            Family obj             = new Family();

            obj.Name     = "New Family 1";
            obj.Children = (from d in db.Children select d).ToList();
            obj.Parents  = (from d in db.Parents select d).ToList();
            db.Familys.Add(obj);

            // act
            db.SaveChanges();

            // Assert -- see if the record retreived from the database matches the one i just added
            Family savedObj = (from d in db.Familys where d.FamilyID == obj.FamilyID select d).Single();

            Assert.AreEqual(savedObj.Name, obj.Name);
            Assert.AreEqual(savedObj.Children, obj.Children);
            Assert.AreEqual(savedObj.Parents, obj.Parents);

            // cleanup
            db.Familys.Remove(savedObj);
            db.SaveChanges();
        }
Beispiel #6
0
        public void UpdateChildInRepository()
        {
            // arrange - Insert a record so that it can be updated.
            // note connection string is in app.config
            FamilyPointsContext db = new FamilyPointsContext();
            Child obj = new Child();

            obj.Name     = "New Child 2";
            obj.Password = "******";
            db.Children.Add(obj);
            db.SaveChanges();


            // act - retrieve the saved record and update it.
            Child savedObj = (from d in db.Children where d.ChildID == obj.ChildID select d).Single();

            savedObj.Name     = "An updated Child 2";
            savedObj.Password = "******";
            db.SaveChanges();

            // Assert -- see if the record retreived from the database matches the one i just updated
            Child updatedObj = (from d in db.Children where d.ChildID == obj.ChildID select d).Single();

            Assert.AreEqual(updatedObj.Name, savedObj.Name);
            Assert.AreEqual(updatedObj.Password, savedObj.Password);

            // cleanup
            db.Children.Remove(updatedObj);
            db.SaveChanges();
        }
Beispiel #7
0
        public void ListofTransactionsInRepository()
        {
            // arrange - Add a record to be listed.
            // note connection string is in app.config
            FamilyPointsContext db = new FamilyPointsContext();
            Behavior            be = (from d in db.Behaviors select d).First();
            Parent      pa         = (from d in db.Parents select d).First();
            Child       ch         = (from d in db.Children select d).First();
            Transaction obj        = new Transaction();

            obj.Date        = DateTime.Now;
            obj.ParentID    = pa.ParentID;
            obj.ChildID     = ch.ChildID;
            obj.PointType   = "Behavior";
            obj.Description = be.Description;
            obj.Points      = be.Points;
            db.Transactions.Add(obj);
            db.SaveChanges();

            // act - retrieve the saved records and put them in a list.
            List <Transaction> savedObjs = (from d in db.Transactions select d).ToList();

            // Assert -- The list of saved objects should have a count greater than 0
            Assert.IsTrue(savedObjs.Count > 0);
        }
Beispiel #8
0
        public void DeleteTransactionFromRepository()
        {
            // arrange - Insert a record so that it can be updated.
            // note connection string is in app.config
            FamilyPointsContext db = new FamilyPointsContext();
            Behavior            be = (from d in db.Behaviors select d).First();
            Parent      pa         = (from d in db.Parents select d).First();
            Child       ch         = (from d in db.Children select d).First();
            Transaction obj        = new Transaction();

            obj.Date        = DateTime.Now;
            obj.ParentID    = pa.ParentID;
            obj.ChildID     = ch.ChildID;
            obj.PointType   = "Behavior";
            obj.Description = be.Description;
            obj.Points      = be.Points;
            db.Transactions.Add(obj);
            db.SaveChanges();

            // act - retrieve the saved record and then remove it.
            Transaction savedObj = (from d in db.Transactions where d.TransactionID == obj.TransactionID select d).Single();

            db.Transactions.Remove(savedObj);
            db.SaveChanges();

            // Assert -- see if the record deleted from the database exists
            Transaction removedObj = (from d in db.Transactions where d.TransactionID == savedObj.TransactionID select d).FirstOrDefault();

            Assert.IsNull(removedObj);
        }
Beispiel #9
0
        public void BehaviorsRepositoryContainsData()
        {
            // arrange
            // note connection string is in app.config
            FamilyPointsContext db = new FamilyPointsContext();

            // act -- go get the first record
            Behavior savedObj = (from d in db.Behaviors where d.BehaviorID == 1 select d).Single();

            // assert
            Assert.AreEqual(savedObj.BehaviorID, 1);
        }
Beispiel #10
0
        public void ListofBehaviorsInRepository()
        {
            // arrange - Add a record to be listed.
            // note connection string is in app.config
            FamilyPointsContext db  = new FamilyPointsContext();
            Behavior            obj = new Behavior();

            obj.Description = "Behavior 1";
            obj.Points      = 1;
            db.Behaviors.Add(obj);
            db.SaveChanges();

            // act - retrieve the saved records and put them in a list.
            List <Behavior> savedObjs = (from d in db.Behaviors select d).ToList();

            // Assert -- The list of saved objects should have a count greater than 0
            Assert.IsTrue(savedObjs.Count > 0);
        }
Beispiel #11
0
        public void ListofChildrenInRepository()
        {
            // arrange - Add a record to be listed.
            // note connection string is in app.config
            FamilyPointsContext db = new FamilyPointsContext();
            Child obj = new Child();

            obj.Name     = "Child 1";
            obj.Password = "******";
            db.Children.Add(obj);
            db.SaveChanges();

            // act - retrieve the saved records and put them in a list.
            List <Child> savedObjs = (from d in db.Children select d).ToList();

            // Assert -- The list of saved objects should have a count greater than 0
            Assert.IsTrue(savedObjs.Count > 0);
        }
Beispiel #12
0
        public void UpdateTransactionInRepository()
        {
            // arrange - Insert a record so that it can be updated.
            // note connection string is in app.config
            FamilyPointsContext db = new FamilyPointsContext();
            Behavior            be = (from d in db.Behaviors select d).First();
            Parent      pa         = (from d in db.Parents select d).First();
            Child       ch         = (from d in db.Children select d).First();
            Transaction obj        = new Transaction();

            obj.Date        = DateTime.Now;
            obj.ParentID    = pa.ParentID;
            obj.ChildID     = ch.ChildID;
            obj.PointType   = "Behavior";
            obj.Description = be.Description;
            obj.Points      = be.Points;
            db.Transactions.Add(obj);
            db.SaveChanges();


            // act - retrieve the saved record and update it.
            Transaction savedObj = (from d in db.Transactions where d.TransactionID == obj.TransactionID select d).Single();

            savedObj.Description = "Behvior Updated";
            savedObj.Points      = 2;
            db.SaveChanges();

            // Assert -- see if the record retreived from the database matches the one i just updated
            Transaction updatedObj = (from d in db.Transactions where d.TransactionID == obj.TransactionID select d).Single();

            Assert.AreEqual(updatedObj.Description, savedObj.Description);
            Assert.AreEqual(updatedObj.Points, savedObj.Points);
            Assert.AreEqual(updatedObj.ParentID, savedObj.ParentID);
            Assert.AreEqual(updatedObj.ChildID, savedObj.ChildID);
            Assert.AreEqual(updatedObj.PointType, savedObj.PointType);
            Assert.AreEqual(updatedObj.Date, savedObj.Date);

            // cleanup
            db.Transactions.Remove(updatedObj);
            db.SaveChanges();
        }
Beispiel #13
0
        public void DeleteBehaviorFromRepository()
        {
            // arrange - Insert a record so that it can be updated.
            // note connection string is in app.config
            FamilyPointsContext db  = new FamilyPointsContext();
            Behavior            obj = new Behavior();

            obj.Description = "Delete this Behavior";
            obj.Points      = 3;
            db.Behaviors.Add(obj);
            db.SaveChanges();

            // act - retrieve the saved record and then remove it.
            Behavior savedObj = (from d in db.Behaviors where d.BehaviorID == obj.BehaviorID select d).Single();

            db.Behaviors.Remove(savedObj);
            db.SaveChanges();

            // Assert -- see if the record deleted from the database exists
            Behavior removedObj = (from d in db.Behaviors where d.BehaviorID == savedObj.BehaviorID select d).FirstOrDefault();

            Assert.IsNull(removedObj);
        }
Beispiel #14
0
        public void DeleteChildFromRepository()
        {
            // arrange - Insert a record so that it can be updated.
            // note connection string is in app.config
            FamilyPointsContext db = new FamilyPointsContext();
            Child obj = new Child();

            obj.Name     = "Delete this Child";
            obj.Password = "******";
            db.Children.Add(obj);
            db.SaveChanges();

            // act - retrieve the saved record and then remove it.
            Child savedObj = (from d in db.Children where d.ChildID == obj.ChildID select d).Single();

            db.Children.Remove(savedObj);
            db.SaveChanges();

            // Assert -- see if the record deleted from the database exists
            Child removedObj = (from d in db.Children where d.ChildID == savedObj.ChildID select d).FirstOrDefault();

            Assert.IsNull(removedObj);
        }
Beispiel #15
0
        public void DeleteFamilyFromRepository()
        {
            // arrange - Insert a record so that it can be updated.
            // note connection string is in app.config
            FamilyPointsContext db = new FamilyPointsContext();
            Family obj             = new Family();

            obj.Name     = "Delete this Family";
            obj.Children = (from d in db.Children select d).ToList();
            obj.Parents  = (from d in db.Parents select d).ToList();
            db.Familys.Add(obj);
            db.SaveChanges();

            // act - retrieve the saved record and then remove it.
            Family savedObj = (from d in db.Familys where d.FamilyID == obj.FamilyID select d).Single();

            db.Familys.Remove(savedObj);
            db.SaveChanges();

            // Assert -- see if the record deleted from the database exists
            Family removedObj = (from d in db.Familys where d.FamilyID == savedObj.FamilyID select d).FirstOrDefault();

            Assert.IsNull(removedObj);
        }