Skip to content

Instantly share code, notes, and snippets.

@bpatra
bpatra / gist:9401745
Last active August 29, 2015 13:57
IFootballClub interface
public interface IFootballClub
{
string FullName { get; }
string NickName { get; }
int CreationYear { get; }
}
@bpatra
bpatra / gist:9401776
Last active August 29, 2015 13:57
IChampionship interface
public interface IChampionship
{
List<IFootballClub> CurrentChampionShipRanking { get; }
List<IFootballClub> UserBet { get; set; }
int GetGoodBetCount();
}
@bpatra
bpatra / gist:9516512
Last active August 29, 2015 13:57
IChampionshipBetViewModel
public interface IChampionshipBetViewModel : IDropTarget
{
ObservableCollection<IFootballClub> FootballClubs { get; }
ICommand ClickSave { get; }
}
@bpatra
bpatra / gist:9516759
Last active August 29, 2015 13:57
ChampionshipBetView
<UserControl x:Class="MvvMSample.Views.ChampionshipBetView" ... >
<UserControl.Resources>
<!-- go to github.com/bpatra/MvvMSample for complete implementation-->
</UserControl.Resources>
<UserControl.DataContext>
<Binding Path="ChampionshipBetViewModel" Source="{StaticResource Locator}" />
</UserControl.DataContext>
<StackPanel>
<ListView ItemsSource="{Binding FootballClubs}"
dd:DragDrop.IsDragSource="True"
@bpatra
bpatra / gist:9517801
Last active August 29, 2015 13:57
ChampionshipBetViewModel overview
public class ChampionshipBetViewModel : IChampionshipBetViewModel, IDropTarget
{
private readonly IChampionship _championship;
public ChampionshipBetViewModel(IChampionship championship)
{
_championship = championship;
FootballClubs = new ObservableCollection<IFootballClub>(championship.UserBet);
}
public ObservableCollection<IFootballClub> FootballClubs { get; private set; }
@bpatra
bpatra / gist:9518156
Last active August 29, 2015 13:57
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;
@bpatra
bpatra / gist:9533498
Last active August 29, 2015 13:57
Examples of testing of the DragOver part
[TestMethod]
public void DragOver_With_A_Block_Source_Then_Effects_Should_Be_Set()
{
var dropInfo = new Mock<IDropInfo>();
dropInfo.SetupGet(m => m.Data).Returns(new[] { _club1, _club2 });
dropInfo.SetupGet(m => m.InsertIndex).Returns(3);
_championshipBetViewModel.DragOver(dropInfo.Object);
dropInfo.VerifySet(x => x.DropTargetAdorner = It.IsAny<Type>(), Times.Once);
@bpatra
bpatra / gist:9537240
Last active August 29, 2015 13:57
detail of the implementation of the methods DragOver and Drop ChampionshipBetViewModel
public class ChampionshipBetViewModel : IChampionshipBetViewModel, IDropTarget
{
//constructor, fields and command same as previous sample
public ObservableCollection<IFootballClub> FootballClubs { get; private set; }
public void DragOver(IDropInfo dropInfo)
{
var selectedIndices = this.GetItemsBlock(dropInfo.Data).Select(c => FootballClubs.IndexOf(c)).ToList();
//important: InsertIndex is the index of the item right AFTER the position we are inserting into
@bpatra
bpatra / sutTests.js
Created May 27, 2014 16:32
Jasmine implementation of tests for the factorial function of sut.js
/// <reference path="~/../WebApplication1/app/app.js" />
/// <reference path="~/../WebApplication1/app/sut.js" />
/// <reference path="~/lib/jasmine-2.0.0/jasmine.js" />
/// <reference path="~/lib/jasmine-2.0.0/jasmine-html.js" />
describe("sut Tests and factorial function", function () {
it("should return 1 with 0", function () {
expect(app.sut.factorial(0)).toBe(1);
});
@bpatra
bpatra / chutzPahTests.ps1
Created May 28, 2014 13:11
Sample powershell script (V4.0) for executing javascript tests with chutzpah runner.
$chutzpahPath = (Join-Path -Path $PSScriptRoot -ChildPath "Chutzpah.3.2.1\chutzpah.console.exe").ToString()
If(-not (Test-Path($chutzpahPath)))
{
Write-Error "Cannot find chutzpath"
throw
}
$testPath = Join-Path -Path $PSScriptRoot -ChildPath "..\WebApplication1.Tests"