using LCU.Api.Internal.CoreApiWrapper.Controllers; using LCU.Api.Internal.CoreApiWrapper.Services; using LCU.Library.Internal.CoreApiWrapperModel.CoreModels; using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreResponses; using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Persons; using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Properties; using Microsoft.AspNetCore.Mvc; 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.Controllers { public class PropertyUserFieldControllerTest { private PropertyUserFieldController _propertyUserFieldController; private Mock _mockPropertyUserFieldService; [SetUp] public void SetUp() { _mockPropertyUserFieldService = new Mock(); _propertyUserFieldController = new PropertyUserFieldController(_mockPropertyUserFieldService.Object); } [Test] public async Task GetPropertyUserField_ExceptionAsync() { _mockPropertyUserFieldService.Setup(x => x.GetPropertyUserFieldsAsync(1000)).Throws(new Exception("Unit Test Failed")); var propertyUserField = new PropertyUserField() { Id = "TEST", PropertyNumber = 1000, UserFieldCode = "TEST", Value = "TEST" }; var results = await _propertyUserFieldController.GetPropertyUserField(1000); Assert.NotNull(results); var badResult = results as ObjectResult; Assert.NotNull(badResult); Assert.AreEqual(500, badResult.StatusCode); } [Test] public async Task PostPropertyUserField_OkAsync() { var propertyUserField = new PropertyUserField() { Id = "TEST", PropertyNumber = 1000, UserFieldCode = "TEST", Value = "TEST" }; BasicResponse basicResponse = new BasicResponse() { Success = true, }; _mockPropertyUserFieldService.Setup(x => x.InsertPropertyUserFieldAsync(It.IsAny())).ReturnsAsync(basicResponse); var results = await _propertyUserFieldController.PostPropertyUserField(propertyUserField); Assert.NotNull(results); var okResult = results as OkObjectResult; Assert.NotNull(okResult); Assert.AreEqual(200, okResult.StatusCode); } [Test] public async Task PostPropertyUserField_ExceptionAsync() { _mockPropertyUserFieldService.Setup(x => x.InsertPropertyUserFieldAsync(It.IsAny())).Throws(new Exception("Unit Test Failed")); var propertyUserField = new PropertyUserField() { Id = "TEST", PropertyNumber = 1000, UserFieldCode = "TEST", Value = "TEST" }; var results = await _propertyUserFieldController.PostPropertyUserField(propertyUserField); Assert.NotNull(results); var badResult = results as ObjectResult; Assert.NotNull(badResult); Assert.AreEqual(500, badResult.StatusCode); } [Test] public async Task PutPropertyUserField_OkAsync() { var propertyUserField = new PropertyUserField() { Id = "TEST", PropertyNumber = 1000, UserFieldCode = "TEST", Value = "TEST" }; BasicResponse basicResponse = new BasicResponse() { Success = true, }; _mockPropertyUserFieldService.Setup(x => x.UpdatePropertyUserFieldAsync(It.IsAny())).ReturnsAsync(basicResponse); var results = await _propertyUserFieldController.PutPropertyUserField(propertyUserField); Assert.NotNull(results); var okResult = results as OkObjectResult; Assert.NotNull(okResult); Assert.AreEqual(200, okResult.StatusCode); } [Test] public async Task PutPropertyUserField_ExceptionAsync() { _mockPropertyUserFieldService.Setup(x => x.UpdatePropertyUserFieldAsync(It.IsAny())).Throws(new Exception("Unit Test Failed")); var propertyUserField = new PropertyUserField() { Id = "TEST", PropertyNumber = 1000, UserFieldCode = "TEST", Value = "TEST" }; var results = await _propertyUserFieldController.PutPropertyUserField(propertyUserField); Assert.NotNull(results); var badResult = results as ObjectResult; Assert.NotNull(badResult); Assert.AreEqual(500, badResult.StatusCode); } } }