Ejemplo n.º 1
0
        public async Task CreateProfilePictureAsyncShouldCreateCorrectly()
        {
            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 UserProfilePicture
            {
                PictureURL        = "mountain.jpg",
                ApplicationUserId = "1",
            };

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

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

            Assert.Equal(1, pictureRepository.All().Count());
        }
Ejemplo n.º 2
0
        public async Task GetAllProfilePicturesAsyncShouldReturnCorrectCount()
        {
            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 UserProfilePicture
            {
                PictureURL        = "mountain.jpg",
                ApplicationUserId = "1",
            };

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

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

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

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

            var resultCount = await service.GetAllProfilePicturesAsync <GetAllProfilePictureForUserViewModel>(userPicture.ApplicationUserId);

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