Skip to content

Instantly share code, notes, and snippets.

[Test]
public void IntroduceMethodShouldWorkCorrectly()
{
var sut = new Employee("Alice", "Programmer", 100000);
var expected = "Hi! My name is Alice and I work as a Programmer.";
string result = sut.Introduce();
Assert.AreEqual(expected, result);
}
[Test]
public void IntroduceMethodShouldWorkCorrectly()
{
// arrange
var sut = new Employee("Alice", "Programmer", 100000);
var expected = "Hi! My name is Alice and I work as a Programmer.";
// act
string result = sut.Introduce();
[Test]
public void GiveNegativeRaiseShouldHaveNoEffectOnSalary()
{
// arrange
var raise = -10;
var salary = 100;
var sut = new Employee("Bob", "Tester", salary);
// act
sut.GiveRaise(raise);
@carlosschults
carlosschults / csharp8-1.cs
Created December 21, 2017 01:31
c#8features-1
public static class IntExtensions
{
public static bool Even(this int value)
{
return value % 2 == 0;
}
}
@carlosschults
carlosschults / csharp8-2.cs
Created December 21, 2017 01:32
csharp8-2.cs
public extension IntExtension extends int
{
public bool Even => this % 2 == 0;
}
@carlosschults
carlosschults / csharp8-3.cs
Created December 21, 2017 01:33
csharp8-3.cs
int x = int.Parse(Console.Readline());
if (x.Even)
{
Console.WriteLine("You’ve typed an even number.");
}
@carlosschults
carlosschults / csharp8-interface.cs
Created December 21, 2017 01:33
csharp8-interface.cs
interface IDisplayService
{
void DisplayMessage(string message) { WriteLine(message); }
}
@carlosschults
carlosschults / csharp8-nonnull.cs
Created December 21, 2017 01:34
csharp8-nonnull.cs
public int CalculateSquareOfAge(Person p)
{
int age = p.Age;
return age * age;
}
@carlosschults
carlosschults / csharp8-null.cs
Created December 21, 2017 01:35
csharp8-null.cs
public int CalculateSquareOfAge(Person? p)
{
int age = p.Age;
return age * age;
}
@carlosschults
carlosschults / csharp8-null-treatment.cs
Last active December 21, 2017 01:36
csharp8-null-treatment.cs
public int CalculateSquareOfAge(Person? p)
{
var result = 0;
if (p != null)
result = p.Age * p.Age;
return result;
}