Files
monorepo/LCU.Api.Internal.CoreApiWrapper/LCU.Api.Internal.CoreApiWrapperTest/Service/PropertyUserFieldServiceTest.cs
T
2026-03-31 14:32:23 -05:00

158 lines
6.2 KiB
C#

using LCU.Api.Internal.CoreApiWrapper.Services;
using LCU.Library.Internal.CoreApiWrapperLib.DataAccess;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreRequests;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreResponses;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Persons;
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Properties;
using LCU.Library.Internal.Exceptions;
using Moq;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LCU.Api.Internal.CoreApiWrapperTest.Service
{
public class PropertyUserFieldServiceTest
{
private readonly PropertyUserFieldService _propertyUserFieldService;
private readonly Mock<IPropertyService> _mockPropertyService;
private readonly Mock<IPropertyUserFieldDao> _mockPropertyUserFieldDao;
public PropertyUserFieldServiceTest()
{
_mockPropertyService = new Mock<IPropertyService>();
_mockPropertyUserFieldDao = new Mock<IPropertyUserFieldDao>();
_propertyUserFieldService = new PropertyUserFieldService(_mockPropertyService.Object, _mockPropertyUserFieldDao.Object);
}
[Test]
public void GetPropertyUserFieldCoreApiResponseAsync_ExceptionThrown()
{
_mockPropertyUserFieldDao.Setup(x => x.FindPropertyUserFieldCoreApiResponseByPersonId(It.IsAny<CoreRequestParameters>(), It.IsAny<int>())).Throws(new ServiceException("Nope"));
Assert.ThrowsAsync<ServiceException>(async () =>
await _propertyUserFieldService.GetPropertyUserFieldsAsync(0));
}
[Test]
public void UpdatePropertyUserFieldAsync_ExceptionThrown()
{
_mockPropertyUserFieldDao.Setup(x => x.UpdatePropertyUserField(It.IsAny<UserFieldRequest>())).Throws(new ServiceException("Unit Test Failed"));
var propertyUserUpdateRequest = new PropertyUserField()
{
PropertyNumber = 100001,
UserFieldCode = "TEST1",
Value = "Y"
};
Assert.ThrowsAsync<ServiceException>(async () =>
await _propertyUserFieldService.UpdatePropertyUserFieldAsync(propertyUserUpdateRequest));
}
[Test]
public async Task UpdatePropertyUserFieldAsync_Ok()
{
var testProperty = new Property()
{
PropertyNumber = 1000
};
var updatedPropertyUserField = new PropertyUserField()
{
PropertyNumber = 1000L,
UserFieldCode = "TEST1",
Value = "Y",
LastMaintained = Convert.ToDateTime("9/1/2001")
};
var listExistingPropertyUserField = new List<PropertyUserField>()
{
new PropertyUserField()
{
PropertyNumber = 1000L,
Id = updatedPropertyUserField.Id,
UserFieldCode = "TEST1",
Value = "N",
LastMaintained = Convert.ToDateTime("8/1/2001")
}
};
var coreMessageheader = new CoreMessageHeader();
var coreApiResponse = new CoreApiMessage<IEnumerable<PropertyUserField>>(coreMessageheader, listExistingPropertyUserField);
BasicResponse response = new BasicResponse()
{
Success = true
};
_mockPropertyUserFieldDao.Setup(x => x.FindPropertyUserFieldCoreApiResponseByPersonId(It.IsAny<CoreRequestParameters>(), It.IsAny<int>())).ReturnsAsync(coreApiResponse);
_mockPropertyUserFieldDao.Setup(x => x.UpdatePropertyUserField(It.IsAny<UserFieldRequest>())).ReturnsAsync(response);
_mockPropertyService.Setup(x => x.GetProperty(It.IsAny<int>())).ReturnsAsync(testProperty);
var propertyUserUpdateRequest = new PropertyUserField()
{
PropertyNumber = 1000L,
UserFieldCode = "TEST1",
Value = "Y"
};
var result = await _propertyUserFieldService.UpdatePropertyUserFieldAsync(propertyUserUpdateRequest);
Assert.NotNull(result);
Assert.AreEqual(response.Success, result.Success);
}
[Test]
public void InsertPersonUserFieldAsync_ExceptionThrown()
{
_mockPropertyUserFieldDao.Setup(x => x.InsertPropertyUserField(It.IsAny<UserFieldRequest>())).Throws(new ServiceException("Oops"));
var propertyUserUpdateRequest = new PropertyUserField()
{
PropertyNumber = 1000,
UserFieldCode = "TEST1",
Value = "Y"
};
Assert.ThrowsAsync<ServiceException>(async () =>
await _propertyUserFieldService.InsertPropertyUserFieldAsync(propertyUserUpdateRequest));
}
[Test]
public async Task InsertPropertyUserFieldAsync_InsertUserFieldsReturned()
{
var property = new Property()
{
PropertyNumber = 1000
};
_mockPropertyService.Setup(x => x.GetProperty(1000)).ReturnsAsync(property);
var createdPropertyUserField = new PropertyUserField()
{
PropertyNumber = 1000L,
UserFieldCode = "TEST1",
Value = "Y",
LastMaintained = Convert.ToDateTime("9/1/2001")
};
BasicResponse response = new BasicResponse()
{
Success = true,
};
_mockPropertyUserFieldDao.Setup(x => x.InsertPropertyUserField(It.IsAny<UserFieldRequest>())).ReturnsAsync(response);
var personUserUpdateRequest = new PropertyUserField()
{
PropertyNumber = 1000,
UserFieldCode = "TEST1",
Value = "Y"
};
var result = await _propertyUserFieldService.InsertPropertyUserFieldAsync(personUserUpdateRequest);
Assert.NotNull(result);
Assert.AreEqual(response.Success, result.Success);
}
}
}