Пример #1
0
        public HomeControllerFixture()
        {
            Db = new SqliteConnection("DataSource=:memory:");
            Db.Open();

            var options = new DbContextOptionsBuilder <EuroFizzBuzzContext>()
                          .UseSqlite(Db)
                          .Options;

            Context = new EuroFizzBuzzContext(options);

            Context.Database.EnsureCreated();
        }
Пример #2
0
        public void TestHomeControllerWritesSubmissionModelToDatabase()
        {
            var controller = new HomeController(_fixture.Context);
            var result     = controller.Index() as ViewResult;

            var options = new DbContextOptionsBuilder <EuroFizzBuzzContext>()
                          .UseSqlite(_fixture.Db)
                          .Options;

            using (var context = new EuroFizzBuzzContext(options))
            {
                var submissions = context.Submissions;
                Assert.True(submissions.Contains(result.Model as Submission));
            }
        }
Пример #3
0
        public void TestCreateSubmissionSuccessfully()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <EuroFizzBuzzContext>()
                              .UseSqlite(connection)
                              .Options;

                using (var context = new EuroFizzBuzzContext(options))
                {
                    context.Database.EnsureCreated();
                }

                using (var context = new EuroFizzBuzzContext(options))
                {
                    var submission = new Submission();
                    submission.StartNumber = 0;
                    submission.EndNumber   = 100;
                    submission.Timestamp   = DateTime.Now;

                    context.Submissions.Add(submission);
                    context.SaveChanges();
                }

                using (var context = new EuroFizzBuzzContext(options))
                {
                    Assert.Equal(1, context.Submissions.Count());
                    Assert.Equal(0, context.Submissions.First().StartNumber);
                }
            }
            finally
            {
                connection.Close();
            }
        }
Пример #4
0
 public HomeController(EuroFizzBuzzContext context)
 {
     _context = context;
 }