Skip to content

Instantly share code, notes, and snippets.

@bpatra
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bpatra/9518156 to your computer and use it in GitHub Desktop.
Save bpatra/9518156 to your computer and use it in GitHub Desktop.
First example of unit test when inserting the first row after the second one
[TestClass]
public class ChampionshipBetViewModel_DragAndDrop_Tests
{
private readonly ChampionshipBetViewModel _championshipBetViewModel;
private readonly Mock<IChampionship> _championShip;
private readonly IFootballClub _club1;
private readonly IFootballClub _club2;
private readonly IFootballClub _club3;
private readonly IFootballClub _club4;
private IFootballClub GetMockClub(int i)
{
var club1 = new Mock<IFootballClub>();
club1.Setup(m => m.FullName).Returns("Club"+i);
return club1.Object;
}
public ChampionshipBetViewModel_DragAndDrop_Tests()
{
_club1 = GetMockClub(1);
_club2 = GetMockClub(2);
_club3 = GetMockClub(3);
_club4 = GetMockClub(4);
_championShip = new Mock<IChampionship>();
_championShip.SetupGet(c => c.UserBet).Returns(new List<IFootballClub>(new[] { _club1, _club2, _club3, _club4}));
_championshipBetViewModel = new ChampionshipBetViewModel(_championShip.Object);
}
[TestMethod]
public void When_Source_Is_FirstRow_And_Target_Second_Then_Drop_Should_Reorder()
{
var dropInfo = new Mock<IDropInfo>();
dropInfo.SetupGet(m => m.Data).Returns(new[] { _club1 });
dropInfo.SetupGet(m => m.InsertIndex).Returns(2);
_championshipBetViewModel.Drop(dropInfo.Object);
var resultClubs = _championshipBetViewModel.FootballClubs.Select(x=>x.FullName).ToArray();
CollectionAssert.AreEqual(new[] { "Club2", "Club1", "Club3", "Club4" }, resultClubs);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment