コード例 #1
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);
            }
        }
コード例 #2
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());
            }
        }
コード例 #3
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());
            }
        }
コード例 #4
0
 public CharacterRepository(EveCMContext context)
 {
     db = context;
 }
コード例 #5
0
 public BulletinRepository(EveCMContext context)
 {
     db = context;
 }