Snippet set

Untidy, but let’s just get a few in one place:

<?xml version=”1.0″ encoding=”utf-8″?>
<CodeSnippets xmlns=”http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet”&gt;
<CodeSnippet Format=”1.0.0″>
<Header>
<Title>Email</Title>
<Author>Dennis</Author>
<Description>Email</Description>
<HelpUrl />
<SnippetTypes />
<Keywords />
<Shortcut>MyEmail</Shortcut>
</Header>
<Snippet>
<References />
<Imports />
<Declarations />
<Code Language=”csharp” Kind=”” Delimiter=”$”><![CDATA[namespace FootballClub.Model {
public class Email {

public string EmailAddress { get; set; }
}
}
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>


<?xml version=”1.0″ encoding=”utf-8″?>
<CodeSnippets xmlns=”http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet”&gt;
<CodeSnippet Format=”1.0.0″>
<Header>
<Title>Address</Title>
<Author>Dennis</Author>
<Description>Address</Description>
<HelpUrl />
<SnippetTypes />
<Keywords />
<Shortcut>MyAddress</Shortcut>
</Header>
<Snippet>
<References />
<Imports />
<Declarations />
<Code Language=”csharp” Kind=”” Delimiter=”$”><![CDATA[namespace FootballClub.Model {
public class Address {

public string FirstLine { get; set; }
public string City { get; set; }
public string County { get; set; }
public string Country { get; set; }
public string PostCode { get; set; }
}
}]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>


<?xml version=”1.0″ encoding=”utf-8″?>
<CodeSnippets xmlns=”http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet”&gt;
<CodeSnippet Format=”1.0.0″>
<Header>
<Title>Club</Title>
<Author>Dennis</Author>
<Description>Club</Description>
<HelpUrl />
<SnippetTypes />
<Keywords />
<Shortcut>MyClub</Shortcut>
</Header>
<Snippet>
<References />
<Imports />
<Declarations />
<Code Language=”csharp” Kind=”” Delimiter=”$”><![CDATA[using System;
using System.Collections.Generic;

namespace FootballClub.Model {
public class Club {

public int Id { get; set; }
public string Name { get; set; }
public DateTime DateOfIncorporation { get; set; }
public Address Address { get; set; }
public List<Email> Emails { get; set; }
}
}]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>


<?xml version=”1.0″ encoding=”utf-8″?>
<CodeSnippets xmlns=”http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet”&gt;
<CodeSnippet Format=”1.0.0″>
<Header>
<Title>BasicTests</Title>
<Author>Dennis</Author>
<Description>BasicTests</Description>
<HelpUrl />
<SnippetTypes />
<Keywords />
<Shortcut>MyTestsBasic</Shortcut>
</Header>
<Snippet>
<References />
<Imports />
<Declarations />
<Code Language=”csharp” Kind=”” Delimiter=”$”><![CDATA[using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FootballClub.Tests {
[TestClass]
public class CoreClubTests {

Model.Club _club = new Model.Club {
Id = 101,
Name = “Tottenham”,
Address = new Model.Address { FirstLine = “99 White Hart Lane” },
DateOfIncorporation = new DateTime(1899, 5, 6)
};

[TestMethod]
public void ModelPropertiesAreUpdatedViaModelFacade() {
var modelFacade = new ClubFacade(_club);
modelFacade.Name = “Arsenal”;
Assert.AreEqual(“Arsenal”, _club.Name);

}

[TestMethod]
public void ModelPropertiesAreGotViaModelFacade() {
var modelFacade = new ClubFacade(_club);
Assert.AreEqual(_club.Id, modelFacade.Id);
}

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ModelFacadeDoesNotAcceptNullClubModel() {
try {
var modelFacade = new ClubFacade(null);
} catch(ArgumentNullException ex) {
if (ex.ParamName != “Model is null: not allowed”) {
Assert.Fail(“Expected exception message not found. Found: ” + ex.ParamName);
}
throw ex;
}
}
}
}
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>


<?xml version=”1.0″ encoding=”utf-8″?>
<CodeSnippets xmlns=”http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet”&gt;
<CodeSnippet Format=”1.0.0″>
<Header>
<Title>ClubFacade</Title>
<Author>Dennis</Author>
<Description>ClubFacade</Description>
<HelpUrl />
<SnippetTypes />
<Keywords />
<Shortcut>MyClubFacade</Shortcut>
</Header>
<Snippet>
<References />
<Imports />
<Declarations />
<Code Language=”csharp” Kind=”” Delimiter=”$”><![CDATA[namespace FootballClub.Tests {
public class ClubFacade : Facade.Observer<Model.Club> {
public ClubFacade(Model.Club Club) : base(Club) {}

public int Id {
get { return GetValue<int>(); }
set { SetValue(value);}
}

public string Name {
get { return GetValue<string>(); }
set { SetValue(value);}
}
}
}]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>


<?xml version=”1.0″ encoding=”utf-8″?>
<CodeSnippets xmlns=”http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet”&gt;
<CodeSnippet Format=”1.0.0″>
<Header>
<Title>Observer</Title>
<Author>Dennis</Author>
<Description>Observer</Description>
<HelpUrl />
<SnippetTypes />
<Keywords />
<Shortcut>MyObserver</Shortcut>
</Header>
<Snippet>
<References />
<Imports />
<Declarations />
<Code Language=”VB” Kind=”” Delimiter=”$”><![CDATA[using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace FootballClub.Facade {
public class Observer<TModel> : INotifyPropertyChanged {

protected readonly TModel _model;
public Observer(TModel Model) {
if (Model == null) {
throw new ArgumentNullException(“Model is null: not allowed”);
}
_model = Model;
}

protected void OnPropertyChanged([CallerMemberName] string caller = null) {
var x = PropertyChanged;
if (x != null) {
x(this, new PropertyChangedEventArgs(caller));
}
}

public event PropertyChangedEventHandler PropertyChanged;

protected void SetValue<TValue>(TValue value, [CallerMemberName] string propertyName = null) {
var propertyInfo = _model.GetType().GetProperty(propertyName);
var currentValue = propertyInfo.GetValue(_model);
if (!Equals(currentValue, value)) {
propertyInfo.SetValue(_model, value);
OnPropertyChanged(propertyName);
}
}

protected TValue GetValue<TValue>([CallerMemberName] string propertyName = null) {
var propertyInfo = _model.GetType().GetProperty(propertyName);
return (TValue)propertyInfo.GetValue(_model);
}
}
}]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>


<?xml version=”1.0″ encoding=”utf-8″?>
<CodeSnippets xmlns=”http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet”&gt;
<CodeSnippet Format=”1.0.0″>
<Header>
<Title>INPC tests</Title>
<Author>Dennis</Author>
<Description>INPC tests</Description>
<HelpUrl />
<SnippetTypes />
<Keywords />
<Shortcut>MyTestInpc</Shortcut>
</Header>
<Snippet>
<References />
<Imports />
<Declarations />
<Code Language=”VB” Kind=”” Delimiter=”$”><![CDATA[using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FootballClub.Tests {
[TestClass]
public class CoreClubTests {

Model.Club _club = new Model.Club {
Id = 101,
Name = “Tottenham”,
Address = new Model.Address { FirstLine = “99 White Hart Lane” },
DateOfIncorporation = new DateTime(1899, 5, 6)
};

[TestMethod]
public void ModelPropertiesAreUpdatedViaModelFacade() {
var modelFacade = new ClubFacade(_club);
modelFacade.Name = “Arsenal”;
Assert.AreEqual(“Arsenal”, _club.Name);

}

[TestMethod]
public void ModelPropertiesAreGotViaModelFacade() {
var modelFacade = new ClubFacade(_club);
Assert.AreEqual(_club.Id, modelFacade.Id);
}

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ModelFacadeDoesNotAcceptNullClubModel() {
try {
var modelFacade = new ClubFacade(null);
} catch(ArgumentNullException ex) {
if (ex.ParamName != “Model is null: not allowed”) {
Assert.Fail(“Expected exception message not found. Found: ” + ex.ParamName);
}
throw ex;
}
}
}
}]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s