public async Task MemeReaction_MemeRatingShouldBeDeleted() { var reaction = StubMemeReaction(0); var repo = CreateMockRepository(reaction, 1); var controller = new MemeListController(repo, Substitute.For <IBgcSessionsRepository>()); var result = await controller.MemeReaction(reaction); Assert.AreEqual(-1, result.Rating); }
public async Task MemeReaction_DbIntegration() { using (var contextProvider = new EFInMemoryDbCreator.Sqlite <BgcFullContext>()) { // arrange var context = contextProvider.CreateContext(c => c.SeedUsers(1).SeedMemes(10)); var repo = new BgcMemeRepo(context); var sessions = new BgcSessionsRepo(context); var controller = new MemeListController(repo, sessions); var reaction = new MemeReaction() { MemeId = _random.Next(1, EFInMemoryDbCreator.MemeCount), UserId = 1, Vote = (sbyte)(_random.Next(0, 10) % 2 == 0 ? -1 : 1) }; var mRating = (await repo.DrawMeme(reaction.MemeId)).Rating; // act var outcome = await controller.MemeReaction(reaction); // fresh context repo = new BgcMemeRepo(contextProvider.GetFreshContext()); // prepare assert var rating = await repo.FetchRating(reaction); var meme2 = await repo.DrawMeme(reaction.MemeId); // assert Assert.AreEqual(reaction.Vote, rating.Vote); Assert.AreNotEqual(meme2.Rating, mRating); mRating += reaction.Vote; Assert.AreEqual(mRating, meme2.Rating); Assert.AreEqual(outcome.Rating, meme2.Rating); Assert.AreEqual(1, rating.Id); } }