Below is my unit test project. I have created a unit test which will test two object's equality. Object is passed by reference to the method GetbookSetName
. GetbookSetName
is responsible for creating a new book object as well as assign new name to book.
using Programme;
using Xunit;
using System;
namespace XUnitTestProject1
{
public class BookTests
{
[Fact]
public void CsharpIsPassbyref()
{
// Get book will return new book object and assigned to book1
var book1 = GetBook("book1");
//getbookSetName method accepts book object as reference parameter and book name.
GetbookSetName(ref book1, "New Book");
}
private void GetbookSetName(ref Book book, string name)
{
book = new Book(name);
var book1 = new Book(name);
Assert.Equal(book, book1);
}
Book GetBook(string name)
{
return new Book(name);
}
}
}
Below is the book class. It has a constructor which initializes the book with it's name.
public class Book
{
public string Name;
public Book(string name)
{
Name = name;
}
}
Error:
Assert.Equal() Failure
Expected: Book { Name = "New Book" }
Actual: Book { Name = "New Book" }Stack Trace:
BookTests.GetbookSetName(Book& book, String name) line 55
BookTests.CsharpIsPassbyref() line 47