Exemplo n.º 1
0
        public async void CreateGramWorksAgain()
        {
            DbContextOptions <NetGramDbContext> options =
                new DbContextOptionsBuilder <NetGramDbContext>
                    ().UseInMemoryDatabase("Create").Options;

            using (NetGramDbContext context = new NetGramDbContext(options))
            {
                // arrange
                NetGram netGram = new NetGram();
                netGram.ID         = 2;
                netGram.NamePoster = "Jason";
                netGram.Caption    = "Seattle";


                // Act
                NetGramManager netGramManager = new NetGramManager(context);

                await netGramManager.SaveNetGram(netGram);

                var created = context.NetGrams.FirstOrDefault(n => n.ID == netGram.ID);

                // Assert
                Assert.Equal(netGram, created);
            }
        }
Exemplo n.º 2
0
        public async void EditGramWorksAgain()
        {
            DbContextOptions <NetGramDbContext> options =
                new DbContextOptionsBuilder <NetGramDbContext>
                    ().UseInMemoryDatabase("Edits").Options;

            using (NetGramDbContext context = new NetGramDbContext(options))
            {
                // arrange
                NetGram netGram = new NetGram();
                netGram.ID         = 2;
                netGram.NamePoster = "Jason";
                netGram.Caption    = "Seattle";


                // Act
                NetGramManager netGramManager = new NetGramManager(context);

                await netGramManager.SaveNetGram(netGram);

                netGram.Caption = "Wow";

                await netGramManager.SaveNetGram(netGram);

                // Assert
                Assert.Equal("Wow", netGram.Caption);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Deletes a net gram
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task Delete(int id)
        {
            NetGram netGram = await _context.NetGrams.FindAsync(id);

            if (netGram != null)
            {
                _context.Remove(netGram);
                await _context.SaveChangesAsync();
            }
        }
Exemplo n.º 4
0
        public void GetWorks()
        {
            //arrange
            NetGram netGram = new NetGram();

            netGram.Caption = "nice pic";

            //assert
            Assert.Equal("nice pic", netGram.Caption);
        }
Exemplo n.º 5
0
        public void GetWorksAgain()
        {
            //arrange
            NetGram netGram = new NetGram();

            netGram.Caption    = "nice pic";
            netGram.NamePoster = "Jason";

            //assert
            Assert.Equal("Jason", netGram.NamePoster);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Saves new and or  updates existing netgrams
        /// </summary>
        /// <param name="netGram"></param>
        /// <returns></returns>
        public async Task SaveNetGram(NetGram netGram)
        {
            if (await _context.NetGrams.FirstOrDefaultAsync(n => n.ID == netGram.ID) == null)
            {
                _context.NetGrams.Add(netGram);
            }
            else
            {
                _context.NetGrams.Update(netGram);
            }

            await _context.SaveChangesAsync();
        }
Exemplo n.º 7
0
        public void SetWorks()
        {
            //arrange
            NetGram netGram = new NetGram();

            netGram.Caption    = "nice pic";
            netGram.NamePoster = "Jason";

            //Act
            netGram.Caption = "crappy pic";
            //assert
            Assert.Equal("crappy pic", netGram.Caption);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Gets details of netgram
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <NetGram> GetDetails(int id)
        {
            NetGram netGram = await _context.NetGrams.FirstOrDefaultAsync(net => net.ID == id);

            return(netGram);
        }
Exemplo n.º 9
0
 public async Task OnGet()
 {
     NetGram = await _netGram.GetDetails(ID);
 }