Let $X$ be a real-valued random. How can we prove that $X$ has density $f$ if and only if $$\operatorname E[h(X)]=\int h(x)f(x)\;{\rm d}x$$ for all Borel measurable bounded $h:\mathbb R\to\mathbb R$?
The direction "$\Rightarrow$" is clear by the law of the unconscious statistician (even when they don't state that the $h$ need to be bounded, $h(X)$ won't be integrable otherwise), but how can we show the other direction?
Proof of the law of the unconscious statistician. $∫_A f(x) \ dx = ∫\Bbb 1_A f(x) \ dx = \Bbb P(X ∈ A) = \Bbb E \Bbb 1_A$. Linearity tells us that the result then holds for all simple functions $h = ∑a_i \Bbb 1_{A_i}$, which proves the result by the density of simple functions.
From the first line of the above proof (i.e. take $h = \Bbb 1_A$ for any Borel $A$) we recover the direction that you are asking for (i.e. if $\Bbb E h(X) = ∫ h(x) f(x) \ dx$, then for every Borel set $A$, $\Bbb P(X∈ A) = ∫_A f dx$)