Ejemplo n.º 1
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MemeBankContext(
                       serviceProvider.GetRequiredService <DbContextOptions <MemeBankContext> >()))
            {
                // Look for any movies.
                if (context.MemeItem.Count() > 0)
                {
                    return;   // DB has been seeded
                }

                context.MemeItem.AddRange(
                    new MemeItem
                {
                    Title    = "Is Mayo an Instrument?",
                    Url      = "https://i.kym-cdn.com/photos/images/original/001/371/723/be6.jpg",
                    Tags     = "spongebob",
                    Uploaded = "07-10-18 4:20T18:25:43.511Z",
                    Width    = "768",
                    Height   = "432"
                }


                    );
                context.SaveChanges();
            }
        }
Ejemplo n.º 2
0
 public void ClearDb()
 {
     using (var context = new MemeBankContext(options))
     {
         context.MemeItem.RemoveRange(context.MemeItem);
         context.SaveChanges();
     };
 }
Ejemplo n.º 3
0
        public async Task TestPutMemeItemUpdate()
        {
            using (var context = new MemeBankContext(options))
            {
                // Given
                string   title     = "putMeme";
                MemeItem memeItem1 = context.MemeItem.Where(x => x.Title == memeTitles[0]).Single();
                memeItem1.Title = title;

                // When
                MemeController memeController = new MemeController(context, configuration);
                IActionResult  result         = await memeController.PutMemeItem(memeItem1.Id, memeItem1) as IActionResult;

                // Then
                memeItem1 = context.MemeItem.Where(x => x.Title == title).Single();
            }
        }
Ejemplo n.º 4
0
        public async Task TestPutMemeItemNoContentStatusCode()
        {
            using (var context = new MemeBankContext(options))
            {
                // Given
                string   title     = "putMeme";
                MemeItem memeItem1 = context.MemeItem.Where(x => x.Title == memeTitles[0]).Single();
                memeItem1.Title = title;

                // When
                MemeController memeController = new MemeController(context, configuration);
                IActionResult  result         = await memeController.PutMemeItem(memeItem1.Id, memeItem1) as IActionResult;

                // Then
                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(NoContentResult));
            }
        }
Ejemplo n.º 5
0
        public void SetupDb()
        {
            using (var context = new MemeBankContext(options))
            {
                MemeItem memeItem1 = new MemeItem()
                {
                    Title = memeTitles[0]
                };

                MemeItem memeItem2 = new MemeItem()
                {
                    Title = memeTitles[1]
                };

                context.MemeItem.Add(memeItem1);
                context.MemeItem.Add(memeItem2);
                context.SaveChanges();
            }
        }
Ejemplo n.º 6
0
 public MemeController(MemeBankContext context, IConfiguration configuration)
 {
     _context       = context;
     _configuration = configuration;
 }
Ejemplo n.º 7
0
 public MemeController(MemeBankContext context)
 {
     _context = context;
 }