diff --git a/gradebook/test/GradeBook.Tests/TypeTests.cs b/gradebook/test/GradeBook.Tests/TypeTests.cs index a9a406e..be2fd45 100644 --- a/gradebook/test/GradeBook.Tests/TypeTests.cs +++ b/gradebook/test/GradeBook.Tests/TypeTests.cs @@ -6,6 +6,50 @@ namespace GradeBook.Tests using GradeBook; public class TypeTests { + [Fact] + public void CSharpCanPassByReference() + { + var book1 = GetBook("Book1"); + GetBookSetName(ref book1, "New Name"); + + Assert.Equal(book1.Name, "New Name"); + } + + private void GetBookSetName(ref Book book, string name) + { + book = new Book(name); + book.Name = name; + } + + [Fact] + public void CSharpIsPassByValue() + { + var book1 = GetBook("Book1"); + GetBookSetName(book1, "New Name"); + + Assert.Equal(book1.Name, "Book1"); + } + + private void GetBookSetName(Book book, string name) + { + book = new Book(name); + book.Name = name; + } + + [Fact] + public void CanSetNameFromReference() + { + var book1 = GetBook("Book1"); + SetName(book1, "New Name"); + + Assert.Equal(book1.Name, "New Name"); + } + + private void SetName(Book book, string name) + { + book.Name = name; + } + [Fact] public void GetBookReturnsDifferentObjects() { @@ -16,6 +60,7 @@ namespace GradeBook.Tests Assert.Equal("Book2", book2.Name); } + [Fact] public void TwoVarsCanReferenceSameObject() { var book1 = GetBook("Book1");