Finished Passing Parameters by Reference

jason.zhu 2021-02-19 00:30:31 +00:00
parent 48b6f32021
commit 6442df3678
1 changed files with 45 additions and 0 deletions

View File

@ -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");