I'm trying to use Nunit more and I am a complete noob with it. I have written some tests methods and it seems to think there are null references.
Test class
using LibraryBL.Loan;
using LibraryBLMock.Mock;
using LibraryBLModel.Model;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LibraryBLTests
{
[TestFixture]
public class LoanManagementTests
{
[Test]
public void CheckReservedFalse() // Passes if reserved = false
{
LoanManagement LoanManagement = new LoanManagement();
MockPublications MockPublications = new LibraryBLMock.Mock.MockPublications();
List<Publication> l = new List<Publication>();
l = MockPublications.MockListPublications();
}
[Test]
public void InitCheckOutTest() // Passes if reserved = false
{
LoanManagement LoanManagement = new LoanManagement();
LoanManagement.InitCheckOut("0-330-28498-4");
}
}
}
For now I am not using asset method to test any values but for CheckReservedFalse I want to test that my method returns false.
Class methods I want to test
public class LoanManagement
{
#region ReservePublication
public void InitCheckOut(string ISBN)
{
if (!CheckReserved(ISBN))
{
}
}
public bool CheckReserved(string ISBN)
{
List<Publication> p = GetPublicationsByISBN("0-330-28498-4");
if (p.Count == 0)
{
return false;
}
else
{
return true;
}
}
public List<Publication> GetPublicationsByISBN(string ISBN)
{
LibraryBLMock.Mock.MockPublications m = new LibraryBLMock.Mock.MockPublications(); // Use MOCK instead of data layer
return m.MockListPublications()
.Where(i => i.ISBN == ISBN && i.reserved == false).ToList();
}
public void SetPublication(string Status)
{
switch(Status)
{
case "CheckOut":
// DB method to set book as reserved
break;
}
}
#endregion
public void CheckOutPublication()
{
string s = "";
if(CheckReserved("0-330-28498-4"))
{
s = "This publication is not available at this current time";
}
else
{
//s = "There are" + p.Count + " of" + p.FirstOrDefault().Title + " available for loan";
}
}
So I want to know how I test the values that my objects return. Why am I get a null reference when in my code it compiles and I am instantiating those classes.
Apologies if my question is a bit dumb.