public void TestGetProgramNotFound() { var connection = new SqliteConnection("Datasource=:memory:"); connection.Open(); try { var options = new DbContextOptionsBuilder <InternalServicesDirectoryV1Context>() .UseSqlite(connection) .Options; // test a successful case using (var context = new InternalServicesDirectoryV1Context(options)) { context.Database.EnsureCreated(); context.Program.Add(new Program()); context.SaveChanges(); ProgramController controller = new ProgramController(context); var actionResult = controller.Get(2).Result; var result = actionResult as NotFoundObjectResult; Assert.IsNotNull(result); Assert.AreEqual(404, result.StatusCode); Assert.AreEqual("No program from given id found.", result.Value); } } finally { connection.Close(); } }