Esempio n. 1
0
        public async Task AddAsync_WithValidData_ShouldReturnPostCreatorId()
        {
            // Arrange
            var context         = InMemoryDbContext.Initiliaze();
            var likesRepository = new EfRepository <Like>(context);
            var usersRepository = new EfRepository <ApplicationUser>(context);
            var postsRepository = new EfRepository <Post>(context);
            var service         = new LikesService(likesRepository, usersRepository, postsRepository);

            await this.SeedUserAndPost(context);

            var model = new AddLikeModel {
                UserId = "userId", PostId = 52
            };

            // Act
            string expectedPostCreatorId = context.Posts.FirstOrDefault().CreatorId;
            string actualPostCreatorId   = await service.AddAsync(model);

            // Assert
            Assert.Equal(expectedPostCreatorId, actualPostCreatorId);
        }
Esempio n. 2
0
        public async Task AddAsync_WithValidData_ShouldAddLikeToDatabase()
        {
            // Arrange
            var context         = InMemoryDbContext.Initiliaze();
            var likesRepository = new EfRepository <Like>(context);
            var usersRepository = new EfRepository <ApplicationUser>(context);
            var postsRepository = new EfRepository <Post>(context);
            var service         = new LikesService(likesRepository, usersRepository, postsRepository);

            await this.SeedUserAndPost(context);

            var model = new AddLikeModel {
                UserId = "userId", PostId = 52
            };

            // Act
            int expectedCount = context.Likes.Count() + 1;
            await service.AddAsync(model);

            int actualCount = context.Likes.Count();

            // Assert
            Assert.Equal(expectedCount, actualCount);
        }