Skip to content

Instantly share code, notes, and snippets.

@ferclaverino
ferclaverino / form.cs
Created July 12, 2012 22:22
Single responsability example, step 1
private void btnLoad_Click(object sender, EventArgs e)
{
listView1.Items.Clear();
var fileName = txtFileName.Text;
using (var fs = new FileStream(fileName, FileMode.Open))
{
var reader = XmlReader.Create(fs);
while (reader.Read())
{
if (reader.Name != "product") continue;
@ferclaverino
ferclaverino / ProductRepository.cs
Created July 12, 2012 22:40
Single responsability example, step 2
class ProductRepository : IProductRepository
{
public IEnumerable<Product> GetByFileName(string fileName)
{
var products = new List<Product>();
using (var fs = new FileStream(fileName, FileMode.Open))
{
var reader = XmlReader.Create(fs);
while (reader.Read())
{
@ferclaverino
ferclaverino / FileLoader.cs
Created July 12, 2012 22:46
Single responsability example, step 3
class FileLoader : IFileLoader
{
public Stream Load(string fileName)
{
return new FileStream(fileName, FileMode.Open);
}
}
@ferclaverino
ferclaverino / ProductRepository.cs
Created July 12, 2012 22:52
Single responsability example, step 4
class ProductRepository : IProductRepository
{
private readonly IFileLoader loader;
private readonly IProductsMapper mapper;
public ProductRepository()
{
loader = new FileLoader();
mapper = new ProductsMapper();
}
@ferclaverino
ferclaverino / FilterTest.cs
Created July 17, 2012 01:32
Open closed example, step 1
[TestFixture]
class FilterTest
{
[Test]
public void filterByBlue_return_2()
{
// arrange
ProductFilter filter = new ProductFilter();
IList<Product> products = BuildProducts();
@ferclaverino
ferclaverino / FilterTest.cs
Created July 17, 2012 01:41
Open closed example, step 2
[TestFixture]
class FilterTest
{
[Test]
public void filterByBlue_return_2()
{
// arrange
ProductFilter filter = new ProductFilter();
IList<Product> products = BuildProducts();
@ferclaverino
ferclaverino / gist:3184523
Created July 26, 2012 21:08
ready() step 1
ready: function (element, options) {
backColor = options.item.BackColor;
var detailHeader = element.querySelector('#detailHeader');
detailHeader.style.msGridColumns = '80px 1fr 325px;'; //'1fr 300px';
detailHeader.style.backgroundColor = backColor;
backButton.className = "win-backbutton backbutton";
var zoomIn = document.querySelector("#zoomIn");
@ferclaverino
ferclaverino / gist:3184544
Created July 26, 2012 21:12
ready() step 2
ready: function (element, options) {
currentSection = options.item;
setHeader(element, currentSection.BackColor);
setAppbarButton(currentSection);
this.updateLayout(element, Windows.UI.ViewManagement.ApplicationView.value);
buildNews(feedToShow);
},
@ferclaverino
ferclaverino / gist:3184637
Created July 26, 2012 21:26
query object
(function () {
"use strict";
var feedNewsMapper;
// constructor function
function init() {
feedNewsMapper = new Mappers.FeedNewsMapper;
}
@ferclaverino
ferclaverino / gist:3252058
Created August 3, 2012 22:13
Pin to a secondary tile
(function () {
"use strict";
function pinByElementAsync(element, newTileID, newTileShortName, newTileDisplayName, tileActivationArguments) {
// Sometimes it's convenient to create our tile and pin it, all in a single asynchronous call.
// We're pinning a secondary tile, so let's build up the tile just like we did in pinByElement
var uriLogo = new Windows.Foundation.Uri("ms-appx:///images/30x30.png");
//var uriSmallLogo = new Windows.Foundation.Uri("ms-appx:///images/pin/smallLogoSecondaryTile-sdk.png");