Exemple #1
0
        public async Task WhenGetById_ShouldReturnSpecificUsefulLink()
        {
            //arange
            var options = new DbContextOptionsBuilder <GravityGymDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetWithId_UsefulLinks")
                          .Options;

            using (var ctx = new GravityGymDbContext(options))
            {
                ctx.UsefulLinks.AddRange(_usefulLinks);
                ctx.SaveChanges();
            }


            using (var ctx = new GravityGymDbContext(options))
            {
                var usefulLinkRepo = new UsefulLinksRepository(ctx, _mapperMoq.Object);


                //act
                var result = await usefulLinkRepo.GetByIdAsync(2L);


                //assert
                var actual = _usefulLinks.Where(ul => ul.Id == 2L).FirstOrDefault();

                Assert.AreEqual(result.Id, actual.Id);
                Assert.AreEqual(result.Link, actual.Link);
                Assert.AreEqual(result.Description, actual.Description);
            }
        }
Exemple #2
0
        public async Task WhenUpdateUL_ShouldBeUpdated()
        {
            //arange
            var options = new DbContextOptionsBuilder <GravityGymDbContext>()
                          .UseInMemoryDatabase(databaseName: "UpdateWithId_UsefulLinks")
                          .Options;

            using (var ctx = new GravityGymDbContext(options))
            {
                ctx.UsefulLinks.AddRange(_usefulLinks);
                ctx.SaveChanges();
            }


            using (var ctx = new GravityGymDbContext(options))
            {
                var usefulLinkRepo = new UsefulLinksRepository(ctx, _mapperMoq.Object);


                //act
                var ul = await usefulLinkRepo.GetByIdAsync(2L);

                ul.Description = "NUnit Test";
                ul.Link        = "https://amdariss.com/";
                await usefulLinkRepo.UpdateAsync(ul);

                var result = await usefulLinkRepo.GetByIdAsync(2L);



                //assert
                Assert.AreEqual(result.Id, ul.Id);
                Assert.AreEqual(result.Link, ul.Link);
                Assert.AreEqual(result.Description, ul.Description);
            }
        }