using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Silverlight.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace SilverlightTest1 {
[TestClass]
public class Tests : SilverlightTest {
private MyView _target;
private MyViewModel _viewModel;
private List<IsoCurrency> _currencies;
[TestInitialize]
public void TestInitialize() {
_target = new MyView();
_viewModel = new MyViewModel();
var ukp = new IsoCurrency { Code = "GBP", Description = "Pound Sterling", LocaleID = 826 };
var usd = new IsoCurrency { Code = "USD", Description = "US Dollar", LocaleID = 840 };
var eur = new IsoCurrency { Code = "EUR", Description = "Euro", LocaleID = 978 };
_currencies = new List<IsoCurrency> { ukp, usd, eur };
GetUIElement<Grid>( "LayoutRoot" ).DataContext = _viewModel;
}
private T GetUIElement<T>( string name ) where T : UIElement { return (T) _target.FindName( name ); }
[TestMethod]
[Asynchronous]
public void TestMethod1() {
_target.Loaded += (s, e) => {
// Set the currency list explicitly
_viewModel.IsoCurrenciesList = _currencies;
var currencyCombo = GetUIElement<ComboBox>("cmbCurrency");
CollectionAssert.AreEquivalent(currencyCombo.Items, _currencies, "Failed to data-bind currencies.");
EnqueueTestComplete();
};
TestPanel.Children.Add(_target);
}
}
}