Ejemplo n.º 1
0
        public async Task CreateCoverPictureAsyncShouldCreateCorrectly()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repositoryNewsFeedPost = new EfDeletableEntityRepository <NewsFeedPost>(dbContext);
            var applicationUser        = new EfDeletableEntityRepository <ApplicationUser>(dbContext);
            var pictureRepository      = new EfRepository <UserProfilePicture>(dbContext);
            var repositoryComment      = new EfDeletableEntityRepository <NewsFeedComment>(dbContext);
            var coverPictureRepository = new EfRepository <UserCoverPicture>(dbContext);
            var friendRepository       = new EfDeletableEntityRepository <Friend>(dbContext);

            var userPicture = new UserCoverPicture
            {
                PictureURL        = "mountain.jpg",
                ApplicationUserId = "1",
            };

            var service = new NewsFeedService(repositoryNewsFeedPost, applicationUser, pictureRepository, repositoryComment, coverPictureRepository, friendRepository);

            var createResult = service.CreateCoverPictureAsync(userPicture.ApplicationUserId, userPicture.PictureURL);

            Assert.Equal(1, coverPictureRepository.All().Count());
        }
        public async Task CreateCoverPictureAsync(string userId, string pictureUrl)
        {
            var userPicture = new UserCoverPicture
            {
                PictureURL        = pictureUrl,
                ApplicationUserId = userId,
            };

            await this.coverPictureRepository.AddAsync(userPicture);

            await this.coverPictureRepository.SaveChangesAsync();
        }
Ejemplo n.º 3
0
        public async Task GetLastCoverPictureShouldReturnLastPicture()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repositoryNewsFeedPost = new EfDeletableEntityRepository <NewsFeedPost>(dbContext);
            var applicationUser        = new EfDeletableEntityRepository <ApplicationUser>(dbContext);
            var pictureRepository      = new EfRepository <UserProfilePicture>(dbContext);
            var repositoryComment      = new EfDeletableEntityRepository <NewsFeedComment>(dbContext);
            var coverPictureRepository = new EfRepository <UserCoverPicture>(dbContext);
            var friendRepository       = new EfDeletableEntityRepository <Friend>(dbContext);

            var firstUserPicture = new UserCoverPicture
            {
                PictureURL        = "mountain.jpg",
                ApplicationUserId = "1",
            };

            var secondUserPicture = new UserCoverPicture
            {
                PictureURL        = "mountain2.jpg",
                ApplicationUserId = "1",
            };

            await coverPictureRepository.AddAsync(firstUserPicture);

            await coverPictureRepository.AddAsync(secondUserPicture);

            await coverPictureRepository.SaveChangesAsync();

            var service = new NewsFeedService(repositoryNewsFeedPost, applicationUser, pictureRepository, repositoryComment, coverPictureRepository, friendRepository);

            var result = await service.LastCoverPictureAsync("1");

            var resultWhenIsNull = await service.LastCoverPictureAsync("2");

            Assert.Equal(secondUserPicture.PictureURL, result);
            Assert.Null(resultWhenIsNull);
        }
Ejemplo n.º 4
0
        public async Task GetAllCoverPicturesAsyncShouldReturnCorrectCount()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repositoryNewsFeedPost = new EfDeletableEntityRepository <NewsFeedPost>(dbContext);
            var applicationUser        = new EfDeletableEntityRepository <ApplicationUser>(dbContext);
            var pictureRepository      = new EfRepository <UserProfilePicture>(dbContext);
            var repositoryComment      = new EfDeletableEntityRepository <NewsFeedComment>(dbContext);
            var coverPictureRepository = new EfRepository <UserCoverPicture>(dbContext);
            var friendRepository       = new EfDeletableEntityRepository <Friend>(dbContext);

            var userPicture = new UserCoverPicture
            {
                PictureURL        = "mountain.jpg",
                ApplicationUserId = "1",
            };

            var secondUserPicture = new UserCoverPicture
            {
                PictureURL        = "mountainTwo.jpg",
                ApplicationUserId = "1",
            };

            var service = new NewsFeedService(repositoryNewsFeedPost, applicationUser, pictureRepository, repositoryComment, coverPictureRepository, friendRepository);

            var firstPictureResult  = service.CreateCoverPictureAsync(userPicture.ApplicationUserId, userPicture.PictureURL);
            var secondPictureResult = service.CreateCoverPictureAsync(secondUserPicture.ApplicationUserId, secondUserPicture.PictureURL);

            AutoMapperConfig.RegisterMappings(typeof(GetAllCoverPictureForUserViewModel).GetTypeInfo().Assembly);

            var resultCount = await service.GetAllCoverPicturesAsync <GetAllCoverPictureForUserViewModel>(userPicture.ApplicationUserId);

            Assert.Equal(2, resultCount.Count());
        }