C
C#6mo ago
FR

Unit Testing | Unsupported expression: ht => ht.LoadAll<ReasonType>()Non-overridable members

anyone know how to fix this error? here a function i tried to test
c++
public List<ReasonType> GetAll()
{
return new List<ReasonType>(_hibernate.LoadAll<ReasonType>());
}
c++
public List<ReasonType> GetAll()
{
return new List<ReasonType>(_hibernate.LoadAll<ReasonType>());
}
and here is my test function
c++
[Test]
public void GetAll_ReasonType()
{
// Arrange
var ReasonTypeList = new List<ReasonType>
{
new ReasonType()
{
TypeId = "TestOne",
Description = "Testing Reason 1"
},
new ReasonType()
{
TypeId = "TestTwo",
Description = "Testing Reason 2"
}
};

var sessionFactoryMock = new Mock<ISessionFactory>();
var sessionMock = new Mock<ISession>();
var hibernateTemplateMock = new Mock<HibernateTemplate>(sessionFactoryMock.Object);
hibernateTemplateMock.Setup(ht => ht.LoadAll<ReasonType>()).Returns(ReasonTypeList);

var ReasonTypePersistenceHibernate = new ReasonTypePersistenceHibernate(hibernateTemplateMock.Object);

// Act
var result = ReasonTypePersistenceHibernate.GetAll();

// Assert
Assert.IsNotNull(result);
Assert.AreEqual(ReasonTypeList.Count, result.Count);
Assert.AreEqual(ReasonTypeList[0].TypeId, result[0].TypeId);
Assert.AreEqual(ReasonTypeList[1].TypeId, result[1].TypeId);

// Verify that LoadAll was called exactly once
hibernateTemplateMock.Verify(ht => ht.LoadAll<ReasonType>(), Times.Once);
}
c++
[Test]
public void GetAll_ReasonType()
{
// Arrange
var ReasonTypeList = new List<ReasonType>
{
new ReasonType()
{
TypeId = "TestOne",
Description = "Testing Reason 1"
},
new ReasonType()
{
TypeId = "TestTwo",
Description = "Testing Reason 2"
}
};

var sessionFactoryMock = new Mock<ISessionFactory>();
var sessionMock = new Mock<ISession>();
var hibernateTemplateMock = new Mock<HibernateTemplate>(sessionFactoryMock.Object);
hibernateTemplateMock.Setup(ht => ht.LoadAll<ReasonType>()).Returns(ReasonTypeList);

var ReasonTypePersistenceHibernate = new ReasonTypePersistenceHibernate(hibernateTemplateMock.Object);

// Act
var result = ReasonTypePersistenceHibernate.GetAll();

// Assert
Assert.IsNotNull(result);
Assert.AreEqual(ReasonTypeList.Count, result.Count);
Assert.AreEqual(ReasonTypeList[0].TypeId, result[0].TypeId);
Assert.AreEqual(ReasonTypeList[1].TypeId, result[1].TypeId);

// Verify that LoadAll was called exactly once
hibernateTemplateMock.Verify(ht => ht.LoadAll<ReasonType>(), Times.Once);
}
ty
No description
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server