예제 #1
0
        public void TestConvertRestaurantListFromDB()
        {
            ICollection <DataProject.Restaurant> dbList = new List <DataProject.Restaurant>();

            dbRest = new DataProject.Restaurant
            {
                Name      = name,
                ID        = restId,
                Address   = address,
                City      = city,
                AvgRating = 5f,
                PhoneNum  = phoneNum,
                Reviews   = new List <DataProject.Review>(),
                State     = state,
                ZIP       = zip
            };
            dbRev = new DataProject.Review
            {
                ID           = revId,
                Rating       = rating,
                Description  = desc,
                RestaurantID = restId
            };
            dbRest.Reviews.Add(dbRev);
            dbList.Add(dbRest);

            ICollection <LibraryProject.Restaurant> blList = Converter.ConvertRestaurantListFromDB(dbList);

            if (dbList.Count != blList.Count)
            {
                Assert.Fail("lists not equal");
            }
            else
            {
                for (int i = 0; i < dbList.Count; i++)
                {
                    dbRest = ((List <DataProject.Restaurant>)dbList)[i];
                    blRest = ((List <LibraryProject.Restaurant>)blList)[i];

                    for (int y = 0; y < dbRest.Reviews.Count; y++)
                    {
                        dbRev = ((List <DataProject.Review>)dbRest.Reviews)[0];
                        blRev = ((List <LibraryProject.Review>)blRest.Reviews)[0];
                        Assert.AreEqual(dbRest.Address, blRest.Address, "Address: \"" + dbRest.Address + "\" \"" + blRest.Address + '"');
                        Assert.AreEqual(dbRest.AvgRating, blRest.AvgRating, "AvgRating: \"" + dbRest.AvgRating + "\" \"" + blRest.AvgRating + '"');
                        Assert.AreEqual(dbRest.City, blRest.City, "City: \"" + dbRest.City + "\" \"" + blRest.City + '"');
                        Assert.AreEqual(dbRest.ID, blRest.ID, "ID: \"" + dbRest.ID + "\" \"" + blRest.ID + '"');
                        Assert.AreEqual(dbRest.Name, blRest.Name, "Name: \"" + dbRest.Name + "\" \"" + blRest.Name + '"');
                        Assert.AreEqual(dbRest.PhoneNum, blRest.PhoneNum, "PhoneNum: \"" + dbRest.PhoneNum + "\" \"" + blRest.PhoneNum + '"');
                        Assert.AreEqual(dbRest.State, blRest.State, "State: \"" + dbRest.State + "\" \"" + blRest.Address + '"');
                        Assert.AreEqual(dbRest.ZIP, blRest.ZIP, "ZIP: \"" + dbRest.ZIP + "\" \"" + blRest.ZIP + '"');
                        Assert.AreEqual(dbRev.Description, blRev.Description, "Description: \"" + dbRev.Description + "\" \"" + blRev.Description + '"');
                        Assert.AreEqual(dbRev.Rating, blRev.Rating, "Rating: \"" + dbRev.Rating + "\" \"" + blRev.Rating + '"');
                        Assert.AreEqual(dbRev.RestaurantID, blRev.RestaurantID, "RestaurantID: \"" + dbRev.RestaurantID + "\" \"" + blRev.RestaurantID + '"');
                        Assert.AreEqual(dbRev.ID, blRev.ID, "ID: \"" + dbRev.ID + "\" \"" + blRev.ID + '"');
                    }
                }
            }
        }
예제 #2
0
        private static Review ConvertReviewFromDB(DataProject.Review dbReview)
        {
            Review result = new Review
            {
                Description  = dbReview.Description,
                Rating       = (int)dbReview.Rating,
                ReviewerID   = (dbReview.ReviewerID != null ? (int)dbReview.ReviewerID : -1),
                ID           = dbReview.ID,
                RestaurantID = dbReview.RestaurantID
            };

            return(result);
        }
예제 #3
0
        private static DataProject.Review ConvertReviewToDB(Review review)
        {
            DataProject.Review result = new DataProject.Review
            {
                Description  = review.Description.Substring(0, Math.Min(200, review.Description.Length)),
                Rating       = review.Rating,
                ID           = review.ID,
                RestaurantID = review.RestaurantID
            };
            if (review.ReviewerID > 0)
            {
                result.ReviewerID = review.ReviewerID;
            }

            return(result);
        }
예제 #4
0
        public void TestConvertRestaurantFromDB()
        {
            dbRest = new DataProject.Restaurant
            {
                Name      = name,
                ID        = restId,
                Address   = address,
                City      = city,
                AvgRating = 5f,
                PhoneNum  = phoneNum,
                Reviews   = new List <DataProject.Review>(),
                State     = state,
                ZIP       = zip
            };
            dbRev = new DataProject.Review
            {
                ID           = revId,
                Rating       = rating,
                Description  = desc,
                RestaurantID = restId
            };
            dbRest.Reviews.Add(dbRev);

            blRest = Converter.ConvertRestaurantFromDB(dbRest);
            blRev  = ((List <LibraryProject.Review>)blRest.Reviews)[0];

            Assert.AreEqual(dbRest.Address, blRest.Address, "Address: \"" + dbRest.Address + "\" \"" + blRest.Address + '"');
            Assert.AreEqual(dbRest.AvgRating, blRest.AvgRating, "AvgRating: \"" + dbRest.AvgRating + "\" \"" + blRest.AvgRating + '"');
            Assert.AreEqual(dbRest.City, blRest.City, "City: \"" + dbRest.City + "\" \"" + blRest.City + '"');
            Assert.AreEqual(dbRest.ID, blRest.ID, "ID: \"" + dbRest.ID + "\" \"" + blRest.ID + '"');
            Assert.AreEqual(dbRest.Name, blRest.Name, "Name: \"" + dbRest.Name + "\" \"" + blRest.Name + '"');
            Assert.AreEqual(dbRest.PhoneNum, blRest.PhoneNum, "PhoneNum: \"" + dbRest.PhoneNum + "\" \"" + blRest.PhoneNum + '"');
            Assert.AreEqual(dbRest.State, blRest.State, "State: \"" + dbRest.State + "\" \"" + blRest.Address + '"');
            Assert.AreEqual(dbRest.ZIP, blRest.ZIP, "ZIP: \"" + dbRest.ZIP + "\" \"" + blRest.ZIP + '"');
            Assert.AreEqual(dbRev.Description, blRev.Description, "Description: \"" + dbRev.Description + "\" \"" + blRev.Description + '"');
            Assert.AreEqual(dbRev.Rating, blRev.Rating, "Rating: \"" + dbRev.Rating + "\" \"" + blRev.Rating + '"');
            Assert.AreEqual(dbRev.RestaurantID, blRev.RestaurantID, "RestaurantID: \"" + dbRev.RestaurantID + "\" \"" + blRev.RestaurantID + '"');
            Assert.AreEqual(dbRev.ID, blRev.ID, "ID: \"" + dbRev.ID + "\" \"" + blRev.ID + '"');
        }
        public static Review ConvertReviewFromDB(DataProject.Review rev)
        {
            Review result;

            if (rev != null)
            {
                result = new Review
                {
                    Description  = rev.Description,
                    ID           = rev.ID,
                    Rating       = rev.Rating,
                    RestaurantID = rev.RestaurantID,
                    ReviewerID   = rev.ReviewerID
                };
            }
            else
            {
                result = null;
            }

            return(result);
        }