示例#1
0
        public void GetBulletins_Should_Return_SpecifiedCount()
        {
            int expectedCount = 5;

            var options = new DbContextOptionsBuilder <EveCMContext>()
                          .UseInMemoryDatabase(databaseName: "GetBulletins_Specific_Count")
                          .Options;

            using (var context = new EveCMContext(options))
            {
                int count = 10;
                for (int i = 1; i < count - 1; i++)
                {
                    context.Bulletins.Add(new Bulletin()
                    {
                        Id          = i,
                        AuthorId    = i.ToString(),
                        Content     = $"This is some content: {i}",
                        Title       = $"This is some title: {i}",
                        CreatedDate = DateTime.Now.AddDays(i - 1)
                    });
                    context.SaveChanges();
                }
            }

            using (var context = new EveCMContext(options))
            {
                IBulletinRepository repository = new BulletinRepository(context);
                var result = repository.GetBulletins(out int total, expectedCount);

                Assert.AreEqual(expectedCount, result.Count());
            }
        }
示例#2
0
        public void SaveBulletin_Should_SaveToDatabase()
        {
            var options = new DbContextOptionsBuilder <EveCMContext>()
                          .UseInMemoryDatabase(databaseName: "GetBulletin_Order")
                          .Options;


            Bulletin bulletin = new Bulletin()
            {
                AuthorId    = "1",
                Content     = "TestContent",
                CreatedDate = DateTime.Now,
                Id          = 1234,
                Title       = "TestTitle"
            };

            using (var context = new EveCMContext(options))
            {
                IBulletinRepository bulletinRepository = new BulletinRepository(context);
                bulletinRepository.SaveBulletin(bulletin);
            }
            using (var context = new EveCMContext(options))
            {
                Bulletin savedBulletin = context.Bulletins.Where(x => x.Id == bulletin.Id).First();

                Assert.AreEqual(bulletin.Id, savedBulletin.Id);
            }
        }
示例#3
0
        //
        // GET: /Bulletins/Delete/5

        public ActionResult Delete(int id)
        {
            IRepository <Models.Bulletin> repo = new BulletinRepository();

            repo.Delete(repo.GetById(id));
            return(RedirectToAction("Index"));
        }
        // GET api/bulletins/5
        public Bulletin Get(int id)
        {
            var repository = new BulletinRepository();
            var bulletin   = repository.GetById(id);

            if (bulletin == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);                      // embrace the HTTP
            }
            return(bulletin);
        }
示例#5
0
 public ActionResult Delete(int id, FormCollection collection)
 {
     try
     {
         IRepository <Models.Bulletin> repo = new BulletinRepository();
         repo.Delete(repo.GetById(id));
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
示例#6
0
        public void GetBulletins_Should_OrderByRecent()
        {
            var options = new DbContextOptionsBuilder <EveCMContext>()
                          .UseInMemoryDatabase(databaseName: "GetBulletins_Order")
                          .Options;

            int entityCount = 10;

            using (var context = new EveCMContext(options))
            {
                for (int i = entityCount - 1; i >= 0; i--)
                {
                    context.Bulletins.Add(new Bulletin()
                    {
                        //allow for id = 0
                        Id       = i + 1,
                        AuthorId = i.ToString(),
                        Content  = $"This is some content: {i}",
                        Title    = $"This is some title: {i}",
                        //add dates in past
                        CreatedDate = DateTime.Now.AddDays(i * -1)
                    });
                    context.SaveChanges();
                }
            }

            using (var context = new EveCMContext(options))
            {
                IBulletinRepository repository = new BulletinRepository(context);
                var result = repository.GetBulletins(out int total);


                Assert.AreEqual(entityCount, result.Count());
                Assert.AreEqual(DateTime.Now.ToShortDateString(), result.First().CreatedDate.ToShortDateString());
                Assert.AreEqual(DateTime.Now.AddDays((entityCount - 1) * -1).ToShortDateString(), result.Last().CreatedDate.ToShortDateString());
            }
        }
        // GET api/bulletins
        public IEnumerable <Bulletin> Get()
        {
            var repository = new BulletinRepository();

            return(repository.GetAll());
        }
示例#8
0
        //
        // GET: /Bulletins/

        public ActionResult Index()
        {
            IRepository <Models.Bulletin> repo = new BulletinRepository();

            return(View(repo.GetAll()));
        }