Skip to content

Instantly share code, notes, and snippets.

@bpatra
bpatra / gist:9518403
Last active December 5, 2020 19:00
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
//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: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 / sut.js
Last active December 8, 2020 20:15
app.sut module with the factorial function
/// <reference path="./app.js" />
app.namespace("app.sut");
app.sut = (function () {
"use strict";
var sut = {};
var factorial = function (n) {
if (n <= 1) return 1;
@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"
@bpatra
bpatra / AssemblyInfo.cs
Last active August 29, 2015 14:03
A sample assembly info file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("armenAnalytics")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("armenAnalytics")]
[assembly: AssemblyCopyright("Copyright © 2014")]
@bpatra
bpatra / PatchAssemblyInfo.ps1
Last active August 29, 2015 14:03
the detail of the PatchAssemblyInfo task
Task PatchAssemblyInfo{
function GetAssemblyVersion {
#skip the details for now -> returns the version major.minor (e.g. "6.7")
}
function GetAssemblyFileVersion {
#skip the details for now -> returns the long version major.minor.build (e.g. "6.7.35698")
}
function PatchFile ([string] $pattern, [string] $replaceString, [string] $fullPath){
@bpatra
bpatra / bootstrap.ps1
Last active August 29, 2015 14:03
This script loads all file and defines the high level targets
#load all targets
Get-ChildItem (Join-Path $PSScriptRoot -ChildPath "./targets") | ForEach-Object{ & $_.FullName }
Task Example -Depends PatchAssemblyInfo, RenameMSI {
Write-Host "Example target executed"
}
@bpatra
bpatra / functionPatchAssemblyInfo.ps1
Created July 8, 2014 21:02
Details of the functions used in the PatchAssemblyInfo PSake task
function GetRevisionNumber {
$major = "1"
$minor = "0"
#we use the environment variable BUILD_NUMBER provided by teamcity, use -1 is not found to test locally the process
$patch= if ([string]::IsNullOrEmpty($env:BUILD_NUMBER)) { "-1" } else { $env:BUILD_NUMBER }
$major + "." + $minor + "." + $patch
}
function PatchFile ([string] $pattern, [string] $replaceString, [string] $fullPath){