Skip to content

Instantly share code, notes, and snippets.

Benoît Patra bpatra

Block or report user

Report or block bpatra

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bpatra
bpatra / gist:9401745
Last active Aug 29, 2015
IFootballClub interface
View gist:9401745
public interface IFootballClub
{
string FullName { get; }
string NickName { get; }
int CreationYear { get; }
}
@bpatra
bpatra / gist:9401776
Last active Aug 29, 2015
IChampionship interface
View gist:9401776
public interface IChampionship
{
List<IFootballClub> CurrentChampionShipRanking { get; }
List<IFootballClub> UserBet { get; set; }
int GetGoodBetCount();
}
@bpatra
bpatra / gist:9518403
Last active Aug 29, 2015
second example of unit test: when the source is the block containing the two last rows and the target is the second one then the order should not be changed
View gist:9518403
//same class as before constructor and fields remain the same
[TestMethod]
public void When_Source_Is_Block_LastTwoRows_And_Target_The_Second_Row_Then_Drop_ShouldNot_Modify_Order()
{
var dropInfo = new Mock<IDropInfo>();
dropInfo.SetupGet(m => m.Data).Returns(new[] { _club3, _club4 });
dropInfo.SetupGet(m => m.InsertIndex).Returns(2);
_championshipBetViewModel.Drop(dropInfo.Object);
@bpatra
bpatra / gist:9518156
Last active Aug 29, 2015
First example of unit test when inserting the first row after the second one
View gist:9518156
[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:9516759
Last active Aug 29, 2015
ChampionshipBetView
View gist:9516759
<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:9516512
Last active Aug 29, 2015
IChampionshipBetViewModel
View gist:9516512
public interface IChampionshipBetViewModel : IDropTarget
{
ObservableCollection<IFootballClub> FootballClubs { get; }
ICommand ClickSave { get; }
}
@bpatra
bpatra / gist:9517801
Last active Aug 29, 2015
ChampionshipBetViewModel overview
View gist:9517801
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:9533498
Last active Aug 29, 2015
Examples of testing of the DragOver part
View gist:9533498
[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 Aug 29, 2015
detail of the implementation of the methods DragOver and Drop ChampionshipBetViewModel
View gist:9537240
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 / app.sut no exception
Created May 27, 2014
app.sut module with the factorial function
View app.sut no exception
/// <reference path="./app.js" />
app.namespace("app.sut");
app.sut = (function () {
"use strict";
var sut = {};
var factorial = function (n) {
if (n <= 1) return 1;
You can’t perform that action at this time.