Exemple #1
0
        private IEnumerable <Comment> SeedReplies(int seedCommentId, MyAlbumDbContext context)
        {
            string seedUserId  = Guid.NewGuid().ToString();
            int    seedPhotoId = new Random().Next(1, 100);
            Photo  seedPhoto   = new Photo()
            {
                Id = seedPhotoId
            };
            string expectedUserName = "******";
            User   seedUser         = new User()
            {
                Id       = seedUserId,
                UserName = expectedUserName
            };
            int            numOfReplies = new Random().Next(3, 5);
            List <Comment> seedReplies  = new List <Comment>(numOfReplies);

            for (int i = 1; i <= numOfReplies; i++)
            {
                Comment seedReply = new Comment()
                {
                    Id       = seedCommentId + i,
                    ParentId = null,
                    Content  = Guid.NewGuid().ToString(),
                    Photo    = seedPhoto,
                    Author   = seedUser
                };
                context.Comments.Add(seedReply);
                seedReplies.Add(seedReply);
            }
            context.SaveChanges();

            return(seedReplies);
        }
        private IEnumerable <Photo> SeedPhotos_HasLocation(MyAlbumDbContext context)
        {
            string seedUserId       = Guid.NewGuid().ToString();
            string expectedUserName = "******";
            User   seedUser         = new User()
            {
                Id       = seedUserId,
                UserName = expectedUserName
            };
            int          numOfPhotos = new Random().Next(1, 20);
            List <Photo> seedPhotos  = new List <Photo>(numOfPhotos);
            int          seedPhotoId = new Random().Next(1, 100);

            for (int i = 1; i <= numOfPhotos; i++)
            {
                Photo seedPhoto = new Photo()
                {
                    Id     = seedPhotoId + i,
                    Name   = Guid.NewGuid().ToString(),
                    Author = seedUser,
                };

                if (RandBoolean())
                {
                    seedPhoto.LocLng = seedPhoto.LocLat = seedPhotoId;
                    seedPhotos.Add(seedPhoto);
                }
                context.Photos.Add(seedPhoto);
            }
            context.SaveChanges();

            return(seedPhotos);
        }
Exemple #3
0
        private IEnumerable <Album> SeedAlbums(MyAlbumDbContext context)
        {
            string seedUserId       = Guid.NewGuid().ToString();
            string expectedUserName = "******";
            User   seedUser         = new User()
            {
                Id       = seedUserId,
                UserName = expectedUserName
            };
            int          numOfAlbums = new Random().Next(5, 20);
            List <Album> seedAlbums  = new List <Album>(numOfAlbums);
            int          seedAlbumId = new Random().Next(1, 100);

            for (int i = 1; i <= numOfAlbums; i++)
            {
                Album seedAlbum = new Album()
                {
                    Id     = seedAlbumId + i,
                    Name   = Guid.NewGuid().ToString(),
                    Author = seedUser
                };
                context.Albums.Add(seedAlbum);
                seedAlbums.Add(seedAlbum);
            }
            context.SaveChanges();

            return(seedAlbums);
        }
Exemple #4
0
        private Comment SeedComment(MyAlbumDbContext context)
        {
            int     seedCommentId    = new Random().Next(1, 100);
            string  seed             = Guid.NewGuid().ToString();
            string  seedUserId       = Guid.NewGuid().ToString();
            int     seedPhotoId      = new Random().Next(1, 100);
            string  expectedUserName = string.Format("test_{0}@gmail.com", seed);
            Comment seedComment      = new Comment()
            {
                Id      = seedCommentId,
                Content = seed,
                Photo   = new Photo()
                {
                    Id = seedPhotoId
                },
                Author = new User()
                {
                    Id       = seedUserId,
                    UserName = expectedUserName
                }
            };

            context.Comments.Add(seedComment);
            context.SaveChanges();
            return(seedComment);
        }
Exemple #5
0
        private User SeedUser(MyAlbumDbContext context)
        {
            string seedUserId = Guid.NewGuid().ToString();
            User   seedUser   = new User()
            {
                Id        = seedUserId,
                UserName  = string.Format("test_{0}@gmail.com", seedUserId),
                FirstName = string.Format("FN_{0}", seedUserId),
                LastName  = string.Format("LN_{0}", seedUserId),
            };

            context.Users.Add(seedUser);
            context.SaveChanges();
            return(seedUser);
        }
Exemple #6
0
        private IEnumerable <Category> SeedCategories(MyAlbumDbContext context)
        {
            int numOfCategories = new Random().Next(1, 20);
            var seedCategories  = new List <Category>();

            for (int i = 0; i < numOfCategories; i++)
            {
                var category = new Category()
                {
                    Id   = new Random().Next(i * 20, (i + 1) * 20),
                    Name = Guid.NewGuid().ToString()
                };
                seedCategories.Add(category);
                context.Category.Add(category);
            }
            context.SaveChanges();
            return(seedCategories);
        }
Exemple #7
0
        private Album SeedAlbum(MyAlbumDbContext context)
        {
            int    seedAlbumId      = new Random().Next(1, 100);
            string seed             = Guid.NewGuid().ToString();
            string seedUserId       = Guid.NewGuid().ToString();
            string expectedUserName = string.Format("test_{0}@gmail.com", seed);
            Album  seedAlbum        = new Album()
            {
                Id     = seedAlbumId,
                Name   = seed,
                Author = new User()
                {
                    Id       = seedUserId,
                    UserName = expectedUserName
                }
            };

            context.Albums.Add(seedAlbum);
            context.SaveChanges();
            return(seedAlbum);
        }
Exemple #8
0
        private Photo SeedPhoto(MyAlbumDbContext context)
        {
            int    seedPhotoId      = new Random().Next(1, 100);
            string seed             = Guid.NewGuid().ToString();
            string seedUserId       = Guid.NewGuid().ToString();
            string expectedUserName = string.Format("test_{0}@gmail.com", seed);
            Photo  seedPhoto        = new Photo()
            {
                Id     = seedPhotoId,
                Name   = seed,
                Author = new User()
                {
                    Id       = seedUserId,
                    UserName = expectedUserName
                }
            };

            context.Photos.Add(seedPhoto);
            context.SaveChanges();
            return(seedPhoto);
        }
Exemple #9
0
        private IEnumerable <Comment> SeedSelfAndAncestors(int seedCommentId, MyAlbumDbContext context)
        {
            string seedUserId  = Guid.NewGuid().ToString();
            int    seedPhotoId = new Random().Next(1, 100);
            Photo  seedPhoto   = new Photo()
            {
                Id = seedPhotoId
            };
            string expectedUserName = "******";
            User   seedUser         = new User()
            {
                Id       = seedUserId,
                UserName = expectedUserName
            };
            int            numOfLevels = new Random().Next(1, 20);
            List <Comment> seedReplies = new List <Comment>(numOfLevels + 1);

            int?parentId = null;

            for (int i = numOfLevels; i >= 0; i--)
            {
                Comment seedReply = new Comment()
                {
                    Id       = seedCommentId + i,
                    ParentId = parentId,
                    Content  = Guid.NewGuid().ToString(),
                    Photo    = seedPhoto,
                    Author   = seedUser
                };
                context.Comments.Add(seedReply);
                seedReplies.Add(seedReply);
                parentId = seedReply.Id;
            }
            context.SaveChanges();
            seedReplies.Reverse();

            return(seedReplies);
        }