Show that $E[\sum_{i=1}^{N}X_i] =E(N)E(X_1)$ 
Let $(X_n)$ be a sequence of random variables that are independent and identically distributed, with $EX_n < \infty$ and $EX_n^2 < \infty$. Let N be a random variable with range $R \subseteq \Bbb{N}$, independent of $(X_n)$, with $EN < \infty$ and $EN^2 < \infty$. Show that $E[\sum_{i=1}^{N}X_i] =E(N)E(X_1)$

So, I tried to calculate $E(\sum_{i=1}^{N}X_i|N)$. I think that it might be $E(X_1)N$, so, I tried to show that $E[t(N)\sum_{i=1}^{N}X_i]=E[NE(X_1)t(N)]$ for all t which are bounded and Borel-measurable, but I don't know how to calculate $E[t(N)\sum_{i=1}^{N}X_i]$. Any hint?
 A: Hint:
$$E \left [ \sum_{i=1}^N X_i \right ] = \sum_{n=1}^\infty E \left [ \left. \sum_{i=1}^N X_i \right | N=n \right ] P(N=n) \\
= \sum_{n=1}^\infty \sum_{i=1}^n E[X_i|N=n] P(N=n).$$
Can you compute the inner expectation?
A: $\begin{align}
\mathsf E(\sum_{n=1}^N X_n) & = \mathsf E(\mathsf E(\sum_{n=1}^N X_n\mid N)) & \textsf{Iterated Expectation}
\\[1ex] & = ~ & \textsf{Linearity of Expectation}
\\[1ex] & = ~ & \textsf{Independence of $\{X_n\}$ from $N$}
\\[1ex] & = ~ & \textsf{Identical Distribution of $\{X_n\}$}
\\[1ex] & = ~ & \textsf{Series of a Constant}
\\[1ex] & = \mathsf E(N)\;\mathsf E(X_1) & \textsf{Linearity of Expectation}
\end{align}$
Fill in the blanks.
A: Let $S_n = X_1 + \cdots + X_n$. Since $N$ is a.s.-finite, it follows that
$$ S_N
= S_N \sum_{n=0}^{\infty} \mathbf{1}_{\{N = n\}}
= \sum_{n=0}^{\infty} S_N \mathbf{1}_{\{N = n\}}
= \sum_{n=0}^{\infty} S_n \mathbf{1}_{\{N = n\}}
\qquad \Bbb{P}\text{-a.s.} $$
(This really shows that $\Bbb{E}[S_N | N] = N \Bbb{E}[X_1]$, but we need to check integrability condition for this to make sense.) Now from a simple estimate
\begin{align*}
\sum_{n=0}^{\infty} \Bbb{E} \big[ |S_n \mathbf{1}_{\{N = n\}}| \big]
& \leq \sum_{n=0}^{\infty} \Bbb{E} \big[ (|X_1| + \cdots + |X_n|) \mathbf{1}_{\{N = n\}} \big] \\
&= \Bbb{E}[|X_1|] \sum_{n=0}^{\infty} n \Bbb{P}(N = n) \\
&= \Bbb{E}[|X_1|] \Bbb{E}[N]
< \infty,
\end{align*}
we know that $S_N$ is integrable and that we can safely apply the Fubini's theorem to have
$$ \Bbb{E}[S_N]
= \Bbb{E}\Bigg[ \sum_{n=0}^{\infty} S_n \mathbf{1}_{\{N = n\}} \Bigg]
= \sum_{n=0}^{\infty} \Bbb{E} \big[ S_n \mathbf{1}_{\{N = n\}} \big]
= \Bbb{E}[X_1] \sum_{n=0}^{\infty} n \Bbb{P}(N = n)
= \Bbb{E}[X_1]\Bbb{E}[N]. $$
