Skip to content

Instantly share code, notes, and snippets.

@Deneas
Last active June 6, 2021 14:35
Show Gist options
  • Select an option

  • Save Deneas/b79b1d8ae58a62070feb77cf64a72664 to your computer and use it in GitHub Desktop.

Select an option

Save Deneas/b79b1d8ae58a62070feb77cf64a72664 to your computer and use it in GitHub Desktop.
Student Validation Example
// Licensed under the MIT License
public class StudentValidationTest
{
[Fact]
public void IsAdultAndHasPaid_IsValid()
{
var student = new Student(18, true);
var isValid = StudentValidator.IsValid(student);
Assert.True(isValid);
}
[Fact]
public void IsUnderageAndHasNotPaid_IsNotValid()
{
var student = new Student(12, false);
var isValid = StudentValidator.IsValid(student);
Assert.False(isValid);
}
[Fact]
public void IsAdultAndHasNotPaid_IsNotValid()
{
var student = new Student(18, false);
var isValid = StudentValidator.IsValid(student);
Assert.False(isValid);
}
}
// Licensed under the MIT License
public class StudentValidationTest
{
[Fact]
public void IsAdultAndHasPaid_IsValid()
{
var student = new Student(18, true);
var isValid = StudentValidator.IsValid(student);
Assert.True(isValid);
}
[Fact]
public void IsUnderageAndHasNotPaid_IsNotValid()
{
var student = new Student(12, false);
var isValid = StudentValidator.IsValid(student);
Assert.False(isValid);
}
}
// Licensed under the MIT License
public class StudentValidator
{
public static bool IsValid(Student student)
{
return student.Age >= 18 && student.HasPaid;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment