Adding
This commit is contained in:
+37
@@ -0,0 +1,37 @@
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.API.Collections.RepoApi.Services.Producer;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class AccountAlertCheckServiceTest
|
||||
{
|
||||
private readonly IAccountAlertCheckService _accountAlertCheckService;
|
||||
private readonly Mock<IEventAlertService> _mockEventAlertService;
|
||||
|
||||
public AccountAlertCheckServiceTest()
|
||||
{
|
||||
_mockEventAlertService = new Mock<IEventAlertService>();
|
||||
_accountAlertCheckService = new AccountAlertCheckService(_mockEventAlertService.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ListAll_Ok()
|
||||
{
|
||||
var testAlert = new EventAlert()
|
||||
{
|
||||
Message = "testing",
|
||||
AccountNo = "123456-789"
|
||||
};
|
||||
_mockEventAlertService.Setup(x => x.SaveAsync(It.IsAny<EventAlert>())).ReturnsAsync(testAlert);
|
||||
|
||||
var manualAlert = await _accountAlertCheckService.ManualAlert(testAlert);
|
||||
Assert.NotNull(manualAlert);
|
||||
_mockEventAlertService.VerifyAll();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+765
@@ -0,0 +1,765 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using LCU.API.Collections.RepoApi.Models.Requests;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.Shared.Collections.RepoApiLib.Exceptions;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
||||
using LCU.Shared.Collections.RepoApiLib.WebServices.AutoIMS;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using AuctionAssignment = LCU.Shared.Collections.RepoApiLib.Models.AuctionAssignment;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class AuctionAssignmentServiceTest
|
||||
{
|
||||
private readonly Mock<IUnitOfWork> mockUnitOfWork;
|
||||
private readonly Mock<IAuctionAssignmentRepository> mockAuctionAssignmentRepository;
|
||||
private readonly Mock<IAutoImsWebService> mockAutoImsWebService;
|
||||
private readonly Mock<IRepoAccountService> mockRepoAccountService;
|
||||
private readonly Mock<IEmailer> mockEmailer;
|
||||
|
||||
private readonly AuctionAssignmentService service;
|
||||
|
||||
public AuctionAssignmentServiceTest()
|
||||
{
|
||||
mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
mockAutoImsWebService = new Mock<IAutoImsWebService>();
|
||||
mockAuctionAssignmentRepository = new Mock<IAuctionAssignmentRepository>();
|
||||
mockRepoAccountService = new Mock<IRepoAccountService>();
|
||||
mockEmailer = new Mock<IEmailer>();
|
||||
service = new AuctionAssignmentService(
|
||||
mockAutoImsWebService.Object,
|
||||
mockRepoAccountService.Object,
|
||||
mockAuctionAssignmentRepository.Object,
|
||||
mockUnitOfWork.Object,
|
||||
mockEmailer.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Post_Success()
|
||||
{
|
||||
mockAuctionAssignmentRepository.Setup(repository => repository.AddAsync(It.IsAny<AuctionAssignment>()))
|
||||
.ReturnsAsync(new AuctionAssignment()
|
||||
{
|
||||
ID = 1914,
|
||||
AuctionId = "MMAA",
|
||||
AuctionCustomerNo = "1234-56"
|
||||
});
|
||||
mockRepoAccountService.Setup(service => service.Get(It.IsAny<int>())).ReturnsAsync(new RepoAccount()
|
||||
{
|
||||
Borrowers = new List<Borrower>
|
||||
{
|
||||
new Borrower()
|
||||
{
|
||||
OwnershipType = 6
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var auctionAssignmentResponse = await service.SaveAsync(new AuctionAssignmentPostRequest()
|
||||
{
|
||||
AuctionAssignment = new AuctionAssignment()
|
||||
{
|
||||
RepoId = 1234
|
||||
},
|
||||
Collaterals = new List<Collateral>
|
||||
{
|
||||
new Collateral { CollateralId = 1 },
|
||||
new Collateral()
|
||||
},
|
||||
VehicleLocation = new VehicleLocation(),
|
||||
PrimaryCollateralId = 1,
|
||||
});
|
||||
|
||||
Assert.NotNull(auctionAssignmentResponse);
|
||||
Assert.NotNull(auctionAssignmentResponse.AuctionAssignment);
|
||||
Assert.NotNull(auctionAssignmentResponse.Collaterals);
|
||||
Assert.NotNull(auctionAssignmentResponse.VehicleLocation);
|
||||
|
||||
Assert.Equal(1914, auctionAssignmentResponse.AuctionAssignment.ID);
|
||||
Assert.Equal("MMAA", auctionAssignmentResponse.AuctionAssignment.AuctionId);
|
||||
Assert.Equal("1234-56", auctionAssignmentResponse.AuctionAssignment.AuctionCustomerNo);
|
||||
|
||||
Assert.Equal(2, auctionAssignmentResponse.Collaterals.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Post_Duplicate_Resource_Error()
|
||||
{
|
||||
// FindByAuctionCustomerNoAndVin() should NOT affect duplicate detection errors
|
||||
mockAuctionAssignmentRepository
|
||||
.Setup(repository => repository.FindByByAuctionCustomerNoAndVin(It.IsAny<string>(), It.IsAny<string>()))
|
||||
.ReturnsAsync(new AuctionAssignment());
|
||||
|
||||
// The Existance of MATCHING active collateral should
|
||||
mockAuctionAssignmentRepository.Setup(repository => repository.FindByRepoIdAsync(It.IsAny<int>()))
|
||||
.ReturnsAsync(
|
||||
new List<AuctionAssignment>()
|
||||
{
|
||||
new AuctionAssignment()
|
||||
{
|
||||
AuctionAssignmentToCollaterals = new List<AuctionAssignmentToCollateral>()
|
||||
{
|
||||
new AuctionAssignmentToCollateral { CollateralId = 42 },
|
||||
new AuctionAssignmentToCollateral { CollateralId = 5 } // Matching Collateral
|
||||
},
|
||||
IsActive = true
|
||||
}
|
||||
});
|
||||
|
||||
mockAuctionAssignmentRepository.Setup(repository => repository.AddAsync(It.IsAny<AuctionAssignment>()))
|
||||
.ReturnsAsync(new AuctionAssignment());
|
||||
mockRepoAccountService.Setup(service => service.Get(It.IsAny<int>())).ReturnsAsync(new RepoAccount()
|
||||
{
|
||||
Borrowers = new List<Borrower>
|
||||
{
|
||||
new Borrower()
|
||||
{
|
||||
OwnershipType = 6
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
var auctionAssignmentResponse = await service.SaveAsync(new AuctionAssignmentPostRequest()
|
||||
{
|
||||
AuctionAssignment = new AuctionAssignment()
|
||||
{
|
||||
RepoId = 1234
|
||||
},
|
||||
Collaterals = new List<Collateral>
|
||||
{
|
||||
new Collateral { CollateralId = 1 },
|
||||
new Collateral() { CollateralId = 5 }
|
||||
},
|
||||
VehicleLocation = new VehicleLocation(),
|
||||
PrimaryCollateralId = 1,
|
||||
});
|
||||
|
||||
Assert.True(false, "An Exception should have been thrown.");
|
||||
}
|
||||
catch (DuplicateResourceException)
|
||||
{
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Assert.True(false,
|
||||
"An DuplicateResourceException should have been thrown. Another exception was thrown instead.");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetAuctionCustomerNo_Success()
|
||||
{
|
||||
mockRepoAccountService.Setup(service => service.Get(It.IsAny<int>())).ReturnsAsync(new RepoAccount()
|
||||
{
|
||||
LoanNo = 56,
|
||||
Borrowers = new List<Borrower>
|
||||
{
|
||||
new Borrower()
|
||||
{
|
||||
OwnershipType = 6,
|
||||
IndividualId = "1234"
|
||||
}
|
||||
},
|
||||
Collaterals = new List<Collateral>
|
||||
{
|
||||
new Collateral()
|
||||
{
|
||||
RefCollateralId = "151834"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var auctionCustomerNo = await service.GetAuctionCustomerNoAsync(1234, "151834");
|
||||
|
||||
Assert.Equal("1234-151834", auctionCustomerNo);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_No_Auction_Change()
|
||||
{
|
||||
// arrange
|
||||
var assignment = new AuctionAssignment()
|
||||
{
|
||||
ID = 5,
|
||||
FloorPrice = 0,
|
||||
AuctionCustomerNo = "123456-789",
|
||||
AuctionId = "Mannheim",
|
||||
CollateralVIN = "12345678901234567",
|
||||
VehicleType = 5,
|
||||
};
|
||||
var assignmentUpdated = new AuctionAssignment()
|
||||
{
|
||||
ID = 5,
|
||||
FloorPrice = 0,
|
||||
AuctionCustomerNo = "123456-789",
|
||||
AuctionId = "Mannheim",
|
||||
CollateralVIN = "12345678901234567",
|
||||
VehicleType = 6
|
||||
};
|
||||
|
||||
mockAuctionAssignmentRepository.Setup(x => x.FindByIdAsync(5)).ReturnsAsync(assignment);
|
||||
mockAuctionAssignmentRepository.Setup(x => x.Update(It.IsAny<AuctionAssignment>())).Verifiable();
|
||||
mockUnitOfWork.Setup(x => x.CompleteAsync()).Verifiable();
|
||||
mockAutoImsWebService.Setup(x => x.PostVehicleAsync<FloorPriceVehicle>(It.IsAny<FloorPriceVehicle>()))
|
||||
.Verifiable();
|
||||
|
||||
// act
|
||||
var result = await service.UpdateAsync(assignmentUpdated);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
mockAuctionAssignmentRepository.Verify(x => x.FindByIdAsync(5), Times.Once);
|
||||
mockAutoImsWebService.Verify(x => x.PostVehicleAsync<FloorPriceVehicle>(It.IsAny<FloorPriceVehicle>()),
|
||||
Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Yes_Auction_Change()
|
||||
{
|
||||
// arrange
|
||||
var assignment = new AuctionAssignment()
|
||||
{
|
||||
ID = 5,
|
||||
FloorPrice = 0,
|
||||
AuctionCustomerNo = "123456-789",
|
||||
AuctionId = "Mannheim",
|
||||
CollateralVIN = "12345678901234567",
|
||||
VehicleType = 5,
|
||||
};
|
||||
var assignmentUpdated = new AuctionAssignment()
|
||||
{
|
||||
ID = 5,
|
||||
FloorPrice = 1000,
|
||||
AuctionCustomerNo = "123456-789",
|
||||
AuctionId = "Mannheim",
|
||||
CollateralVIN = "12345678901234567",
|
||||
VehicleType = 6
|
||||
};
|
||||
|
||||
mockAuctionAssignmentRepository.Setup(x => x.FindByIdAsync(5)).ReturnsAsync(assignment);
|
||||
mockAuctionAssignmentRepository.Setup(x => x.Update(It.IsAny<AuctionAssignment>())).Verifiable();
|
||||
mockAutoImsWebService.Setup(x => x.PostVehicleAsync<FloorPriceVehicle>(It.IsAny<FloorPriceVehicle>()))
|
||||
.Verifiable();
|
||||
mockAutoImsWebService.Setup(x => x.PostVehicleAsync<FloorPriceVehicle>(It.IsAny<FloorPriceVehicle>()))
|
||||
.ReturnsAsync((WebServiceResponse)null);
|
||||
|
||||
// act
|
||||
var result = await service.UpdateAsync(assignmentUpdated);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
|
||||
mockAuctionAssignmentRepository.Verify(x => x.FindByIdAsync(5), Times.Once);
|
||||
mockAutoImsWebService.Verify(x => x.PostVehicleAsync<FloorPriceVehicle>(It.IsAny<FloorPriceVehicle>()),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Floor_Price_Change_Manual_Success()
|
||||
{
|
||||
// arrange
|
||||
var assignment = new AuctionAssignment()
|
||||
{
|
||||
ID = 5,
|
||||
FloorPrice = 0,
|
||||
AuctionCustomerNo = "123456-789",
|
||||
AuctionId = "Mannheim",
|
||||
CollateralVIN = "12345678901234567",
|
||||
VehicleType = 5,
|
||||
};
|
||||
var assignmentUpdated = new AuctionAssignment()
|
||||
{
|
||||
ID = 5,
|
||||
FloorPrice = 1000,
|
||||
AuctionCustomerNo = "123456-789",
|
||||
AuctionId = "Mannheim",
|
||||
CollateralVIN = "12345678901234567",
|
||||
VehicleType = 6
|
||||
};
|
||||
WebServiceResponse response = new WebServiceResponse()
|
||||
{
|
||||
AuctionCollateralVin = assignmentUpdated.CollateralVIN,
|
||||
Status = new WebServiceResponseStatus()
|
||||
{
|
||||
Description = "success",
|
||||
Code = 1
|
||||
}
|
||||
};
|
||||
|
||||
mockAutoImsWebService.Setup(x => x.PostVehicleAsync<FloorPriceVehicle>(It.IsAny<FloorPriceVehicle>()))
|
||||
.ReturnsAsync(response);
|
||||
mockEmailer.Setup(x =>
|
||||
x.SendFloorPriceAcceptedEmail(It.IsAny<bool>(), It.IsAny<string>(), It.IsAny<decimal>(),
|
||||
It.IsAny<decimal>())).ReturnsAsync(new HttpResponseMessage(System.Net.HttpStatusCode.OK));
|
||||
|
||||
// act
|
||||
service.UpdateAuctionFloor(assignmentUpdated, assignment).GetAwaiter().GetResult();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(assignment);
|
||||
Assert.Equal(1000, assignment.FloorPrice);
|
||||
mockAutoImsWebService.Verify(x => x.PostVehicleAsync<FloorPriceVehicle>(It.IsAny<FloorPriceVehicle>()),
|
||||
Times.Once);
|
||||
mockEmailer.Verify(
|
||||
x => x.SendFloorPriceAcceptedEmail(It.IsAny<bool>(), It.IsAny<string>(), It.IsAny<decimal>(),
|
||||
It.IsAny<decimal>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Floor_Price_Change_Fail()
|
||||
{
|
||||
// arrange
|
||||
var assignment = new AuctionAssignment()
|
||||
{
|
||||
ID = 5,
|
||||
FloorPrice = 0,
|
||||
AuctionCustomerNo = "123456-789",
|
||||
AuctionId = "Mannheim",
|
||||
CollateralVIN = "12345678901234567",
|
||||
VehicleType = 5,
|
||||
};
|
||||
var assignmentUpdated = new AuctionAssignment()
|
||||
{
|
||||
ID = 5,
|
||||
FloorPrice = 1000,
|
||||
AuctionCustomerNo = "123456-789",
|
||||
AuctionId = "Mannheim",
|
||||
CollateralVIN = "12345678901234567",
|
||||
VehicleType = 5
|
||||
};
|
||||
WebServiceResponse response = new WebServiceResponse()
|
||||
{
|
||||
AuctionCollateralVin = assignmentUpdated.CollateralVIN,
|
||||
Status = new WebServiceResponseStatus()
|
||||
{
|
||||
Description = "success",
|
||||
Code = 5,
|
||||
ValidationError = new WebServiceResponseStatusValidationError[]
|
||||
{
|
||||
new WebServiceResponseStatusValidationError()
|
||||
{
|
||||
Message = "test failure",
|
||||
Code = "5"
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
mockAutoImsWebService.Setup(x => x.PostVehicleAsync<FloorPriceVehicle>(It.IsAny<FloorPriceVehicle>()))
|
||||
.ReturnsAsync(response);
|
||||
|
||||
// act
|
||||
service.UpdateAuctionFloor(assignmentUpdated, assignment).GetAwaiter().GetResult();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(assignment);
|
||||
Assert.Equal(0, assignment.FloorPrice);
|
||||
mockAutoImsWebService.Verify(x => x.PostVehicleAsync<FloorPriceVehicle>(It.IsAny<FloorPriceVehicle>()),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Floor_Price_Change_Automatic_Success()
|
||||
{
|
||||
// arrange
|
||||
var assignment = new AuctionAssignment()
|
||||
{
|
||||
ID = 5,
|
||||
FloorPrice = 0,
|
||||
AuctionCustomerNo = "123456-789",
|
||||
AuctionId = "Mannheim",
|
||||
CollateralVIN = "12345678901234567",
|
||||
VehicleType = 5,
|
||||
};
|
||||
var assignmentUpdated = new AuctionAssignment()
|
||||
{
|
||||
ID = 5,
|
||||
FloorPrice = 1000,
|
||||
FloorPriceValuesUsed = new FloorPriceValuesUsed
|
||||
{ MMRRegionalAdjustedPrice = 1000, NADAAverageAdjustedAuctionValue = 1000, PercentageOf = 100 },
|
||||
AuctionCustomerNo = "123456-789",
|
||||
AuctionId = "Mannheim",
|
||||
CollateralVIN = "12345678901234567",
|
||||
VehicleType = 5
|
||||
};
|
||||
mockRepoAccountService.Setup(x => x.FindByAuctionAssignmentId(It.IsAny<int>()))
|
||||
.ReturnsAsync(new RepoAccount { AccountNo = "1234567-98" });
|
||||
WebServiceResponse response = new WebServiceResponse()
|
||||
{
|
||||
AuctionCollateralVin = assignmentUpdated.CollateralVIN,
|
||||
Status = new WebServiceResponseStatus()
|
||||
{
|
||||
Description = "success",
|
||||
Code = 1
|
||||
}
|
||||
};
|
||||
|
||||
mockAutoImsWebService.Setup(x => x.PostVehicleAsync<FloorPriceVehicle>(It.IsAny<FloorPriceVehicle>()))
|
||||
.ReturnsAsync(response);
|
||||
mockEmailer.Setup(x =>
|
||||
x.SendFloorPriceAcceptedEmail(It.IsAny<bool>(), It.IsAny<string>(), It.IsAny<decimal>(),
|
||||
It.IsAny<decimal>())).ReturnsAsync(new HttpResponseMessage(System.Net.HttpStatusCode.OK));
|
||||
|
||||
// act
|
||||
service.UpdateAuctionFloor(assignmentUpdated, assignment).GetAwaiter().GetResult();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(assignment);
|
||||
Assert.Equal(1000, assignment.FloorPrice);
|
||||
mockAutoImsWebService.Verify(x => x.PostVehicleAsync<FloorPriceVehicle>(It.IsAny<FloorPriceVehicle>()),
|
||||
Times.Once);
|
||||
mockEmailer.Verify(
|
||||
x => x.SendFloorPriceAcceptedEmail(It.IsAny<bool>(), It.IsAny<string>(), It.IsAny<decimal>(),
|
||||
It.IsAny<decimal>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Title_Sent_Date_Change_Success()
|
||||
{
|
||||
// arrange
|
||||
var assignment = new AuctionAssignment()
|
||||
{
|
||||
ID = 5,
|
||||
FloorPrice = 0,
|
||||
AuctionCustomerNo = "123456-789",
|
||||
AuctionId = "Mannheim",
|
||||
CollateralVIN = "12345678901234567",
|
||||
VehicleType = 5,
|
||||
SentTitleDocsDate = null
|
||||
};
|
||||
var assignmentUpdated = new AuctionAssignment()
|
||||
{
|
||||
ID = 5,
|
||||
FloorPrice = 0,
|
||||
AuctionCustomerNo = "123456-789",
|
||||
AuctionId = "Mannheim",
|
||||
CollateralVIN = "12345678901234567",
|
||||
VehicleType = 5,
|
||||
SentTitleDocsDate = new System.DateTime(2017, 12, 21)
|
||||
};
|
||||
WebServiceResponse response = new WebServiceResponse()
|
||||
{
|
||||
AuctionCollateralVin = assignmentUpdated.CollateralVIN,
|
||||
Status = new WebServiceResponseStatus()
|
||||
{
|
||||
Description = "success",
|
||||
Code = 1
|
||||
}
|
||||
};
|
||||
|
||||
mockAutoImsWebService.Setup(x => x.TitleSent(It.IsAny<string>())).ReturnsAsync(response);
|
||||
|
||||
// act
|
||||
service.UpdateTitleSentDate(assignmentUpdated, assignment).GetAwaiter().GetResult();
|
||||
|
||||
// assert
|
||||
Assert.NotNull(assignment);
|
||||
Assert.Equal(new System.DateTime(2017, 12, 21), assignment.SentTitleDocsDate);
|
||||
mockAutoImsWebService.Verify(x => x.TitleSent(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Title_Sent_Date_Change_Fail()
|
||||
{
|
||||
// arrange
|
||||
var assignment = new AuctionAssignment()
|
||||
{
|
||||
ID = 5,
|
||||
FloorPrice = 0,
|
||||
AuctionCustomerNo = "123456-789",
|
||||
AuctionId = "Mannheim",
|
||||
CollateralVIN = "12345678901234567",
|
||||
VehicleType = 5,
|
||||
};
|
||||
var assignmentUpdated = new AuctionAssignment()
|
||||
{
|
||||
ID = 5,
|
||||
FloorPrice = 0,
|
||||
AuctionCustomerNo = "123456-789",
|
||||
AuctionId = "Mannheim",
|
||||
CollateralVIN = "12345678901234567",
|
||||
VehicleType = 5,
|
||||
SentTitleDocsDate = new System.DateTime(2017, 12, 21)
|
||||
};
|
||||
WebServiceResponse response = new WebServiceResponse()
|
||||
{
|
||||
AuctionCollateralVin = assignmentUpdated.CollateralVIN,
|
||||
Status = new WebServiceResponseStatus()
|
||||
{
|
||||
Description = "success",
|
||||
Code = 5,
|
||||
ValidationError = new WebServiceResponseStatusValidationError[]
|
||||
{
|
||||
new WebServiceResponseStatusValidationError()
|
||||
{
|
||||
Message = "test failure",
|
||||
Code = "5"
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
mockAutoImsWebService.Setup(x => x.TitleSent(It.IsAny<string>())).ReturnsAsync(response);
|
||||
|
||||
// act
|
||||
service.UpdateTitleSentDate(assignmentUpdated, assignment).GetAwaiter().GetResult();
|
||||
|
||||
// assert
|
||||
Assert.NotNull(assignment);
|
||||
Assert.Null(assignment.SentTitleDocsDate);
|
||||
mockAutoImsWebService.Verify(x => x.TitleSent(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Redeemed_Date_Change_Success()
|
||||
{
|
||||
// arrange
|
||||
var assignment = new AuctionAssignment()
|
||||
{
|
||||
ID = 5,
|
||||
FloorPrice = 0,
|
||||
AuctionCustomerNo = "123456-789",
|
||||
AuctionId = "Mannheim",
|
||||
CollateralVIN = "12345678901234567",
|
||||
VehicleType = 5,
|
||||
RedeemedDate = null
|
||||
};
|
||||
var assignmentUpdated = new AuctionAssignment()
|
||||
{
|
||||
ID = 5,
|
||||
FloorPrice = 0,
|
||||
AuctionCustomerNo = "123456-789",
|
||||
AuctionId = "Mannheim",
|
||||
CollateralVIN = "12345678901234567",
|
||||
VehicleType = 5,
|
||||
RedeemedDate = new System.DateTime(2017, 12, 21)
|
||||
};
|
||||
WebServiceResponse response = new WebServiceResponse()
|
||||
{
|
||||
AuctionCollateralVin = assignmentUpdated.CollateralVIN,
|
||||
Status = new WebServiceResponseStatus()
|
||||
{
|
||||
Description = "success",
|
||||
Code = 1
|
||||
}
|
||||
};
|
||||
|
||||
mockAutoImsWebService.Setup(x => x.Redeem(It.IsAny<string>())).ReturnsAsync(response);
|
||||
|
||||
// act
|
||||
service.UpdateRedeemedDate(assignmentUpdated, assignment).GetAwaiter().GetResult();
|
||||
|
||||
// assert
|
||||
Assert.NotNull(assignment);
|
||||
Assert.Equal(new System.DateTime(2017, 12, 21), assignment.RedeemedDate);
|
||||
mockAutoImsWebService.Verify(x => x.Redeem(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Redeemed_Date_Change_Fail()
|
||||
{
|
||||
// arrange
|
||||
var assignment = new AuctionAssignment()
|
||||
{
|
||||
ID = 5,
|
||||
FloorPrice = 0,
|
||||
AuctionCustomerNo = "123456-789",
|
||||
AuctionId = "Mannheim",
|
||||
CollateralVIN = "12345678901234567",
|
||||
VehicleType = 5,
|
||||
};
|
||||
var assignmentUpdated = new AuctionAssignment()
|
||||
{
|
||||
ID = 5,
|
||||
FloorPrice = 0,
|
||||
AuctionCustomerNo = "123456-789",
|
||||
AuctionId = "Mannheim",
|
||||
CollateralVIN = "12345678901234567",
|
||||
VehicleType = 5,
|
||||
RedeemedDate = new System.DateTime(2017, 12, 21)
|
||||
};
|
||||
WebServiceResponse response = new WebServiceResponse()
|
||||
{
|
||||
AuctionCollateralVin = assignmentUpdated.CollateralVIN,
|
||||
Status = new WebServiceResponseStatus()
|
||||
{
|
||||
Description = "success",
|
||||
Code = 5,
|
||||
ValidationError = new WebServiceResponseStatusValidationError[]
|
||||
{
|
||||
new WebServiceResponseStatusValidationError()
|
||||
{
|
||||
Message = "test failure",
|
||||
Code = "5"
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
mockAutoImsWebService.Setup(x => x.Redeem(It.IsAny<string>())).ReturnsAsync(response);
|
||||
|
||||
// act
|
||||
service.UpdateRedeemedDate(assignmentUpdated, assignment).GetAwaiter().GetResult();
|
||||
|
||||
// assert
|
||||
Assert.NotNull(assignment);
|
||||
Assert.Null(assignment.RedeemedDate);
|
||||
mockAutoImsWebService.Verify(x => x.Redeem(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Auction_Hold_Change_Success()
|
||||
{
|
||||
// arrange
|
||||
var assignment = new AuctionAssignment()
|
||||
{
|
||||
ID = 5,
|
||||
FloorPrice = 0,
|
||||
AuctionCustomerNo = "123456-789",
|
||||
AuctionId = "Mannheim",
|
||||
CollateralVIN = "12345678901234567",
|
||||
VehicleType = 5,
|
||||
};
|
||||
var assignmentUpdated = new AuctionAssignment()
|
||||
{
|
||||
ID = 5,
|
||||
FloorPrice = 0,
|
||||
AuctionCustomerNo = "123456-789",
|
||||
AuctionId = "Mannheim",
|
||||
CollateralVIN = "12345678901234567",
|
||||
VehicleType = 5,
|
||||
HoldStatus = 3,
|
||||
HoldUntil = new DateTime(2017, 12, 21)
|
||||
};
|
||||
WebServiceResponse response = new WebServiceResponse()
|
||||
{
|
||||
AuctionCollateralVin = assignmentUpdated.CollateralVIN,
|
||||
Status = new WebServiceResponseStatus()
|
||||
{
|
||||
Description = "success",
|
||||
Code = 1
|
||||
}
|
||||
};
|
||||
|
||||
mockAutoImsWebService.Setup(x => x.PlaceHold(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<DateTime>()))
|
||||
.ReturnsAsync(response);
|
||||
|
||||
// act
|
||||
service.UpdateHoldData(assignmentUpdated, assignment).GetAwaiter().GetResult();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(assignment);
|
||||
Assert.Equal(3, assignment.HoldStatus);
|
||||
Assert.Equal(new DateTime(2017, 12, 21), assignment.HoldUntil);
|
||||
mockAutoImsWebService.Verify(x => x.PlaceHold(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<DateTime>()),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Auction_Hold_Change_Fail()
|
||||
{
|
||||
// arrange
|
||||
var assignment = new AuctionAssignment()
|
||||
{
|
||||
ID = 5,
|
||||
FloorPrice = 0,
|
||||
AuctionCustomerNo = "123456-789",
|
||||
AuctionId = "Mannheim",
|
||||
CollateralVIN = "12345678901234567",
|
||||
VehicleType = 5,
|
||||
};
|
||||
var assignmentUpdated = new AuctionAssignment()
|
||||
{
|
||||
ID = 5,
|
||||
FloorPrice = 0,
|
||||
AuctionCustomerNo = "123456-789",
|
||||
AuctionId = "Mannheim",
|
||||
CollateralVIN = "12345678901234567",
|
||||
VehicleType = 5,
|
||||
HoldStatus = 3
|
||||
};
|
||||
WebServiceResponse response = new WebServiceResponse()
|
||||
{
|
||||
AuctionCollateralVin = assignmentUpdated.CollateralVIN,
|
||||
Status = new WebServiceResponseStatus()
|
||||
{
|
||||
Description = "success",
|
||||
Code = 5,
|
||||
ValidationError = new WebServiceResponseStatusValidationError[]
|
||||
{
|
||||
new WebServiceResponseStatusValidationError()
|
||||
{
|
||||
Message = "test failure",
|
||||
Code = "5"
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
mockAutoImsWebService.Setup(x => x.PlaceHold(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<DateTime>()))
|
||||
.ReturnsAsync(response);
|
||||
|
||||
// act
|
||||
await service.UpdateHoldData(assignmentUpdated, assignment);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(assignment);
|
||||
Assert.Null(assignment.HoldStatus);
|
||||
Assert.Null(assignment.HoldUntil);
|
||||
mockAutoImsWebService.Verify(x => x.PlaceHold(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<DateTime>()),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetByRepoId_Ok()
|
||||
{
|
||||
// Arrange
|
||||
mockAuctionAssignmentRepository.Setup(repo => repo.FindByRepoIdAsync(It.IsAny<int>())).ReturnsAsync(
|
||||
new List<AuctionAssignment>()
|
||||
{
|
||||
new AuctionAssignment(),
|
||||
new AuctionAssignment()
|
||||
});
|
||||
|
||||
// Act
|
||||
var auctionAssignments = await service.GetByRepoIdAsync(5);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(auctionAssignments);
|
||||
Assert.Equal(2, auctionAssignments.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void RemoveAuction_Ok()
|
||||
{
|
||||
// Arrange
|
||||
mockAuctionAssignmentRepository.Setup(x => x.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(
|
||||
new AuctionAssignment()
|
||||
{
|
||||
ID = 1,
|
||||
IsActive = true,
|
||||
CollateralVIN = "123456789",
|
||||
AuctionCustomerNo = "123-45"
|
||||
});
|
||||
|
||||
// Act
|
||||
var result = await service.RemoveAuction(1);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.False(result.IsActive);
|
||||
|
||||
mockAutoImsWebService.Verify(x => x.RemoveFromAuction(It.IsAny<string>(), It.IsAny<string>()),
|
||||
Times.Once());
|
||||
mockAuctionAssignmentRepository.Verify(x => x.Update(It.IsAny<AuctionAssignment>()), Times.Once());
|
||||
mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Once());
|
||||
}
|
||||
}
|
||||
}
|
||||
+389
@@ -0,0 +1,389 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Collections.RepoApi.Exceptions;
|
||||
using LCU.API.Collections.RepoApi.Factories;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
|
||||
public class AuctionHouseServiceTest
|
||||
{
|
||||
[Fact]
|
||||
public async void ListAll_Ok()
|
||||
{
|
||||
var mockAuctionHouseRepository = new Mock<IAuctionHouseRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
mockAuctionHouseRepository.Setup(repo => repo.ListAllAsync()).ReturnsAsync(new List<AuctionHouse>() { new AuctionHouse(), new AuctionHouse(), new AuctionHouse() });
|
||||
|
||||
AuctionHouseService auctionHouseService = new AuctionHouseService(mockAuctionHouseRepository.Object, mockUnitOfWork.Object);
|
||||
|
||||
var res = await auctionHouseService.ListAllAsync();
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(3, res.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ListAll_Exception()
|
||||
{
|
||||
var mockAuctionHouseRepository = new Mock<IAuctionHouseRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
mockAuctionHouseRepository.Setup(repo => repo.ListAllAsync()).ThrowsAsync(new Exception("oops"));
|
||||
|
||||
AuctionHouseService auctionHouseService = new AuctionHouseService(mockAuctionHouseRepository.Object, mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await auctionHouseService.ListAllAsync());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void SaveAsync_OK()
|
||||
{
|
||||
AuctionHouse AuctionHouse = new AuctionHouse()
|
||||
{
|
||||
AuctionID = "5"
|
||||
};
|
||||
|
||||
var mockAuctionHouseRepository = new Mock<IAuctionHouseRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
mockAuctionHouseRepository.Setup(repo => repo.AddAsync(It.Is<AuctionHouse>(param => param.AuctionID == "5"))).Returns(Task.CompletedTask);
|
||||
mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
AuctionHouseService auctionHouseService = new AuctionHouseService(mockAuctionHouseRepository.Object, mockUnitOfWork.Object);
|
||||
|
||||
var res = await auctionHouseService.SaveAsync(AuctionHouse);
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(AuctionHouse, res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void SaveAsync_DuplicateResource_Exception()
|
||||
{
|
||||
AuctionHouse AuctionHouse = new AuctionHouse()
|
||||
{
|
||||
AuctionID = "5"
|
||||
};
|
||||
|
||||
var mockAuctionHouseRepository = new Mock<IAuctionHouseRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
mockAuctionHouseRepository.Setup(repo => repo.AddAsync(It.Is<AuctionHouse>(param => param.AuctionID == "5"))).ThrowsAsync(new Exception("Oops"));
|
||||
mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
AuctionHouseService auctionHouseService = new AuctionHouseService(mockAuctionHouseRepository.Object, mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await auctionHouseService.SaveAsync(AuctionHouse));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void SaveAsync_Exception()
|
||||
{
|
||||
AuctionHouse AuctionHouse = new AuctionHouse()
|
||||
{
|
||||
AuctionID = "5"
|
||||
};
|
||||
|
||||
var mockAuctionHouseRepository = new Mock<IAuctionHouseRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
mockAuctionHouseRepository.Setup(repo => repo.AddAsync(It.Is<AuctionHouse>(param => param.AuctionID == "5"))).ThrowsAsync(new Exception("oops"));
|
||||
mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
AuctionHouseService auctionHouseService = new AuctionHouseService(mockAuctionHouseRepository.Object, mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await auctionHouseService.SaveAsync(AuctionHouse));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Ok()
|
||||
{
|
||||
var mockAuctionHouseRepository = new Mock<IAuctionHouseRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
mockAuctionHouseRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<string>())).ReturnsAsync(new AuctionHouse() { AuctionID = "5" });
|
||||
mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
AuctionHouseService auctionHouseService = new AuctionHouseService(mockAuctionHouseRepository.Object, mockUnitOfWork.Object);
|
||||
|
||||
var res = await auctionHouseService.GetAsync("5");
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal("5", res.AuctionID);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Exception()
|
||||
{
|
||||
var mockAuctionHouseRepository = new Mock<IAuctionHouseRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
mockAuctionHouseRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<string>())).ThrowsAsync(new Exception("Oops"));
|
||||
mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
AuctionHouseService auctionHouseService = new AuctionHouseService(mockAuctionHouseRepository.Object, mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await auctionHouseService.GetAsync("5"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Null_Exception()
|
||||
{
|
||||
var mockAuctionHouseRepository = new Mock<IAuctionHouseRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
mockAuctionHouseRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<string>())).Returns(Task.FromResult<AuctionHouse>(null));
|
||||
mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
AuctionHouseService auctionHouseService = new AuctionHouseService(mockAuctionHouseRepository.Object, mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<NotFoundException>(async () => await auctionHouseService.GetAsync("5"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Null()
|
||||
{
|
||||
var mockAuctionHouseRepository = new Mock<IAuctionHouseRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
mockAuctionHouseRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<string>())).Returns(Task.FromResult<AuctionHouse>(null));
|
||||
|
||||
var auctionHouseService = new AuctionHouseService(mockAuctionHouseRepository.Object, mockUnitOfWork.Object);
|
||||
|
||||
var auctionHouse = new AuctionHouse
|
||||
{
|
||||
AuctionID = "5"
|
||||
};
|
||||
|
||||
await Assert.ThrowsAsync<NotFoundException>(async () => await auctionHouseService.UpdateAsync(auctionHouse));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Exception()
|
||||
{
|
||||
var mockAuctionHouseRepository = new Mock<IAuctionHouseRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
mockAuctionHouseRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<string>())).ReturnsAsync(new AuctionHouse());
|
||||
|
||||
var auctionHouseService = new AuctionHouseService(mockAuctionHouseRepository.Object, mockUnitOfWork.Object);
|
||||
|
||||
var auctionHouse = new AuctionHouse
|
||||
{
|
||||
AuctionID = "5"
|
||||
};
|
||||
|
||||
mockAuctionHouseRepository.Setup(repo => repo.Update(It.IsAny<AuctionHouse>())).Throws(new Exception("oops"));
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await auctionHouseService.UpdateAsync(auctionHouse));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Ok()
|
||||
{
|
||||
var mockAuctionHouseRepository = new Mock<IAuctionHouseRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
mockAuctionHouseRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<string>())).ReturnsAsync(new AuctionHouse() {AuctionID = "6"});
|
||||
|
||||
var auctionHouseService = new AuctionHouseService(mockAuctionHouseRepository.Object, mockUnitOfWork.Object);
|
||||
|
||||
var auctionHouse = new AuctionHouse
|
||||
{
|
||||
AuctionID = "5",
|
||||
|
||||
};
|
||||
|
||||
var result = await auctionHouseService.UpdateAsync(auctionHouse);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("6", result.AuctionID);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Existing_Exception()
|
||||
{
|
||||
var mockAuctionHouseRepository = new Mock<IAuctionHouseRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
mockAuctionHouseRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<string>())).Throws(new Exception("oops"));
|
||||
|
||||
var auctionHouseService = new AuctionHouseService(mockAuctionHouseRepository.Object, mockUnitOfWork.Object);
|
||||
|
||||
var auctionHouse = new AuctionHouse
|
||||
{
|
||||
AuctionID = "5"
|
||||
};
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await auctionHouseService.UpdateAsync(auctionHouse));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DeleteAsync_Ok()
|
||||
{
|
||||
var auctionHouse = new AuctionHouse
|
||||
{
|
||||
AuctionID = "5"
|
||||
};
|
||||
|
||||
var mockAuctionHouseRepository = new Mock<IAuctionHouseRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
mockAuctionHouseRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<string>())).ReturnsAsync(auctionHouse);
|
||||
mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
mockAuctionHouseRepository.Setup(repo => repo.Remove(It.Is<AuctionHouse>(param => param.AuctionID == "5")));
|
||||
|
||||
AuctionHouseService auctionHouseService = new AuctionHouseService(mockAuctionHouseRepository.Object, mockUnitOfWork.Object);
|
||||
|
||||
var res = await auctionHouseService.DeleteAsync("5");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DeleteAsync_Null()
|
||||
{
|
||||
var dummyAlert = new AuctionHouse
|
||||
{
|
||||
AuctionID = "5"
|
||||
};
|
||||
|
||||
|
||||
var mockAuctionHouseRepository = new Mock<IAuctionHouseRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
mockAuctionHouseRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<string>())).Returns(Task.FromResult<AuctionHouse>(null));
|
||||
mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
mockAuctionHouseRepository.Setup(repo => repo.Remove(It.Is<AuctionHouse>(param => param.AuctionID == "5")));
|
||||
|
||||
AuctionHouseService auctionHouseService = new AuctionHouseService(mockAuctionHouseRepository.Object, mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<NotFoundException>(async () => await auctionHouseService.DeleteAsync("5"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DeleteAsync_Remove_Exception()
|
||||
{
|
||||
var auctionHouse = new AuctionHouse
|
||||
{
|
||||
AuctionID = "5"
|
||||
};
|
||||
|
||||
var mockAuctionHouseRepository = new Mock<IAuctionHouseRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
mockAuctionHouseRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<string>())).ReturnsAsync(auctionHouse);
|
||||
mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
mockAuctionHouseRepository.Setup(repo => repo.Remove(It.Is<AuctionHouse>(param => param.AuctionID == "5"))).Throws(new Exception("oops"));
|
||||
|
||||
AuctionHouseService auctionHouseService = new AuctionHouseService(mockAuctionHouseRepository.Object, mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await auctionHouseService.DeleteAsync("5"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DeleteAsync_Existing_Exception()
|
||||
{
|
||||
|
||||
var auctionHouse = new AuctionHouse
|
||||
{
|
||||
AuctionID = "5"
|
||||
};
|
||||
|
||||
var mockAuctionHouseRepository = new Mock<IAuctionHouseRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
mockAuctionHouseRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<string>())).Throws(new Exception("oops"));
|
||||
mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
mockAuctionHouseRepository.Setup(repo => repo.Remove(It.Is<AuctionHouse>(param => param.AuctionID == "5")));
|
||||
|
||||
AuctionHouseService auctionHouseService = new AuctionHouseService(mockAuctionHouseRepository.Object, mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await auctionHouseService.DeleteAsync("5"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ListAll_Ok_2()
|
||||
{
|
||||
var repository = new Mock<IAuctionHouseRepository>();
|
||||
var unitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
repository.Setup(repo => repo.ListAllAsync()).ReturnsAsync(new List<AuctionHouse>()
|
||||
{
|
||||
new AuctionHouse()
|
||||
{
|
||||
Name = "Auction House A"
|
||||
}
|
||||
});
|
||||
|
||||
var service = new AuctionHouseService(repository.Object, unitOfWork.Object);
|
||||
|
||||
var value = await service.ListAllAsync();
|
||||
Assert.NotNull(value);
|
||||
|
||||
var enumerator = value.GetEnumerator();
|
||||
enumerator.MoveNext();
|
||||
Assert.NotNull(enumerator);
|
||||
Assert.Equal("Auction House A", enumerator.Current.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_One_OK()
|
||||
{
|
||||
var repository = new Mock<IAuctionHouseRepository>();
|
||||
var unitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
repository.Setup(repo => repo.FindByIdAsync(It.IsAny<string>())).ReturnsAsync(new AuctionHouse()
|
||||
{
|
||||
Name = "Auction House A"
|
||||
});
|
||||
|
||||
var service = new AuctionHouseService(repository.Object, unitOfWork.Object);
|
||||
|
||||
var value = await service.GetAsync("someId");
|
||||
Assert.NotNull(value);
|
||||
Assert.Equal("Auction House A", value.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_One_Does_Not_Exist()
|
||||
{
|
||||
var repository = new Mock<IAuctionHouseRepository>();
|
||||
var unitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
repository.Setup(repo => repo.FindByIdAsync(It.IsAny<string>())).ReturnsAsync((AuctionHouse) null);
|
||||
|
||||
var service = new AuctionHouseService(repository.Object, unitOfWork.Object);
|
||||
|
||||
try
|
||||
{
|
||||
var value = await service.GetAsync("someId");
|
||||
Assert.True(false, "Exception not thrown for null return.");
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Delete_Does_Not_Exist()
|
||||
{
|
||||
var repository = new Mock<IAuctionHouseRepository>();
|
||||
var unitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
repository.Setup(repo => repo.FindByIdAsync(It.IsAny<string>())).ReturnsAsync((AuctionHouse) null);
|
||||
|
||||
var service = new AuctionHouseService(repository.Object, unitOfWork.Object);
|
||||
|
||||
try
|
||||
{
|
||||
var value = await service.DeleteAsync("someId");
|
||||
Assert.True(false, "Exception not thrown for null return.");
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+472
@@ -0,0 +1,472 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using LCU.API.Collections.RepoApi.Models.Requests;
|
||||
using LCU.API.Collections.RepoApi.Services.Reporting;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models.Reporting;
|
||||
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class AuctionReportingServiceTest
|
||||
{
|
||||
private IAuctionReportingService _auctionReportingService;
|
||||
private Mock<IReportingRepository> _mockReportingRepository;
|
||||
|
||||
public AuctionReportingServiceTest()
|
||||
{
|
||||
_mockReportingRepository = new Mock<IReportingRepository>();
|
||||
_auctionReportingService = new AuctionReportingService(_mockReportingRepository.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Empty_Result_Set_Ok()
|
||||
{
|
||||
// arrange
|
||||
var rawResults = new List<StdReportEntry>() { };
|
||||
_mockReportingRepository.Setup(x => x.GetAccountsByDateRepoed(It.IsAny<DateTime>(), It.IsAny<DateTime>()))
|
||||
.ReturnsAsync(rawResults);
|
||||
var request = new ReportingRequest();
|
||||
|
||||
// act
|
||||
var result = await _auctionReportingService.GetAssignedBalance(request.LowDate, request.HighDate);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GrossAmount_Two_Month_Set_Ok()
|
||||
{
|
||||
// arrange - should produce 4 rows with 3 columns... 2 months + total for columns and totals, two auctions, and null auctions row.
|
||||
var rawResults = new List<StdReportEntry>()
|
||||
{
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 1000,
|
||||
AuctionId = "A1",
|
||||
AuctionName = "Ted",
|
||||
AccountNo = "123456-789",
|
||||
Balance = 1000,
|
||||
CollateralId = 100,
|
||||
DateRepoed = DateTime.Parse("12/15/2019"),
|
||||
RepoCompanyId = 400,
|
||||
DateEnteredAutoIMS = DateTime.Parse("10/01/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 1001,
|
||||
AuctionId = "A2",
|
||||
AuctionName = "Tiger",
|
||||
AccountNo = "234561-789",
|
||||
Balance = 500,
|
||||
CollateralId = 101,
|
||||
DateRepoed = DateTime.Parse("11/15/2019"),
|
||||
RepoCompanyId = 500,
|
||||
DateEnteredAutoIMS = DateTime.Parse("10/01/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 1001,
|
||||
AuctionId = "A2",
|
||||
AuctionName = "Tiger",
|
||||
AccountNo = "234561-789",
|
||||
Balance = 500,
|
||||
CollateralId = 102,
|
||||
DateRepoed = DateTime.Parse("11/15/2019"),
|
||||
RepoCompanyId = 500,
|
||||
DateEnteredAutoIMS = DateTime.Parse("10/01/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 1002,
|
||||
AuctionId = "A1",
|
||||
AuctionName = "Ted",
|
||||
AccountNo = "345612-789",
|
||||
Balance = 500,
|
||||
CollateralId = 102,
|
||||
DateRepoed = DateTime.Parse("11/15/2019"),
|
||||
RepoCompanyId = 500,
|
||||
DateEnteredAutoIMS = DateTime.Parse("10/01/2019")
|
||||
}
|
||||
};
|
||||
_mockReportingRepository.Setup(x => x.GetAccountsByDateRepoed(It.IsAny<DateTime>(), It.IsAny<DateTime>()))
|
||||
.ReturnsAsync(rawResults);
|
||||
var highDate = DateTime.Parse("12/31/2019");
|
||||
var lowDate = DateTime.Parse("11/01/2019");
|
||||
var request = new ReportingRequest()
|
||||
{
|
||||
HighDate = highDate,
|
||||
LowDate = lowDate
|
||||
};
|
||||
|
||||
// act
|
||||
var result = await _auctionReportingService.GetAssignedBalance(request.LowDate, request.HighDate);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(4, result.DataTable.Rows.Count());
|
||||
Assert.Equal(16, result.ReportTable.Cells.Length); // 4 rows of 4.
|
||||
|
||||
Assert.Equal("Ted", result.ReportTable.Cells[1, 0].Display);
|
||||
Assert.Equal("$1,000.00", result.ReportTable.Cells[0, 1].Display);
|
||||
Assert.Equal("$1,000.00", result.ReportTable.Cells[0, 2].Display);
|
||||
Assert.Equal("$2,000.00", result.ReportTable.Cells[0, 3].Display);
|
||||
Assert.Equal("-", result.ReportTable.Cells[3, 3].Display);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetActiveInventoryCountAtAuction_Two_Month_Set_Ok()
|
||||
{
|
||||
// arrange - should produce 4 rows with 3 columns... 2 months + total for columns and totals, two auctions, and null auctions row.
|
||||
var rawResults = new List<StdReportEntry>()
|
||||
{
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 1,
|
||||
AuctionName = "Ted",
|
||||
DateRepoed = DateTime.Parse("12/15/2019"),
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 2,
|
||||
AuctionName = "Tiger",
|
||||
DateRepoed = DateTime.Parse("11/15/2019"),
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 3,
|
||||
AuctionName = "Tiger",
|
||||
DateRepoed = DateTime.Parse("11/15/2019"),
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 4,
|
||||
AuctionName = "Ted",
|
||||
DateRepoed = DateTime.Parse("11/15/2019"),
|
||||
}
|
||||
};
|
||||
_mockReportingRepository.Setup(x => x.GetAccountsByDateRepoed(It.IsAny<DateTime>(), It.IsAny<DateTime>()))
|
||||
.ReturnsAsync(rawResults);
|
||||
var highDate = DateTime.Parse("12/31/2019");
|
||||
var lowDate = DateTime.Parse("11/01/2019");
|
||||
var request = new ReportingRequest()
|
||||
{
|
||||
HighDate = highDate,
|
||||
LowDate = lowDate
|
||||
};
|
||||
|
||||
// act
|
||||
var result = await _auctionReportingService.GetAssignedCollateralCount(request.LowDate, request.HighDate);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(4, result.DataTable.Rows.Count());
|
||||
Assert.Equal(16, result.ReportTable.Cells.Length); // 4 rows of 4.
|
||||
|
||||
// Assert Display
|
||||
Assert.Equal("All Auctions", result.ReportTable.Cells[0, 0].Display);
|
||||
Assert.Equal("3", result.ReportTable.Cells[0, 1].Display);
|
||||
Assert.Equal("1", result.ReportTable.Cells[0, 2].Display);
|
||||
Assert.Equal("4", result.ReportTable.Cells[0, 3].Display);
|
||||
|
||||
Assert.Equal("Ted", result.ReportTable.Cells[1, 0].Display);
|
||||
Assert.Equal("1", result.ReportTable.Cells[1, 1].Display);
|
||||
Assert.Equal("1", result.ReportTable.Cells[1, 2].Display);
|
||||
Assert.Equal("2", result.ReportTable.Cells[1, 3].Display);
|
||||
|
||||
Assert.Equal("Tiger", result.ReportTable.Cells[2, 0].Display);
|
||||
Assert.Equal("2", result.ReportTable.Cells[2, 1].Display);
|
||||
Assert.Equal("-", result.ReportTable.Cells[2, 2].Display);
|
||||
Assert.Equal("2", result.ReportTable.Cells[2, 3].Display);
|
||||
|
||||
Assert.Equal("No Auctions", result.ReportTable.Cells[3, 0].Display);
|
||||
Assert.Equal("-", result.ReportTable.Cells[3, 1].Display);
|
||||
Assert.Equal("-", result.ReportTable.Cells[3, 2].Display);
|
||||
Assert.Equal("-", result.ReportTable.Cells[3, 3].Display);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetSoldPriceReport_Two_Month_Set_Ok()
|
||||
{
|
||||
// arrange - should produce 4 rows with 3 columns... 2 months + total for columns and totals, two auctions, and null auctions row.
|
||||
var rawResults = new List<StdReportEntry>()
|
||||
{
|
||||
new StdReportEntry()
|
||||
{
|
||||
AuctionName = "Ted",
|
||||
RepoId = 1,
|
||||
SoldDate = DateTime.Parse("11/15/2019"),
|
||||
GrossSalePrice = 1500
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
AuctionName = "Tiger",
|
||||
RepoId = 2,
|
||||
SoldDate = DateTime.Parse("11/10/2019"),
|
||||
GrossSalePrice = 500
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
AuctionName = "Tiger",
|
||||
RepoId = 3,
|
||||
SoldDate = DateTime.Parse("11/20/2019"),
|
||||
GrossSalePrice = 1000
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
AuctionName = "Ted",
|
||||
RepoId = 4,
|
||||
SoldDate = DateTime.Parse("12/02/2019"),
|
||||
GrossSalePrice = 3500
|
||||
}
|
||||
};
|
||||
_mockReportingRepository.Setup(x => x.GetAccountsByDateSoldInAutoIMS(It.IsAny<DateTime>(), It.IsAny<DateTime>()))
|
||||
.ReturnsAsync(rawResults);
|
||||
var highDate = DateTime.Parse("12/31/2019");
|
||||
var lowDate = DateTime.Parse("11/01/2019");
|
||||
var request = new ReportingRequest()
|
||||
{
|
||||
HighDate = highDate,
|
||||
LowDate = lowDate
|
||||
};
|
||||
|
||||
// act
|
||||
var result = await _auctionReportingService.GetSalePriceReport(request.LowDate, request.HighDate);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(4, result.DataTable.Rows.Count());
|
||||
Assert.Equal(12, result.ReportTable.Cells.Length); // 3 rows of 4.
|
||||
|
||||
// Assert Display
|
||||
Assert.Equal("All Auctions", result.ReportTable.Cells[0, 0].Display);
|
||||
Assert.Equal("$3,000.00", result.ReportTable.Cells[0, 1].Display);
|
||||
Assert.Equal("$3,500.00", result.ReportTable.Cells[0, 2].Display);
|
||||
Assert.Equal("$6,500.00", result.ReportTable.Cells[0, 3].Display);
|
||||
|
||||
Assert.Equal("Ted", result.ReportTable.Cells[1, 0].Display);
|
||||
Assert.Equal("$1,500.00", result.ReportTable.Cells[1, 1].Display);
|
||||
Assert.Equal("$3,500.00", result.ReportTable.Cells[1, 2].Display);
|
||||
Assert.Equal("$5,000.00", result.ReportTable.Cells[1, 3].Display);
|
||||
|
||||
Assert.Equal("Tiger", result.ReportTable.Cells[2, 0].Display);
|
||||
Assert.Equal("$1,500.00", result.ReportTable.Cells[2, 1].Display);
|
||||
Assert.Equal("-", result.ReportTable.Cells[2, 2].Display);
|
||||
Assert.Equal("$1,500.00", result.ReportTable.Cells[2, 3].Display);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetAuctionFeeReport_Two_Month_Set_Ok()
|
||||
{
|
||||
// arrange - should produce 4 rows with 3 columns... 2 months + total for columns and totals, two auctions, and null auctions row.
|
||||
var rawResults = new List<StdReportEntry>()
|
||||
{
|
||||
new StdReportEntry()
|
||||
{
|
||||
AuctionName = "Ted",
|
||||
RepoId = 1,
|
||||
SoldDate = DateTime.Parse("11/15/2019"),
|
||||
TotalCharges = 250
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
AuctionName = "Tiger",
|
||||
RepoId = 2,
|
||||
SoldDate = DateTime.Parse("11/10/2019"),
|
||||
TotalCharges = 150
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
AuctionName = "Tiger",
|
||||
RepoId = 3,
|
||||
SoldDate = DateTime.Parse("11/20/2019"),
|
||||
TotalCharges = 350
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
AuctionName = "Ted",
|
||||
RepoId = 4,
|
||||
SoldDate = DateTime.Parse("12/02/2019"),
|
||||
TotalCharges = 750
|
||||
}
|
||||
};
|
||||
_mockReportingRepository.Setup(x => x.GetAccountsByDateSoldInAutoIMS(It.IsAny<DateTime>(), It.IsAny<DateTime>()))
|
||||
.ReturnsAsync(rawResults);
|
||||
var highDate = DateTime.Parse("12/31/2019");
|
||||
var lowDate = DateTime.Parse("11/01/2019");
|
||||
var request = new ReportingRequest()
|
||||
{
|
||||
HighDate = highDate,
|
||||
LowDate = lowDate
|
||||
};
|
||||
|
||||
// act
|
||||
var result = await _auctionReportingService.GetAuctionFeeReport(request.LowDate, request.HighDate);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(4, result.DataTable.Rows.Count());
|
||||
Assert.Equal(12, result.ReportTable.Cells.Length); // 3 rows of 4.
|
||||
|
||||
// Assert Display
|
||||
Assert.Equal("All Auctions", result.ReportTable.Cells[0, 0].Display);
|
||||
Assert.Equal("$750.00", result.ReportTable.Cells[0, 1].Display);
|
||||
Assert.Equal("$750.00", result.ReportTable.Cells[0, 2].Display);
|
||||
Assert.Equal("$1,500.00", result.ReportTable.Cells[0, 3].Display);
|
||||
|
||||
Assert.Equal("Ted", result.ReportTable.Cells[1, 0].Display);
|
||||
Assert.Equal("$250.00", result.ReportTable.Cells[1, 1].Display);
|
||||
Assert.Equal("$750.00", result.ReportTable.Cells[1, 2].Display);
|
||||
Assert.Equal("$1,000.00", result.ReportTable.Cells[1, 3].Display);
|
||||
|
||||
Assert.Equal("Tiger", result.ReportTable.Cells[2, 0].Display);
|
||||
Assert.Equal("$500.00", result.ReportTable.Cells[2, 1].Display);
|
||||
Assert.Equal("-", result.ReportTable.Cells[2, 2].Display);
|
||||
Assert.Equal("$500.00", result.ReportTable.Cells[2, 3].Display);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetAvgDaysAssignedToSold_Two_Month_Set_Ok()
|
||||
{
|
||||
// arrange - should produce 4 rows with 3 columns... 2 months + total for columns and totals, two auctions, and null auctions row.
|
||||
var rawResults = new List<StdReportEntry>()
|
||||
{
|
||||
new StdReportEntry()
|
||||
{
|
||||
AuctionName = "Ted",
|
||||
RepoId = 1,
|
||||
DateEnteredAutoIMS = DateTime.Parse("11/05/2019"),
|
||||
SoldDate = DateTime.Parse("11/15/2019"),
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
AuctionName = "Tiger",
|
||||
RepoId = 2,
|
||||
DateEnteredAutoIMS = DateTime.Parse("11/05/2019"),
|
||||
SoldDate = DateTime.Parse("11/10/2019"),
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
AuctionName = "Tiger",
|
||||
RepoId = 3,
|
||||
DateEnteredAutoIMS = DateTime.Parse("11/05/2019"),
|
||||
SoldDate = DateTime.Parse("11/20/2019"),
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
AuctionName = "Ted",
|
||||
RepoId = 4,
|
||||
DateEnteredAutoIMS = DateTime.Parse("12/01/2019"),
|
||||
SoldDate = DateTime.Parse("12/02/2019"),
|
||||
}
|
||||
};
|
||||
_mockReportingRepository.Setup(x => x.GetAccountsByDateSoldInAutoIMS(It.IsAny<DateTime>(), It.IsAny<DateTime>()))
|
||||
.ReturnsAsync(rawResults);
|
||||
var highDate = DateTime.Parse("12/31/2019");
|
||||
var lowDate = DateTime.Parse("11/01/2019");
|
||||
var request = new ReportingRequest()
|
||||
{
|
||||
HighDate = highDate,
|
||||
LowDate = lowDate
|
||||
};
|
||||
|
||||
// act
|
||||
var result = await _auctionReportingService.GetAvgDaysAssignedToSold(request.LowDate, request.HighDate);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(4, result.DataTable.Rows.Count());
|
||||
Assert.Equal(12, result.ReportTable.Cells.Length); // 3 rows of 4.
|
||||
|
||||
// Assert Display
|
||||
Assert.Equal("All Auctions", result.ReportTable.Cells[0, 0].Display);
|
||||
Assert.Equal("10", result.ReportTable.Cells[0, 1].Display);
|
||||
Assert.Equal("1", result.ReportTable.Cells[0, 2].Display);
|
||||
Assert.Equal("8", result.ReportTable.Cells[0, 3].Display);
|
||||
|
||||
Assert.Equal("Ted", result.ReportTable.Cells[1, 0].Display);
|
||||
Assert.Equal("10", result.ReportTable.Cells[1, 1].Display);
|
||||
Assert.Equal("1", result.ReportTable.Cells[1, 2].Display);
|
||||
Assert.Equal("6", result.ReportTable.Cells[1, 3].Display);
|
||||
|
||||
Assert.Equal("Tiger", result.ReportTable.Cells[2, 0].Display);
|
||||
Assert.Equal("10", result.ReportTable.Cells[2, 1].Display);
|
||||
Assert.Equal("-", result.ReportTable.Cells[2, 2].Display);
|
||||
Assert.Equal("10", result.ReportTable.Cells[2, 3].Display);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetAvgNetOfFloor_Two_Month_Set_Ok()
|
||||
{
|
||||
// arrange - should produce 4 rows with 3 columns... 2 months + total for columns and totals, two auctions, and null auctions row.
|
||||
var rawResults = new List<StdReportEntry>()
|
||||
{
|
||||
new StdReportEntry()
|
||||
{
|
||||
AuctionName = "Ted",
|
||||
RepoId = 1,
|
||||
NetPercentFloor = 110,
|
||||
SoldDate = DateTime.Parse("11/15/2019"),
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
AuctionName = "Tiger",
|
||||
RepoId = 2,
|
||||
NetPercentFloor = 80,
|
||||
SoldDate = DateTime.Parse("11/10/2019"),
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
AuctionName = "Tiger",
|
||||
RepoId = 3,
|
||||
NetPercentFloor = 99.28m,
|
||||
SoldDate = DateTime.Parse("11/20/2019"),
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
AuctionName = "Ted",
|
||||
RepoId = 4,
|
||||
NetPercentFloor = 45,
|
||||
SoldDate = DateTime.Parse("12/02/2019"),
|
||||
}
|
||||
};
|
||||
_mockReportingRepository.Setup(x => x.GetAccountsByDateSoldInAutoIMS(It.IsAny<DateTime>(), It.IsAny<DateTime>()))
|
||||
.ReturnsAsync(rawResults);
|
||||
var highDate = DateTime.Parse("12/31/2019");
|
||||
var lowDate = DateTime.Parse("11/01/2019");
|
||||
var request = new ReportingRequest()
|
||||
{
|
||||
HighDate = highDate,
|
||||
LowDate = lowDate
|
||||
};
|
||||
|
||||
// act
|
||||
var result = await _auctionReportingService.GetAvgNetOfFloor(request.LowDate, request.HighDate);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(4, result.DataTable.Rows.Count());
|
||||
Assert.Equal(12, result.ReportTable.Cells.Length); // 3 rows of 4.
|
||||
|
||||
// Assert Display
|
||||
Assert.Equal("All Auctions", result.ReportTable.Cells[0, 0].Display);
|
||||
Assert.Equal("96.43 %", result.ReportTable.Cells[0, 1].Display);
|
||||
Assert.Equal("45.00 %", result.ReportTable.Cells[0, 2].Display);
|
||||
Assert.Equal("83.57 %", result.ReportTable.Cells[0, 3].Display);
|
||||
|
||||
Assert.Equal("Ted", result.ReportTable.Cells[1, 0].Display);
|
||||
Assert.Equal("110.00 %", result.ReportTable.Cells[1, 1].Display);
|
||||
Assert.Equal("45.00 %", result.ReportTable.Cells[1, 2].Display);
|
||||
Assert.Equal("77.50 %", result.ReportTable.Cells[1, 3].Display);
|
||||
|
||||
Assert.Equal("Tiger", result.ReportTable.Cells[2, 0].Display);
|
||||
Assert.Equal("89.64 %", result.ReportTable.Cells[2, 1].Display);
|
||||
Assert.Equal("-", result.ReportTable.Cells[2, 2].Display);
|
||||
Assert.Equal("89.64 %", result.ReportTable.Cells[2, 3].Display);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+311
@@ -0,0 +1,311 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
using Moq;
|
||||
using System.Linq;
|
||||
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using LCU.API.Collections.RepoApi.Models.Filters;
|
||||
using LCU.API.Collections.RepoApi.Models.Responses;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models.Results;
|
||||
using Castle.DynamicProxy.Generators;
|
||||
using LCU.API.Collections.RepoApi.Exceptions;
|
||||
using Xunit.Sdk;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class AuditRecordServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public async void ListAll_Ok()
|
||||
{
|
||||
PageFilter filter = new PageFilter()
|
||||
{
|
||||
Limit = 5,
|
||||
Page = 1
|
||||
};
|
||||
|
||||
var _mockAuditRecordRepo = new Mock<IAuditRecordRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockAuditRecordRepo.Setup(repo => repo.ListAllAsync(It.IsAny<int>(), It.IsAny<int>())).ReturnsAsync(new PagedResult<AuditRecord>() { Total = 1 });
|
||||
|
||||
AuditRecordService auditRecordService = new AuditRecordService(_mockAuditRecordRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
var res = await auditRecordService.ListAll(filter);
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(1,res.Total);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ListAll_Exception()
|
||||
{
|
||||
PageFilter filter = new PageFilter()
|
||||
{
|
||||
Limit = 5,
|
||||
Page = 1
|
||||
};
|
||||
|
||||
var _mockAuditRecordRepo = new Mock<IAuditRecordRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockAuditRecordRepo.Setup(repo => repo.ListAllAsync(It.IsAny<int>(), It.IsAny<int>())).ThrowsAsync(new Exception("oops"));
|
||||
|
||||
AuditRecordService auditRecordService = new AuditRecordService(_mockAuditRecordRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await auditRecordService.ListAll(filter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void SaveAsync_Ok()
|
||||
{
|
||||
|
||||
AuditRecord auditRecord = new AuditRecord()
|
||||
{
|
||||
ID = 5
|
||||
};
|
||||
|
||||
var _mockAuditRecordRepo = new Mock<IAuditRecordRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockAuditRecordRepo.Setup(repo => repo.AddAsync(It.IsAny<AuditRecord>())).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
AuditRecordService auditRecordService = new AuditRecordService(_mockAuditRecordRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
var res = await auditRecordService.SaveAsync(auditRecord);
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(auditRecord, res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void SaveAsync_Exception()
|
||||
{
|
||||
|
||||
AuditRecord auditRecord = new AuditRecord()
|
||||
{
|
||||
ID = 5
|
||||
};
|
||||
|
||||
var _mockAuditRecordRepo = new Mock<IAuditRecordRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockAuditRecordRepo.Setup(repo => repo.AddAsync(It.IsAny<AuditRecord>()));
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
AuditRecordService auditRecordService = new AuditRecordService(_mockAuditRecordRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await auditRecordService.SaveAsync(auditRecord));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_OK()
|
||||
{
|
||||
AuditRecord auditRecord = new AuditRecord()
|
||||
{
|
||||
ID = 5
|
||||
};
|
||||
|
||||
var _mockAuditRecordRepo = new Mock<IAuditRecordRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockAuditRecordRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(auditRecord);
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
AuditRecordService auditRecordService = new AuditRecordService(_mockAuditRecordRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
var res = await auditRecordService.Get(5);
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(auditRecord, res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Exception()
|
||||
{
|
||||
AuditRecord auditRecord = new AuditRecord()
|
||||
{
|
||||
ID = 5
|
||||
};
|
||||
|
||||
var _mockAuditRecordRepo = new Mock<IAuditRecordRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockAuditRecordRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ThrowsAsync(new Exception("oops"));
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
AuditRecordService auditRecordService = new AuditRecordService(_mockAuditRecordRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async() => await auditRecordService.Get(5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateAsync_OK()
|
||||
{
|
||||
AuditRecord auditRecord = new AuditRecord()
|
||||
{
|
||||
ID = 5
|
||||
};
|
||||
|
||||
var _mockAuditRecordRepo = new Mock<IAuditRecordRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockAuditRecordRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(auditRecord);
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
_mockAuditRecordRepo.Setup(repo => repo.Update(It.IsAny<AuditRecord>()));
|
||||
|
||||
AuditRecordService auditRecordService = new AuditRecordService(_mockAuditRecordRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
var res = await auditRecordService.UpdateAsync(auditRecord);
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(auditRecord,res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateAsync_Existing_Exception()
|
||||
{
|
||||
AuditRecord auditRecord = new AuditRecord()
|
||||
{
|
||||
ID = 5
|
||||
};
|
||||
|
||||
var _mockAuditRecordRepo = new Mock<IAuditRecordRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockAuditRecordRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ThrowsAsync(new Exception("oops"));
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
_mockAuditRecordRepo.Setup(repo => repo.Update(It.IsAny<AuditRecord>()));
|
||||
|
||||
AuditRecordService auditRecordService = new AuditRecordService(_mockAuditRecordRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await auditRecordService.UpdateAsync(auditRecord));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateAsync_Existing_Null()
|
||||
{
|
||||
AuditRecord auditRecord = new AuditRecord()
|
||||
{
|
||||
ID = 5
|
||||
};
|
||||
|
||||
var _mockAuditRecordRepo = new Mock<IAuditRecordRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockAuditRecordRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).Returns(Task.FromResult<AuditRecord>(null));
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
_mockAuditRecordRepo.Setup(repo => repo.Update(It.IsAny<AuditRecord>()));
|
||||
|
||||
AuditRecordService auditRecordService = new AuditRecordService(_mockAuditRecordRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<NotFoundException>(async () => await auditRecordService.UpdateAsync(auditRecord));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateAsync_Update_Exception()
|
||||
{
|
||||
AuditRecord auditRecord = new AuditRecord()
|
||||
{
|
||||
ID = 5
|
||||
};
|
||||
|
||||
var _mockAuditRecordRepo = new Mock<IAuditRecordRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockAuditRecordRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(auditRecord);
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
_mockAuditRecordRepo.Setup(repo => repo.Update(It.IsAny<AuditRecord>())).Throws(new Exception("oops"));
|
||||
|
||||
AuditRecordService auditRecordService = new AuditRecordService(_mockAuditRecordRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await auditRecordService.UpdateAsync(auditRecord));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DeleteAsync_OK()
|
||||
{
|
||||
AuditRecord auditRecord = new AuditRecord()
|
||||
{
|
||||
ID = 5
|
||||
};
|
||||
|
||||
var _mockAuditRecordRepo = new Mock<IAuditRecordRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockAuditRecordRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(auditRecord);
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
_mockAuditRecordRepo.Setup(repo => repo.Remove(It.IsAny<AuditRecord>()));
|
||||
|
||||
AuditRecordService auditRecordService = new AuditRecordService(_mockAuditRecordRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
var res = await auditRecordService.DeleteAsync(5);
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(auditRecord, res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DeleteAsync_Existing_Exception()
|
||||
{
|
||||
AuditRecord auditRecord = new AuditRecord()
|
||||
{
|
||||
ID = 5
|
||||
};
|
||||
|
||||
var _mockAuditRecordRepo = new Mock<IAuditRecordRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockAuditRecordRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ThrowsAsync(new Exception("oops"));
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
_mockAuditRecordRepo.Setup(repo => repo.Remove(It.IsAny<AuditRecord>()));
|
||||
|
||||
AuditRecordService auditRecordService = new AuditRecordService(_mockAuditRecordRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await auditRecordService.DeleteAsync(5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DeleteAsync_Existing_Null()
|
||||
{
|
||||
AuditRecord auditRecord = new AuditRecord()
|
||||
{
|
||||
ID = 5
|
||||
};
|
||||
|
||||
var _mockAuditRecordRepo = new Mock<IAuditRecordRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockAuditRecordRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).Returns(Task.FromResult<AuditRecord>(null));
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
_mockAuditRecordRepo.Setup(repo => repo.Remove(It.IsAny<AuditRecord>()));
|
||||
|
||||
AuditRecordService auditRecordService = new AuditRecordService(_mockAuditRecordRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<NotFoundException>(async () => await auditRecordService.DeleteAsync(5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DeleteAsync_Update_Exception()
|
||||
{
|
||||
AuditRecord auditRecord = new AuditRecord()
|
||||
{
|
||||
ID = 5
|
||||
};
|
||||
|
||||
var _mockAuditRecordRepo = new Mock<IAuditRecordRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockAuditRecordRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(auditRecord);
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
_mockAuditRecordRepo.Setup(repo => repo.Remove(It.IsAny<AuditRecord>())).Throws(new Exception("oops"));
|
||||
|
||||
AuditRecordService auditRecordService = new AuditRecordService(_mockAuditRecordRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await auditRecordService.DeleteAsync(5));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using LCU.API.Collections.RepoApi.Configuration;
|
||||
using LCU.API.Collections.RepoApi.HostedServices;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.API.Collections.RepoApi.Services.AutoIms;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using Microsoft.AspNetCore.Identity.UI.V3.Pages.Internal.Account.Manage;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class AutoImsServiceTest
|
||||
{
|
||||
private readonly AutoImsService _autoImsProcessor;
|
||||
private readonly Mock<IImsAutoFileDataConverter> mockImsAutoFileDataConverter;
|
||||
private readonly Mock<IImsAutoFileNoteConverter> mockImsAutoFileNoteConverter;
|
||||
private readonly Mock<IAutoImsDownloaderService> mockDownloader;
|
||||
private readonly RepoApiConfiguration testConfig;
|
||||
private readonly Mock<IAutoImsImporterService> mockAutoImsImporterService;
|
||||
private readonly Mock<IEmailer> mockEmailer;
|
||||
|
||||
public AutoImsServiceTest()
|
||||
{
|
||||
mockImsAutoFileDataConverter = new Mock<IImsAutoFileDataConverter>();
|
||||
mockImsAutoFileNoteConverter = new Mock<IImsAutoFileNoteConverter>();
|
||||
mockDownloader = new Mock<IAutoImsDownloaderService>();
|
||||
testConfig = new RepoApiConfiguration()
|
||||
{
|
||||
CheckForLocalFiles = true,
|
||||
DownloadNewFiles = true,
|
||||
MoveProcessedFiles = false,
|
||||
LocalDirectoryPath = ".\\SampleData",
|
||||
RemoteFilePath = "."
|
||||
};
|
||||
mockAutoImsImporterService = new Mock<IAutoImsImporterService>();
|
||||
mockEmailer = new Mock<IEmailer>();
|
||||
|
||||
_autoImsProcessor = new AutoImsService(mockDownloader.Object,
|
||||
testConfig, mockAutoImsImporterService.Object, mockImsAutoFileDataConverter.Object,
|
||||
mockImsAutoFileNoteConverter.Object, mockEmailer.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Test_Download_Exception()
|
||||
{
|
||||
mockDownloader.Setup(down => down.DownLoadAuctionFiles()).Throws(new Exception("oops"));
|
||||
mockDownloader.Setup(down => down.CombineWithLocalFiles(It.IsAny<Dictionary<FileInfo,string>>())).Returns(new Dictionary<FileInfo, string>() { { new FileInfo("filename"), "test1" } });
|
||||
|
||||
var res = _autoImsProcessor.Download();
|
||||
Assert.NotNull(res);
|
||||
Assert.Empty(res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Basic_Download_Test()
|
||||
{
|
||||
mockDownloader.Setup(service => service.DownLoadAuctionFiles())
|
||||
.Verifiable("Call Download");
|
||||
mockDownloader.Setup(service => service.CombineWithLocalFiles(It.IsAny<Dictionary<FileInfo, string>>()))
|
||||
.Verifiable("Call Download");
|
||||
mockDownloader.Setup(service => service.ConvertToFileList(It.IsAny<Dictionary<FileInfo, string>>()))
|
||||
.Returns(
|
||||
new List<FileInfo>());
|
||||
Assert.True(testConfig.DownloadNewFiles);
|
||||
Assert.True(testConfig.CheckForLocalFiles);
|
||||
var files = _autoImsProcessor.Download();
|
||||
mockDownloader.VerifyAll();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProcessDownloadedFiles_Ok()
|
||||
{
|
||||
var fileInfos = new List<FileInfo>() { new FileInfo("Test1"), new FileInfo("Test2") };
|
||||
|
||||
_autoImsProcessor.ProcessDownloadedFiles(fileInfos);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProcessDownloadedFiles_Exception()
|
||||
{
|
||||
List<FileInfo> fileInfos = null;
|
||||
|
||||
Assert.Throws<Exception>(() => _autoImsProcessor.ProcessDownloadedFiles(fileInfos));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Basic_Construct_Test()
|
||||
{
|
||||
Assert.NotNull(_autoImsProcessor);
|
||||
Assert.Throws<Exception>(() => { _autoImsProcessor.ProcessDownloadedFiles(null); });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void No_Files_Test()
|
||||
{
|
||||
testConfig.DownloadNewFiles = false;
|
||||
testConfig.CheckForLocalFiles = false;
|
||||
mockDownloader.Setup(service => service.DownLoadAuctionFiles())
|
||||
.Verifiable("Call Download");
|
||||
mockDownloader.Setup(service => service.CombineWithLocalFiles(It.IsAny<Dictionary<FileInfo, string>>()))
|
||||
.Verifiable("Call Download");
|
||||
mockDownloader.Setup(service => service.ConvertToFileList(It.IsAny<Dictionary<FileInfo, string>>()))
|
||||
.Returns(
|
||||
new List<FileInfo>());
|
||||
Assert.False(testConfig.DownloadNewFiles);
|
||||
Assert.False(testConfig.CheckForLocalFiles);
|
||||
var files = _autoImsProcessor.Download();
|
||||
mockDownloader.Verify(foo => foo.DownLoadAuctionFiles(), Times.Never());
|
||||
mockDownloader.Verify(foo => foo.CombineWithLocalFiles(It.IsAny<Dictionary<FileInfo, string>>()),
|
||||
Times.Never());
|
||||
}
|
||||
}
|
||||
}
|
||||
+277
@@ -0,0 +1,277 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.API.Collections.RepoApi.Exceptions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class CollateralServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public async void ListAll_Ok()
|
||||
{
|
||||
var _mockCollateralRepo = new Mock<ICollateralRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockCollateralRepo.Setup(repo => repo.ListAllAsync()).ReturnsAsync(new List<Collateral>() { new Collateral() { }, new Collateral() { } });
|
||||
|
||||
CollateralService collateralService = new CollateralService(_mockCollateralRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
var res = await collateralService.ListAll();
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(2, res.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async System.Threading.Tasks.Task ListAll_Exception()
|
||||
{
|
||||
var _mockCollateralRepo = new Mock<ICollateralRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockCollateralRepo.Setup(repo => repo.ListAllAsync()).ThrowsAsync(new Exception("oops"));
|
||||
|
||||
CollateralService collateralService = new CollateralService(_mockCollateralRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(() => collateralService.ListAll());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void SaveAsync_Ok()
|
||||
{
|
||||
Collateral collateral = new Collateral()
|
||||
{
|
||||
Make = "Sienar Fleet Systems",
|
||||
Model = "TIE/ln space superiority starfighter",
|
||||
BodyStyle = "Starfighter",
|
||||
CollateralId = 12345
|
||||
};
|
||||
|
||||
var _mockCollateralRepo = new Mock<ICollateralRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockCollateralRepo.Setup(repo => repo.AddAsync(It.IsAny<Collateral>())).ReturnsAsync(collateral);
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
CollateralService collateralService = new CollateralService(_mockCollateralRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
var res = await collateralService.SaveAsync(collateral);
|
||||
|
||||
Assert.Equal(collateral, res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void SaveAsync_Exception()
|
||||
{
|
||||
Collateral collateral = new Collateral()
|
||||
{
|
||||
Make = "Sienar Fleet Systems",
|
||||
Model = "TIE/ln space superiority starfighter",
|
||||
BodyStyle = "Starfighter",
|
||||
CollateralId = 12345
|
||||
};
|
||||
|
||||
var _mockCollateralRepo = new Mock<ICollateralRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockCollateralRepo.Setup(repo => repo.AddAsync(It.Is<Collateral>(param => param == collateral))).ThrowsAsync(new Exception("oops"));
|
||||
|
||||
CollateralService collateralService = new CollateralService(_mockCollateralRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await collateralService.SaveAsync(collateral));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Exception()
|
||||
{
|
||||
Collateral collateral = new Collateral()
|
||||
{
|
||||
Make = "Sienar Fleet Systems",
|
||||
Model = "TIE/ln space superiority starfighter",
|
||||
BodyStyle = "Starfighter",
|
||||
CollateralId = 12345
|
||||
};
|
||||
|
||||
var _mockCollateralRepo = new Mock<ICollateralRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockCollateralRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ThrowsAsync(new Exception("oops"));
|
||||
|
||||
CollateralService collateralService = new CollateralService(_mockCollateralRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await collateralService.Get(12345));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Null_Exception()
|
||||
{
|
||||
Collateral collateral = new Collateral()
|
||||
{
|
||||
Make = "Sienar Fleet Systems",
|
||||
Model = "TIE/ln space superiority starfighter",
|
||||
BodyStyle = "Starfighter",
|
||||
CollateralId = 12345
|
||||
};
|
||||
|
||||
var _mockCollateralRepo = new Mock<ICollateralRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockCollateralRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).Returns(Task.FromResult<Collateral>(null));
|
||||
|
||||
CollateralService collateralService = new CollateralService(_mockCollateralRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<NotFoundException>(async () => await collateralService.Get(12345));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Ok()
|
||||
{
|
||||
Collateral collateral = new Collateral()
|
||||
{
|
||||
Make = "Sienar Fleet Systems",
|
||||
Model = "TIE/ln space superiority starfighter",
|
||||
BodyStyle = "Starfighter",
|
||||
CollateralId = 12345
|
||||
};
|
||||
|
||||
var _mockCollateralRepo = new Mock<ICollateralRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockCollateralRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(collateral);
|
||||
|
||||
CollateralService collateralService = new CollateralService(_mockCollateralRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
var res = await collateralService.Get(12345);
|
||||
Assert.Equal(collateral, res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateAsync_Ok()
|
||||
{
|
||||
Collateral collateral = new Collateral()
|
||||
{
|
||||
Make = "Sienar Fleet Systems",
|
||||
Model = "TIE/ln space superiority starfighter",
|
||||
BodyStyle = "Starfighter",
|
||||
CollateralId = 12345,
|
||||
Vin = "r2d2c3p0",
|
||||
Year = 10,
|
||||
Description = "starfighter of choice for the Galactic Empire",
|
||||
VehicleType = 5,
|
||||
Inoperable = false,
|
||||
CollateralTypeId = 1,
|
||||
RetitledInLandmarkName = DateTime.Now
|
||||
};
|
||||
|
||||
var _mockCollateralRepo = new Mock<ICollateralRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockCollateralRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(collateral);
|
||||
_mockCollateralRepo.Setup(repo => repo.Update(It.Is<Collateral>(param => param.Vin == "r2d2c3p0")));
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
CollateralService collateralService = new CollateralService(_mockCollateralRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
var res = await collateralService.UpdateAsync(collateral);
|
||||
Assert.Equal(collateral, res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateAsync_Existing_Null()
|
||||
{
|
||||
Collateral collateral = new Collateral()
|
||||
{
|
||||
Make = "Sienar Fleet Systems",
|
||||
Model = "TIE/ln space superiority starfighter",
|
||||
BodyStyle = "Starfighter",
|
||||
CollateralId = 12345,
|
||||
Vin = "r2d2c3p0",
|
||||
Year = 10,
|
||||
Description = "starfighter of choice for the Galactic Empire",
|
||||
VehicleType = 5,
|
||||
Inoperable = false,
|
||||
CollateralTypeId = 1,
|
||||
RetitledInLandmarkName = DateTime.Now
|
||||
};
|
||||
|
||||
var _mockCollateralRepo = new Mock<ICollateralRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockCollateralRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).Returns(Task.FromResult<Collateral>(null));
|
||||
_mockCollateralRepo.Setup(repo => repo.Update(It.Is<Collateral>(param => param.Vin == "r2d2c3p0")));
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
CollateralService collateralService = new CollateralService(_mockCollateralRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<NotFoundException>(async () => await collateralService.UpdateAsync(collateral));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateAsync_Existing_Exception()
|
||||
{
|
||||
Collateral collateral = new Collateral()
|
||||
{
|
||||
Make = "Sienar Fleet Systems",
|
||||
Model = "TIE/ln space superiority starfighter",
|
||||
BodyStyle = "Starfighter",
|
||||
CollateralId = 12345,
|
||||
Vin = "r2d2c3p0",
|
||||
Year = 10,
|
||||
Description = "starfighter of choice for the Galactic Empire",
|
||||
VehicleType = 5,
|
||||
Inoperable = false,
|
||||
CollateralTypeId = 1,
|
||||
RetitledInLandmarkName = DateTime.Now
|
||||
};
|
||||
|
||||
var _mockCollateralRepo = new Mock<ICollateralRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockCollateralRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ThrowsAsync(new Exception("oops"));
|
||||
_mockCollateralRepo.Setup(repo => repo.Update(It.Is<Collateral>(param => param.Vin == "r2d2c3p0")));
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
CollateralService collateralService = new CollateralService(_mockCollateralRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await collateralService.UpdateAsync(collateral));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateAsync_Update_Exception()
|
||||
{
|
||||
Collateral collateral = new Collateral()
|
||||
{
|
||||
Make = "Sienar Fleet Systems",
|
||||
Model = "TIE/ln space superiority starfighter",
|
||||
BodyStyle = "Starfighter",
|
||||
CollateralId = 12345,
|
||||
Vin = "r2d2c3p0",
|
||||
Year = 10,
|
||||
Description = "starfighter of choice for the Galactic Empire",
|
||||
VehicleType = 5,
|
||||
Inoperable = false,
|
||||
CollateralTypeId = 1,
|
||||
RetitledInLandmarkName = DateTime.Now
|
||||
};
|
||||
|
||||
var _mockCollateralRepo = new Mock<ICollateralRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockCollateralRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(collateral);
|
||||
_mockCollateralRepo.Setup(repo => repo.Update(It.Is<Collateral>(param => param.Vin == "r2d2c3p0"))).Throws(new Exception("oops"));
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
CollateralService collateralService = new CollateralService(_mockCollateralRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await collateralService.UpdateAsync(collateral));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+739
@@ -0,0 +1,739 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Castle.DynamicProxy.Generators;
|
||||
using LCU.API.Collections.RepoApi.Exceptions;
|
||||
using LCU.API.Collections.RepoApi.Models;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.Shared.Collections.RepoApiLib.Exceptions;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using Xunit.Sdk;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class EventAlertServiceTest
|
||||
{
|
||||
[Fact]
|
||||
public async void ListAll_Ok()
|
||||
{
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.ListAllAsync()).ReturnsAsync(new List<EventAlert>() { new EventAlert(), new EventAlert(), new EventAlert() });
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
var res = await eventAlertService.ListAll();
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(3, res.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ListAll_Exception()
|
||||
{
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.ListAllAsync()).ThrowsAsync(new Exception("oops"));
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await eventAlertService.ListAll());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ListUnread_Ok()
|
||||
{
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.ListUnreadAsync()).ReturnsAsync(new List<EventAlert>() { new EventAlert(), new EventAlert(), new EventAlert() });
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
var res = await eventAlertService.ListUnread();
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(3, res.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ListUnread_Exception()
|
||||
{
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.ListUnreadAsync()).ThrowsAsync(new Exception("oops"));
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await eventAlertService.ListUnread());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ListWithinDateRange_OK()
|
||||
{
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.ListWithinDateRangeAsync(It.IsAny<DateTime>(), It.IsAny<DateTime>())).ReturnsAsync(new List<EventAlert>() { new EventAlert(), new EventAlert(), new EventAlert() });
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
var res = await eventAlertService.ListWithinDateRange(DateTime.Now, DateTime.Now.AddDays(5));
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(3, res.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ListWithinDateRange_Exception()
|
||||
{
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.ListWithinDateRangeAsync(It.IsAny<DateTime>(), It.IsAny<DateTime>())).ThrowsAsync(new Exception("oops"));
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await eventAlertService.ListWithinDateRange(DateTime.Now, DateTime.Now.AddDays(5)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ListActionNeeded_Exception()
|
||||
{
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.ListRepoNoAuctionAsync()).ReturnsAsync(new List<EventAlert>() { new EventAlert(), new EventAlert() });
|
||||
mockEventAlertRepository.Setup(repo => repo.ListRepoNoCompanyAsync()).ReturnsAsync(new List<EventAlert>() { new EventAlert() });
|
||||
mockEventAlertRepository.Setup(repo => repo.ListO4rNoCompanyAsync()).ReturnsAsync(new List<EventAlert>() { new EventAlert(), new EventAlert() });
|
||||
mockEventAlertRepository.Setup(repo => repo.ListReadyForRetitleAsync()).ReturnsAsync(new List<EventAlert>() { new EventAlert(), new EventAlert(), new EventAlert() });
|
||||
mockEventAlertRepository.Setup(repo => repo.ListFloorUpdateFailedAsync()).ThrowsAsync(new Exception("oops"));
|
||||
mockEventAlertRepository.Setup(repo => repo.ListFloorNeedsSettingAsync()).ReturnsAsync(new List<EventAlert>() { new EventAlert(), new EventAlert(), new EventAlert() });
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await eventAlertService.ListActionNeeded());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ListActionNeeded_OK()
|
||||
{
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.ListRepoNoAuctionAsync()).ReturnsAsync(new List<EventAlert>() { new EventAlert(), new EventAlert() });
|
||||
mockEventAlertRepository.Setup(repo => repo.ListRepoNoCompanyAsync()).ReturnsAsync(new List<EventAlert>() { new EventAlert() });
|
||||
mockEventAlertRepository.Setup(repo => repo.ListO4rNoCompanyAsync()).ReturnsAsync(new List<EventAlert>() { new EventAlert(), new EventAlert() });
|
||||
mockEventAlertRepository.Setup(repo => repo.ListReadyForRetitleAsync()).ReturnsAsync(new List<EventAlert>() { new EventAlert(), new EventAlert(), new EventAlert() });
|
||||
mockEventAlertRepository.Setup(repo => repo.ListFloorUpdateFailedAsync()).ReturnsAsync(new List<EventAlert>() { new EventAlert() });
|
||||
mockEventAlertRepository.Setup(repo => repo.ListFloorNeedsSettingAsync()).ReturnsAsync(new List<EventAlert>() { new EventAlert(), new EventAlert(), new EventAlert() });
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
var res = await eventAlertService.ListActionNeeded();
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(12, res.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void SaveAsync_OK()
|
||||
{
|
||||
EventAlert eventAlert = new EventAlert()
|
||||
{
|
||||
Id = 5,
|
||||
RepoId = 100
|
||||
};
|
||||
|
||||
RepoAccount account = new RepoAccount()
|
||||
{
|
||||
RepoId = 100,
|
||||
Status = "O4R"
|
||||
};
|
||||
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.AddAsync(It.Is<EventAlert>(param => param.Id == 5))).Returns(Task.CompletedTask);
|
||||
mockRepoRepository.Setup(repo => repo.FindByIdAsync(It.Is<Int32>(param => param == 100))).Returns(Task.FromResult(account));
|
||||
mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
var res = await eventAlertService.SaveAsync(eventAlert);
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(eventAlert, res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void SaveAsync_DuplicateResource_Exception()
|
||||
{
|
||||
EventAlert eventAlert = new EventAlert()
|
||||
{
|
||||
Id = 5,
|
||||
RepoId = 100,
|
||||
Message = "RTC Letter Not Found"
|
||||
};
|
||||
|
||||
RepoAccount account = new RepoAccount()
|
||||
{
|
||||
RepoId = 100,
|
||||
Status = "RTC Letter Not Found"
|
||||
};
|
||||
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.AddAsync(It.Is<EventAlert>(param => param.Id == 5))).ThrowsAsync(new DuplicateResourceException("resource"));
|
||||
mockRepoRepository.Setup(repo => repo.FindByIdAsync(It.Is<Int32>(param => param == 100))).Returns(Task.FromResult(account));
|
||||
mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
await Assert.ThrowsAsync<DuplicateResourceException>(async () => await eventAlertService.SaveAsync(eventAlert));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void SaveAsync_Exception()
|
||||
{
|
||||
EventAlert eventAlert = new EventAlert()
|
||||
{
|
||||
Id = 5
|
||||
};
|
||||
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.AddAsync(It.Is<EventAlert>(param => param.Id == 5))).ThrowsAsync(new Exception("oops"));
|
||||
mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await eventAlertService.SaveAsync(eventAlert));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void saveRangeAsync_Ok()
|
||||
{
|
||||
List<EventAlert> range = new List<EventAlert>() { new EventAlert(), new EventAlert(), new EventAlert() };
|
||||
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
mockEventAlertRepository.Setup(repo => repo.AddRangeAsync(It.Is<List<EventAlert>>(param => param.Count() == 3))).ReturnsAsync(new List<EventAlert>() { new EventAlert(), new EventAlert() });
|
||||
mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
var res = await eventAlertService.SaveRangeAsync(range);
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(2, res.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void saveRangeAsync_Exception()
|
||||
{
|
||||
List<EventAlert> range = new List<EventAlert>() { new EventAlert(), new EventAlert(), new EventAlert() };
|
||||
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.AddRangeAsync(It.Is<List<EventAlert>>(param => param.Count() == 3))).ThrowsAsync(new Exception("oops"));
|
||||
mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
var res = await eventAlertService.SaveRangeAsync(range);
|
||||
Assert.NotNull(res);
|
||||
Assert.Empty(res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Ok()
|
||||
{
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
mockEventAlertRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(new EventAlert() { Id = 5 });
|
||||
mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
var res = await eventAlertService.Get(5);
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(5, res.Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Exception()
|
||||
{
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
mockEventAlertRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ThrowsAsync(new Exception("Oops"));
|
||||
mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await eventAlertService.Get(5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Null_Exception()
|
||||
{
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
mockEventAlertRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).Returns(Task.FromResult<EventAlert>(null));
|
||||
mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
await Assert.ThrowsAsync<NotFoundException>(async () => await eventAlertService.Get(5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Null()
|
||||
{
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).Returns(Task.FromResult<EventAlert>(null));
|
||||
|
||||
var eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
var dummyAlert = new EventAlert
|
||||
{
|
||||
Message = "Message",
|
||||
DateMarkedRead = DateTime.Now,
|
||||
CreatedBy = "Some Guy"
|
||||
};
|
||||
|
||||
var dummyUser = new AppUser
|
||||
{
|
||||
FirstName = "John",
|
||||
LastName = "Doe"
|
||||
};
|
||||
|
||||
await Assert.ThrowsAsync<NotFoundException>(async () => await eventAlertService.UpdateAsync(dummyAlert, dummyUser));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Exception()
|
||||
{
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(new EventAlert());
|
||||
|
||||
var eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
var dummyAlert = new EventAlert
|
||||
{
|
||||
Message = "Message",
|
||||
DateMarkedRead = DateTime.Now,
|
||||
CreatedBy = "Some Guy"
|
||||
};
|
||||
|
||||
var dummyUser = new AppUser
|
||||
{
|
||||
FirstName = "John",
|
||||
LastName = "Doe"
|
||||
};
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.Update(It.IsAny<EventAlert>())).Throws(new Exception("oops"));
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await eventAlertService.UpdateAsync(dummyAlert, dummyUser));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Ok()
|
||||
{
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(new EventAlert());
|
||||
|
||||
var eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
var dummyAlert = new EventAlert
|
||||
{
|
||||
Message = "Message",
|
||||
DateMarkedRead = DateTime.Now,
|
||||
CreatedBy = "Some Guy"
|
||||
};
|
||||
|
||||
var dummyUser = new AppUser
|
||||
{
|
||||
FirstName = "John",
|
||||
LastName = "Doe"
|
||||
};
|
||||
|
||||
var result = await eventAlertService.UpdateAsync(dummyAlert, dummyUser);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(dummyAlert.DateMarkedRead, result.DateMarkedRead);
|
||||
Assert.Equal("Message", result.Message);
|
||||
Assert.Equal("John Doe", result.MarkedReadBy);
|
||||
Assert.Null(result.CreatedBy);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Existing_Exception()
|
||||
{
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).Throws(new Exception("oops"));
|
||||
|
||||
var eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
var dummyAlert = new EventAlert
|
||||
{
|
||||
Message = "Message",
|
||||
DateMarkedRead = DateTime.Now,
|
||||
CreatedBy = "Some Guy"
|
||||
};
|
||||
|
||||
var dummyUser = new AppUser
|
||||
{
|
||||
FirstName = "John",
|
||||
LastName = "Doe"
|
||||
};
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await eventAlertService.UpdateAsync(dummyAlert, dummyUser));
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async void Duplicate_Add_Exception()
|
||||
{
|
||||
RepoAccount account = new RepoAccount()
|
||||
{
|
||||
RepoId = 100,
|
||||
Status = "RTC Letter Not Found"
|
||||
};
|
||||
EventAlert eventAlert = new EventAlert()
|
||||
{
|
||||
Id = 5,
|
||||
RepoId = 100
|
||||
};
|
||||
// arrange
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.AddAsync(It.Is<EventAlert>(param => param.Id == 5))).ThrowsAsync(new DuplicateResourceException("EventAlert"));
|
||||
mockRepoRepository.Setup(repo => repo.FindByIdAsync(It.Is<Int32>(param => param == 100))).Returns(Task.FromResult(account));
|
||||
var eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
// act / assert
|
||||
try
|
||||
{
|
||||
var result = await eventAlertService.SaveAsync(eventAlert);
|
||||
Assert.True(false, "An exception should have been thrown.");
|
||||
}
|
||||
catch (DuplicateResourceException ex)
|
||||
{
|
||||
Assert.Equal("Duplicate Resources of type EventAlert were found.", ex.Message);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Assert.True(false, "An exception other than DuplicateResourceException was thrown.");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DeleteAsync_Ok()
|
||||
{
|
||||
var dummyAlert = new EventAlert
|
||||
{
|
||||
Message = "Message",
|
||||
DateMarkedRead = DateTime.Now,
|
||||
CreatedBy = "Some Guy"
|
||||
};
|
||||
|
||||
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(dummyAlert);
|
||||
mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
mockEventAlertRepository.Setup(repo => repo.Remove(It.Is<EventAlert>(param => param.Message == "message")));
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
var res = await eventAlertService.DeleteAsync(5);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DeleteAsync_Null()
|
||||
{
|
||||
var dummyAlert = new EventAlert
|
||||
{
|
||||
Message = "Message",
|
||||
DateMarkedRead = DateTime.Now,
|
||||
CreatedBy = "Some Guy"
|
||||
};
|
||||
|
||||
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).Returns(Task.FromResult<EventAlert>(null));
|
||||
mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
mockEventAlertRepository.Setup(repo => repo.Remove(It.Is<EventAlert>(param => param.Message == "message")));
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
await Assert.ThrowsAsync<NotFoundException>(async () => await eventAlertService.DeleteAsync(5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DeleteAsync_Remove_Exception()
|
||||
{
|
||||
var dummyAlert = new EventAlert
|
||||
{
|
||||
Message = "Message",
|
||||
DateMarkedRead = DateTime.Now,
|
||||
CreatedBy = "Some Guy"
|
||||
};
|
||||
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(dummyAlert);
|
||||
mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
mockEventAlertRepository.Setup(repo => repo.Remove(It.Is<EventAlert>(param => param.Message == "Message"))).Throws(new Exception("oops"));
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await eventAlertService.DeleteAsync(5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DeleteAsync_Existing_Exception()
|
||||
{
|
||||
var dummyAlert = new EventAlert
|
||||
{
|
||||
Message = "Message",
|
||||
DateMarkedRead = DateTime.Now,
|
||||
CreatedBy = "Some Guy"
|
||||
};
|
||||
|
||||
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).Throws(new Exception("oops"));
|
||||
mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
mockEventAlertRepository.Setup(repo => repo.Remove(It.Is<EventAlert>(param => param.Message == "message")));
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await eventAlertService.DeleteAsync(5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void MarkAllAsRead_OK()
|
||||
{
|
||||
var alertList = new List<EventAlert> {
|
||||
new EventAlert
|
||||
{
|
||||
Id = 1,
|
||||
Message = "Message",
|
||||
CreatedBy = "Some Guy",
|
||||
AccountNo = "123-04566"
|
||||
},
|
||||
new EventAlert
|
||||
{
|
||||
Id = 2,
|
||||
Message = "Message",
|
||||
CreatedBy = "Some Guy",
|
||||
AccountNo = "123-04566"
|
||||
},
|
||||
new EventAlert
|
||||
{
|
||||
Id = 3,
|
||||
Message = "Message",
|
||||
CreatedBy = "Some Guy",
|
||||
AccountNo = "123-04566"
|
||||
}
|
||||
};
|
||||
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.ListUnreadByAccountNoAsync(It.IsAny<string>())).ReturnsAsync(alertList);
|
||||
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
var result = await eventAlertService.MarkAllAsRead("123-04566");
|
||||
|
||||
mockUnitOfWork.Verify(m => m.CompleteAsync(), Times.Once());
|
||||
mockEventAlertRepository.Verify(m => m.Update(It.IsAny<EventAlert>()), Times.Exactly(3));
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(3, result.Count());
|
||||
Assert.Equal(alertList, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void MarkAllAsRead_NotFoundException()
|
||||
{
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.ListUnreadByAccountNoAsync(It.IsAny<string>())).Returns(Task.FromResult<IEnumerable<EventAlert>>(null));
|
||||
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
await Assert.ThrowsAsync<NotFoundException>(async () => await eventAlertService.MarkAllAsRead("123-04566"));
|
||||
|
||||
mockUnitOfWork.Verify(m => m.CompleteAsync(), Times.Never());
|
||||
mockEventAlertRepository.Verify(m => m.Update(It.IsAny<EventAlert>()), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void MarkAllAsRead_Existing_Exception()
|
||||
{
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.ListUnreadByAccountNoAsync(It.IsAny<string>())).ThrowsAsync(new Exception("oops"));
|
||||
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await eventAlertService.MarkAllAsRead("123-04566"));
|
||||
|
||||
mockUnitOfWork.Verify(m => m.CompleteAsync(), Times.Never());
|
||||
mockEventAlertRepository.Verify(m => m.Update(It.IsAny<EventAlert>()), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void MarkAllAsRead_Update_Exception()
|
||||
{
|
||||
var alertList = new List<EventAlert> {
|
||||
new EventAlert
|
||||
{
|
||||
Id = 1,
|
||||
Message = "Message",
|
||||
CreatedBy = "Some Guy",
|
||||
AccountNo = "123-04566"
|
||||
},
|
||||
new EventAlert
|
||||
{
|
||||
Id = 2,
|
||||
Message = "Message",
|
||||
CreatedBy = "Some Guy",
|
||||
AccountNo = "123-04566"
|
||||
},
|
||||
new EventAlert
|
||||
{
|
||||
Id = 3,
|
||||
Message = "Message",
|
||||
CreatedBy = "Some Guy",
|
||||
AccountNo = "123-04566"
|
||||
}
|
||||
};
|
||||
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.ListUnreadByAccountNoAsync(It.IsAny<string>())).ReturnsAsync(alertList);
|
||||
mockEventAlertRepository.Setup(m => m.Update(It.IsAny<EventAlert>())).Throws(new Exception("oops"));
|
||||
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await eventAlertService.MarkAllAsRead("123-04566"));
|
||||
|
||||
mockUnitOfWork.Verify(m => m.CompleteAsync(), Times.Never());
|
||||
mockEventAlertRepository.Verify(m => m.Update(It.IsAny<EventAlert>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void MarkAllAsRead_Update_Exception_On_2nd()
|
||||
{
|
||||
var count = 0;
|
||||
var alertList = new List<EventAlert> {
|
||||
new EventAlert
|
||||
{
|
||||
Id = 1,
|
||||
Message = "Message",
|
||||
CreatedBy = "Some Guy",
|
||||
AccountNo = "123-04566"
|
||||
},
|
||||
new EventAlert
|
||||
{
|
||||
Id = 2,
|
||||
Message = "Message",
|
||||
CreatedBy = "Some Guy",
|
||||
AccountNo = "123-04566"
|
||||
},
|
||||
new EventAlert
|
||||
{
|
||||
Id = 3,
|
||||
Message = "Message",
|
||||
CreatedBy = "Some Guy",
|
||||
AccountNo = "123-04566"
|
||||
}
|
||||
};
|
||||
|
||||
var mockEventAlertRepository = new Mock<IEventAlertRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
var mockRepoRepository = new Mock<IRepoAccountRepository>();
|
||||
|
||||
mockEventAlertRepository.Setup(repo => repo.ListUnreadByAccountNoAsync(It.IsAny<string>())).ReturnsAsync(alertList);
|
||||
mockEventAlertRepository.Setup(m => m.Update(It.IsAny<EventAlert>())).Callback(() =>
|
||||
{
|
||||
count++;
|
||||
if (count == 2)
|
||||
{
|
||||
throw new Exception("oops");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
EventAlertService eventAlertService = new EventAlertService(mockEventAlertRepository.Object, mockUnitOfWork.Object, mockRepoRepository.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await eventAlertService.MarkAllAsRead("123-04566"));
|
||||
|
||||
mockUnitOfWork.Verify(m => m.CompleteAsync(), Times.Never());
|
||||
mockEventAlertRepository.Verify(m => m.Update(It.IsAny<EventAlert>()), Times.Exactly(2));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+363
@@ -0,0 +1,363 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class FactoidServiceTest
|
||||
{
|
||||
private IFactoidService _factoidService;
|
||||
private Mock<IReportingRepository> _mockReportingRepository;
|
||||
private Mock<IRepoAccountRepository> _mockRepoAccountRepository;
|
||||
private Mock<IImsAutoFileDataRepository> _mockImsAutoFileDataRepository;
|
||||
|
||||
public FactoidServiceTest()
|
||||
{
|
||||
_mockReportingRepository = new Mock<IReportingRepository>();
|
||||
_mockRepoAccountRepository = new Mock<IRepoAccountRepository>();
|
||||
_mockImsAutoFileDataRepository = new Mock<IImsAutoFileDataRepository>();
|
||||
_factoidService = new FactoidService(_mockReportingRepository.Object, _mockRepoAccountRepository.Object,
|
||||
_mockImsAutoFileDataRepository.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Find_Auction_Index()
|
||||
{
|
||||
// arrange
|
||||
var auctionHouses = new List<string>()
|
||||
{
|
||||
"Gross Active Balance", "a1", "a2", "No Auction"
|
||||
};
|
||||
|
||||
// act
|
||||
var result = _factoidService.FindAuctionIndex(auctionHouses, "A1");
|
||||
var result2 = _factoidService.FindAuctionIndex(auctionHouses, null);
|
||||
var result3 = _factoidService.FindAuctionIndex(auctionHouses, "A3");
|
||||
|
||||
// assert
|
||||
Assert.Equal(1, result);
|
||||
Assert.Equal(3, result2);
|
||||
Assert.Equal(3, result3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_All_Accounts_O4R_Ok()
|
||||
{
|
||||
// arrange
|
||||
_mockReportingRepository.Setup(x => x.GetAllAccountsInO4R()).ReturnsAsync(new List<RepoAccount>()
|
||||
{
|
||||
new RepoAccount(),
|
||||
new RepoAccount()
|
||||
});
|
||||
|
||||
// act
|
||||
var result = await _factoidService.GetAllAccountsO4R();
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("Accounts", result.Name);
|
||||
Assert.Equal("Total Accounts in O4R", result.Description);
|
||||
Assert.Equal("fa-car", result.FontAwesomeIcon);
|
||||
Assert.Equal("2", result.CumulativeValue);
|
||||
Assert.Equal(2, result.Records.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Percent_Floor_Price_Ok()
|
||||
{
|
||||
// arrange
|
||||
var fakeAutoIms = new List<ImsAutoFileData>()
|
||||
{
|
||||
new ImsAutoFileData() {GrossPercentFloor = 50, RepoId = 111},
|
||||
new ImsAutoFileData() {GrossPercentFloor = 100, RepoId = 111}
|
||||
};
|
||||
var fakeAccounts = new List<RepoAccount>()
|
||||
{
|
||||
new RepoAccount(),
|
||||
new RepoAccount()
|
||||
};
|
||||
var highDate = DateTime.Parse("12/31/2019");
|
||||
var lowDate = DateTime.Parse("11/01/2019");
|
||||
_mockImsAutoFileDataRepository
|
||||
.Setup(x => x.GetImsSoldRecordsForPeriod(It.IsAny<DateTime>(), It.IsAny<DateTime>()))
|
||||
.ReturnsAsync(fakeAutoIms);
|
||||
|
||||
_mockRepoAccountRepository.Setup(
|
||||
x => x.FindByRepoIdAsync(It.IsAny<List<string>>()))
|
||||
.ReturnsAsync(fakeAccounts);
|
||||
|
||||
// act
|
||||
var result = await _factoidService.GetPercentFloorPrice(lowDate, highDate);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("Percentage of Floor", result.Name);
|
||||
Assert.Equal("Last 30 Days", result.Description);
|
||||
Assert.Equal("fa-money", result.FontAwesomeIcon);
|
||||
Assert.Equal("75%", result.CumulativeValue);
|
||||
Assert.Equal(2, result.Records.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Recently_Redeemed_Ok()
|
||||
{
|
||||
// arrange
|
||||
var fakeAccounts = new List<RepoAccount>()
|
||||
{
|
||||
new RepoAccount(),
|
||||
new RepoAccount()
|
||||
};
|
||||
var highDate = DateTime.Parse("12/31/2019");
|
||||
var lowDate = DateTime.Parse("11/01/2019");
|
||||
|
||||
_mockRepoAccountRepository.Setup(
|
||||
x => x.FindByStatusChangeInPeriod(It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(),
|
||||
It.IsAny<string>()))
|
||||
.ReturnsAsync(fakeAccounts);
|
||||
|
||||
// act
|
||||
var result = await _factoidService.GetRecentlyRedeemed(lowDate, highDate);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("Recently Redeemed", result.Name);
|
||||
Assert.Equal("Last 30 Days", result.Description);
|
||||
Assert.Equal("fa-calendar", result.FontAwesomeIcon);
|
||||
Assert.Equal("2", result.CumulativeValue);
|
||||
Assert.Equal(2, result.Records.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetAvgDaysO4RToREPO_Ok()
|
||||
{
|
||||
// Arrange
|
||||
var fakeAccounts = new List<RepoAccount>()
|
||||
{
|
||||
new RepoAccount()
|
||||
{
|
||||
RepoStatusChanges = new List<RepoStatusChange>()
|
||||
{
|
||||
new RepoStatusChange()
|
||||
{
|
||||
StatusFrom = "REHO",
|
||||
StatusTo = "O4R",
|
||||
ChangedDate = DateTime.Parse("10/01/2019")
|
||||
},
|
||||
new RepoStatusChange()
|
||||
{
|
||||
StatusFrom = "O4R",
|
||||
StatusTo = "REPO",
|
||||
ChangedDate = DateTime.Parse("10/21/2019")
|
||||
}
|
||||
}
|
||||
},
|
||||
new RepoAccount()
|
||||
{
|
||||
RepoStatusChanges = new List<RepoStatusChange>()
|
||||
{
|
||||
new RepoStatusChange()
|
||||
{
|
||||
StatusFrom = "REDEEMED",
|
||||
StatusTo = "O4R",
|
||||
ChangedDate = DateTime.Parse("10/15/2019")
|
||||
},
|
||||
new RepoStatusChange()
|
||||
{
|
||||
StatusFrom = "O4R",
|
||||
StatusTo = "REDEEMED",
|
||||
ChangedDate = DateTime.Parse("10/20/2019")
|
||||
},
|
||||
new RepoStatusChange()
|
||||
{
|
||||
StatusFrom = "REDEEMED",
|
||||
StatusTo = "O4R",
|
||||
ChangedDate = DateTime.Parse("10/21/2019")
|
||||
},
|
||||
new RepoStatusChange()
|
||||
{
|
||||
StatusFrom = "REDEEMED",
|
||||
StatusTo = "REPO",
|
||||
ChangedDate = DateTime.Parse("10/31/2019")
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var highDate = DateTime.Parse("12/31/2019");
|
||||
var lowDate = DateTime.Parse("11/01/2019");
|
||||
|
||||
_mockRepoAccountRepository.Setup(
|
||||
x => x.FindByStatusChangeInPeriod(It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(),
|
||||
It.IsAny<string>()))
|
||||
.ReturnsAsync(fakeAccounts);
|
||||
|
||||
// act
|
||||
var result = await _factoidService.GetAvgDaysO4RToREPO(lowDate, highDate);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("Avg. Days O4R to Repo", result.Name);
|
||||
Assert.Equal("Last 30 Days", result.Description);
|
||||
Assert.Equal("fa-calendar", result.FontAwesomeIcon);
|
||||
Assert.Equal("15", result.CumulativeValue);
|
||||
Assert.Equal(2, result.Records.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetAvgDaysO4RToREPO_Does_Not_Divide_By_Zero_No_Accounts()
|
||||
{
|
||||
// Arrange
|
||||
var fakeAccounts = new List<RepoAccount>();
|
||||
var highDate = DateTime.Parse("12/31/2019");
|
||||
var lowDate = DateTime.Parse("11/01/2019");
|
||||
|
||||
_mockRepoAccountRepository.Setup(
|
||||
x => x.FindByStatusChangeInPeriod(It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(),
|
||||
It.IsAny<string>()))
|
||||
.ReturnsAsync(fakeAccounts);
|
||||
|
||||
// act
|
||||
var result = await _factoidService.GetAvgDaysO4RToREPO(lowDate, highDate);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("Avg. Days O4R to Repo", result.Name);
|
||||
Assert.Equal("Last 30 Days", result.Description);
|
||||
Assert.Equal("fa-calendar", result.FontAwesomeIcon);
|
||||
Assert.Equal("N/A", result.CumulativeValue);
|
||||
Assert.Equal(0, result.Records.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetCurrentInventory_Success()
|
||||
{
|
||||
// Arrange
|
||||
_mockRepoAccountRepository.Setup(repo => repo.FindByCurrentStatus(It.IsAny<string>())).ReturnsAsync(
|
||||
new List<RepoAccount>()
|
||||
{
|
||||
new RepoAccount()
|
||||
{
|
||||
Collaterals = new List<Collateral>()
|
||||
{
|
||||
new Collateral(),
|
||||
new Collateral()
|
||||
}
|
||||
},
|
||||
new RepoAccount()
|
||||
{
|
||||
Collaterals = new List<Collateral>()
|
||||
{
|
||||
new Collateral()
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Act
|
||||
var result = await _factoidService.GetCurrentInventory();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("3", result.CumulativeValue);
|
||||
Assert.Equal(2, result.Records.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetAvgDaysDelqToO4R_Success()
|
||||
{
|
||||
// Arrange
|
||||
var fakeAccounts = new List<RepoAccount>()
|
||||
{
|
||||
new RepoAccount()
|
||||
{
|
||||
DaysDelinquent = 125
|
||||
},
|
||||
new RepoAccount()
|
||||
{
|
||||
DaysDelinquent = 25
|
||||
},
|
||||
new RepoAccount()
|
||||
};
|
||||
|
||||
_mockRepoAccountRepository.Setup(
|
||||
x => x.FindByStatusChangeInPeriod(It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(),
|
||||
It.IsAny<string>()))
|
||||
.ReturnsAsync(fakeAccounts);
|
||||
|
||||
// act
|
||||
var result = await _factoidService.GetGetAvgDaysDelqToO4R(It.IsAny<DateTime>(), It.IsAny<DateTime>());
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("Avg. Days Dlqt To O4R", result.Name);
|
||||
Assert.Equal("Last 30 Days", result.Description);
|
||||
Assert.Equal("fa-calendar", result.FontAwesomeIcon);
|
||||
Assert.Equal("75", result.CumulativeValue);
|
||||
Assert.Equal(2, result.Records.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetAvgDaysRepoToSold_Success()
|
||||
{
|
||||
// Arrange
|
||||
var fakeAccounts = new List<RepoAccount>()
|
||||
{
|
||||
new RepoAccount()
|
||||
{
|
||||
RepoStatusChanges = new List<RepoStatusChange>()
|
||||
{
|
||||
new RepoStatusChange()
|
||||
{
|
||||
StatusFrom = "REPO",
|
||||
StatusTo = "SOLD",
|
||||
ChangedDate = DateTime.Parse("10/21/2019")
|
||||
},
|
||||
new RepoStatusChange()
|
||||
{
|
||||
StatusFrom = "O4R",
|
||||
StatusTo = "REPO",
|
||||
ChangedDate = DateTime.Parse("10/01/2019")
|
||||
}
|
||||
}
|
||||
},
|
||||
new RepoAccount()
|
||||
{
|
||||
RepoStatusChanges = new List<RepoStatusChange>()
|
||||
{
|
||||
new RepoStatusChange()
|
||||
{
|
||||
StatusFrom = "REPO",
|
||||
StatusTo = "SOLD",
|
||||
ChangedDate = DateTime.Parse("10/01/2019")
|
||||
},
|
||||
new RepoStatusChange()
|
||||
{
|
||||
StatusFrom = "O4R",
|
||||
StatusTo = "REPO",
|
||||
ChangedDate = DateTime.Parse("09/01/2019")
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_mockRepoAccountRepository.Setup(
|
||||
x => x.FindByStatusChangeInPeriod(It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(),
|
||||
It.IsAny<string>()))
|
||||
.ReturnsAsync(fakeAccounts);
|
||||
|
||||
// act
|
||||
var result = await _factoidService.GetGetAvgDaysRepoToSold(It.IsAny<DateTime>(), It.IsAny<DateTime>());
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("Avg. Days Repo to Sold", result.Name);
|
||||
Assert.Equal("Last 30 Days", result.Description);
|
||||
Assert.Equal("fa-calendar", result.FontAwesomeIcon);
|
||||
Assert.Equal("25", result.CumulativeValue);
|
||||
Assert.Equal(2, result.Records.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using LCU.API.Collections.RepoApi.Domain.FloorPricing;
|
||||
using LCU.API.Collections.RepoApi.Domain.FloorPricing.Strategies;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using LCU.Shared.Collections.RepoApiLib.WebServices.NADA;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class FloorPricingServiceTest
|
||||
{
|
||||
private readonly Mock<IVehicleFloorPricingParametersService> mockFloorPriceService;
|
||||
private readonly Mock<ICollateralValueService> mockCollateralValueService;
|
||||
private readonly Mock<IImsAutoFileDataService> mockImsAutoFileDataService;
|
||||
private readonly Mock<IFloorPricingStrategyFactory> mockStrategyFactory;
|
||||
|
||||
private readonly FloorPricingService service;
|
||||
|
||||
public FloorPricingServiceTest()
|
||||
{
|
||||
mockFloorPriceService = new Mock<IVehicleFloorPricingParametersService>();
|
||||
mockCollateralValueService = new Mock<ICollateralValueService>();
|
||||
mockImsAutoFileDataService = new Mock<IImsAutoFileDataService>();
|
||||
mockStrategyFactory = new Mock<IFloorPricingStrategyFactory>();
|
||||
service = new FloorPricingService(
|
||||
mockStrategyFactory.Object,
|
||||
mockFloorPriceService.Object,
|
||||
mockImsAutoFileDataService.Object,
|
||||
mockCollateralValueService.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Full_Calculate_Floor_Price_OK()
|
||||
{
|
||||
// arrange
|
||||
var strategies = new List<IFloorPricingStrategy>()
|
||||
{
|
||||
new AutoImsSuggestedValue(),
|
||||
new NadaMmrConditionValue()
|
||||
};
|
||||
FloorPriceCalculationParams fpcParams = new FloorPriceCalculationParams();
|
||||
mockStrategyFactory.Setup(x => x.GetFloorPricingStrategies()).Returns(strategies);
|
||||
|
||||
// act
|
||||
var results = service.GetCalculatedFloorPrices(fpcParams);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
Assert.True(results.Any());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Select_Floor_Price_OK()
|
||||
{
|
||||
// arrange
|
||||
List<FloorPriceCalculationResult> results = new List<FloorPriceCalculationResult>()
|
||||
{
|
||||
new FloorPriceCalculationResult()
|
||||
{
|
||||
Success = true,
|
||||
FloorPrice = 1000,
|
||||
StrategyName = "a",
|
||||
ResultWeight = 100
|
||||
},
|
||||
new FloorPriceCalculationResult()
|
||||
{
|
||||
Success = false,
|
||||
FloorPrice = 0,
|
||||
StrategyName = "b",
|
||||
ResultWeight = 1001
|
||||
},
|
||||
new FloorPriceCalculationResult()
|
||||
{
|
||||
Success = true,
|
||||
FloorPrice = 0,
|
||||
StrategyName = "c",
|
||||
ResultWeight = -1
|
||||
},
|
||||
new FloorPriceCalculationResult()
|
||||
{
|
||||
Success = true,
|
||||
FloorPrice = 1200,
|
||||
StrategyName = "d",
|
||||
ResultWeight = 101
|
||||
}
|
||||
};
|
||||
var strategies = new List<IFloorPricingStrategy>()
|
||||
{
|
||||
new AutoImsSuggestedValue(),
|
||||
new NadaMmrConditionValue()
|
||||
};
|
||||
|
||||
mockStrategyFactory.Setup(x => x.GetFloorPricingStrategies()).Returns(strategies);
|
||||
|
||||
// act
|
||||
var result = service.SelectBestFloorPrice(results);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(1200, result.FloorPrice);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Failed_NADA_Soap_Request_CollateralValuation_Not_Null()
|
||||
{
|
||||
mockCollateralValueService.Setup(x => x.GetCollateralValue("", 0, 0)).Throws<System.ServiceModel.FaultException>();
|
||||
var results = service.GetCollateralValuation("",0,0);
|
||||
Assert.NotNull(results);
|
||||
}
|
||||
}
|
||||
}
|
||||
+345
@@ -0,0 +1,345 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
using Moq;
|
||||
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
||||
using Xunit.Sdk;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using System.Linq;
|
||||
using LCU.API.Collections.RepoApi.Exceptions;
|
||||
using System.Threading.Tasks;
|
||||
using Castle.Core.Resource;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.IO;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class ImsAutoFileDataServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public async void ListAll_Ok()
|
||||
{
|
||||
var _mockImsAutoFileDataRepo = new Mock<IImsAutoFileDataRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.ListAllAsync()).ReturnsAsync(new List<ImsAutoFileData>() { new ImsAutoFileData() { } });
|
||||
ImsAutoFileDataService imsAutoFileDataService = new ImsAutoFileDataService(_mockImsAutoFileDataRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
var res = await imsAutoFileDataService.ListAll();
|
||||
Assert.NotNull(res);
|
||||
Assert.Single(res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ListAll_Exception()
|
||||
{
|
||||
var _mockImsAutoFileDataRepo = new Mock<IImsAutoFileDataRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.ListAllAsync()).ThrowsAsync(new Exception("oops"));
|
||||
ImsAutoFileDataService imsAutoFileDataService = new ImsAutoFileDataService(_mockImsAutoFileDataRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await imsAutoFileDataService.ListAll());
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void SaveAsync_Ok()
|
||||
{
|
||||
ImsAutoFileData filedata = new ImsAutoFileData()
|
||||
{
|
||||
RepoId = 5
|
||||
};
|
||||
|
||||
var _mockImsAutoFileDataRepo = new Mock<IImsAutoFileDataRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.AddAsync(It.IsAny<ImsAutoFileData>())).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
ImsAutoFileDataService imsAutoFileDataService = new ImsAutoFileDataService(_mockImsAutoFileDataRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
var res = await imsAutoFileDataService.SaveAsync(filedata);
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(5,res.RepoId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void SaveAsync_Exception()
|
||||
{
|
||||
ImsAutoFileData filedata = new ImsAutoFileData()
|
||||
{
|
||||
RepoId = 5
|
||||
};
|
||||
|
||||
var _mockImsAutoFileDataRepo = new Mock<IImsAutoFileDataRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.AddAsync(It.IsAny<ImsAutoFileData>())).ThrowsAsync(new Exception("oops"));
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
ImsAutoFileDataService imsAutoFileDataService = new ImsAutoFileDataService(_mockImsAutoFileDataRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await imsAutoFileDataService.SaveAsync(filedata));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Exception()
|
||||
{
|
||||
|
||||
var _mockImsAutoFileDataRepo = new Mock<IImsAutoFileDataRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<string>(), It.IsAny<int>())).ThrowsAsync(new Exception("oops"));
|
||||
|
||||
ImsAutoFileDataService imsAutoFileDataService = new ImsAutoFileDataService(_mockImsAutoFileDataRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await imsAutoFileDataService.Get("VinNumber", 12345));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Null_Exception()
|
||||
{
|
||||
var _mockImsAutoFileDataRepo = new Mock<IImsAutoFileDataRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<string>(), It.IsAny<int>())).Returns(Task.FromResult<ImsAutoFileData>(null));
|
||||
|
||||
ImsAutoFileDataService imsAutoFileDataService = new ImsAutoFileDataService(_mockImsAutoFileDataRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<NotFoundException>(async () => await imsAutoFileDataService.Get("VinNumber", 12345));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Ok()
|
||||
{
|
||||
ImsAutoFileData filedata = new ImsAutoFileData()
|
||||
{
|
||||
RepoId = 5,
|
||||
VIN = "VinNumber"
|
||||
};
|
||||
var _mockImsAutoFileDataRepo = new Mock<IImsAutoFileDataRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<string>(), It.IsAny<int>())).ReturnsAsync(filedata);
|
||||
|
||||
ImsAutoFileDataService imsAutoFileDataService = new ImsAutoFileDataService(_mockImsAutoFileDataRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
var res = await imsAutoFileDataService.Get("VinNumber", 12345);
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(filedata, res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetByAuctionAssignmentId_Exception()
|
||||
{
|
||||
|
||||
var _mockImsAutoFileDataRepo = new Mock<IImsAutoFileDataRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.FindByAuctionAssignmentIdAsync(It.IsAny<int>())).ThrowsAsync(new Exception("oops"));
|
||||
|
||||
ImsAutoFileDataService imsAutoFileDataService = new ImsAutoFileDataService(_mockImsAutoFileDataRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await imsAutoFileDataService.GetByAuctionAssignmentId(12345));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetByAuctionAssignmentId_Null_Exception()
|
||||
{
|
||||
var _mockImsAutoFileDataRepo = new Mock<IImsAutoFileDataRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.FindByAuctionAssignmentIdAsync(It.IsAny<int>())).Returns(Task.FromResult<ImsAutoFileData>(null));
|
||||
|
||||
ImsAutoFileDataService imsAutoFileDataService = new ImsAutoFileDataService(_mockImsAutoFileDataRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<NotFoundException>(async () => await imsAutoFileDataService.GetByAuctionAssignmentId(12345));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetByAuctionAssignmentId_Ok()
|
||||
{
|
||||
ImsAutoFileData filedata = new ImsAutoFileData()
|
||||
{
|
||||
RepoId = 12345,
|
||||
VIN = "VinNumber"
|
||||
};
|
||||
var _mockImsAutoFileDataRepo = new Mock<IImsAutoFileDataRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.FindByAuctionAssignmentIdAsync(It.IsAny<int>())).ReturnsAsync(filedata);
|
||||
|
||||
ImsAutoFileDataService imsAutoFileDataService = new ImsAutoFileDataService(_mockImsAutoFileDataRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
var res = await imsAutoFileDataService.GetByAuctionAssignmentId(12345);
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(filedata, res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateAsync_Ok()
|
||||
{
|
||||
ImsAutoFileData filedata = new ImsAutoFileData()
|
||||
{
|
||||
RepoId = 12345,
|
||||
VIN = "VinNumber"
|
||||
};
|
||||
var _mockImsAutoFileDataRepo = new Mock<IImsAutoFileDataRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<string>(), It.IsAny<int>())).ReturnsAsync(filedata);
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.Update(It.IsAny<ImsAutoFileData>()));
|
||||
|
||||
ImsAutoFileDataService imsAutoFileDataService = new ImsAutoFileDataService(_mockImsAutoFileDataRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
var res = await imsAutoFileDataService.UpdateAsync(filedata);
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(filedata, res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateAsync_Null_Exception()
|
||||
{
|
||||
ImsAutoFileData filedata = new ImsAutoFileData()
|
||||
{
|
||||
RepoId = 12345,
|
||||
VIN = "VinNumber"
|
||||
};
|
||||
var _mockImsAutoFileDataRepo = new Mock<IImsAutoFileDataRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<string>(), It.IsAny<int>())).Returns(Task.FromResult<ImsAutoFileData>(null));
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.Update(It.IsAny<ImsAutoFileData>()));
|
||||
|
||||
ImsAutoFileDataService imsAutoFileDataService = new ImsAutoFileDataService(_mockImsAutoFileDataRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<NotFoundException>(async () => await imsAutoFileDataService.UpdateAsync(filedata));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateAsync_Existing_Exception()
|
||||
{
|
||||
ImsAutoFileData filedata = new ImsAutoFileData()
|
||||
{
|
||||
RepoId = 12345,
|
||||
VIN = "VinNumber"
|
||||
};
|
||||
var _mockImsAutoFileDataRepo = new Mock<IImsAutoFileDataRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<string>(), It.IsAny<int>())).ThrowsAsync(new Exception("oops"));
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.Update(It.IsAny<ImsAutoFileData>()));
|
||||
|
||||
ImsAutoFileDataService imsAutoFileDataService = new ImsAutoFileDataService(_mockImsAutoFileDataRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await imsAutoFileDataService.UpdateAsync(filedata));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateAsync_Update_Exception()
|
||||
{
|
||||
ImsAutoFileData filedata = new ImsAutoFileData()
|
||||
{
|
||||
RepoId = 12345,
|
||||
VIN = "VinNumber"
|
||||
};
|
||||
var _mockImsAutoFileDataRepo = new Mock<IImsAutoFileDataRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<string>(), It.IsAny<int>())).ReturnsAsync(filedata);
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.Update(It.IsAny<ImsAutoFileData>())).Throws(new Exception("oops"));
|
||||
|
||||
ImsAutoFileDataService imsAutoFileDataService = new ImsAutoFileDataService(_mockImsAutoFileDataRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await imsAutoFileDataService.UpdateAsync(filedata));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DeleteAsync_Ok()
|
||||
{
|
||||
ImsAutoFileData filedata = new ImsAutoFileData()
|
||||
{
|
||||
RepoId = 12345,
|
||||
VIN = "VinNumber"
|
||||
};
|
||||
var _mockImsAutoFileDataRepo = new Mock<IImsAutoFileDataRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<string>(), It.IsAny<int>())).ReturnsAsync(filedata);
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.Remove(It.IsAny<ImsAutoFileData>()));
|
||||
|
||||
ImsAutoFileDataService imsAutoFileDataService = new ImsAutoFileDataService(_mockImsAutoFileDataRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
var res = await imsAutoFileDataService.DeleteAsync("vin",5);
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(filedata, res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DeleteAsync_Null_Exception()
|
||||
{
|
||||
ImsAutoFileData filedata = new ImsAutoFileData()
|
||||
{
|
||||
RepoId = 12345,
|
||||
VIN = "VinNumber"
|
||||
};
|
||||
var _mockImsAutoFileDataRepo = new Mock<IImsAutoFileDataRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<string>(), It.IsAny<int>())).Returns(Task.FromResult<ImsAutoFileData>(null));
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.Remove(It.IsAny<ImsAutoFileData>()));
|
||||
|
||||
ImsAutoFileDataService imsAutoFileDataService = new ImsAutoFileDataService(_mockImsAutoFileDataRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<NotFoundException>(async () => await imsAutoFileDataService.DeleteAsync("vin", 5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DeleteAsync_Existing_Exception()
|
||||
{
|
||||
ImsAutoFileData filedata = new ImsAutoFileData()
|
||||
{
|
||||
RepoId = 12345,
|
||||
VIN = "VinNumber"
|
||||
};
|
||||
var _mockImsAutoFileDataRepo = new Mock<IImsAutoFileDataRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<string>(), It.IsAny<int>())).ThrowsAsync(new Exception("oops"));
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.Remove(It.IsAny<ImsAutoFileData>()));
|
||||
|
||||
ImsAutoFileDataService imsAutoFileDataService = new ImsAutoFileDataService(_mockImsAutoFileDataRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await imsAutoFileDataService.DeleteAsync("vin", 5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DeleteAsync_Update_Exception()
|
||||
{
|
||||
ImsAutoFileData filedata = new ImsAutoFileData()
|
||||
{
|
||||
RepoId = 12345,
|
||||
VIN = "VinNumber"
|
||||
};
|
||||
var _mockImsAutoFileDataRepo = new Mock<IImsAutoFileDataRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<string>(), It.IsAny<int>())).ReturnsAsync(filedata);
|
||||
_mockUnitOfWork.Setup(mock => mock.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
_mockImsAutoFileDataRepo.Setup(repo => repo.Remove(It.IsAny<ImsAutoFileData>())).Throws(new Exception("oops"));
|
||||
|
||||
ImsAutoFileDataService imsAutoFileDataService = new ImsAutoFileDataService(_mockImsAutoFileDataRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await imsAutoFileDataService.DeleteAsync("vin", 5));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+430
@@ -0,0 +1,430 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using LCU.API.Collections.RepoApi.Services.Reporting;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models.Reporting;
|
||||
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class LandmarkReportingServiceTest
|
||||
{
|
||||
private LandmarkReportingService _landmarkReportingService;
|
||||
private Mock<IReportingRepository> _mockRepository;
|
||||
|
||||
public LandmarkReportingServiceTest()
|
||||
{
|
||||
_mockRepository = new Mock<IReportingRepository>();
|
||||
_landmarkReportingService = new LandmarkReportingService(_mockRepository.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetAvgDaysRepoToSold_Ok()
|
||||
{
|
||||
// Arrange
|
||||
var reportData = new List<StdReportEntry>()
|
||||
{
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 1,
|
||||
DateRepoed = DateTime.Parse("11/01/2019"),
|
||||
FilteredStatusChangeDate = DateTime.Parse("12/01/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 2,
|
||||
DateRepoed = DateTime.Parse("11/15/2019"),
|
||||
FilteredStatusChangeDate = DateTime.Parse("11/25/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 3
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 4,
|
||||
DateRepoed = DateTime.Parse("11/22/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 5,
|
||||
FilteredStatusChangeDate = DateTime.Parse("12/21/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 6,
|
||||
DateRepoed = DateTime.Parse("12/21/2019"),
|
||||
FilteredStatusChangeDate = DateTime.Parse("12/31/2019")
|
||||
},
|
||||
};
|
||||
_mockRepository.Setup(repo =>
|
||||
repo.GetAccountsByStatusChangeInPeriod(It.IsAny<string>(), It.IsAny<DateTime>(),
|
||||
It.IsAny<DateTime>()))
|
||||
.ReturnsAsync(reportData);
|
||||
|
||||
// Act
|
||||
var result =
|
||||
await _landmarkReportingService.GetAvgDaysRepoToSoldReport(DateTime.Parse("11/01/2019"),
|
||||
DateTime.Parse("12/31/2019"));
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(6, result.DataTable.Rows.Count());
|
||||
Assert.Equal(4, result.ReportTable.Cells.Length);
|
||||
|
||||
Assert.Equal("All Sold Accounts", result.ReportTable.Cells[0, 0].Display);
|
||||
Assert.Equal("10", result.ReportTable.Cells[0, 1].Display);
|
||||
Assert.Equal("20", result.ReportTable.Cells[0, 2].Display);
|
||||
Assert.Equal("17", result.ReportTable.Cells[0, 3].Display);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetRedemptionCountReport_Ok()
|
||||
{
|
||||
// Arrange
|
||||
var reportData = new List<StdReportEntry>()
|
||||
{
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 1,
|
||||
FilteredStatusChangeDate = DateTime.Parse("11/01/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 1,
|
||||
FilteredStatusChangeDate = DateTime.Parse("11/02/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 1,
|
||||
FilteredStatusChangeDate = DateTime.Parse("11/02/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 5,
|
||||
FilteredStatusChangeDate = DateTime.Parse("12/01/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 6,
|
||||
FilteredStatusChangeDate = DateTime.Parse("11/30/2019")
|
||||
},
|
||||
};
|
||||
_mockRepository.Setup(repo =>
|
||||
repo.GetAccountsByStatusChangeInPeriod(It.IsAny<string>(), It.IsAny<DateTime>(),
|
||||
It.IsAny<DateTime>()))
|
||||
.ReturnsAsync(reportData);
|
||||
|
||||
// Act
|
||||
var result =
|
||||
await _landmarkReportingService.GetRedemptionCountReport(DateTime.Parse("11/01/2019"),
|
||||
DateTime.Parse("12/31/2019"));
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(5, result.DataTable.Rows.Count());
|
||||
Assert.Equal(4, result.ReportTable.Cells.Length);
|
||||
|
||||
Assert.Equal("All Redemptions", result.ReportTable.Cells[0, 0].Display);
|
||||
Assert.Equal("3", result.ReportTable.Cells[0, 1].Display);
|
||||
Assert.Equal("1", result.ReportTable.Cells[0, 2].Display);
|
||||
Assert.Equal("4", result.ReportTable.Cells[0, 3].Display);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetAvgDaysDelqWhenAddedReport_Ok()
|
||||
{
|
||||
// Arrange
|
||||
var reportData = new List<StdReportEntry>()
|
||||
{
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 1,
|
||||
DaysDelqWhenAdded = 25,
|
||||
O4RDate = DateTime.Parse("11/01/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 2,
|
||||
DaysDelqWhenAdded = 38,
|
||||
O4RDate = DateTime.Parse("11/02/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 3,
|
||||
DaysDelqWhenAdded = 19,
|
||||
O4RDate = DateTime.Parse("11/02/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 4,
|
||||
DaysDelqWhenAdded = 12,
|
||||
O4RDate = DateTime.Parse("12/01/2019")
|
||||
},
|
||||
};
|
||||
_mockRepository.Setup(repo => repo.GetAccountsByO4RDate(It.IsAny<DateTime>(), It.IsAny<DateTime>()))
|
||||
.ReturnsAsync(reportData);
|
||||
|
||||
// Act
|
||||
var result =
|
||||
await _landmarkReportingService.GetAvgDaysDelqWhenAddedReport(DateTime.Parse("11/01/2019"),
|
||||
DateTime.Parse("12/31/2019"));
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(4, result.DataTable.Rows.Count());
|
||||
Assert.Equal(4, result.ReportTable.Cells.Length);
|
||||
|
||||
Assert.Equal("All Accounts", result.ReportTable.Cells[0, 0].Display);
|
||||
Assert.Equal("27", result.ReportTable.Cells[0, 1].Display);
|
||||
Assert.Equal("12", result.ReportTable.Cells[0, 2].Display);
|
||||
Assert.Equal("24", result.ReportTable.Cells[0, 3].Display);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetCountOfSalesReport_Ok()
|
||||
{
|
||||
// Arrange
|
||||
var reportData = new List<StdReportEntry>()
|
||||
{
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 1,
|
||||
FilteredStatusChangeDate = DateTime.Parse("11/01/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 2,
|
||||
FilteredStatusChangeDate = DateTime.Parse("11/02/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 3,
|
||||
FilteredStatusChangeDate = DateTime.Parse("11/02/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 4,
|
||||
FilteredStatusChangeDate = DateTime.Parse("12/01/2019")
|
||||
},
|
||||
};
|
||||
_mockRepository.Setup(repo =>
|
||||
repo.GetAccountsByStatusChangeInPeriod(It.IsAny<string>(), It.IsAny<DateTime>(),
|
||||
It.IsAny<DateTime>()))
|
||||
.ReturnsAsync(reportData);
|
||||
|
||||
// Act
|
||||
var result =
|
||||
await _landmarkReportingService.GetCountOfSalesReport(DateTime.Parse("11/01/2019"),
|
||||
DateTime.Parse("12/31/2019"));
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(4, result.DataTable.Rows.Count());
|
||||
Assert.Equal(4, result.ReportTable.Cells.Length);
|
||||
|
||||
Assert.Equal("All Sold Accounts", result.ReportTable.Cells[0, 0].Display);
|
||||
Assert.Equal("3", result.ReportTable.Cells[0, 1].Display);
|
||||
Assert.Equal("1", result.ReportTable.Cells[0, 2].Display);
|
||||
Assert.Equal("4", result.ReportTable.Cells[0, 3].Display);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetAvgSurplusReport_Ok()
|
||||
{
|
||||
// Arrange
|
||||
var reportData = new List<StdReportEntry>()
|
||||
{
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 1,
|
||||
GrossSalePrice = 3000,
|
||||
Balance = 3500,
|
||||
AuctionName = "Auction A",
|
||||
SoldDate = DateTime.Parse("11/01/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 2,
|
||||
GrossSalePrice = 500,
|
||||
Balance = 1200,
|
||||
AuctionName = "Auction B",
|
||||
SoldDate = DateTime.Parse("11/02/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 3,
|
||||
GrossSalePrice = 700,
|
||||
Balance = 650,
|
||||
AuctionName = "Auction B",
|
||||
SoldDate = DateTime.Parse("11/02/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 4,
|
||||
GrossSalePrice = 8000,
|
||||
Balance = 4000,
|
||||
AuctionName = "Auction A",
|
||||
SoldDate = DateTime.Parse("12/01/2019")
|
||||
},
|
||||
};
|
||||
_mockRepository.Setup(repo =>
|
||||
repo.GetAccountsByDateSoldInAutoIMS(It.IsAny<DateTime>(), It.IsAny<DateTime>()))
|
||||
.ReturnsAsync(reportData);
|
||||
|
||||
// Act
|
||||
var result =
|
||||
await _landmarkReportingService.GetAvgSurplusReport(DateTime.Parse("11/01/2019"),
|
||||
DateTime.Parse("12/31/2019"));
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(4, result.DataTable.Rows.Count());
|
||||
Assert.Equal(12, result.ReportTable.Cells.Length);
|
||||
|
||||
Assert.Equal("All Sold Accounts", result.ReportTable.Cells[0, 0].Display);
|
||||
Assert.Equal("($383.33)", result.ReportTable.Cells[0, 1].Display);
|
||||
Assert.Equal("$4,000.00", result.ReportTable.Cells[0, 2].Display);
|
||||
Assert.Equal("$712.50", result.ReportTable.Cells[0, 3].Display);
|
||||
|
||||
Assert.Equal("Auction A", result.ReportTable.Cells[1, 0].Display);
|
||||
Assert.Equal("($500.00)", result.ReportTable.Cells[1, 1].Display);
|
||||
Assert.Equal("$4,000.00", result.ReportTable.Cells[1, 2].Display);
|
||||
Assert.Equal("$1,750.00", result.ReportTable.Cells[1, 3].Display);
|
||||
|
||||
Assert.Equal("Auction B", result.ReportTable.Cells[2, 0].Display);
|
||||
Assert.Equal("($325.00)", result.ReportTable.Cells[2, 1].Display);
|
||||
Assert.Equal("-", result.ReportTable.Cells[2, 2].Display);
|
||||
Assert.Equal("($325.00)", result.ReportTable.Cells[2, 3].Display);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetRepoBalanceReport_Ok()
|
||||
{
|
||||
// Arrange
|
||||
var reportData = new List<StdReportEntry>()
|
||||
{
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 1,
|
||||
Balance = 300m,
|
||||
RepoCompany = "Company A",
|
||||
DateRepoed = DateTime.Parse("11/01/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 2,
|
||||
Balance = 275.49005m,
|
||||
RepoCompany = "Company A",
|
||||
DateRepoed = DateTime.Parse("11/02/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 3,
|
||||
Balance = 999.91m,
|
||||
RepoCompany = "Company B",
|
||||
DateRepoed = DateTime.Parse("11/02/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 4,
|
||||
Balance = 100m,
|
||||
RepoCompany = "Company B",
|
||||
DateRepoed = DateTime.Parse("12/01/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 5,
|
||||
Balance = 210m,
|
||||
DateRepoed = DateTime.Parse("12/11/2019")
|
||||
},
|
||||
};
|
||||
_mockRepository.Setup(repo => repo.GetAccountsByDateRepoed(It.IsAny<DateTime>(), It.IsAny<DateTime>()))
|
||||
.ReturnsAsync(reportData);
|
||||
|
||||
// Act
|
||||
var result =
|
||||
await _landmarkReportingService.GetRepoBalanceReport(DateTime.Parse("11/01/2019"),
|
||||
DateTime.Parse("12/31/2019"));
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(5, result.DataTable.Rows.Count());
|
||||
Assert.Equal(16, result.ReportTable.Cells.Length);
|
||||
|
||||
Assert.Equal("All Companies", result.ReportTable.Cells[0, 0].Display);
|
||||
Assert.Equal("$1,575.40", result.ReportTable.Cells[0, 1].Display);
|
||||
Assert.Equal("$310.00", result.ReportTable.Cells[0, 2].Display);
|
||||
Assert.Equal("$1,885.40", result.ReportTable.Cells[0, 3].Display);
|
||||
|
||||
Assert.Equal("Company A", result.ReportTable.Cells[1, 0].Display);
|
||||
Assert.Equal("$575.49", result.ReportTable.Cells[1, 1].Display);
|
||||
Assert.Equal("-", result.ReportTable.Cells[1, 2].Display);
|
||||
Assert.Equal("$575.49", result.ReportTable.Cells[1, 3].Display);
|
||||
|
||||
Assert.Equal("Company B", result.ReportTable.Cells[2, 0].Display);
|
||||
Assert.Equal("$999.91", result.ReportTable.Cells[2, 1].Display);
|
||||
Assert.Equal("$100.00", result.ReportTable.Cells[2, 2].Display);
|
||||
Assert.Equal("$1,099.91", result.ReportTable.Cells[2, 3].Display);
|
||||
|
||||
Assert.Equal("No Companies", result.ReportTable.Cells[3, 0].Display);
|
||||
Assert.Equal("-", result.ReportTable.Cells[3, 1].Display);
|
||||
Assert.Equal("$210.00", result.ReportTable.Cells[3, 2].Display);
|
||||
Assert.Equal("$210.00", result.ReportTable.Cells[3, 3].Display);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetRedemptionBalanceReport_Ok()
|
||||
{
|
||||
// Arrange
|
||||
var reportData = new List<StdReportEntry>()
|
||||
{
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 1,
|
||||
Balance = 250,
|
||||
FilteredStatusChangeDate = DateTime.Parse("11/01/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 2,
|
||||
Balance = 150,
|
||||
FilteredStatusChangeDate = DateTime.Parse("11/02/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 3,
|
||||
Balance = 99.99m,
|
||||
FilteredStatusChangeDate = DateTime.Parse("11/02/2019")
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
RepoId = 4,
|
||||
Balance = 1.49m,
|
||||
FilteredStatusChangeDate = DateTime.Parse("12/01/2019")
|
||||
},
|
||||
};
|
||||
_mockRepository.Setup(repo =>
|
||||
repo.GetAccountsByStatusChangeInPeriod(It.IsAny<string>(), It.IsAny<DateTime>(),
|
||||
It.IsAny<DateTime>()))
|
||||
.ReturnsAsync(reportData);
|
||||
|
||||
// Act
|
||||
var result =
|
||||
await _landmarkReportingService.GetRedemptionBalanceReport(DateTime.Parse("11/01/2019"),
|
||||
DateTime.Parse("12/31/2019"));
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(4, result.DataTable.Rows.Count());
|
||||
Assert.Equal(4, result.ReportTable.Cells.Length);
|
||||
|
||||
Assert.Equal("All Redeemed Accounts", result.ReportTable.Cells[0, 0].Display);
|
||||
Assert.Equal("$499.99", result.ReportTable.Cells[0, 1].Display);
|
||||
Assert.Equal("$1.49", result.ReportTable.Cells[0, 2].Display);
|
||||
Assert.Equal("$501.48", result.ReportTable.Cells[0, 3].Display);
|
||||
}
|
||||
}
|
||||
}
|
||||
+372
@@ -0,0 +1,372 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Collections.RepoApi.DataAccess;
|
||||
using LCU.API.Collections.RepoApi.Domain;
|
||||
using LCU.API.Collections.RepoApi.Domain.Extensions;
|
||||
using LCU.API.Collections.RepoApi.Exceptions;
|
||||
using LCU.API.Collections.RepoApi.Models;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.API.Collections.RepoApi.Services.Producer;
|
||||
using LCU.API.Collections.RepoApiTests.Domain;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models.Producer;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models.Settings;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services.Processor
|
||||
{
|
||||
public class RepoAccountProcessorIntegrationTest
|
||||
{
|
||||
private readonly RepoAccountProcessor _repoAccountProcessor;
|
||||
private readonly IRepoAccountProcessorService _repoAccountProcessorService;
|
||||
private readonly Mock<IAccountAlertCheckService> _mockAccountAlertCheckService;
|
||||
private readonly Mock<ISettingsService> _mockSettingsService;
|
||||
private readonly Mock<IRepoAccountService> _mockRepoAccountService;
|
||||
private readonly Mock<ICollectionsDao> _mockCollectionsDao;
|
||||
private readonly Mock<ICoreDao> _mockCoreDao;
|
||||
private readonly Mock<IRepoLetterService> _mockRepoLetterService;
|
||||
private readonly Mock<IEmailer> _mockEmailer;
|
||||
private readonly Mock<IAuctionAssignmentService> _mockAuctionAssignmentService;
|
||||
private readonly Mock<IEventAlertService> _mockEventAlertService;
|
||||
private readonly Mock<IRepoCompanySelectionService> _mockRepoCompanySelectionService;
|
||||
|
||||
public RepoAccountProcessorIntegrationTest()
|
||||
{
|
||||
_mockAccountAlertCheckService = new Mock<IAccountAlertCheckService>();
|
||||
_mockSettingsService = new Mock<ISettingsService>();
|
||||
_mockRepoAccountService = new Mock<IRepoAccountService>();
|
||||
_mockCollectionsDao = new Mock<ICollectionsDao>();
|
||||
_mockCoreDao = new Mock<ICoreDao>();
|
||||
_mockEmailer = new Mock<IEmailer>();
|
||||
_mockAuctionAssignmentService = new Mock<IAuctionAssignmentService>();
|
||||
_mockRepoLetterService = new Mock<IRepoLetterService>();
|
||||
_mockEventAlertService = new Mock<IEventAlertService>();
|
||||
_mockRepoCompanySelectionService = new Mock<IRepoCompanySelectionService>();
|
||||
var repoSettings = DbContextFromJson.GetTestObjectFromFile<Settings>("Services/Processor/repoSettings.json");
|
||||
_mockSettingsService.Setup(x => x.GetCachedRepoSettingsAsync()).ReturnsAsync(repoSettings);
|
||||
_repoAccountProcessorService = new RepoAccountProcessorService( _mockCoreDao.Object,
|
||||
new RedemptionExpiredDateCalculator(), _mockAccountAlertCheckService.Object,
|
||||
_mockEventAlertService.Object, _mockRepoCompanySelectionService.Object);
|
||||
_repoAccountProcessor = new RepoAccountProcessor(
|
||||
_repoAccountProcessorService, _mockAccountAlertCheckService.Object, _mockCollectionsDao.Object,
|
||||
_mockEmailer.Object, _mockSettingsService.Object, _mockRepoAccountService.Object,
|
||||
_mockRepoLetterService.Object, _mockCoreDao.Object, _mockAuctionAssignmentService.Object);
|
||||
|
||||
// _mockRepoAccountProcessorService.Setup(mock => mock.TryUpdateCollateralRetitleDate(It.IsAny<RepoAccount>(), It.IsAny<TemenosCase>()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Basic_Construct_Test()
|
||||
{
|
||||
Assert.NotNull(_repoAccountProcessor);
|
||||
await Assert.ThrowsAsync<IneligibleAccountException>(() => { return _repoAccountProcessor.HandleAccount(null); });
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this test to make more tests when things go wrong, you can dump raw JSON files from the sources into the test
|
||||
* and make sure you get expected results. Remember to remove member's PII.
|
||||
*/
|
||||
[Fact]
|
||||
public async Task Should_Create_Account()
|
||||
{
|
||||
var testInput = DbContextFromJson.GetTestObjectFromFile<ProcessorTestInput>("Services/Processor/newAccount.json");
|
||||
Assert.NotNull(testInput);
|
||||
_mockCollectionsDao.Setup(cd => cd.RetrieveAccountAsync(It.IsAny<string>())).ReturnsAsync(testInput.TemenosAccount);
|
||||
_mockRepoAccountService.Setup(ras => ras.GetNewestOpenAccount(It.IsAny<string>()))
|
||||
.ReturnsAsync((RepoAccount) null);
|
||||
_mockCoreDao.Setup(cd => cd.RetrieveLoanAsync(It.IsAny<string>())).ReturnsAsync(testInput.LoanDetail);
|
||||
_mockCoreDao.Setup(cd => cd.RetrieveMemberAsync(It.IsAny<string>())).ReturnsAsync(testInput.MemberDetail);
|
||||
_mockCoreDao.Setup(cd => cd.RetrieveTransactionsAsync(It.IsAny<string>())).ReturnsAsync(testInput.CoreTransactions);
|
||||
_mockCoreDao.Setup(cd => cd.RetrieveCollateralAsync(It.IsAny<string>())).ReturnsAsync(testInput.CollateralDetails);
|
||||
_mockRepoLetterService.Setup(x => x.ListByAccountIdAsync(It.IsAny<int>())).ReturnsAsync(
|
||||
RepoLetterService.ProcessLetters(testInput.TemenosHistory, testInput.RepoLetters));
|
||||
_mockAuctionAssignmentService.Setup(x => x.GetListByIdsAsync(It.IsAny<IReadOnlyCollection<int>>()))
|
||||
.ReturnsAsync(new List<AuctionAssignment>());
|
||||
var result = await _repoAccountProcessor.HandleAccount(new ProcessingItem()
|
||||
{
|
||||
AccountNo = "6466120143"
|
||||
});
|
||||
Assert.Equal(RepoProcessingResult.Created, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Select_Correct_Case()
|
||||
{
|
||||
/**
|
||||
* Given an account with three cases, choose the correct one:
|
||||
* 1. Wrong case type
|
||||
* 2. Ineligible case stage (repoStatus)
|
||||
* 3. Eligible case with valid stage/status.
|
||||
*/
|
||||
var testInput = DbContextFromJson.GetTestObjectFromFile<ProcessorTestInput>("Services/Processor/selectCorrectCase.json");
|
||||
Assert.NotNull(testInput);
|
||||
var selectedCase = testInput.TemenosAccount.FindRecoveryCaseOrDefault(0);
|
||||
Assert.Equal( 342, selectedCase.CaseId);
|
||||
selectedCase = testInput.TemenosAccount.FindRecoveryCaseOrDefault(25);
|
||||
Assert.Equal( 25, selectedCase.CaseId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Should_Not_Create_Ineligible_Account_Temenos_Event()
|
||||
{
|
||||
// Temenos Events will specify a case id.
|
||||
var testInput = DbContextFromJson.GetTestObjectFromFile<ProcessorTestInput>("Services/Processor/ineligibleAccount.json");
|
||||
Assert.NotNull(testInput);
|
||||
_mockCollectionsDao.Setup(cd => cd.RetrieveAccountAsync(It.IsAny<string>())).ReturnsAsync(testInput.TemenosAccount);
|
||||
_mockRepoAccountService.Setup(ras => ras.GetNewestOpenAccount(It.IsAny<string>()))
|
||||
.ReturnsAsync((RepoAccount) null);
|
||||
_mockCoreDao.Setup(cd => cd.RetrieveLoanAsync(It.IsAny<string>())).ReturnsAsync(testInput.LoanDetail);
|
||||
_mockCoreDao.Setup(cd => cd.RetrieveMemberAsync(It.IsAny<string>())).ReturnsAsync(testInput.MemberDetail);
|
||||
_mockCoreDao.Setup(cd => cd.RetrieveTransactionsAsync(It.IsAny<string>())).ReturnsAsync(testInput.CoreTransactions);
|
||||
_mockCoreDao.Setup(cd => cd.RetrieveCollateralAsync(It.IsAny<string>())).ReturnsAsync(testInput.CollateralDetails);
|
||||
_mockRepoLetterService.Setup(x => x.ListByAccountIdAsync(It.IsAny<int>())).ReturnsAsync(
|
||||
RepoLetterService.ProcessLetters(testInput.TemenosHistory, testInput.RepoLetters));
|
||||
_mockAuctionAssignmentService.Setup(x => x.GetListByIdsAsync(It.IsAny<IReadOnlyCollection<int>>()))
|
||||
.ReturnsAsync(new List<AuctionAssignment>());
|
||||
var result = await _repoAccountProcessor.HandleAccount(new ProcessingItem()
|
||||
{
|
||||
AccountNo = "6466120143",
|
||||
CaseId = "306"
|
||||
});
|
||||
Assert.Equal(RepoProcessingResult.Ineligible, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Should_Update_Retitled_And_Redemption_Expired_Account()
|
||||
{
|
||||
RepoAccount resultAccount = null;
|
||||
var testInput = DbContextFromJson.GetTestObjectFromFile<ProcessorTestInput>("Services/Processor/update-retitle-redemption-exp.json");
|
||||
Assert.NotNull(testInput);
|
||||
_mockCollectionsDao.Setup(cd => cd.RetrieveAccountAsync(It.IsAny<string>())).ReturnsAsync(testInput.TemenosAccount);
|
||||
_mockRepoAccountService.Setup(ras => ras.GetNewestOpenAccount(It.IsAny<string>()))
|
||||
.ReturnsAsync(testInput.RepoAccount);
|
||||
_mockRepoAccountService.Setup(x => x.UpdateAsync(It.IsAny<RepoAccount>(), It.IsAny<AppUser>()))
|
||||
.ReturnsAsync((RepoAccount inAccount, AppUser inUser) => {
|
||||
resultAccount = inAccount;
|
||||
return inAccount;
|
||||
});
|
||||
_mockCoreDao.Setup(cd => cd.RetrieveLoanAsync(It.IsAny<string>())).ReturnsAsync(testInput.LoanDetail);
|
||||
_mockCoreDao.Setup(cd => cd.RetrieveMemberAsync(It.IsAny<string>())).ReturnsAsync(testInput.MemberDetail);
|
||||
_mockCoreDao.Setup(cd => cd.RetrieveTransactionsAsync(It.IsAny<string>())).ReturnsAsync(testInput.CoreTransactions);
|
||||
_mockRepoLetterService.Setup(x => x.ListByAccountIdAsync(It.IsAny<int>())).ReturnsAsync(
|
||||
RepoLetterService.ProcessLetters(testInput.TemenosHistory, testInput.RepoLetters));
|
||||
_mockAuctionAssignmentService.Setup(x => x.GetListByIdsAsync(It.IsAny<IReadOnlyCollection<int>>()))
|
||||
.ReturnsAsync(new List<AuctionAssignment>());
|
||||
|
||||
// Pre-Assert.
|
||||
Assert.Null(resultAccount);
|
||||
Assert.Null(testInput.RepoAccount.RedemptionExpiredDate);
|
||||
Assert.NotNull(testInput.TemenosAccount.Cases.First().RedemptionExpiredDateWi);
|
||||
|
||||
var existingSelections = testInput.RepoAccount.Collaterals.First();
|
||||
Assert.Null(existingSelections.RetitledInLandmarkName);
|
||||
Assert.NotEmpty(existingSelections.RepoCompanySelections);
|
||||
Assert.Collection(existingSelections.RepoCompanySelections,
|
||||
item =>
|
||||
{
|
||||
Assert.Equal(5, item.RepoCompanyId);
|
||||
Assert.NotNull(item.DateRepoed);
|
||||
});
|
||||
|
||||
// Run
|
||||
var result = await _repoAccountProcessor.HandleAccount(new ProcessingItem()
|
||||
{
|
||||
AccountNo = "7584700143"
|
||||
});
|
||||
|
||||
// Post-Assert
|
||||
Assert.Equal(RepoProcessingResult.Updated, result);
|
||||
Assert.NotNull(resultAccount);
|
||||
Assert.NotNull(resultAccount.RedemptionExpiredDate);
|
||||
var newSelections = resultAccount.Collaterals.First();
|
||||
Assert.NotNull(newSelections.RetitledInLandmarkName);
|
||||
Assert.Collection(newSelections.RepoCompanySelections,
|
||||
|
||||
item =>
|
||||
{
|
||||
Assert.Equal(5, item.RepoCompanyId);
|
||||
Assert.NotNull(item.DateRepoed);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Should_Update_WrittenOff_And_RepoSelection_Account()
|
||||
{
|
||||
RepoAccount resultAccount = null;
|
||||
var testInput = DbContextFromJson.GetTestObjectFromFile<ProcessorTestInput>("Services/Processor/written-off-account.json");
|
||||
Assert.NotNull(testInput);
|
||||
_mockCollectionsDao.Setup(cd => cd.RetrieveAccountAsync(It.IsAny<string>())).ReturnsAsync(testInput.TemenosAccount);
|
||||
_mockRepoAccountService.Setup(ras => ras.GetNewestOpenAccount(It.IsAny<string>()))
|
||||
.ReturnsAsync(testInput.RepoAccount);
|
||||
_mockRepoAccountService.Setup(x => x.UpdateAsync(It.IsAny<RepoAccount>(), It.IsAny<AppUser>()))
|
||||
.ReturnsAsync((RepoAccount inAccount, AppUser inUser) => {
|
||||
resultAccount = inAccount;
|
||||
return inAccount;
|
||||
});
|
||||
_mockCoreDao.Setup(cd => cd.RetrieveLoanAsync(It.IsAny<string>())).ReturnsAsync(testInput.LoanDetail);
|
||||
_mockCoreDao.Setup(cd => cd.RetrieveMemberAsync(It.IsAny<string>())).ReturnsAsync(testInput.MemberDetail);
|
||||
_mockCoreDao.Setup(cd => cd.RetrieveTransactionsAsync(It.IsAny<string>())).ReturnsAsync(testInput.CoreTransactions);
|
||||
_mockRepoLetterService.Setup(x => x.ListByAccountIdAsync(It.IsAny<int>())).ReturnsAsync(
|
||||
RepoLetterService.ProcessLetters(testInput.TemenosHistory, testInput.RepoLetters));
|
||||
_mockAuctionAssignmentService.Setup(x => x.GetListByIdsAsync(It.IsAny<IReadOnlyCollection<int>>()))
|
||||
.ReturnsAsync(new List<AuctionAssignment>());
|
||||
|
||||
// Pre-Assert.
|
||||
Assert.Null(resultAccount);
|
||||
Assert.Null(testInput.RepoAccount.ReferenceStatus);
|
||||
Assert.Null(testInput.RepoAccount.WrittenOffDate);
|
||||
var existingSelections = testInput.RepoAccount.Collaterals.First();
|
||||
Assert.NotEmpty(existingSelections.RepoCompanySelections);
|
||||
Assert.Collection(existingSelections.RepoCompanySelections,
|
||||
item =>
|
||||
{
|
||||
Assert.Equal(4, item.RepoCompanyId);
|
||||
Assert.Null(item.DateRepoed);
|
||||
},
|
||||
item =>
|
||||
{
|
||||
Assert.Equal(13, item.RepoCompanyId);
|
||||
Assert.Null(item.DateRepoed);
|
||||
});
|
||||
|
||||
// Run
|
||||
var result = await _repoAccountProcessor.HandleAccount(new ProcessingItem()
|
||||
{
|
||||
AccountNo = "5730350143"
|
||||
});
|
||||
|
||||
// Post-Assert
|
||||
Assert.Equal(RepoProcessingResult.Updated, result);
|
||||
Assert.NotNull(resultAccount);
|
||||
Assert.Equal("Written Off", resultAccount.ReferenceStatus);
|
||||
Assert.NotNull(resultAccount.WrittenOffDate);
|
||||
var newSelections = resultAccount.Collaterals.First();
|
||||
Assert.Collection(newSelections.RepoCompanySelections,
|
||||
|
||||
item =>
|
||||
{
|
||||
Assert.Equal(4, item.RepoCompanyId);
|
||||
Assert.Null(item.DateRepoed);
|
||||
},
|
||||
item =>
|
||||
{
|
||||
Assert.Equal(13, item.RepoCompanyId);
|
||||
Assert.NotNull(item.DateRepoed);
|
||||
},
|
||||
item =>
|
||||
{
|
||||
Assert.Equal(7, item.RepoCompanyId);
|
||||
Assert.Null(item.DateRepoed);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Should_Update_WrittenOff_And_RepoSelection_Account2()
|
||||
{
|
||||
RepoAccount resultAccount = null;
|
||||
var testInput = DbContextFromJson.GetTestObjectFromFile<ProcessorTestInput>("Services/Processor/written-off-account-2.json");
|
||||
Assert.NotNull(testInput);
|
||||
_mockCollectionsDao.Setup(cd => cd.RetrieveAccountAsync(It.IsAny<string>())).ReturnsAsync(testInput.TemenosAccount);
|
||||
_mockRepoAccountService.Setup(ras => ras.GetNewestOpenAccount(It.IsAny<string>()))
|
||||
.ReturnsAsync(testInput.RepoAccount);
|
||||
_mockRepoAccountService.Setup(x => x.UpdateAsync(It.IsAny<RepoAccount>(), It.IsAny<AppUser>()))
|
||||
.ReturnsAsync((RepoAccount inAccount, AppUser inUser) => {
|
||||
resultAccount = inAccount;
|
||||
return inAccount;
|
||||
});
|
||||
_mockCoreDao.Setup(cd => cd.RetrieveLoanAsync(It.IsAny<string>())).ReturnsAsync(testInput.LoanDetail);
|
||||
_mockCoreDao.Setup(cd => cd.RetrieveMemberAsync(It.IsAny<string>())).ReturnsAsync(testInput.MemberDetail);
|
||||
_mockCoreDao.Setup(cd => cd.RetrieveTransactionsAsync(It.IsAny<string>())).ReturnsAsync(testInput.CoreTransactions);
|
||||
_mockRepoLetterService.Setup(x => x.ListByAccountIdAsync(It.IsAny<int>())).ReturnsAsync(
|
||||
RepoLetterService.ProcessLetters(testInput.TemenosHistory, testInput.RepoLetters));
|
||||
_mockAuctionAssignmentService.Setup(x => x.GetListByIdsAsync(It.IsAny<IReadOnlyCollection<int>>()))
|
||||
.ReturnsAsync(new List<AuctionAssignment>());
|
||||
|
||||
// Pre-Assert.
|
||||
Assert.Null(resultAccount);
|
||||
Assert.Equal("Written Off", testInput.RepoAccount.ReferenceStatus);
|
||||
Assert.Null(testInput.RepoAccount.WrittenOffDate);
|
||||
var existingSelections = testInput.RepoAccount.Collaterals.First();
|
||||
Assert.NotEmpty(existingSelections.RepoCompanySelections);
|
||||
Assert.Collection(existingSelections.RepoCompanySelections,
|
||||
item =>
|
||||
{
|
||||
Assert.Equal(11, item.RepoCompanyId);
|
||||
Assert.Null(item.DateRepoed);
|
||||
},
|
||||
item =>
|
||||
{
|
||||
Assert.Equal(11, item.RepoCompanyId);
|
||||
Assert.NotNull(item.DateRepoed);
|
||||
},
|
||||
item =>
|
||||
{
|
||||
Assert.Equal(1, item.RepoCompanyId);
|
||||
Assert.NotNull(item.DateRepoed);
|
||||
},
|
||||
item =>
|
||||
{
|
||||
Assert.Equal(5, item.RepoCompanyId);
|
||||
Assert.NotNull(item.DateRepoed);
|
||||
},
|
||||
item =>
|
||||
{
|
||||
Assert.Equal(13, item.RepoCompanyId);
|
||||
Assert.NotNull(item.DateRepoed);
|
||||
},
|
||||
item =>
|
||||
{
|
||||
Assert.Equal(13, item.RepoCompanyId);
|
||||
Assert.Null(item.DateRepoed);
|
||||
});
|
||||
|
||||
// Run
|
||||
var result = await _repoAccountProcessor.HandleAccount(new ProcessingItem()
|
||||
{
|
||||
AccountNo = "7115520143"
|
||||
});
|
||||
|
||||
// Post-Assert
|
||||
Assert.Equal(RepoProcessingResult.Updated, result);
|
||||
Assert.NotNull(resultAccount);
|
||||
Assert.Equal("Written Off", resultAccount.ReferenceStatus);
|
||||
Assert.NotNull(resultAccount.WrittenOffDate);
|
||||
var newSelections = resultAccount.Collaterals.First();
|
||||
Assert.Collection(existingSelections.RepoCompanySelections,
|
||||
item =>
|
||||
{
|
||||
Assert.Equal(11, item.RepoCompanyId);
|
||||
Assert.Null(item.DateRepoed);
|
||||
},
|
||||
item =>
|
||||
{
|
||||
Assert.Equal(11, item.RepoCompanyId);
|
||||
Assert.NotNull(item.DateRepoed);
|
||||
},
|
||||
item =>
|
||||
{
|
||||
Assert.Equal(1, item.RepoCompanyId);
|
||||
Assert.NotNull(item.DateRepoed);
|
||||
},
|
||||
item =>
|
||||
{
|
||||
Assert.Equal(5, item.RepoCompanyId);
|
||||
Assert.NotNull(item.DateRepoed);
|
||||
},
|
||||
item =>
|
||||
{
|
||||
Assert.Equal(13, item.RepoCompanyId);
|
||||
Assert.NotNull(item.DateRepoed);
|
||||
},
|
||||
item =>
|
||||
{
|
||||
Assert.Equal(13, item.RepoCompanyId);
|
||||
Assert.Null(item.DateRepoed);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
+1654
File diff suppressed because it is too large
Load Diff
+650
@@ -0,0 +1,650 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Collections.CollectionsApiLib.Models;
|
||||
using LCU.API.Collections.RepoApi.DataAccess;
|
||||
using LCU.API.Collections.RepoApi.Domain.Extensions;
|
||||
using LCU.API.Collections.RepoApi.Domain.Processing;
|
||||
using LCU.API.Collections.RepoApi.Exceptions;
|
||||
using LCU.API.Collections.RepoApi.Models;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.API.Collections.RepoApi.Services.Producer;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models.Consumer;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models.Producer;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models.Settings;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services.Processor
|
||||
{
|
||||
public class RepoAccountProcessorTest
|
||||
{
|
||||
private readonly RepoAccountProcessor _repoAccountProcessor;
|
||||
private readonly Mock<IRepoAccountProcessorService> _mockRepoAccountProcessorService;
|
||||
private readonly Mock<IAccountAlertCheckService> _mockAccountAlertCheckService;
|
||||
private readonly Mock<ISettingsService> _mockSettingsService;
|
||||
private readonly Mock<IRepoAccountService> _mockRepoAccountService;
|
||||
private readonly Mock<ICollectionsDao> _mockCollectionsDao;
|
||||
private readonly Mock<ICoreDao> _mockCoreDao;
|
||||
private readonly Mock<IRepoLetterService> _mockRepoLetterService;
|
||||
private readonly Mock<IEmailer> _mockEmailer;
|
||||
private readonly Mock<IAuctionAssignmentService> _mockAuctionAssignmentService;
|
||||
|
||||
public RepoAccountProcessorTest()
|
||||
{
|
||||
_mockRepoAccountProcessorService = new Mock<IRepoAccountProcessorService>();
|
||||
_mockAccountAlertCheckService = new Mock<IAccountAlertCheckService>();
|
||||
_mockSettingsService = new Mock<ISettingsService>();
|
||||
_mockRepoAccountService = new Mock<IRepoAccountService>();
|
||||
_mockCollectionsDao = new Mock<ICollectionsDao>();
|
||||
_mockCoreDao = new Mock<ICoreDao>();
|
||||
_mockEmailer = new Mock<IEmailer>();
|
||||
_mockAuctionAssignmentService = new Mock<IAuctionAssignmentService>();
|
||||
_mockRepoLetterService = new Mock<IRepoLetterService>();
|
||||
var repoSettings = DbContextFromJson.GetTestObjectFromFile<Settings>("Services/Processor/repoSettings.json");
|
||||
_mockSettingsService.Setup(x => x.GetCachedRepoSettingsAsync()).ReturnsAsync(repoSettings);
|
||||
_repoAccountProcessor = new RepoAccountProcessor(
|
||||
_mockRepoAccountProcessorService.Object, _mockAccountAlertCheckService.Object, _mockCollectionsDao.Object,
|
||||
_mockEmailer.Object, _mockSettingsService.Object, _mockRepoAccountService.Object,
|
||||
_mockRepoLetterService.Object, _mockCoreDao.Object, _mockAuctionAssignmentService.Object);
|
||||
|
||||
_mockRepoAccountProcessorService.Setup(mock => mock.TryUpdateCollateralRetitleDate(It.IsAny<RepoAccount>(), It.IsAny<TemenosCase>()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Basic_Construct_Test()
|
||||
{
|
||||
Assert.NotNull(_repoAccountProcessor);
|
||||
await Assert.ThrowsAsync<IneligibleAccountException>(() => { return _repoAccountProcessor.HandleAccount(null); });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Verify_AccountNo_Test()
|
||||
{
|
||||
Assert.NotNull(_repoAccountProcessor);
|
||||
Assert.Throws<IneligibleAccountException>(() => { _repoAccountProcessor.VerifyAccountNo(null); });
|
||||
Assert.Throws<IneligibleAccountException>(() => { _repoAccountProcessor.VerifyAccountNo(new ProcessingItem()); });
|
||||
// Assert.Throws<IneligibleAccountException>(() => { _repoAccountProcessor.VerifyAccountNo(new ProcessingItem()
|
||||
// {
|
||||
// AccountNo = "a;sldkfj"
|
||||
// }); });
|
||||
Assert.Equal("123456789", _repoAccountProcessor.VerifyAccountNo(new ProcessingItem()
|
||||
{
|
||||
CaseId = "1",
|
||||
AccountNo = "123456789",
|
||||
QueuedBy = "tester"
|
||||
}) );
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UnconvertedAccount_HasFallbackField_Test()
|
||||
{
|
||||
var temenosAccount = new TemenosAccount()
|
||||
{
|
||||
CustomFieldMap = new Dictionary<string, string>()
|
||||
};
|
||||
temenosAccount.CustomFieldMap.Add(RepoAccountProcessor.UserStatusFieldOld, "REPO");
|
||||
var repoAccount = new RepoAccount()
|
||||
{
|
||||
RepoId = 5,
|
||||
Status = "REPO"
|
||||
};
|
||||
var slip = new RepoAccountProcessingSlip()
|
||||
{
|
||||
ExistingRepoAccount = repoAccount,
|
||||
RecoveryAccount = temenosAccount
|
||||
};
|
||||
// repoAccount, temenosAccount, 0, "123456-789"
|
||||
Assert.True(_repoAccountProcessor.IsUnconvertedIntellectAccount(slip));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UnconvertedAccount_Missing_Test()
|
||||
{
|
||||
var temenosAccount = new TemenosAccount()
|
||||
{
|
||||
CustomFieldMap = new Dictionary<string, string>()
|
||||
};
|
||||
temenosAccount.CustomFieldMap.Add(RepoAccountProcessor.UserStatusFieldOld, "REPO");
|
||||
var repoAccount = new RepoAccount()
|
||||
{
|
||||
RepoId = 5,
|
||||
Status = "REPO"
|
||||
};
|
||||
var slip = new RepoAccountProcessingSlip()
|
||||
{
|
||||
ExistingRepoAccount = repoAccount,
|
||||
RecoveryAccount = null
|
||||
};
|
||||
// repoAccount, temenosAccount, 0, "123456-789"
|
||||
var result = _repoAccountProcessor.IsUnconvertedIntellectAccount(slip);
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UnconvertedAccount_NoFallbackfield_Test()
|
||||
{
|
||||
var temenosAccount = new TemenosAccount()
|
||||
{
|
||||
AccountIdentifier = "123456-789"
|
||||
};
|
||||
var repoAccount = new RepoAccount()
|
||||
{
|
||||
RepoId = 5,
|
||||
Status = "REPO"
|
||||
};
|
||||
var slip = new RepoAccountProcessingSlip()
|
||||
{
|
||||
ExistingRepoAccount = repoAccount,
|
||||
RecoveryAccount = temenosAccount
|
||||
};
|
||||
Assert.False(_repoAccountProcessor.IsUnconvertedIntellectAccount(slip));
|
||||
|
||||
temenosAccount.CustomFieldMap = new Dictionary<string, string>();
|
||||
Assert.False(_repoAccountProcessor.IsUnconvertedIntellectAccount(slip));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShouldCreateNew_Test()
|
||||
{
|
||||
var slip = new RepoAccountProcessingSlip();
|
||||
Assert.NotNull(_repoAccountProcessor);
|
||||
Assert.False(_repoAccountProcessor.ShouldCreateNewAccount(null));
|
||||
Assert.True(_repoAccountProcessor.ShouldCreateNewAccount(slip));
|
||||
slip.ExistingRepoAccount = new RepoAccount();
|
||||
Assert.False(_repoAccountProcessor.ShouldCreateNewAccount(slip));
|
||||
slip.ExistingRepoAccount = new RepoAccount()
|
||||
{
|
||||
DateClosed = DateTime.Today
|
||||
};
|
||||
Assert.True(_repoAccountProcessor.ShouldCreateNewAccount(slip));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Run_Complete_Update_Test()
|
||||
{
|
||||
var temenosCase = new TemenosCase();
|
||||
var temenosAccount = new TemenosAccount();
|
||||
var repoAccount = new RepoAccount();
|
||||
var slip = new RepoAccountProcessingSlip();
|
||||
Assert.NotNull(_repoAccountProcessor);
|
||||
Assert.Throws<MissingRequirementException>(() => { _repoAccountProcessor.ShouldRunCompleteUpdate(slip); });
|
||||
|
||||
slip.RecoveryAccount = temenosAccount;
|
||||
slip.RecoveryCase = temenosCase;
|
||||
slip.ExistingRepoAccount = repoAccount;
|
||||
|
||||
temenosCase.RepoStatus = RepoStatus.REPO;
|
||||
repoAccount.Status = "O4R";
|
||||
repoAccount.Balance = 1;
|
||||
temenosAccount.Balance = 2;
|
||||
Assert.True( _repoAccountProcessor.ShouldRunCompleteUpdate(slip));
|
||||
|
||||
temenosCase.RepoStatus = RepoStatus.O4R;
|
||||
repoAccount.Status = "O4R";
|
||||
repoAccount.Balance = 1;
|
||||
temenosAccount.Balance = 2;
|
||||
Assert.True( _repoAccountProcessor.ShouldRunCompleteUpdate(slip));
|
||||
|
||||
temenosCase.RepoStatus = RepoStatus.O4R;
|
||||
repoAccount.Status = "O4R";
|
||||
repoAccount.Balance = 1;
|
||||
temenosAccount.Balance = 1;
|
||||
repoAccount.ReferenceStatus = "Open";
|
||||
temenosAccount.AccountStatus = "Open";
|
||||
Assert.False( _repoAccountProcessor.ShouldRunCompleteUpdate(slip));
|
||||
|
||||
temenosCase.RepoStatus = RepoStatus.O4R;
|
||||
repoAccount.Status = "O4R";
|
||||
repoAccount.Balance = 1;
|
||||
temenosAccount.Balance = 1;
|
||||
repoAccount.ReferenceStatus = "Open";
|
||||
temenosAccount.AccountStatus = "Written Off";
|
||||
Assert.True( _repoAccountProcessor.ShouldRunCompleteUpdate(slip));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[CollectionsJsonFileData("test_accounts.json", "newAccounts04R")]
|
||||
public async Task New_Accounts_04R(RepoUpdateTestRow row)
|
||||
{
|
||||
// Setup
|
||||
_mockCollectionsDao.Setup(x => x.RetrieveAccountAsync(It.IsAny<string>()))
|
||||
.ReturnsAsync(row.CollectionAccount);
|
||||
_mockRepoAccountService.Setup(x => x.GetNewestOpenAccount(row.CollectionAccount.AccountIdentifier))
|
||||
.ReturnsAsync(row.ExistingRepoAccount);
|
||||
_mockRepoAccountProcessorService.Setup(service => service.CreateRepoAccount(It.IsAny<TemenosAccount>(), It.IsAny<TemenosCase>(), It.IsAny<LoanDetail>()))
|
||||
.Returns(row.NewRepoAccount);
|
||||
_mockRepoAccountService.Setup(service => service.SaveAsync(It.IsAny<RepoAccount>()))
|
||||
.ReturnsAsync(row.NewRepoAccount);
|
||||
_mockRepoLetterService.Setup(service => service.ListByAccountIdAsync(It.IsAny<int>()))
|
||||
.ReturnsAsync(new List<RepoLetter>());
|
||||
_mockCoreDao.Setup(service => service.RetrieveTransactionsAsync(It.IsAny<string>())).ReturnsAsync(
|
||||
new List<CoreTransaction>());
|
||||
_mockCoreDao.Setup(service => service.RetrieveMemberAsync(It.IsAny<string>())).ReturnsAsync(
|
||||
new MemberDetail());
|
||||
_mockCoreDao.Setup(service => service.RetrieveLoanAsync(It.IsAny<string>())).ReturnsAsync(
|
||||
new LoanDetail());
|
||||
_mockAuctionAssignmentService
|
||||
.Setup(service => service.GetListByIdsAsync(It.IsAny<IReadOnlyCollection<int>>())).ReturnsAsync(
|
||||
new LinkedList<AuctionAssignment>());
|
||||
_mockAccountAlertCheckService.Setup(service => service.AlertChecksPrimary(It.IsAny<RepoAccountProcessingSlip>()))
|
||||
.Returns(Task.FromResult<object>(null)).Verifiable();
|
||||
|
||||
// Run, don't provide collections account so it loads it...
|
||||
var result = await _repoAccountProcessor.HandleAccount(new ProcessingItem()
|
||||
{
|
||||
AccountNo = row.CollectionAccount.AccountIdentifier,
|
||||
CaseId = $"{row.CollectionCase.CaseId}"
|
||||
});
|
||||
|
||||
// Verify.
|
||||
_mockRepoAccountService.VerifyAll();
|
||||
_mockAccountAlertCheckService.VerifyAll();
|
||||
Assert.Equal(RepoProcessingResult.Created, result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[CollectionsJsonFileData("test_accounts.json", "existingAccounts04R")]
|
||||
public async Task Existing_Accounts_04R(RepoUpdateTestRow row)
|
||||
{
|
||||
// Setup
|
||||
_mockCollectionsDao.Setup(x => x.RetrieveAccountAsync(It.IsAny<string>()))
|
||||
.ReturnsAsync(row.CollectionAccount);
|
||||
_mockRepoAccountService.Setup(x => x.GetNewestOpenAccount(row.CollectionAccount.AccountIdentifier))
|
||||
.ReturnsAsync(row.ExistingRepoAccount);
|
||||
_mockRepoAccountProcessorService.Setup(service => service.UpdateRepoAccountFromParts( It.IsAny<RepoAccountProcessingSlip>()))
|
||||
.Returns(row.NewRepoAccount);
|
||||
_mockRepoAccountService.Setup(service => service.UpdateAsync(It.IsAny<RepoAccount>(), It.IsAny<AppUser>()))
|
||||
.ReturnsAsync(row.NewRepoAccount);
|
||||
_mockRepoLetterService.Setup(service => service.ListByAccountIdAsync(It.IsAny<int>()))
|
||||
.ReturnsAsync(new List<RepoLetter>());
|
||||
_mockCoreDao.Setup(service => service.RetrieveTransactionsAsync(It.IsAny<string>())).ReturnsAsync(
|
||||
new List<CoreTransaction>());
|
||||
_mockCoreDao.Setup(service => service.RetrieveMemberAsync(It.IsAny<string>())).ReturnsAsync(
|
||||
new MemberDetail());
|
||||
_mockCoreDao.Setup(service => service.RetrieveLoanAsync(It.IsAny<string>())).ReturnsAsync(
|
||||
new LoanDetail());
|
||||
_mockAuctionAssignmentService
|
||||
.Setup(service => service.GetListByIdsAsync(It.IsAny<IReadOnlyCollection<int>>())).ReturnsAsync(
|
||||
new LinkedList<AuctionAssignment>());
|
||||
_mockAccountAlertCheckService.Setup(service => service.AlertChecksPrimary(It.IsAny<RepoAccountProcessingSlip>()))
|
||||
.Returns(Task.FromResult<object>(null)).Verifiable();
|
||||
|
||||
// Run, don't provide collections account so it loads it...
|
||||
var result = await _repoAccountProcessor.HandleAccount(new ProcessingItem()
|
||||
{
|
||||
AccountNo = row.CollectionAccount.AccountIdentifier,
|
||||
CaseId = $"{row.CollectionCase.CaseId}"
|
||||
});
|
||||
|
||||
// Verify.
|
||||
Assert.NotEqual(RepoProcessingResult.Error, result);
|
||||
Assert.NotEqual(RepoProcessingResult.Autoclosed, result);
|
||||
Assert.NotEqual(RepoProcessingResult.Ineligible, result);
|
||||
Assert.NotEqual(RepoProcessingResult.Unconverted, result);
|
||||
Assert.Equal(RepoProcessingResult.Updated, result);
|
||||
_mockRepoAccountService.VerifyAll();
|
||||
_mockAccountAlertCheckService.VerifyAll();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[CollectionsJsonFileData("test_accounts - RECA.json", "existingAccountsRECA")]
|
||||
public async Task Existing_Accounts_RECA(RepoUpdateTestRow row)
|
||||
{
|
||||
// Setup
|
||||
_mockCollectionsDao.Setup(x => x.RetrieveAccountAsync(It.IsAny<string>()))
|
||||
.ReturnsAsync(row.CollectionAccount);
|
||||
_mockRepoAccountService.Setup(x => x.GetNewestOpenAccount(row.CollectionAccount.AccountIdentifier))
|
||||
.ReturnsAsync(row.ExistingRepoAccount);
|
||||
_mockRepoAccountProcessorService.Setup(service => service.UpdateRepoAccountFromParts(It.IsAny<RepoAccountProcessingSlip>()))
|
||||
.Returns(row.NewRepoAccount);
|
||||
_mockRepoAccountService.Setup(service => service.UpdateAsync(It.IsAny<RepoAccount>(), It.IsAny<AppUser>()))
|
||||
.ReturnsAsync(row.NewRepoAccount);
|
||||
_mockRepoLetterService.Setup(service => service.ListByAccountIdAsync(It.IsAny<int>()))
|
||||
.ReturnsAsync(new List<RepoLetter>());
|
||||
_mockCoreDao.Setup(service => service.RetrieveTransactionsAsync(It.IsAny<string>())).ReturnsAsync(
|
||||
new List<CoreTransaction>());
|
||||
_mockCoreDao.Setup(service => service.RetrieveMemberAsync(It.IsAny<string>())).ReturnsAsync(
|
||||
new MemberDetail());
|
||||
_mockCoreDao.Setup(service => service.RetrieveLoanAsync(It.IsAny<string>())).ReturnsAsync(
|
||||
new LoanDetail());
|
||||
_mockAuctionAssignmentService
|
||||
.Setup(service => service.GetListByIdsAsync(It.IsAny<IReadOnlyCollection<int>>())).ReturnsAsync(
|
||||
new LinkedList<AuctionAssignment>());
|
||||
|
||||
|
||||
var result = await _repoAccountProcessor.HandleAccount(new ProcessingItem()
|
||||
{
|
||||
AccountNo = row.CollectionAccount.AccountIdentifier,
|
||||
CaseId = $"{row.CollectionCase.CaseId}"
|
||||
});
|
||||
|
||||
|
||||
Assert.NotEqual(RepoProcessingResult.Error, result);
|
||||
Assert.NotEqual(RepoProcessingResult.Autoclosed, result);
|
||||
Assert.NotEqual(RepoProcessingResult.Ineligible, result);
|
||||
Assert.NotEqual(RepoProcessingResult.Unconverted, result);
|
||||
|
||||
Assert.Equal(RepoProcessingResult.Updated, result);
|
||||
|
||||
_mockRepoAccountService.VerifyAll(); //should not verify alert checks will exit
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Update_Account_Existing_Collateral()
|
||||
{
|
||||
var testAccount = new TemenosAccount()
|
||||
{
|
||||
AccountIdentifier = "123456134",
|
||||
ActiveFlag = true,
|
||||
AccountTypeId = 4, // "L ",
|
||||
Cases = new List<TemenosCase>()
|
||||
{
|
||||
new TemenosCase()
|
||||
{
|
||||
CaseId = 999,
|
||||
RepoStatus = RepoStatus.REPO,
|
||||
CaseTypeId = 7
|
||||
}
|
||||
}
|
||||
// UserStatusCode1 = "REPO"
|
||||
};
|
||||
var repoAccount = new RepoAccount()
|
||||
{
|
||||
RepoId = 555,
|
||||
Status = "O4R",
|
||||
Collaterals = new List<Collateral>()
|
||||
{
|
||||
new Collateral()
|
||||
{
|
||||
RepoId = 555
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_mockCollectionsDao.Setup(x => x.RetrieveAccountAsync(It.IsAny<string>()))
|
||||
.ReturnsAsync(testAccount);
|
||||
|
||||
_mockRepoAccountService.Setup(x => x.GetNewestOpenAccount(It.IsAny<string>()))
|
||||
.ReturnsAsync(repoAccount);
|
||||
|
||||
_mockRepoAccountProcessorService
|
||||
.Setup(service => service.CreateRepoAccount(It.IsAny<TemenosAccount>(), It.IsAny<TemenosCase>(), It.IsAny<LoanDetail>()))
|
||||
.Returns(repoAccount);
|
||||
|
||||
_mockRepoLetterService.Setup(service => service.ListByAccountIdAsync(It.IsAny<int>()))
|
||||
.ReturnsAsync(new List<RepoLetter>());
|
||||
_mockCoreDao.Setup(service => service.RetrieveTransactionsAsync(It.IsAny<string>())).ReturnsAsync(
|
||||
new List<CoreTransaction>());
|
||||
_mockCoreDao.Setup(service => service.RetrieveMemberAsync(It.IsAny<string>())).ReturnsAsync(
|
||||
new MemberDetail());
|
||||
_mockCoreDao.Setup(service => service.RetrieveLoanAsync(It.IsAny<string>())).ReturnsAsync(
|
||||
new LoanDetail());
|
||||
_mockAuctionAssignmentService
|
||||
.Setup(service => service.GetListByIdsAsync(It.IsAny<IReadOnlyCollection<int>>())).ReturnsAsync(
|
||||
new LinkedList<AuctionAssignment>());
|
||||
_mockRepoAccountProcessorService.Setup(service =>
|
||||
service.UpdateRepoAccountFromParts(It.IsAny<RepoAccountProcessingSlip>()))
|
||||
.Returns(repoAccount);
|
||||
|
||||
var result = await _repoAccountProcessor.HandleAccount(new ProcessingItem()
|
||||
{AccountNo = testAccount.AccountIdentifier, CaseId = "999"});
|
||||
_mockRepoAccountProcessorService.Verify(foo => foo.UpdateRepoAccountFromParts(It.IsAny<RepoAccountProcessingSlip>()), Times.Once);
|
||||
_mockRepoAccountProcessorService.Verify(foo => foo.CreateRepoAccount( It.IsAny<TemenosAccount>(), It.IsAny<TemenosCase>(), It.IsAny<LoanDetail>()), Times.Never());
|
||||
_mockRepoAccountProcessorService.Verify(mock => mock.TryUpdateCollateralRetitleDate(It.IsAny<RepoAccount>(), It.IsAny<TemenosCase>()), Times.Exactly(1));
|
||||
Assert.NotNull(_repoAccountProcessor);
|
||||
Assert.Equal(RepoProcessingResult.Updated, result);
|
||||
}
|
||||
//add test
|
||||
|
||||
[Fact]
|
||||
public async Task Update_Account_No_Collateral()
|
||||
{
|
||||
var testAccount = new TemenosAccount()
|
||||
{
|
||||
AccountIdentifier = "123456134",
|
||||
Cases = new List<TemenosCase>()
|
||||
{
|
||||
new TemenosCase()
|
||||
{
|
||||
CaseId = 99,
|
||||
RepoStatus = RepoStatus.O4R,
|
||||
CaseTypeId = 7
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_mockCollectionsDao.Setup(x => x.RetrieveAccountAsync(It.IsAny<string>()))
|
||||
.ReturnsAsync(testAccount);
|
||||
_mockRepoAccountService.Setup(x => x.GetNewestOpenAccount(It.IsAny<string>()))
|
||||
.ReturnsAsync(new RepoAccount()
|
||||
{
|
||||
Status = "O4R",
|
||||
RepoId = 555 /* no collateral! */
|
||||
});
|
||||
|
||||
_mockRepoAccountProcessorService.Setup(service => service.CreateRepoAccount(It.IsAny<TemenosAccount>(), It.IsAny<TemenosCase>(), It.IsAny<LoanDetail>()))
|
||||
.Verifiable("Called create");
|
||||
_mockRepoAccountProcessorService.Setup(service =>
|
||||
service.UpdateRepoAccountFromParts(It.IsAny<RepoAccountProcessingSlip>()))
|
||||
.Verifiable("merge existing");
|
||||
_mockRepoLetterService.Setup(service => service.ListByAccountIdAsync(It.IsAny<int>()))
|
||||
.ReturnsAsync(new List<RepoLetter>());
|
||||
_mockEmailer.Setup(service => service.MaybeSendO4rNoCollateralEmail(It.IsAny<RepoAccount>()))
|
||||
.ReturnsAsync(new HttpResponseMessage { StatusCode = HttpStatusCode.OK }).Verifiable("Send e-mail");
|
||||
_mockCoreDao.Setup(service => service.RetrieveLoanAsync(It.IsAny<string>())).ReturnsAsync(
|
||||
new LoanDetail());
|
||||
|
||||
await Assert.ThrowsAsync<MissingRequirementException>(() => _repoAccountProcessor.HandleAccount(
|
||||
new ProcessingItem()
|
||||
{
|
||||
AccountNo = testAccount.AccountIdentifier,
|
||||
CaseId = $"{testAccount.Cases.First().CaseId}"
|
||||
}));
|
||||
_mockRepoAccountProcessorService.Verify(foo => foo.CreateRepoAccount(It.IsAny<TemenosAccount>(), It.IsAny<TemenosCase>(), It.IsAny<LoanDetail>()), Times.Never());
|
||||
// _mockRepoAccountProcessorService.VerifyAll();
|
||||
_mockRepoAccountProcessorService.Verify(
|
||||
service => service.UpdateRepoAccountFromParts(It.IsAny<RepoAccountProcessingSlip>()),
|
||||
Times.Never());
|
||||
|
||||
_mockEmailer.Verify(x => x.MaybeSendO4rNoCollateralEmail(It.IsAny<RepoAccount>()), Times.Once);
|
||||
Assert.NotNull(_repoAccountProcessor);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Find_Recovery_Case_OK()
|
||||
{
|
||||
var testAccount = new TemenosAccount()
|
||||
{
|
||||
AccountIdentifier = "123456-134",
|
||||
Cases = new List<TemenosCase>()
|
||||
{
|
||||
new TemenosCase()
|
||||
{
|
||||
CaseId = 99
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var temenosCase = testAccount.FindRecoveryCaseOrDefault(99);
|
||||
Assert.True(testAccount.HasRecoveryCase(99));
|
||||
Assert.NotNull(temenosCase);
|
||||
Assert.Equal(99,temenosCase.CaseId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Find_Recovery_Case_OK_No_Case_Id_No_RepoStatus()
|
||||
{
|
||||
var testAccount = new TemenosAccount()
|
||||
{
|
||||
AccountIdentifier = "123456-134",
|
||||
Cases = new List<TemenosCase>()
|
||||
{
|
||||
new TemenosCase()
|
||||
{
|
||||
CaseId = 99,
|
||||
CaseStatusId = 33,
|
||||
RepoStatus = RepoStatus.UNKNOWN
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Assert.False(testAccount.HasRecoveryCase(0));
|
||||
Assert.False(testAccount.HasRecoveryCase(88));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Find_Recovery_Case_OK_No_Case_Id()
|
||||
{
|
||||
var testAccount = new TemenosAccount()
|
||||
{
|
||||
AccountIdentifier = "123456-134",
|
||||
Cases = new List<TemenosCase>()
|
||||
{
|
||||
new TemenosCase()
|
||||
{
|
||||
CaseId = 99,
|
||||
CaseStatusId = 33,
|
||||
RepoStatus = RepoStatus.O4R,
|
||||
CaseTypeId = 7
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var temenosCase = testAccount.FindRecoveryCaseOrDefault(0);
|
||||
Assert.True(testAccount.HasRecoveryCase(0));
|
||||
Assert.NotNull(temenosCase);
|
||||
Assert.Equal(99,temenosCase.CaseId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateExistingRepoAccount_FullUpdate_OK()
|
||||
{
|
||||
var repoAccount = new RepoAccount()
|
||||
{
|
||||
RepoId = 555,
|
||||
AccountNo = "123456-789",
|
||||
Status = "O4R",
|
||||
Collaterals = new List<Collateral>()
|
||||
{
|
||||
new Collateral()
|
||||
{
|
||||
RepoId = 555
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_mockRepoAccountProcessorService.Setup(serv => serv.UpdateRepoAccountFromParts(It.IsAny<RepoAccountProcessingSlip>())).Returns(repoAccount);
|
||||
_mockRepoAccountProcessorService.Setup(serv => serv.CheckForRejectedStatusChange(It.IsAny<RepoAccount>(), It.IsAny<RepoAccount>(), It.IsAny<Settings>()));
|
||||
_mockRepoAccountProcessorService.Setup(serv =>
|
||||
serv.TryUpdateOrCreateRepoCompanyAssignment(It.IsAny<RepoAccount>(), It.IsAny<TemenosCase>(),
|
||||
It.IsAny<Settings>()));
|
||||
_mockRepoAccountProcessorService.Setup(serv => serv.TryUpdateCollateralRetitleDate(It.IsAny<RepoAccount>(), It.IsAny<TemenosCase>()));
|
||||
_mockRepoAccountProcessorService.Setup(serv => serv.UpdateRepoAccountDateClosed(It.IsAny<RepoAccount>()));
|
||||
|
||||
_mockAccountAlertCheckService
|
||||
.Setup(serv => serv.AlertChecksPreStatusReject(It.IsAny<RepoAccountProcessingSlip>()))
|
||||
.Returns(Task.FromResult<object>(null));
|
||||
|
||||
_mockRepoAccountService.Setup(serv => serv.UpdateAsync(It.IsAny<RepoAccount>(), It.IsAny<AppUser>())).ReturnsAsync(repoAccount);
|
||||
|
||||
var temenosCase = new TemenosCase();
|
||||
var temenosAccount = new TemenosAccount();
|
||||
|
||||
//Full Update Criteria
|
||||
temenosCase.RepoStatus = RepoStatus.REPO;
|
||||
repoAccount.Status = "O4R";
|
||||
repoAccount.Balance = 1;
|
||||
temenosAccount.Balance = 2;
|
||||
|
||||
var slip = new RepoAccountProcessingSlip()
|
||||
{
|
||||
RecoveryCase = temenosCase,
|
||||
RecoveryAccount = temenosAccount,
|
||||
ExistingRepoAccount = repoAccount,
|
||||
RequestedBy = new ProcessingItem()
|
||||
{
|
||||
QueuedBy = "testing",
|
||||
AccountNo = "123456-789",
|
||||
CaseId = "0"
|
||||
}
|
||||
};
|
||||
|
||||
// repoAccount, temenosAccount, temenosCase, "123213123"
|
||||
var res = await _repoAccountProcessor.UpdateExistingRepoAccount(slip);
|
||||
|
||||
_mockRepoAccountService.Verify(serv => serv.UpdateAsync(It.IsAny<RepoAccount>(), It.IsAny<AppUser>()), Times.Once);
|
||||
_mockRepoAccountProcessorService.Verify(serv =>
|
||||
serv.TryUpdateOrCreateRepoCompanyAssignment(It.IsAny<RepoAccount>(), It.IsAny<TemenosCase>(),
|
||||
It.IsAny<Settings>()));
|
||||
|
||||
Assert.NotNull(res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateExistingRepoAccount_HalfUpdate_OK()
|
||||
{
|
||||
var repoAccount = new RepoAccount()
|
||||
{
|
||||
RepoId = 555,
|
||||
AccountNo = "123456-789",
|
||||
Status = "O4R",
|
||||
Collaterals = new List<Collateral>()
|
||||
{
|
||||
new Collateral()
|
||||
{
|
||||
RepoId = 555
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_mockRepoAccountProcessorService.Setup(serv => serv.UpdateRepoAccountFromParts(It.IsAny<RepoAccountProcessingSlip>())).Returns(repoAccount);
|
||||
_mockRepoAccountProcessorService.Setup(serv => serv.CheckForRejectedStatusChange(It.IsAny<RepoAccount>(), It.IsAny<RepoAccount>(), It.IsAny<Settings>()));
|
||||
_mockRepoAccountProcessorService.Setup(serv =>
|
||||
serv.TryUpdateOrCreateRepoCompanyAssignment(It.IsAny<RepoAccount>(), It.IsAny<TemenosCase>(), It.IsAny<Settings>()));
|
||||
_mockRepoAccountProcessorService.Setup(serv => serv.TryUpdateCollateralRetitleDate(It.IsAny<RepoAccount>(), It.IsAny<TemenosCase>()));
|
||||
_mockRepoAccountProcessorService.Setup(serv => serv.UpdateRepoAccountDateClosed(It.IsAny<RepoAccount>()));
|
||||
|
||||
_mockAccountAlertCheckService.Setup(serv => serv.AlertChecksPreStatusReject(It.IsAny<RepoAccountProcessingSlip>()));
|
||||
|
||||
_mockRepoAccountService.Setup(serv => serv.UpdateAsync(It.IsAny<RepoAccount>(), It.IsAny<AppUser>())).ReturnsAsync(repoAccount);
|
||||
|
||||
var temenosCase = new TemenosCase();
|
||||
var temenosAccount = new TemenosAccount();
|
||||
|
||||
//Not Full Update Criteria
|
||||
temenosCase.RepoStatus = RepoStatus.O4R;
|
||||
repoAccount.Status = "O4R";
|
||||
repoAccount.Balance = 1;
|
||||
temenosAccount.Balance = 1;
|
||||
var slip = new RepoAccountProcessingSlip()
|
||||
{
|
||||
RecoveryCase = temenosCase,
|
||||
RecoveryAccount = temenosAccount,
|
||||
ExistingRepoAccount = repoAccount,
|
||||
RequestedBy = new ProcessingItem()
|
||||
{
|
||||
QueuedBy = "testing",
|
||||
AccountNo = "123456-789",
|
||||
CaseId = "0"
|
||||
}
|
||||
};
|
||||
|
||||
// repoAccount, temenosAccount, temenosCase, "123213123"
|
||||
var res = await _repoAccountProcessor.UpdateExistingRepoAccount(slip);
|
||||
|
||||
_mockRepoAccountProcessorService.Verify(serv => serv.UpdateRepoAccountDateClosed(It.IsAny<RepoAccount>()), Times.Once);
|
||||
_mockRepoAccountProcessorService.Verify(serv => serv.TryUpdateCollateralRetitleDate(It.IsAny<RepoAccount>(), It.IsAny<TemenosCase>()),Times.Once);
|
||||
_mockRepoAccountProcessorService.Verify(serv => serv.UpdateRepoAccountDateClosed(It.IsAny<RepoAccount>()), Times.Once);
|
||||
_mockRepoAccountProcessorService.Verify(serv =>
|
||||
serv.TryUpdateOrCreateRepoCompanyAssignment(It.IsAny<RepoAccount>(), It.IsAny<TemenosCase>(), It.IsAny<Settings>()),Times.Once);
|
||||
|
||||
Assert.NotNull(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
+3492
File diff suppressed because one or more lines are too long
+4909
File diff suppressed because one or more lines are too long
+3228
File diff suppressed because it is too large
Load Diff
+761
@@ -0,0 +1,761 @@
|
||||
{
|
||||
"repoLetters": [],
|
||||
"coreTransactions": [],
|
||||
"temenosHistory": [],
|
||||
"temenosAccount": {
|
||||
"accountId": 875981,
|
||||
"accountIdentifier": "2035090143",
|
||||
"accountNumber": "2035090",
|
||||
"accountStatus": "",
|
||||
"accountTypeId": 1005,
|
||||
"accountType": {
|
||||
"id": 1005,
|
||||
"description": "Auto New Indirect",
|
||||
"code": "ANI"
|
||||
},
|
||||
"activeFlag": true,
|
||||
"amountLastPaid": null,
|
||||
"balance": 41637.96,
|
||||
"bankruptcyFlag": false,
|
||||
"branch": null,
|
||||
"dueDate": null,
|
||||
"firstPaymentDueDate": null,
|
||||
"loanOfficer": "",
|
||||
"originalLoanAmount": null,
|
||||
"originalLoanDate": null,
|
||||
"dqAmount": null,
|
||||
"daysDq": null,
|
||||
"suffix": "143",
|
||||
"linkedAccount": "2035090143",
|
||||
"productType": "",
|
||||
"closedDate": null,
|
||||
"dateLastPaid": null,
|
||||
"dateFirstDelinquent": "7/7/2020 12:00:00 AM",
|
||||
"cases": [
|
||||
{
|
||||
"caseId": 24,
|
||||
"caseNumber": "DE-00000024",
|
||||
"caseDescription": "",
|
||||
"caseStageId": 0,
|
||||
"repoStatus": 0,
|
||||
"caseStatusId": 33,
|
||||
"caseTitle": "DE-00000024",
|
||||
"caseTypeBasisId": 6,
|
||||
"caseTypeId": 44,
|
||||
"closedDate": null,
|
||||
"createdDate": "2021-04-13T11:10:52.32",
|
||||
"createdUserId": 13,
|
||||
"currentStageDate": "2021-04-13T11:10:51.85",
|
||||
"currentStatusDate": "2021-04-13T11:10:51.85",
|
||||
"lastReviewDate": null,
|
||||
"nextReviewDate": null,
|
||||
"stage1CompletionDate": null,
|
||||
"stage2CompletionDate": null,
|
||||
"stage3CompletionDate": null,
|
||||
"stage4CompletionDate": null,
|
||||
"stage5CompletionDate": null,
|
||||
"titleOrdered": false,
|
||||
"titleOrderedDate": null,
|
||||
"redemptionExpiredDateIl": null,
|
||||
"redemptionExpiredDateWi": null,
|
||||
"customFieldMap": {
|
||||
"Case Modification Status": "",
|
||||
"Case Loss Mitigation Stage": "",
|
||||
"Case Loss Mitigation Type": "",
|
||||
"Case Loss Mitigation Status": "",
|
||||
"BRP Hardship Letter": "",
|
||||
"BRP Bank Statements": "",
|
||||
"BRP Paycheck Stubs": "",
|
||||
"BRP Other Income If Applicable": "",
|
||||
"BRP Tax Returns": "",
|
||||
"BRP 4506T Form Signed": "",
|
||||
"BRP Financial Worksheet": "",
|
||||
"BRP 1st Mortgage Statement": "",
|
||||
"BRP HOI Declaration Page": "",
|
||||
"BRP Escrow Authorization Signed": "",
|
||||
"BRP Additional Information Needed": "",
|
||||
"Def Fore Financial Filed": "",
|
||||
"Def Fore Case Number": "",
|
||||
"Def Fore Date Filed": "",
|
||||
"Def Fore Property Address is Mailing Address": "",
|
||||
"Def Fore Property Address if not Mailing Address": "",
|
||||
"Def Fore Attorney Name": "",
|
||||
"Def Fore Attorney Number": "",
|
||||
"Fore Referral Date": "",
|
||||
"Fore SCRA Checked Date": "",
|
||||
"Fore RTC Expiration Date": "",
|
||||
"Fore On Hold Date": "",
|
||||
"Fore On Hold Reason": "",
|
||||
"Fore Reinstated Date": "",
|
||||
"Fore Withdrawn Date": "",
|
||||
"Fore Withdrawn Reason": "",
|
||||
"Fore Withdrawn Reason If Other": "",
|
||||
"Fore Date Last Payment": "",
|
||||
"Fore Sale Scheduled Date": "",
|
||||
"Fore Confirmation Scheduled Date": "",
|
||||
"Fore Confirmation Complete Date": "",
|
||||
"Fore Sale Result": "",
|
||||
"Collection Agency": "False",
|
||||
"Todays Date Case Lvl": "",
|
||||
"DQ Amount Case Lvl": "",
|
||||
"Performance Pymnts Case Lvl": "",
|
||||
"Late Charges Case Lvl": "",
|
||||
"Repo Fees Case Lvl": "",
|
||||
"Redemption Amount Case Lvl": "0.0000",
|
||||
"Balance Due Case Lvl": "",
|
||||
"Legal Requested State Case Lvl": "",
|
||||
"Judgement Dropdown Case Lvl": "",
|
||||
"Attorney Firm Case Lvl": "",
|
||||
"Documents Sent Date Case Lvl": "",
|
||||
"Date Sent to Attorney Case Lvl": "",
|
||||
"Date Served Case Lvl": "",
|
||||
"Attorney Invoice Number Case Lvl": "",
|
||||
"WRIT Flag Case Lvl": "False",
|
||||
"Date Last RTC Letter Sent Case Lvl": "",
|
||||
"RTC Sent Flag Case Lvl": "False",
|
||||
"WRIT Date Case Lvl": "",
|
||||
"Bond Obtained Flag Case Lvl": "False",
|
||||
"Bond Obtained Date Case Lvl": "",
|
||||
"Sent to Sheriff Date Case Lvl": "",
|
||||
"Garnishment Employer Case Lvl": "",
|
||||
"Financial Disclosure Sent Flag Case Lvl": "False",
|
||||
"Garnishment Paying Flag Case Lvl": "False",
|
||||
"Garnishment Review Date Case Lvl": "",
|
||||
"Post Judgement Rate Case Lvl": "",
|
||||
"Judgement Property Address 1 Case Lvl": "",
|
||||
"Judgement Property Address 2 Case Lvl": "",
|
||||
"Judgement Property Address 3 Case Lvl": "",
|
||||
"Docket Date 1 Case Lvl": "",
|
||||
"Docket Date 2 Case Lvl": "",
|
||||
"Docket Date 3 Case Lvl": "",
|
||||
"Stip Payment Amount Case Lvl": "",
|
||||
"Stip Payment Frequency Case Lvl": "",
|
||||
"Stip Total Amount Case Level": "",
|
||||
"Legal Closed Reason Case Lvl": "",
|
||||
"Date Redeemed Repo": ""
|
||||
},
|
||||
"dateRepossessed": null,
|
||||
"repoTypeId": "",
|
||||
"repoType": 0,
|
||||
"dateRepoAssigned": null,
|
||||
"repoAgentId": null
|
||||
},
|
||||
{
|
||||
"caseId": 25,
|
||||
"caseNumber": "DE-00000025",
|
||||
"caseDescription": "",
|
||||
"caseStageId": 2000067,
|
||||
"repoStatus": 999,
|
||||
"caseStatusId": 33,
|
||||
"caseTitle": "DE-00000024",
|
||||
"caseTypeBasisId": 6,
|
||||
"caseTypeId": 7,
|
||||
"closedDate": null,
|
||||
"createdDate": "2021-04-17T11:10:52.32",
|
||||
"createdUserId": 13,
|
||||
"currentStageDate": "2021-04-17T11:10:51.85",
|
||||
"currentStatusDate": "2021-04-17T11:10:51.85",
|
||||
"lastReviewDate": null,
|
||||
"nextReviewDate": null,
|
||||
"stage1CompletionDate": null,
|
||||
"stage2CompletionDate": null,
|
||||
"stage3CompletionDate": null,
|
||||
"stage4CompletionDate": null,
|
||||
"stage5CompletionDate": null,
|
||||
"titleOrdered": false,
|
||||
"titleOrderedDate": null,
|
||||
"redemptionExpiredDateIl": null,
|
||||
"redemptionExpiredDateWi": null,
|
||||
"customFieldMap": {
|
||||
"Case Modification Status": "",
|
||||
"Case Loss Mitigation Stage": "",
|
||||
"Case Loss Mitigation Type": "",
|
||||
"Case Loss Mitigation Status": "",
|
||||
"BRP Hardship Letter": "",
|
||||
"BRP Bank Statements": "",
|
||||
"BRP Paycheck Stubs": "",
|
||||
"BRP Other Income If Applicable": "",
|
||||
"BRP Tax Returns": "",
|
||||
"BRP 4506T Form Signed": "",
|
||||
"BRP Financial Worksheet": "",
|
||||
"BRP 1st Mortgage Statement": "",
|
||||
"BRP HOI Declaration Page": "",
|
||||
"BRP Escrow Authorization Signed": "",
|
||||
"BRP Additional Information Needed": "",
|
||||
"Def Fore Financial Filed": "",
|
||||
"Def Fore Case Number": "",
|
||||
"Def Fore Date Filed": "",
|
||||
"Def Fore Property Address is Mailing Address": "",
|
||||
"Def Fore Property Address if not Mailing Address": "",
|
||||
"Def Fore Attorney Name": "",
|
||||
"Def Fore Attorney Number": "",
|
||||
"Fore Referral Date": "",
|
||||
"Fore SCRA Checked Date": "",
|
||||
"Fore RTC Expiration Date": "",
|
||||
"Fore On Hold Date": "",
|
||||
"Fore On Hold Reason": "",
|
||||
"Fore Reinstated Date": "",
|
||||
"Fore Withdrawn Date": "",
|
||||
"Fore Withdrawn Reason": "",
|
||||
"Fore Withdrawn Reason If Other": "",
|
||||
"Fore Date Last Payment": "",
|
||||
"Fore Sale Scheduled Date": "",
|
||||
"Fore Confirmation Scheduled Date": "",
|
||||
"Fore Confirmation Complete Date": "",
|
||||
"Fore Sale Result": "",
|
||||
"Collection Agency": "False",
|
||||
"Todays Date Case Lvl": "",
|
||||
"DQ Amount Case Lvl": "",
|
||||
"Performance Pymnts Case Lvl": "",
|
||||
"Late Charges Case Lvl": "",
|
||||
"Repo Fees Case Lvl": "",
|
||||
"Redemption Amount Case Lvl": "0.0000",
|
||||
"Balance Due Case Lvl": "",
|
||||
"Legal Requested State Case Lvl": "",
|
||||
"Judgement Dropdown Case Lvl": "",
|
||||
"Attorney Firm Case Lvl": "",
|
||||
"Documents Sent Date Case Lvl": "",
|
||||
"Date Sent to Attorney Case Lvl": "",
|
||||
"Date Served Case Lvl": "",
|
||||
"Attorney Invoice Number Case Lvl": "",
|
||||
"WRIT Flag Case Lvl": "False",
|
||||
"Date Last RTC Letter Sent Case Lvl": "",
|
||||
"RTC Sent Flag Case Lvl": "False",
|
||||
"WRIT Date Case Lvl": "",
|
||||
"Bond Obtained Flag Case Lvl": "False",
|
||||
"Bond Obtained Date Case Lvl": "",
|
||||
"Sent to Sheriff Date Case Lvl": "",
|
||||
"Garnishment Employer Case Lvl": "",
|
||||
"Financial Disclosure Sent Flag Case Lvl": "False",
|
||||
"Garnishment Paying Flag Case Lvl": "False",
|
||||
"Garnishment Review Date Case Lvl": "",
|
||||
"Post Judgement Rate Case Lvl": "",
|
||||
"Judgement Property Address 1 Case Lvl": "",
|
||||
"Judgement Property Address 2 Case Lvl": "",
|
||||
"Judgement Property Address 3 Case Lvl": "",
|
||||
"Docket Date 1 Case Lvl": "",
|
||||
"Docket Date 2 Case Lvl": "",
|
||||
"Docket Date 3 Case Lvl": "",
|
||||
"Stip Payment Amount Case Lvl": "",
|
||||
"Stip Payment Frequency Case Lvl": "",
|
||||
"Stip Total Amount Case Level": "",
|
||||
"Legal Closed Reason Case Lvl": "",
|
||||
"Date Redeemed Repo": ""
|
||||
},
|
||||
"dateRepossessed": null,
|
||||
"repoTypeId": "",
|
||||
"repoType": 0,
|
||||
"dateRepoAssigned": null,
|
||||
"repoAgentId": null
|
||||
},
|
||||
{
|
||||
"caseId": 342,
|
||||
"caseNumber": "REPO-00000342",
|
||||
"caseDescription": "",
|
||||
"caseStageId": 2000122,
|
||||
"repoStatus": 100,
|
||||
"caseStatusId": 33,
|
||||
"caseTitle": "REPO-00000342",
|
||||
"caseTypeBasisId": 2,
|
||||
"caseTypeId": 7,
|
||||
"closedDate": null,
|
||||
"createdDate": "2021-04-15T12:41:53.23",
|
||||
"createdUserId": 6,
|
||||
"currentStageDate": "2021-04-15T12:41:52.497",
|
||||
"currentStatusDate": "2021-04-15T12:41:52.497",
|
||||
"lastReviewDate": null,
|
||||
"nextReviewDate": null,
|
||||
"stage1CompletionDate": null,
|
||||
"stage2CompletionDate": null,
|
||||
"stage3CompletionDate": null,
|
||||
"stage4CompletionDate": null,
|
||||
"stage5CompletionDate": null,
|
||||
"titleOrdered": false,
|
||||
"titleOrderedDate": null,
|
||||
"redemptionExpiredDateIl": null,
|
||||
"redemptionExpiredDateWi": null,
|
||||
"customFieldMap": {
|
||||
"Case Modification Status": "",
|
||||
"Case Loss Mitigation Stage": "",
|
||||
"Case Loss Mitigation Type": "",
|
||||
"Case Loss Mitigation Status": "",
|
||||
"BRP Hardship Letter": "",
|
||||
"BRP Bank Statements": "",
|
||||
"BRP Paycheck Stubs": "",
|
||||
"BRP Other Income If Applicable": "",
|
||||
"BRP Tax Returns": "",
|
||||
"BRP 4506T Form Signed": "",
|
||||
"BRP Financial Worksheet": "",
|
||||
"BRP 1st Mortgage Statement": "",
|
||||
"BRP HOI Declaration Page": "",
|
||||
"BRP Escrow Authorization Signed": "",
|
||||
"BRP Additional Information Needed": "",
|
||||
"Def Fore Financial Filed": "",
|
||||
"Def Fore Case Number": "",
|
||||
"Def Fore Date Filed": "",
|
||||
"Def Fore Property Address is Mailing Address": "",
|
||||
"Def Fore Property Address if not Mailing Address": "",
|
||||
"Def Fore Attorney Name": "",
|
||||
"Def Fore Attorney Number": "",
|
||||
"Fore Referral Date": "",
|
||||
"Fore SCRA Checked Date": "",
|
||||
"Fore RTC Expiration Date": "",
|
||||
"Fore On Hold Date": "",
|
||||
"Fore On Hold Reason": "",
|
||||
"Fore Reinstated Date": "",
|
||||
"Fore Withdrawn Date": "",
|
||||
"Fore Withdrawn Reason": "",
|
||||
"Fore Withdrawn Reason If Other": "",
|
||||
"Fore Date Last Payment": "",
|
||||
"Fore Sale Scheduled Date": "",
|
||||
"Fore Confirmation Scheduled Date": "",
|
||||
"Fore Confirmation Complete Date": "",
|
||||
"Fore Sale Result": "",
|
||||
"Collection Agency": "False",
|
||||
"Todays Date Case Lvl": "",
|
||||
"DQ Amount Case Lvl": "",
|
||||
"Performance Pymnts Case Lvl": "",
|
||||
"Late Charges Case Lvl": "",
|
||||
"Repo Fees Case Lvl": "",
|
||||
"Redemption Amount Case Lvl": "0.0000",
|
||||
"Balance Due Case Lvl": "",
|
||||
"Legal Requested State Case Lvl": "",
|
||||
"Judgement Dropdown Case Lvl": "",
|
||||
"Attorney Firm Case Lvl": "",
|
||||
"Documents Sent Date Case Lvl": "",
|
||||
"Date Sent to Attorney Case Lvl": "",
|
||||
"Date Served Case Lvl": "",
|
||||
"Attorney Invoice Number Case Lvl": "",
|
||||
"WRIT Flag Case Lvl": "False",
|
||||
"Date Last RTC Letter Sent Case Lvl": "",
|
||||
"RTC Sent Flag Case Lvl": "False",
|
||||
"WRIT Date Case Lvl": "",
|
||||
"Bond Obtained Flag Case Lvl": "False",
|
||||
"Bond Obtained Date Case Lvl": "",
|
||||
"Sent to Sheriff Date Case Lvl": "",
|
||||
"Garnishment Employer Case Lvl": "",
|
||||
"Financial Disclosure Sent Flag Case Lvl": "False",
|
||||
"Garnishment Paying Flag Case Lvl": "False",
|
||||
"Garnishment Review Date Case Lvl": "",
|
||||
"Post Judgement Rate Case Lvl": "",
|
||||
"Judgement Property Address 1 Case Lvl": "",
|
||||
"Judgement Property Address 2 Case Lvl": "",
|
||||
"Judgement Property Address 3 Case Lvl": "",
|
||||
"Docket Date 1 Case Lvl": "",
|
||||
"Docket Date 2 Case Lvl": "",
|
||||
"Docket Date 3 Case Lvl": "",
|
||||
"Stip Payment Amount Case Lvl": "",
|
||||
"Stip Payment Frequency Case Lvl": "",
|
||||
"Stip Total Amount Case Level": "",
|
||||
"Legal Closed Reason Case Lvl": "",
|
||||
"Date Redeemed Repo": ""
|
||||
},
|
||||
"dateRepossessed": null,
|
||||
"repoTypeId": "2000143",
|
||||
"repoType": 1,
|
||||
"dateRepoAssigned": "2021-04-15T00:00:00",
|
||||
"repoAgentId": "2000399"
|
||||
}
|
||||
],
|
||||
"customFieldMap": {
|
||||
"Charge Off Status": "",
|
||||
"Foreclosure Status - Lookup": "",
|
||||
"Reason for Charge Off": "",
|
||||
"Post Charge Off Intentions": "",
|
||||
"BK Discharged Flag": "False",
|
||||
"BK Reaffirmed Flag": "False",
|
||||
"Fraud Suspected Flag": "False",
|
||||
"Management Review Flag": "False",
|
||||
"Balance at time of Charge Off": "",
|
||||
"Date Approved for Charge Off": "",
|
||||
"Date Approved for Foreclosure": "",
|
||||
"Date Approved for Legal": "",
|
||||
"Date Approved for Repo": "",
|
||||
"Foreclosure Requested Flag": "False",
|
||||
"Legal Requested Flag": "False",
|
||||
"Lookup Value 4 - Lookup": "",
|
||||
"Lookup Value 5 - Lookup": "",
|
||||
"Repo Requested Flag": "True",
|
||||
"Status Code 1": "",
|
||||
"Status Code 2": "",
|
||||
"Status Code 3": "",
|
||||
"Status Code 4": "",
|
||||
"Status Code 5": "",
|
||||
"External Loan Number": "",
|
||||
"Product Code": "",
|
||||
"Product Name": "L-PN- Dealer New Vehicle",
|
||||
"CORS Court Name": "",
|
||||
"Loan Type": "",
|
||||
"Original Interest Rate": "",
|
||||
"Original Rate Type": "",
|
||||
"Current Rate Type": "",
|
||||
"Current Rate Term": "",
|
||||
"Required Payment Amount": "",
|
||||
"Times Late Count": "",
|
||||
"Times Late 30 Days Count": "",
|
||||
"Times Late 60 Days Count": "",
|
||||
"Times Late 90 Days Count": "",
|
||||
"Troubled Debt Restructure": "False",
|
||||
"Modification Date": "",
|
||||
"Modification Count": "",
|
||||
"Modification Type": "",
|
||||
"Financial Condition": "",
|
||||
"Modification Reason": "",
|
||||
"Membership Address 1": "",
|
||||
"Membership Address 2": "",
|
||||
"Membership City": "",
|
||||
"Membership State Code": "",
|
||||
"Membership Postal Code": "",
|
||||
"User Status Code 1": "CLEX",
|
||||
"User Status Code 2": "DE",
|
||||
"Intellect Permanent Comments": "143 RTC $1,851.20 Exp. 8/4/20 DOD 8/15/19 death cert, added to PBF 8/21/19 Fontessa Moore 414-202-4706 temp disc wi number & **cell 803-387-8944 / 803-662-6311 transfer by affidavit on file ftezzm",
|
||||
"PRI Metro 2 Code": "",
|
||||
"S1 Metro 2 Code": "",
|
||||
"S2 Metro 2 Code": "",
|
||||
"PRI Metro 2 Code Description": "",
|
||||
"S1 Metro 2 Code Description": "",
|
||||
"S2 Metro 2 Code Description": "",
|
||||
"PRI Affiliation Description": "",
|
||||
"S1 Affiliation Description": "",
|
||||
"S2 Affiliation Description": "",
|
||||
"CORS Employer Address 1": "",
|
||||
"CORS Employer Address 2": "",
|
||||
"CORS Employer City": "",
|
||||
"CORS Employer State Code": "",
|
||||
"CORS Employer Postal Code": "",
|
||||
"CORS Employer Comment": "",
|
||||
"CORS Loan CORS date": "",
|
||||
"CORS Demand Agency": "",
|
||||
"CORS Assigned Agency": "",
|
||||
"CORS Bankruptcy Case Number": "",
|
||||
"CORS Bankruptcy File Date": "",
|
||||
"CORS Bankruptcy Discharged Date": "",
|
||||
"CORS Consumer Info Indicator": "False",
|
||||
"CORS Trustee Name": "",
|
||||
"CORS Bankruptcy Comment": "",
|
||||
"CORS Motion Date": "",
|
||||
"CORS Judgement Recordation": "",
|
||||
"CORS Judgement Amount": "",
|
||||
"CORS Judgement Status": "",
|
||||
"CORS Judgement Comment": "",
|
||||
"CORS Transaction Code": "",
|
||||
"CORS Payment Amount": "",
|
||||
"CORS Payment Frequency": "",
|
||||
"CORS Payment Start Date": "",
|
||||
"CORS User Assigned Name": "",
|
||||
"CORS User Assigned Start Date": "",
|
||||
"CORS User Assigned End Date": "",
|
||||
"CORS Workflow Entered Date": "",
|
||||
"CORS Workflow To Do Date": "",
|
||||
"CORS Workflow Completed By Date": "",
|
||||
"CORS Workflow User Name": "Schetter",
|
||||
"CORS Workflow Action Description": "Loan Comment",
|
||||
"CORS Workflow Comment": "emailed fontessa for update on",
|
||||
"Organization Number": "",
|
||||
"Client Number": "",
|
||||
"Date High Balance": "",
|
||||
"External Status Date 1": "",
|
||||
"External Status 2": "",
|
||||
"External Status Date 2": "",
|
||||
"Insurance Code 1": "",
|
||||
"Insurance Status 1": "",
|
||||
"Insurance Status 2": "",
|
||||
"Insurance Code 2": "",
|
||||
"Insurance Status 3": "",
|
||||
"Insurance Code 3": "",
|
||||
"Most Recent Credit Score": "",
|
||||
"Credit Score Less Recent": "",
|
||||
"Relationship Flag": "",
|
||||
"Relationship Number": "",
|
||||
"S1 Original Credit Union": "",
|
||||
"S1 Most Recent Credit Score": "",
|
||||
"S1 Credit Score Less Recent": "",
|
||||
"Client Name": "",
|
||||
"Mortgage Insurer": "",
|
||||
"Last Analyzed Date": "",
|
||||
"Deferred Principal Balance": "",
|
||||
"Prepetition Unapplied Balance": "",
|
||||
"Stipulation Unapplied Balance": "",
|
||||
"Other Funds Payment Amount": "",
|
||||
"Assistance Payment Amount": "",
|
||||
"Reserve Account Payment Amount": "",
|
||||
"Default Interest Amount": "",
|
||||
"Last NSF Fee Date": "",
|
||||
"Last Letter Date": "",
|
||||
"Other Fee Amount": "",
|
||||
"Last Late Charge Waived Date": "",
|
||||
"Last Late Charge Waived Amount": "",
|
||||
"Next Late Charge Amount": "",
|
||||
"Times Late LOL Count": "",
|
||||
"Times Late Last 12 Months Count": "",
|
||||
"Times Late 120 Days Count": "",
|
||||
"Times Late 150 Days Count": "",
|
||||
"Times Late 180 Days Count": "",
|
||||
"First Payment Due Date": "",
|
||||
"Maturity Type Description": "",
|
||||
"Inspection Ordered Date": "",
|
||||
"Last Inspection Date": "",
|
||||
"Inspection Received Date": "",
|
||||
"Current Occupancy Code": "",
|
||||
"Inspected By": "",
|
||||
"Property Type Description": "",
|
||||
"Property Condition Description": "",
|
||||
"Neighborhood Condition": "",
|
||||
"Collateral 1 Property Type Code": "",
|
||||
"Collateral 1 Lein Position": "",
|
||||
"Bankruptcy Case Number": "",
|
||||
"Bankruptcy Date Filed": "",
|
||||
"DNU Bankruptcy Chapter Filed": "",
|
||||
"Bankruptcy Claim Number": "",
|
||||
"Bankruptcy Trustee Claim Number 1": "",
|
||||
"Bankruptcy Trustee Claim Number 2": "",
|
||||
"Bankruptcy Trustee Claim Number 3": "",
|
||||
"Bankruptcy Name": "",
|
||||
"Bankruptcy Event Code": "",
|
||||
"Bankruptcy Event Legal": "",
|
||||
"Bankruptcy Event Warning": "",
|
||||
"Active Bankruptcy Flag": "False",
|
||||
"Active Bankruptcy Plan Flag": "False",
|
||||
"Bankruptcy Payment Status Date": "",
|
||||
"Bankruptcy Milestone Due Date": "",
|
||||
"Bankruptcy Milestone Completion Date": "",
|
||||
"Bankruptcy Milestone Scheduled Date": "",
|
||||
"Bankruptcy Milestone Actual Date": "",
|
||||
"Bankruptcy Servicer Only": "",
|
||||
"Contact Promise Date 1": "",
|
||||
"Contact Promise Amount 1": "",
|
||||
"Contact Promise Date 2": "",
|
||||
"Contact Promise Amount 2": "",
|
||||
"Contact Promise Date 3": "",
|
||||
"Contact Promise Amount 3": "",
|
||||
"Contact Reason": "",
|
||||
"Contact Demeanor": "",
|
||||
"Contact Outcome": "",
|
||||
"Contact Permanent Comments": "",
|
||||
"Legal Fee Amount": "",
|
||||
"Collateral 1 Seller Name": "",
|
||||
"Collateral 2 Seller Name": "",
|
||||
"Collateral 3 Seller Name": "",
|
||||
"Net Capitalized Cost Amount": "",
|
||||
"Total Payments Count": "",
|
||||
"Times Late 90 Plus Days Count": "",
|
||||
"Late Fee Amount": "",
|
||||
"Date 22 Day Letter Sent": "",
|
||||
"Date 32 Day Letter Sent": "",
|
||||
"Date 60 Day Letter Sent": "",
|
||||
"Collateral 1 Legal Description": "",
|
||||
"Collateral 2 Legal Description": "",
|
||||
"Collateral 3 Legal Description": "",
|
||||
"Collateral 4 Legal Description": "",
|
||||
"SD Contact Follow Up Date": "",
|
||||
"CORS Next Follow Up Date": "2/15/2021 12:00:00 AM",
|
||||
"Waive Fee Reason DropDown": "",
|
||||
"Waive Fee Reason Dropdown Spanish": "",
|
||||
"Case Stages 1": "2000122",
|
||||
"Dollar Amount": "",
|
||||
"Case Stages 2": "",
|
||||
"SCRA Flag": "False",
|
||||
"TCPA Consent": "",
|
||||
"Request Outcome": "",
|
||||
"Request Outcome Date": "",
|
||||
"Offset Request Reason DropDown": "",
|
||||
"Intellect Next Follow Up Date": "9/10/2020 12:00:00 AM",
|
||||
"Original Product Type": "",
|
||||
"Recovery Branch": "57",
|
||||
"Reason For Repo": "deceased account 3rd party can't afford to keep it",
|
||||
"Repo Recovery Address": "2000141",
|
||||
"Right to Cure Expired": "False",
|
||||
"RTC Expiration Date": "",
|
||||
"Repo Type": "",
|
||||
"Repossession Type": "2000143",
|
||||
"Secondary Recovery Address": "2000141",
|
||||
"Redemption Calc WI Perfrmnce Pymnts": "0.0000",
|
||||
"Redemption Calc WI Repo Fees": "",
|
||||
"Redemption Calc WI Total Due": "80.0000",
|
||||
"Redemption Calc WI Exp Date": "",
|
||||
"Redemption Date Current Date": "",
|
||||
"Redemption Calc WI Expiration Date": "",
|
||||
"Investor": "",
|
||||
"Money Field 2": "",
|
||||
"Money Field 1": "",
|
||||
"Loan Status": "L (From INTELLECT)",
|
||||
"Redemption Calc IL 30 Percent Amnt Paid": "0.0000",
|
||||
"Redemption Calc IL 30 Percent Yes or No": "True",
|
||||
"Redemption Calc IL Total Due": "80.0000",
|
||||
"Redemption Calc IL Exp Date": "",
|
||||
"Current LTV Amount": "",
|
||||
"Original LTV Amount": "",
|
||||
"Redemption Calc IL Repo Fees": "",
|
||||
"Redemption Calc IL Expiration Date": "",
|
||||
"Repo Agencies": "",
|
||||
"Bankruptcy Trustee": "",
|
||||
"Title Ordered": "False",
|
||||
"Title Received": "False",
|
||||
"Vehicle ReTitled": "False",
|
||||
"Title Ordered Date": "",
|
||||
"ReTitled Date": "",
|
||||
"Title Received Date": "",
|
||||
"X Deceased Flag Dont Use": "True",
|
||||
"CPI Active": "False",
|
||||
"Branch Location": "",
|
||||
"Collection Agency": "",
|
||||
"Consumer Credit Counseling Services Flag": "False",
|
||||
"Skip Trace Requested": "False",
|
||||
"Loss Mitigation Status": "",
|
||||
"Judgement Dropdown": "",
|
||||
"Claim Type": "",
|
||||
"Refund Status": "",
|
||||
"Maintenance Requested": "False",
|
||||
"BK Chapter": "",
|
||||
"Settlement": "False",
|
||||
"Repayment Plan Status": "",
|
||||
"BK No Reaffirmation Flag": "False",
|
||||
"test": "",
|
||||
"Totaled Vehicle": "False",
|
||||
"Fees Due": "",
|
||||
"Original Input Code": "",
|
||||
"Fraud Status": "",
|
||||
"CORS Recovery Amt": "0.0000",
|
||||
"CORS Recovery Amount Principal": "0.0000",
|
||||
"Expense Applied Amount": "0.0000",
|
||||
"Interest Applied Amount": "0.0000",
|
||||
"Exp Amp": "80.0000",
|
||||
"Input Code": "",
|
||||
"Report Blank": "",
|
||||
"Totaled Vehicle Notification Date": "",
|
||||
"Warranty Cancellation Date": "",
|
||||
"Refunds Requested Date": "",
|
||||
"Repayment Plan Active": "False",
|
||||
"Estate Attorney": "",
|
||||
"Estate Attorney Phone Number": "",
|
||||
"Personal Representative": "",
|
||||
"Final Date to File Claim": "",
|
||||
"Estate Closing Dates": "",
|
||||
"Date Entered to Probate Finder": "8/21/2019 12:00:00 AM",
|
||||
"Date Notified Deceased": "8/21/2019 12:00:00 AM",
|
||||
"Death Notification Type": "2000224",
|
||||
"Visible Assets": "False",
|
||||
"CCCS Status": "",
|
||||
"Consumer Credit Counseling Service Company": "",
|
||||
"CCCS Amount Approved": "",
|
||||
"CCCS Decision Date": "",
|
||||
"Settlement Amount": "",
|
||||
"Primary Insurance Company": "",
|
||||
"Primary Insurance Company Phone Number": "",
|
||||
"Claim Number": "",
|
||||
"Date of Loss": "",
|
||||
"Totaled Vehicle Mileage": "",
|
||||
"Totaled Vehicle Settlement Amount": "",
|
||||
"Totaled Vehicle Warranty Refund": "",
|
||||
"Totaled Vehicle Refunds Received Date": "",
|
||||
"Totaled Vehicle Refunds Received Amount": "",
|
||||
"GAP Payment Received Date": "",
|
||||
"Defensive Foreclosure Flag Do Not Use": "False",
|
||||
"Defensive Foreclosure Flag": "False",
|
||||
"Collateral Still Exists Flags": "False",
|
||||
"Bankrupt Collectible Non Filing Borrower Flag": "False",
|
||||
"Manual Transfer Amount": "",
|
||||
"Manual Transfer Frequency": "",
|
||||
"Transfer From Account": "",
|
||||
"Transfer To Account": "",
|
||||
"CBR Request": "",
|
||||
"CBR Date Received": "",
|
||||
"Additional CBR Information Needed": "",
|
||||
"CBR Approved": "",
|
||||
"CBR Yes No Reason": "",
|
||||
"BRP Sent Flag": "False",
|
||||
"BRP Sent Date": "",
|
||||
"Manual Transfer Start Date": "",
|
||||
"Loss Mitigation Stage": "",
|
||||
"Loss Mitigation Type": "",
|
||||
"Date Last RTC Letter Sent": "",
|
||||
"Skip Trace Phone No1": "",
|
||||
"Skip Trace Phone No2": "",
|
||||
"Skip Trace Phone No3": "",
|
||||
"Skip Trace Phone No4": "",
|
||||
"Skip Trace Phone No5": "",
|
||||
"Skip Trace Phone No6": "",
|
||||
"Skip Trace Phone No7": "",
|
||||
"Skip Trace Phone No8": "",
|
||||
"Skip Trace Phone No9": "",
|
||||
"Skip Trace Phone No10": "",
|
||||
"Skip Trace Address No1": "",
|
||||
"Skip Trace Address No2": "",
|
||||
"Skip Trace Address No3": "",
|
||||
"Skip Trace Address No4": "",
|
||||
"Skip Trace Address No5": "",
|
||||
"Skip Trace Address No6": "",
|
||||
"Skip Trace Email No1": "",
|
||||
"Skip Trace Email No2": "",
|
||||
"Skip Trace Email No3": "",
|
||||
"Skip Trace Email No4": "",
|
||||
"Skip Trace Email No5": "",
|
||||
"Skip Trace POE No1": "",
|
||||
"Skip Trace POE No2": "",
|
||||
"Skip Trace Comments": "",
|
||||
"TLO Basic Flag": "False",
|
||||
"TLO Comprehensive Flag": "False",
|
||||
"DRN Flag": "False",
|
||||
"RDN Flag": "False",
|
||||
"CarFax Flag": "False",
|
||||
"Equifax Flag": "False",
|
||||
"Facebook Flag": "False",
|
||||
"Skip Trace Date": "",
|
||||
"GainLoss Value Amount": "",
|
||||
"GainLoss Value Date": "",
|
||||
"GainLoss Senior Balance": "",
|
||||
"GainLoss Senior Name": "",
|
||||
"GainLoss Value Source": "",
|
||||
"GainLoss Outstanding Taxes": "",
|
||||
"GainLoss Marketing Costs": "5000.0000",
|
||||
"GainLoss 1yr Taxes": "",
|
||||
"GainLoss Review Date": "",
|
||||
"GainLoss Marketing Commission": "0.0000",
|
||||
"GainLoss Total Amount": "-46637.9600",
|
||||
"Collection Agency Flag": "False",
|
||||
"Chapter 128 Flag": "False",
|
||||
"Chapter 128 Case Number": "",
|
||||
"Chapter 128 Date Filed": "",
|
||||
"CORS Trustee Number": "",
|
||||
"CORS Trustee Address": "",
|
||||
"CORS Trustee Email": "",
|
||||
"CORS Loan type Description": "L-PN- Dealer New Vehicle",
|
||||
"Host Code": "L-PN",
|
||||
"CORS Initial Charge Off Balance Amount": "41637.9600",
|
||||
"CORS Initial Charge Off Date": "1/5/2021 12:00:00 AM",
|
||||
"CORS Initial Principal Amount": "41637.9600",
|
||||
"CORS Initial Interest Amount": "1559.9500",
|
||||
"CORS Initial Expense Amount": "80.0000",
|
||||
"CORS Transfer Date": "1/5/2021 12:00:00 AM",
|
||||
"CORS Initial Interest Rate Type": "Fixed Rate",
|
||||
"CORS Initial Interest Rate Percent": "7.3000",
|
||||
"CORS Initial Day Count": "",
|
||||
"CORS Current Principal Amount": "41637.9600",
|
||||
"CORS Current Interest Amount": "2334.4200",
|
||||
"CORS Current Expense Amount": "80.0000",
|
||||
"CORS Curent Non Reimbursable Expense Amount": "0.0000",
|
||||
"CORS Current Other Amount": "0.0000",
|
||||
"CORS Non Reimbursable Other Amount": "0.0000",
|
||||
"CORS Current Loan Balance Amount": "44052.3800",
|
||||
"Attorney Firm": "",
|
||||
"Legal Requested State": "",
|
||||
"Garnishment Flag": "False",
|
||||
"Money Judgement Flag": "False",
|
||||
"Replevin Judgement Flag": "False",
|
||||
"Stipulation Flag": "False",
|
||||
"Summary Judgement Flag": "False",
|
||||
"Wage Assignment Flag": "False",
|
||||
"Date No Phone Number Letter Sent": "",
|
||||
"Fraud Data Type": "",
|
||||
"Active Fraud CRIF File": "",
|
||||
"Repo User Assigned": "2000440",
|
||||
"Skip Trace Reason": "",
|
||||
"CORS Branch Number": "01",
|
||||
"CORS Bankruptcy Chapter": "",
|
||||
"Judgement Status": ""
|
||||
}
|
||||
},
|
||||
"loanDetail" :{},
|
||||
"memberDetail" : {},
|
||||
"collateralDetails": []
|
||||
}
|
||||
+2464
File diff suppressed because one or more lines are too long
+3861
File diff suppressed because it is too large
Load Diff
+2033
File diff suppressed because it is too large
Load Diff
+180
@@ -0,0 +1,180 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using LCU.API.Collections.RepoApi.Exceptions;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class RefundStatusServiceTest
|
||||
{
|
||||
private IRefundStatusService _refundStatusService;
|
||||
private Mock<IRefundStatusRepository> _refundStatusRepository;
|
||||
private Mock<IUnitOfWork> _unitOfWork;
|
||||
private Mock<IRepoAccountService> _repoAccountService;
|
||||
private Mock<IEmailer> _emailer;
|
||||
|
||||
public RefundStatusServiceTest()
|
||||
{
|
||||
_refundStatusRepository = new Mock<IRefundStatusRepository>();
|
||||
_unitOfWork = new Mock<IUnitOfWork>();
|
||||
_repoAccountService = new Mock<IRepoAccountService>();
|
||||
_emailer = new Mock<IEmailer>();
|
||||
_refundStatusService = new RefundStatusService(
|
||||
_refundStatusRepository.Object,
|
||||
_unitOfWork.Object,
|
||||
_repoAccountService.Object,
|
||||
_emailer.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetAsync_Ok()
|
||||
{
|
||||
// Arrange
|
||||
_refundStatusRepository.Setup(repo => repo.FindByRepoIdAsync(It.IsAny<int>())).ReturnsAsync(
|
||||
new RefundStatus());
|
||||
|
||||
// Act
|
||||
var result = await _refundStatusService.GetAsync(1);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetAsync_Throws_NFE_When_RefundStatusRepository_Throws_Exception()
|
||||
{
|
||||
// Arrange
|
||||
_refundStatusRepository.Setup(repo => repo.FindByRepoIdAsync(It.IsAny<int>())).ThrowsAsync(
|
||||
new Exception());
|
||||
|
||||
// Act / Assert
|
||||
try
|
||||
{
|
||||
var result = await _refundStatusService.GetAsync(1);
|
||||
Assert.True(false, "An Exception in the RefundStatusRepository should have triggered an Exception upward. No Exception triggered.");
|
||||
}
|
||||
catch (NotFoundException) { }
|
||||
catch (Exception)
|
||||
{
|
||||
Assert.True(false, "A NotFoundException should be thrown when any Exception occurs in RefundStatusRepository. Another Exception was thrown instead.");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetAsync_Throws_NFE_When_RefundStatusRepository_Returns_Null()
|
||||
{
|
||||
// Arrange
|
||||
_refundStatusRepository.Setup(repo => repo.FindByRepoIdAsync(It.IsAny<int>())).ReturnsAsync((RefundStatus) null);
|
||||
|
||||
// Act / Assert
|
||||
try
|
||||
{
|
||||
var result = await _refundStatusService.GetAsync(1);
|
||||
Assert.True(false, "An Exception should have been thrown when the RefundStatusRepository returns a null value. No Exception triggered.");
|
||||
}
|
||||
catch (NotFoundException) { }
|
||||
catch (Exception)
|
||||
{
|
||||
Assert.True(false, "A NotFoundException should be thrown when the RefundStatusRepository returns a null value. Another Exception was thrown instead.");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void SaveASync_Ok()
|
||||
{
|
||||
// Arrange
|
||||
_refundStatusRepository.Setup(repo => repo.AddAsync(It.IsAny<RefundStatus>())).ReturnsAsync(
|
||||
new RefundStatus());
|
||||
|
||||
// Act
|
||||
var result = await _refundStatusService.SaveAsync(new RefundStatus()
|
||||
{
|
||||
RepoId = 123
|
||||
});
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void SaveAsynhc_Throws_Exception_When_RepoAccountService_Throws_Exception()
|
||||
{
|
||||
// Arrange
|
||||
_repoAccountService.Setup(service => service.Get(It.IsAny<int>())).ThrowsAsync(
|
||||
new Exception());
|
||||
|
||||
// Act / Assert
|
||||
try
|
||||
{
|
||||
var result = await _refundStatusService.SaveAsync(new RefundStatus() { RepoId = 123 });
|
||||
Assert.True(false, "An Exception in the RefundStatusRepository should have triggered an Exception upward. No Exception triggered.");
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateAsync_Ok()
|
||||
{
|
||||
// Arrange
|
||||
_refundStatusRepository.Setup(repo => repo.FindByRepoIdAsync(It.IsAny<int>())).ReturnsAsync(
|
||||
new RefundStatus());
|
||||
_repoAccountService.Setup(service => service.Get(It.IsAny<int>())).ReturnsAsync(
|
||||
new RepoAccount());
|
||||
|
||||
// Act
|
||||
var result = await _refundStatusService.UpdateAsync(new RefundStatus()
|
||||
{
|
||||
RepoId = 123
|
||||
});
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateAsync_With_Refunds_Received_Date_Sends_Email()
|
||||
{
|
||||
// Arrange
|
||||
_refundStatusRepository.Setup(repo => repo.FindByRepoIdAsync(It.IsAny<int>())).ReturnsAsync(
|
||||
new RefundStatus());
|
||||
_repoAccountService.Setup(service => service.Get(It.IsAny<int>())).ReturnsAsync(
|
||||
new RepoAccount());
|
||||
_emailer.Setup(emailer => emailer.SendSurplusDeficiencyLetterEmailAsync(It.IsAny<RepoAccount>())).ReturnsAsync(new HttpResponseMessage(System.Net.HttpStatusCode.OK));
|
||||
|
||||
// Act
|
||||
var result = await _refundStatusService.UpdateAsync(new RefundStatus()
|
||||
{
|
||||
RepoId = 123,
|
||||
RefundsReceivedDate = DateTime.Now
|
||||
});
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.NotNull(result.RefundsReceivedDate);
|
||||
_emailer.Verify(x => x.SendSurplusDeficiencyLetterEmailAsync(It.IsAny<RepoAccount>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateAsync_Returns_NFE_When_RefundStatusRepository_Throws_NFE()
|
||||
{
|
||||
// Act / Assert
|
||||
try
|
||||
{
|
||||
await _refundStatusService.UpdateAsync(new RefundStatus()
|
||||
{
|
||||
RepoId = 123
|
||||
});
|
||||
Assert.True(false, "A Failure to Find a RefundStatus should have sent an Exception upward. No Exception triggered.");
|
||||
}
|
||||
catch (NotFoundException) { }
|
||||
catch (Exception)
|
||||
{
|
||||
Assert.True(false, "A Failure to Find a RefundStatus should have trigerred a NotFoundException. Another Exception was thrown instead.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+544
@@ -0,0 +1,544 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Collections.RepoApi.Exceptions;
|
||||
using LCU.API.Collections.RepoApi.Models;
|
||||
using LCU.API.Collections.RepoApi.Models.Filters;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models.Producer;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models.Results;
|
||||
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class RepoAccountServiceTest
|
||||
{
|
||||
private readonly Mock<IRepoAccountRepository> _mockRepoAccountRepository;
|
||||
private readonly Mock<IRepoStatusChangeRepository> _mockStatusChangeRepository;
|
||||
private readonly Mock<IRepoManualStatusRepository> _mockRepoManualStatusRepository;
|
||||
private readonly IRepoAccountService _repoAccountService;
|
||||
|
||||
public RepoAccountServiceTest()
|
||||
{
|
||||
_mockRepoAccountRepository = new Mock<IRepoAccountRepository>();
|
||||
_mockStatusChangeRepository = new Mock<IRepoStatusChangeRepository>();
|
||||
_mockRepoManualStatusRepository = new Mock<IRepoManualStatusRepository>();
|
||||
var mockUnitOfWrk = new Mock<IUnitOfWork>();
|
||||
_repoAccountService = new RepoAccountService(_mockRepoAccountRepository.Object, _mockStatusChangeRepository.Object,
|
||||
_mockRepoManualStatusRepository.Object, mockUnitOfWrk.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ListAccounts_Ok()
|
||||
{
|
||||
// arrange
|
||||
var repos = new List<RepoAccount>
|
||||
{
|
||||
new RepoAccount()
|
||||
{
|
||||
RepoId = 5,
|
||||
AccountNo = "1234567-98"
|
||||
}
|
||||
};
|
||||
var paged = new PagedResult<RepoAccount>() { Total = 1, Items = repos };
|
||||
_mockRepoAccountRepository
|
||||
.Setup(x => x.ListAsync(It.IsAny<List<int?>>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int?>(), It.IsAny<bool?>()))
|
||||
.ReturnsAsync(paged);
|
||||
|
||||
// act
|
||||
var result = await _repoAccountService.ListAll(new PageFilter());
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(1, result.Total);
|
||||
Assert.True(repos.SequenceEqual(result.Items));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void List_Pollable_Accounts_Ok()
|
||||
{
|
||||
// arrange
|
||||
var statusList = new List<string>
|
||||
{
|
||||
"O4R", "REPO", "REDEEMED"
|
||||
};
|
||||
var repos = new List<ProcessingItem>
|
||||
{
|
||||
new ProcessingItem()
|
||||
{
|
||||
AccountNo = "1234567-98"
|
||||
}
|
||||
};
|
||||
|
||||
_mockRepoManualStatusRepository.Setup(x => x.ListWatchStatusesAsync())
|
||||
.ReturnsAsync(statusList);
|
||||
_mockRepoAccountRepository
|
||||
.Setup(x => x.GetItemsForProcessing(statusList))
|
||||
.ReturnsAsync(repos);
|
||||
|
||||
// act
|
||||
var result = await _repoAccountService.GetItemsForProcessing();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(1, result.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Save_With_Borrower_OK()
|
||||
{
|
||||
// arrange
|
||||
var repo = new RepoAccount()
|
||||
{
|
||||
RepoId = 5,
|
||||
AccountNo = "1234567-98",
|
||||
Status = "O4R",
|
||||
Borrowers = new List<Borrower>()
|
||||
{
|
||||
new Borrower()
|
||||
{
|
||||
IndividualName = "John Doe",
|
||||
OwnershipType = 6,
|
||||
IndividualId = "123456"
|
||||
}
|
||||
}
|
||||
};
|
||||
var statusChange = new RepoStatusChange()
|
||||
{
|
||||
RepoId = 5,
|
||||
ChangedBy = "System",
|
||||
StatusTo = "O4R",
|
||||
StatusFrom = "None"
|
||||
};
|
||||
_mockRepoAccountRepository.Setup(x => x.AddAsync(It.IsAny<RepoAccount>())).ReturnsAsync(repo);
|
||||
_mockStatusChangeRepository.Setup(x => x.AddAsync(It.IsAny<RepoStatusChange>())).ReturnsAsync(statusChange);
|
||||
|
||||
// act
|
||||
var result = await _repoAccountService.SaveAsync(repo);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(repo, result);
|
||||
|
||||
_mockStatusChangeRepository.Verify(x => x.AddAsync(It.IsAny<RepoStatusChange>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_With_Borrower_OK()
|
||||
{
|
||||
// arrange
|
||||
var oldRepo = new RepoAccount()
|
||||
{
|
||||
RepoId = 5,
|
||||
AccountNo = "1234567-98",
|
||||
Status = "O4R",
|
||||
Borrowers = new List<Borrower>()
|
||||
{
|
||||
new Borrower()
|
||||
{
|
||||
IndividualName = "John Doe",
|
||||
OwnershipType = 6,
|
||||
IndividualId = "123456"
|
||||
}
|
||||
},
|
||||
Collaterals = new List<Collateral>()
|
||||
{
|
||||
new Collateral()
|
||||
{
|
||||
Description = "used mitsubishi",
|
||||
Inoperable = true, // Inoperable = (Make == "Mitsubishi")
|
||||
Make = "Mitsubishi",
|
||||
RepoId = 5,
|
||||
CollateralId = 919,
|
||||
RetitledInLandmarkName = null
|
||||
}
|
||||
}
|
||||
};
|
||||
var repo = new RepoAccount()
|
||||
{
|
||||
RepoId = 5,
|
||||
AccountNo = "1234567-98",
|
||||
Status = "REPO",
|
||||
Borrowers = new List<Borrower>()
|
||||
{
|
||||
new Borrower()
|
||||
{
|
||||
IndividualName = "John Doe",
|
||||
OwnershipType = 6,
|
||||
IndividualId = "123456"
|
||||
}
|
||||
},
|
||||
Collaterals = new List<Collateral>()
|
||||
{
|
||||
new Collateral()
|
||||
{
|
||||
Description = "used mitsubishi",
|
||||
Inoperable = true, // Inoperable = (Make == "Mitsubishi")
|
||||
Make = "Mitsubishi",
|
||||
RepoId = 5,
|
||||
CollateralId = 919,
|
||||
RetitledInLandmarkName = null
|
||||
}
|
||||
}
|
||||
};
|
||||
var statusChange = new RepoStatusChange()
|
||||
{
|
||||
RepoId = 5,
|
||||
ChangedBy = "System",
|
||||
StatusTo = "O4R",
|
||||
StatusFrom = "None"
|
||||
};
|
||||
_mockRepoAccountRepository.Setup(x => x.Update(It.IsAny<RepoAccount>())).Verifiable();
|
||||
_mockRepoAccountRepository.Setup(x => x.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(oldRepo);
|
||||
_mockStatusChangeRepository.Setup(x => x.AddAsync(It.IsAny<RepoStatusChange>())).ReturnsAsync(statusChange);
|
||||
|
||||
// act
|
||||
var result = await _repoAccountService.UpdateAsync(repo, new AppUser()
|
||||
{
|
||||
FirstName = "TEst",
|
||||
LastName = "test"
|
||||
});
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(oldRepo, result);
|
||||
Assert.Equal("REPO", oldRepo.Status);
|
||||
|
||||
_mockStatusChangeRepository.Verify(x => x.AddAsync(It.IsAny<RepoStatusChange>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_With_Borrower_No_Status_Change_OK()
|
||||
{
|
||||
// arrange
|
||||
var oldRepo = new RepoAccount()
|
||||
{
|
||||
RepoId = 5,
|
||||
AccountNo = "1234567-98",
|
||||
Status = "REPO",
|
||||
Borrowers = new List<Borrower>()
|
||||
{
|
||||
new Borrower()
|
||||
{
|
||||
IndividualName = "John Doe",
|
||||
OwnershipType = 6,
|
||||
IndividualId = "123456"
|
||||
}
|
||||
},
|
||||
Collaterals = new List<Collateral>()
|
||||
{
|
||||
new Collateral()
|
||||
{
|
||||
Description = "used mitsubishi",
|
||||
Inoperable = true, // Inoperable = (Make == "Mitsubishi")
|
||||
Make = "Mitsubishi",
|
||||
RepoId = 5,
|
||||
CollateralId = 919,
|
||||
RetitledInLandmarkName = null
|
||||
}
|
||||
}
|
||||
};
|
||||
var repo = new RepoAccount()
|
||||
{
|
||||
RepoId = 5,
|
||||
AccountNo = "1234567-98",
|
||||
Status = "REPO",
|
||||
Collector = "collector_changed",
|
||||
Borrowers = new List<Borrower>()
|
||||
{
|
||||
new Borrower()
|
||||
{
|
||||
IndividualName = "John Doe",
|
||||
OwnershipType = 6,
|
||||
IndividualId = "123456"
|
||||
}
|
||||
},
|
||||
Collaterals = new List<Collateral>()
|
||||
{
|
||||
new Collateral()
|
||||
{
|
||||
Description = "used mitsubishi",
|
||||
Inoperable = true, // Inoperable = (Make == "Mitsubishi")
|
||||
Make = "Mitsubishi",
|
||||
RepoId = 5,
|
||||
CollateralId = 919,
|
||||
RetitledInLandmarkName = null
|
||||
}
|
||||
}
|
||||
};
|
||||
var statusChange = new RepoStatusChange()
|
||||
{
|
||||
RepoId = 5,
|
||||
ChangedBy = "System",
|
||||
StatusTo = "O4R",
|
||||
StatusFrom = "None"
|
||||
};
|
||||
_mockRepoAccountRepository.Setup(x => x.Update(It.IsAny<RepoAccount>())).Verifiable();
|
||||
_mockRepoAccountRepository.Setup(x => x.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(oldRepo);
|
||||
_mockStatusChangeRepository.Setup(x => x.AddAsync(It.IsAny<RepoStatusChange>())).ReturnsAsync(statusChange);
|
||||
|
||||
// act
|
||||
var result = await _repoAccountService.UpdateAsync(repo, new AppUser()
|
||||
{
|
||||
FirstName = "TEst",
|
||||
LastName = "test"
|
||||
});
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(oldRepo, result);
|
||||
Assert.Equal("REPO", oldRepo.Status);
|
||||
|
||||
_mockStatusChangeRepository.Verify(x => x.AddAsync(It.IsAny<RepoStatusChange>()), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetAccount_Id_Ok()
|
||||
{
|
||||
// arrange
|
||||
var repo = new RepoAccount()
|
||||
{
|
||||
RepoId = 5,
|
||||
AccountNo = "1234567-98"
|
||||
};
|
||||
_mockRepoAccountRepository.Setup(x => x.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(repo);
|
||||
|
||||
// act
|
||||
var result = await _repoAccountService.Get(4);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(repo, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetAccount_AccountNo_Ok()
|
||||
{
|
||||
// arrange
|
||||
var repos = new List<RepoAccount>()
|
||||
{
|
||||
new RepoAccount()
|
||||
{
|
||||
RepoId = 5,
|
||||
AccountNo = "1234567-98"
|
||||
}
|
||||
};
|
||||
_mockRepoAccountRepository.Setup(x => x.FindByAccountNoAsync(It.IsAny<string>())).ReturnsAsync(repos);
|
||||
|
||||
// act
|
||||
var result = await _repoAccountService.GetByAccountNo("4567");
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(repos, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetNewestOpenAccount_AccountNo_Open_Ok()
|
||||
{
|
||||
|
||||
// arrange
|
||||
var repos = new List<RepoAccount>()
|
||||
{
|
||||
new RepoAccount()
|
||||
{
|
||||
RepoId = 5,
|
||||
AccountNo = "1234567-98",
|
||||
DateClosed = DateTime.Parse("12-01-2010")
|
||||
},
|
||||
new RepoAccount()
|
||||
{
|
||||
RepoId = 6,
|
||||
AccountNo = "1234567-98",
|
||||
DateClosed = null
|
||||
}
|
||||
};
|
||||
_mockRepoAccountRepository.Setup(x => x.FindByAccountNoAsync(It.IsAny<string>())).ReturnsAsync(repos);
|
||||
|
||||
// act
|
||||
var result = await _repoAccountService.GetNewestOpenAccount("4567");
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.True(result.RepoId == 6 && result.DateClosed == null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SelectAccount_AccountNo_Multi_Ok()
|
||||
{
|
||||
|
||||
// arrange
|
||||
var repos = new List<RepoAccount>()
|
||||
{
|
||||
new RepoAccount()
|
||||
{
|
||||
RepoId = 5,
|
||||
AccountNo = "1234567-98",
|
||||
DateClosed = DateTime.Parse("12-01-2010")
|
||||
},
|
||||
new RepoAccount()
|
||||
{
|
||||
RepoId = 6,
|
||||
AccountNo = "1234567-98",
|
||||
DateClosed = null
|
||||
}
|
||||
};
|
||||
|
||||
// act
|
||||
var result = _repoAccountService.SelectFirstOpenAccount(repos);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.True(result.RepoId == 6 && result.DateClosed == null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SelectAccount_AccountNo_Single_Ok()
|
||||
{
|
||||
|
||||
// arrange
|
||||
var repos = new List<RepoAccount>()
|
||||
{
|
||||
new RepoAccount()
|
||||
{
|
||||
RepoId = 5,
|
||||
AccountNo = "1234567-98",
|
||||
DateClosed = DateTime.Parse("12-01-2010")
|
||||
}
|
||||
};
|
||||
|
||||
// act
|
||||
var result = _repoAccountService.SelectFirstOpenAccount(repos);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.True(result.RepoId == 5 && result.DateClosed != null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetNewestOpenAccount_AccountNo_Newest_Ok()
|
||||
{
|
||||
|
||||
// arrange
|
||||
var repos = new List<RepoAccount>()
|
||||
{
|
||||
new RepoAccount()
|
||||
{
|
||||
RepoId = 5,
|
||||
AccountNo = "1234567-98",
|
||||
DateClosed = DateTime.Parse("12-01-2010")
|
||||
},
|
||||
new RepoAccount()
|
||||
{
|
||||
RepoId = 6,
|
||||
AccountNo = "1234567-98",
|
||||
DateClosed = DateTime.Parse("04-01-2019")
|
||||
}
|
||||
};
|
||||
_mockRepoAccountRepository.Setup(x => x.FindByAccountNoAsync(It.IsAny<string>())).ReturnsAsync(repos);
|
||||
|
||||
// act
|
||||
var result = await _repoAccountService.GetNewestOpenAccount("4567");
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.True(result.RepoId == 6 && result.DateClosed == DateTime.Parse("04-01-2019"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetNewestOpenAccount_AccountNo_Single_Ok()
|
||||
{
|
||||
|
||||
// arrange
|
||||
var repos = new List<RepoAccount>()
|
||||
{
|
||||
new RepoAccount()
|
||||
{
|
||||
RepoId = 5,
|
||||
AccountNo = "1234567-98",
|
||||
DateClosed = DateTime.Parse("12-01-2010")
|
||||
}
|
||||
};
|
||||
_mockRepoAccountRepository.Setup(x => x.FindByAccountNoAsync(It.IsAny<string>())).ReturnsAsync(repos);
|
||||
|
||||
// act
|
||||
var result = await _repoAccountService.GetNewestOpenAccount("4567");
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.True(result.RepoId == 5 && result.DateClosed == DateTime.Parse("12-01-2010"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetNewestOpenAccount_AccountNo_Null_Ok()
|
||||
{
|
||||
// arrange
|
||||
_mockRepoAccountRepository.Setup(x => x.FindByAccountNoAsync(It.IsAny<string>())).ReturnsAsync(new List<RepoAccount>());
|
||||
|
||||
// act
|
||||
var result = await _repoAccountService.GetNewestOpenAccount("4567");
|
||||
|
||||
// Assert
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DeleteAsync_Ok()
|
||||
{
|
||||
var repo = new RepoAccount()
|
||||
{
|
||||
RepoId = 5,
|
||||
AccountNo = "1234567-98",
|
||||
DateClosed = DateTime.Parse("12-01-2010")
|
||||
};
|
||||
|
||||
_mockRepoAccountRepository.Setup(x => x.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(repo);
|
||||
|
||||
//act
|
||||
var result = await _repoAccountService.DeleteAsync (5);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(5, result.RepoId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DeleteAsync_Existing_Null()
|
||||
{
|
||||
_mockRepoAccountRepository.Setup(x => x.FindByIdAsync(It.IsAny<int>())).Returns(Task.FromResult<RepoAccount>(null));
|
||||
|
||||
//act
|
||||
await Assert.ThrowsAsync<NotFoundException>(async () => await _repoAccountService.DeleteAsync(5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DeleteAsync_Existing_Exception()
|
||||
{
|
||||
_mockRepoAccountRepository.Setup(x => x.FindByIdAsync(It.IsAny<int>())).ThrowsAsync(new Exception("oops"));
|
||||
|
||||
//act
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await _repoAccountService.DeleteAsync(5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DeleteAsync_Remove_Exception()
|
||||
{
|
||||
var repo = new RepoAccount()
|
||||
{
|
||||
RepoId = 5,
|
||||
AccountNo = "1234567-98",
|
||||
DateClosed = DateTime.Parse("12-01-2010")
|
||||
};
|
||||
|
||||
_mockRepoAccountRepository.Setup(x => x.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(repo);
|
||||
_mockRepoAccountRepository.Setup(x => x.Remove(It.IsAny<RepoAccount>())).Throws(new Exception("oops"));
|
||||
|
||||
//act
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await _repoAccountService.DeleteAsync(5));
|
||||
}
|
||||
}
|
||||
}
|
||||
+334
@@ -0,0 +1,334 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using LCU.API.Collections.RepoApi.Services.Reporting;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models.Reporting;
|
||||
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class RepoCompanyReportingServiceTest
|
||||
{
|
||||
private IRepoCompanyReportingService _repoCompanyReportingService;
|
||||
private Mock<IReportingRepository> _mockReportingRepository;
|
||||
|
||||
public RepoCompanyReportingServiceTest()
|
||||
{
|
||||
_mockReportingRepository = new Mock<IReportingRepository>();
|
||||
_repoCompanyReportingService =
|
||||
new RepoCompanyReportingService(_mockReportingRepository.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetActiveCountReport_Ok()
|
||||
{
|
||||
// Arrange
|
||||
var reportData = new List<StdReportEntry>()
|
||||
{
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 1,
|
||||
RepoCompanyAssignmentDate = DateTime.Parse("11/05/2019"),
|
||||
RepoCompany = "Company A"
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 1,
|
||||
RepoCompanyAssignmentDate = DateTime.Parse("11/05/2019"),
|
||||
RepoCompany = "Company A"
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 2,
|
||||
RepoCompanyAssignmentDate = DateTime.Parse("11/15/2019"),
|
||||
RepoCompany = "Company A"
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 3,
|
||||
RepoCompanyAssignmentDate = DateTime.Parse("11/15/2019"),
|
||||
RepoCompany = "Company B"
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 4,
|
||||
RepoCompanyAssignmentDate = DateTime.Parse("12/20/2019"),
|
||||
RepoCompany = "Company B"
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 5,
|
||||
RepoCompanyAssignmentDate = DateTime.Parse("12/22/2019")
|
||||
}
|
||||
};
|
||||
_mockReportingRepository.Setup(x => x.GetAccountsByDateAssigned(It.IsAny<DateTime>(), It.IsAny<DateTime>()))
|
||||
.ReturnsAsync(reportData);
|
||||
|
||||
// act
|
||||
var result =
|
||||
await _repoCompanyReportingService.GetAssignmentCountReport(DateTime.Parse("11/01/2019"),
|
||||
DateTime.Parse("12/31/2019"));
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(6, result.DataTable.Rows.Count());
|
||||
Assert.Equal(16, result.ReportTable.Cells.Length); // 4 rows of 4.
|
||||
|
||||
Assert.Equal("All Repo Companies", result.ReportTable.Cells[0, 0].Display);
|
||||
Assert.Equal("3", result.ReportTable.Cells[0, 1].Display);
|
||||
Assert.Equal("2", result.ReportTable.Cells[0, 2].Display);
|
||||
Assert.Equal("5", result.ReportTable.Cells[0, 3].Display);
|
||||
|
||||
Assert.Equal("Company A", result.ReportTable.Cells[1, 0].Display);
|
||||
Assert.Equal("2", result.ReportTable.Cells[1, 1].Display);
|
||||
Assert.Equal("-", result.ReportTable.Cells[1, 2].Display);
|
||||
Assert.Equal("2", result.ReportTable.Cells[1, 3].Display);
|
||||
|
||||
Assert.Equal("Company B", result.ReportTable.Cells[2, 0].Display);
|
||||
Assert.Equal("1", result.ReportTable.Cells[2, 1].Display);
|
||||
Assert.Equal("1", result.ReportTable.Cells[2, 2].Display);
|
||||
Assert.Equal("2", result.ReportTable.Cells[2, 3].Display);
|
||||
|
||||
Assert.Equal("No Repo Companies", result.ReportTable.Cells[3, 0].Display);
|
||||
Assert.Equal("-", result.ReportTable.Cells[3, 1].Display);
|
||||
Assert.Equal("1", result.ReportTable.Cells[3, 2].Display);
|
||||
Assert.Equal("1", result.ReportTable.Cells[3, 3].Display);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetAvgDaysAssignedToRepoed_Ok()
|
||||
{
|
||||
// Arrange
|
||||
var reportData = new List<StdReportEntry>()
|
||||
{
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 1,
|
||||
RepoDuration = 10,
|
||||
DateRepoed = DateTime.Parse("11/05/2019"),
|
||||
RepoCompany = "Company A"
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 2,
|
||||
RepoDuration = 20,
|
||||
DateRepoed = DateTime.Parse("11/01/2019"),
|
||||
RepoCompany = "Company A"
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 3,
|
||||
RepoDuration = 5,
|
||||
DateRepoed = DateTime.Parse("11/29/2019"),
|
||||
RepoCompany = "Company A"
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 4,
|
||||
RepoDuration = 1,
|
||||
DateRepoed = DateTime.Parse("12/08/2019"),
|
||||
RepoCompany = "Company B"
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 5,
|
||||
RepoDuration = 5,
|
||||
DateRepoed = DateTime.Parse("12/31/2019"),
|
||||
RepoCompany = "Company B"
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 6,
|
||||
DateRepoed = DateTime.Parse("11/21/2019"),
|
||||
}
|
||||
};
|
||||
_mockReportingRepository.Setup(x => x.GetAccountsByDateRepoed(It.IsAny<DateTime>(), It.IsAny<DateTime>()))
|
||||
.ReturnsAsync(reportData);
|
||||
|
||||
// act
|
||||
var result =
|
||||
await _repoCompanyReportingService.GetAvgDaysAssignedToRepoed(DateTime.Parse("11/01/2019"),
|
||||
DateTime.Parse("12/31/2019"));
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(6, result.DataTable.Rows.Count());
|
||||
Assert.Equal(12, result.ReportTable.Cells.Length);
|
||||
|
||||
Assert.Equal("All Repo Companies", result.ReportTable.Cells[0, 0].Display);
|
||||
Assert.Equal("12", result.ReportTable.Cells[0, 1].Display);
|
||||
Assert.Equal("3", result.ReportTable.Cells[0, 2].Display);
|
||||
Assert.Equal("8", result.ReportTable.Cells[0, 3].Display);
|
||||
|
||||
Assert.Equal("Company A", result.ReportTable.Cells[1, 0].Display);
|
||||
Assert.Equal("12", result.ReportTable.Cells[1, 1].Display);
|
||||
Assert.Equal("-", result.ReportTable.Cells[1, 2].Display);
|
||||
Assert.Equal("12", result.ReportTable.Cells[1, 3].Display);
|
||||
|
||||
Assert.Equal("Company B", result.ReportTable.Cells[2, 0].Display);
|
||||
Assert.Equal("-", result.ReportTable.Cells[2, 1].Display);
|
||||
Assert.Equal("3", result.ReportTable.Cells[2, 2].Display);
|
||||
Assert.Equal("3", result.ReportTable.Cells[2, 3].Display);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetRepoCountReport_Ok()
|
||||
{
|
||||
// Arrange
|
||||
var reportData = new List<StdReportEntry>()
|
||||
{
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 1,
|
||||
DateRepoed = DateTime.Parse("11/05/2019"),
|
||||
RepoCompany = "Company A"
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 8,
|
||||
DateRepoed = DateTime.Parse("11/05/2019"),
|
||||
RepoCompany = "Company A"
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 2,
|
||||
DateRepoed = DateTime.Parse("11/15/2019"),
|
||||
RepoCompany = "Company A"
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 3,
|
||||
DateRepoed = DateTime.Parse("11/15/2019"),
|
||||
RepoCompany = "Company B"
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 4,
|
||||
DateRepoed = DateTime.Parse("12/20/2019"),
|
||||
RepoCompany = "Company B"
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 5,
|
||||
DateRepoed = DateTime.Parse("12/22/2019")
|
||||
}
|
||||
};
|
||||
_mockReportingRepository.Setup(x => x.GetAccountsByDateRepoed(It.IsAny<DateTime>(), It.IsAny<DateTime>()))
|
||||
.ReturnsAsync(reportData);
|
||||
|
||||
// act
|
||||
var result =
|
||||
await _repoCompanyReportingService.GetRepoedCountReport(DateTime.Parse("11/01/2019"),
|
||||
DateTime.Parse("12/31/2019"));
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(6, result.DataTable.Rows.Count());
|
||||
Assert.Equal(16, result.ReportTable.Cells.Length); // 4 rows of 4.
|
||||
|
||||
Assert.Equal("All Repo Companies", result.ReportTable.Cells[0, 0].Display);
|
||||
Assert.Equal("4", result.ReportTable.Cells[0, 1].Display);
|
||||
Assert.Equal("2", result.ReportTable.Cells[0, 2].Display);
|
||||
Assert.Equal("6", result.ReportTable.Cells[0, 3].Display);
|
||||
|
||||
Assert.Equal("Company A", result.ReportTable.Cells[1, 0].Display);
|
||||
Assert.Equal("3", result.ReportTable.Cells[1, 1].Display);
|
||||
Assert.Equal("-", result.ReportTable.Cells[1, 2].Display);
|
||||
Assert.Equal("3", result.ReportTable.Cells[1, 3].Display);
|
||||
|
||||
Assert.Equal("Company B", result.ReportTable.Cells[2, 0].Display);
|
||||
Assert.Equal("1", result.ReportTable.Cells[2, 1].Display);
|
||||
Assert.Equal("1", result.ReportTable.Cells[2, 2].Display);
|
||||
Assert.Equal("2", result.ReportTable.Cells[2, 3].Display);
|
||||
|
||||
Assert.Equal("No Repo Companies", result.ReportTable.Cells[3, 0].Display);
|
||||
Assert.Equal("-", result.ReportTable.Cells[3, 1].Display);
|
||||
Assert.Equal("1", result.ReportTable.Cells[3, 2].Display);
|
||||
Assert.Equal("1", result.ReportTable.Cells[3, 3].Display);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetAssignedBalance_Ok()
|
||||
{
|
||||
// Arrange
|
||||
var reportData = new List<StdReportEntry>()
|
||||
{
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 1,
|
||||
Balance = 500,
|
||||
RepoCompanyAssignmentDate = DateTime.Parse("11/05/2019"),
|
||||
RepoCompany = "Company A"
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 8,
|
||||
Balance = 425.51m,
|
||||
RepoCompanyAssignmentDate = DateTime.Parse("11/05/2019"),
|
||||
RepoCompany = "Company A"
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 2,
|
||||
Balance = 121,
|
||||
RepoCompanyAssignmentDate = DateTime.Parse("11/15/2019"),
|
||||
RepoCompany = "Company A"
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 3,
|
||||
Balance = 383,
|
||||
RepoCompanyAssignmentDate = DateTime.Parse("11/15/2019"),
|
||||
RepoCompany = "Company B"
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 4,
|
||||
Balance = 99.011m,
|
||||
RepoCompanyAssignmentDate = DateTime.Parse("12/20/2019"),
|
||||
RepoCompany = "Company B"
|
||||
},
|
||||
new StdReportEntry()
|
||||
{
|
||||
CollateralId = 5,
|
||||
Balance = 4,
|
||||
RepoCompanyAssignmentDate = DateTime.Parse("12/22/2019")
|
||||
}
|
||||
};
|
||||
_mockReportingRepository.Setup(x => x.GetAccountsByDateAssigned(It.IsAny<DateTime>(), It.IsAny<DateTime>()))
|
||||
.ReturnsAsync(reportData);
|
||||
|
||||
// act
|
||||
var result =
|
||||
await _repoCompanyReportingService.GetAssignedBalance(DateTime.Parse("11/01/2019"),
|
||||
DateTime.Parse("12/31/2019"));
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(6, result.DataTable.Rows.Count());
|
||||
Assert.Equal(16, result.ReportTable.Cells.Length); // 4 rows of 4.
|
||||
|
||||
Assert.Equal("All Repo Companies", result.ReportTable.Cells[0, 0].Display);
|
||||
Assert.Equal("$1,429.51", result.ReportTable.Cells[0, 1].Display);
|
||||
Assert.Equal("$103.01", result.ReportTable.Cells[0, 2].Display);
|
||||
Assert.Equal("$1,532.52", result.ReportTable.Cells[0, 3].Display);
|
||||
|
||||
Assert.Equal("Company A", result.ReportTable.Cells[1, 0].Display);
|
||||
Assert.Equal("$1,046.51", result.ReportTable.Cells[1, 1].Display);
|
||||
Assert.Equal("-", result.ReportTable.Cells[1, 2].Display);
|
||||
Assert.Equal("$1,046.51", result.ReportTable.Cells[1, 3].Display);
|
||||
|
||||
Assert.Equal("Company B", result.ReportTable.Cells[2, 0].Display);
|
||||
Assert.Equal("$383.00", result.ReportTable.Cells[2, 1].Display);
|
||||
Assert.Equal("$99.01", result.ReportTable.Cells[2, 2].Display);
|
||||
Assert.Equal("$482.01", result.ReportTable.Cells[2, 3].Display);
|
||||
|
||||
Assert.Equal("No Repo Companies", result.ReportTable.Cells[3, 0].Display);
|
||||
Assert.Equal("-", result.ReportTable.Cells[3, 1].Display);
|
||||
Assert.Equal("$4.00", result.ReportTable.Cells[3, 2].Display);
|
||||
Assert.Equal("$4.00", result.ReportTable.Cells[3, 3].Display);
|
||||
}
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using LCU.API.Collections.CollectionsApiLib.Models;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class RepoCompanySelectionServiceTest
|
||||
{
|
||||
private RepoCompanySelectionService _repoCompanySelectionService;
|
||||
private Mock<IRepoCompanySelectionRepository> _mockRepository;
|
||||
private Mock<IUnitOfWork> _mockUnitOfWork;
|
||||
|
||||
public RepoCompanySelectionServiceTest()
|
||||
{
|
||||
_mockRepository = new Mock<IRepoCompanySelectionRepository>();
|
||||
_mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
_repoCompanySelectionService = new RepoCompanySelectionService(
|
||||
_mockRepository.Object,
|
||||
_mockUnitOfWork.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
var list = new List<RepoCompanySelection>()
|
||||
{
|
||||
new RepoCompanySelection()
|
||||
{
|
||||
Id = 1,
|
||||
CollateralId = 2,
|
||||
RepoCompanyId = 3,
|
||||
RepoType = RepoType.Involuntary,
|
||||
DateTimeCreated = DateTime.Parse("08/14/1945"),
|
||||
RepoCompanyAssignmentDate = DateTime.Parse("04/24/1916"),
|
||||
DateRepoed = DateTime.Parse("04/29/1916")
|
||||
},
|
||||
new RepoCompanySelection()
|
||||
{
|
||||
CollateralId = 2,
|
||||
RepoCompanyId = 13,
|
||||
RepoType = RepoType.Involuntary,
|
||||
DateTimeCreated = DateTime.Parse("08/14/1945"),
|
||||
RepoCompanyAssignmentDate = DateTime.Parse("04/24/1916"),
|
||||
DateRepoed = DateTime.Parse("04/29/1916")
|
||||
}
|
||||
};
|
||||
|
||||
_mockRepository.Setup(repository => repository.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(new RepoCompanySelection()
|
||||
{
|
||||
RepoCompanyId = 3
|
||||
});
|
||||
|
||||
_mockRepository.Setup(repository => repository.FindByCollateralIdAsync(It.IsAny<int>())).ReturnsAsync(new List<RepoCompanySelection>()
|
||||
{
|
||||
new RepoCompanySelection()
|
||||
{
|
||||
Id = 1
|
||||
}
|
||||
});
|
||||
|
||||
// Act
|
||||
await _repoCompanySelectionService.SaveChangesAsync(list);
|
||||
|
||||
Assert.Collection(list,
|
||||
item =>
|
||||
{
|
||||
Assert.NotNull(item.DateTimeCreated);
|
||||
},
|
||||
item =>
|
||||
{
|
||||
Assert.NotNull(item.DateTimeCreated);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using LCU.API.Collections.RepoApi.Models;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class RepoCompanyServiceTest
|
||||
{
|
||||
[Fact]
|
||||
public async void ListAll_Ok()
|
||||
{
|
||||
var mockCompany = getMockCompany();
|
||||
var repoCompanyService = getRepoCompanyService();
|
||||
|
||||
var result = await repoCompanyService.ListAll();
|
||||
var companyEnumerator = result.GetEnumerator();
|
||||
|
||||
companyEnumerator.MoveNext();
|
||||
var firstCompanyFromService = companyEnumerator.Current;
|
||||
Assert.Equal(mockCompany.ID, firstCompanyFromService.ID);
|
||||
Assert.Equal(mockCompany.Name, firstCompanyFromService.Name);
|
||||
Assert.Equal(mockCompany.Email, firstCompanyFromService.Email);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetOne_Ok()
|
||||
{
|
||||
var mockCompany = getMockCompany();
|
||||
var repoCompanyService = getRepoCompanyService();
|
||||
|
||||
var result = await repoCompanyService.Get(1);
|
||||
Assert.Equal(mockCompany.ID, result.ID);
|
||||
Assert.Equal(mockCompany.Name, result.Name);
|
||||
Assert.Equal(mockCompany.Email, result.Email);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Ok()
|
||||
{
|
||||
var mockCompany = getMockCompany();
|
||||
var repoCompanyService = getRepoCompanyService();
|
||||
|
||||
var oldId = mockCompany.ID;
|
||||
mockCompany.ID = 2;
|
||||
mockCompany.Name = "New Name";
|
||||
mockCompany.Email = "New Email";
|
||||
|
||||
var result = await repoCompanyService.Update(mockCompany, new AppUser());
|
||||
Assert.Equal(mockCompany.Name, result.Name);
|
||||
Assert.Equal(mockCompany.Email, result.Email);
|
||||
Assert.Equal(oldId, result.ID);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Date_Disabled_Saves_User()
|
||||
{
|
||||
var mockCompany = getMockCompany();
|
||||
var repoCompanyService = getRepoCompanyService();
|
||||
|
||||
mockCompany.ID = 2;
|
||||
mockCompany.Name = "New Name";
|
||||
mockCompany.Email = "New Email";
|
||||
mockCompany.DisabledDate = DateTime.Now;
|
||||
|
||||
var result = await repoCompanyService.Update(mockCompany, new AppUser()
|
||||
{
|
||||
FirstName = "John",
|
||||
LastName = "Doe"
|
||||
});
|
||||
Assert.Equal("John Doe", result.DisabledBy);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Date_Disabled__NUll_Clears_User()
|
||||
{
|
||||
var mockCompany = getMockCompany();
|
||||
var repoCompanyService = getRepoCompanyService();
|
||||
|
||||
mockCompany.ID = 2;
|
||||
mockCompany.Name = "New Name";
|
||||
mockCompany.Email = "New Email";
|
||||
mockCompany.DisabledBy = "Bobby Boy";
|
||||
|
||||
var result = await repoCompanyService.Update(mockCompany, new AppUser()
|
||||
{
|
||||
FirstName = "John",
|
||||
LastName = "Doe"
|
||||
});
|
||||
Assert.Null(result.DisabledBy);
|
||||
}
|
||||
|
||||
private RepoCompanyService getRepoCompanyService()
|
||||
{
|
||||
var companies = getMockCompanyList();
|
||||
|
||||
var mockRepository = new Mock<IRepoCompanyRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
mockRepository.Setup(repo => repo.ListAsync()).ReturnsAsync(companies);
|
||||
mockRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(companies[0]);
|
||||
mockRepository.Setup(repo => repo.Update(It.IsAny<RepoCompany>()));
|
||||
|
||||
return new RepoCompanyService(mockRepository.Object, mockUnitOfWork.Object);
|
||||
}
|
||||
|
||||
private IList<RepoCompany> getMockCompanyList()
|
||||
{
|
||||
return new List<RepoCompany>
|
||||
{
|
||||
getMockCompany()
|
||||
};
|
||||
}
|
||||
|
||||
private RepoCompany getMockCompany()
|
||||
{
|
||||
return new RepoCompany() {ID = 1, Email = "[email protected]", Name = "A Inc."};
|
||||
}
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using LCU.API.Collections.CollectionsApiLib.Models;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using LCU.API.Collections.RepoApi.DataAccess;
|
||||
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class RepoLetterServiceTest
|
||||
{
|
||||
[Fact]
|
||||
public async void ListByRepoId_Ok()
|
||||
{
|
||||
var mockLetterRepository = new Mock<ILetterRepository>();
|
||||
var mockCollectionsDao = new Mock<ICollectionsDao>();
|
||||
|
||||
var collectionsLetters = new List<TemenosHistory>
|
||||
{
|
||||
new TemenosHistory()
|
||||
{
|
||||
Name= "Comment",
|
||||
Message= "Sent letter(s): Repo Assignment Form.",
|
||||
UserId= 56,
|
||||
Created = DateTime.Parse("2015-05-09"),
|
||||
Type = (HistoryType)2
|
||||
},
|
||||
new TemenosHistory()
|
||||
{
|
||||
Name= "Comment",
|
||||
Message= "asdfasdfsda",
|
||||
UserId= 56,
|
||||
Created = DateTime.Parse("2015-05-09"),
|
||||
Type = (HistoryType)1
|
||||
}
|
||||
};
|
||||
|
||||
var letters = new List<Letter>
|
||||
{
|
||||
new Letter
|
||||
{
|
||||
ActionCode = "RTC 3",
|
||||
DaysToWait = 10,
|
||||
LetterDescription = "Sent letter(s): Repo Assignment Form."
|
||||
}
|
||||
};
|
||||
|
||||
mockCollectionsDao.Setup(x => x.RetrieveHistoryAsync(It.IsAny<int>())).ReturnsAsync(collectionsLetters);
|
||||
mockLetterRepository.Setup(x => x.ListAsync()).ReturnsAsync(letters);
|
||||
|
||||
// arrange
|
||||
var service = new RepoLetterService( mockLetterRepository.Object, mockCollectionsDao.Object);
|
||||
|
||||
// act
|
||||
var result = await service.ListByAccountIdAsync(1234567);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Single(result);
|
||||
|
||||
RepoLetter first = result.First();
|
||||
Assert.Equal("Sent letter(s): Repo Assignment Form.", first.NoticeType);
|
||||
Assert.Equal(DateTime.Parse("2015-05-09"), first.DateSent);
|
||||
Assert.Equal(DateTime.Parse("2015-05-19"), first.DateExpired);
|
||||
Assert.Equal(10, first.DaysToRedeem);
|
||||
Assert.Equal("RTC 3", first.ActionCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
using Moq;
|
||||
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.API.Collections.RepoApi.Exceptions;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class RepoStatusChangeServiceTest
|
||||
{
|
||||
private readonly Mock<IRepoStatusChangeRepository> _mockStatusChangeRepo;
|
||||
private readonly RepoStatusChangeService _changeService;
|
||||
|
||||
public RepoStatusChangeServiceTest()
|
||||
{
|
||||
_mockStatusChangeRepo = new Mock<IRepoStatusChangeRepository>();
|
||||
_changeService = new RepoStatusChangeService(_mockStatusChangeRepo.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ListByAccount_Exception()
|
||||
{
|
||||
_mockStatusChangeRepo.Setup(repo => repo.ListForAccountAsync(It.IsAny<int>()))
|
||||
.ThrowsAsync(new Exception("oops"));
|
||||
|
||||
var res = await Assert.ThrowsAsync<ServerErrorException>(async () =>
|
||||
{
|
||||
await _changeService.ListByAccount(5);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ListByAccount_Ok()
|
||||
{
|
||||
_mockStatusChangeRepo.Setup(repo => repo.ListForAccountAsync(It.IsAny<int>()))
|
||||
.ReturnsAsync(new List<RepoStatusChange>() {new RepoStatusChange() { }});
|
||||
|
||||
var res = await _changeService.ListByAccount(5);
|
||||
Assert.NotNull(res);
|
||||
Assert.Single(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
using System.Collections.Generic;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class SavedLocationServiceTest
|
||||
{
|
||||
[Fact]
|
||||
public async void ListAll_Ok()
|
||||
{
|
||||
var mockLocation = getMockLocation();
|
||||
var savedLocationService = getSavedLocationService();
|
||||
|
||||
var result = await savedLocationService.ListAllAsync();
|
||||
var locationEnumerator = result.GetEnumerator();
|
||||
|
||||
locationEnumerator.MoveNext();
|
||||
var firstLocationFromService = locationEnumerator.Current;
|
||||
Assert.Equal(mockLocation.ID, firstLocationFromService.ID);
|
||||
Assert.Equal(mockLocation.Name, firstLocationFromService.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetOne_Ok()
|
||||
{
|
||||
var mockLocation = getMockLocation();
|
||||
var savedLocationService = getSavedLocationService();
|
||||
|
||||
var result = await savedLocationService.GetAsync(1);
|
||||
Assert.Equal(mockLocation.ID, result.ID);
|
||||
Assert.Equal(mockLocation.Name, result.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Ok()
|
||||
{
|
||||
var mockLocation = getMockLocation();
|
||||
var savedLocationService = getSavedLocationService();
|
||||
|
||||
var oldId = mockLocation.ID;
|
||||
mockLocation.ID = 2;
|
||||
mockLocation.Name = "New Name";
|
||||
|
||||
var result = await savedLocationService.UpdateAsync(mockLocation);
|
||||
Assert.Equal(mockLocation.Name, result.Name);
|
||||
Assert.Equal(oldId, result.ID);
|
||||
}
|
||||
|
||||
private SavedLocationService getSavedLocationService()
|
||||
{
|
||||
var savedLocations = getMockLocationList();
|
||||
|
||||
var mockRepository = new Mock<ISavedLocationRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
mockRepository.Setup(repo => repo.ListAsync()).ReturnsAsync(savedLocations);
|
||||
mockRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(savedLocations[0]);
|
||||
mockRepository.Setup(repo => repo.Update(It.IsAny<SavedLocation>()));
|
||||
|
||||
return new SavedLocationService(mockRepository.Object, mockUnitOfWork.Object);
|
||||
}
|
||||
|
||||
private IList<SavedLocation> getMockLocationList()
|
||||
{
|
||||
return new List<SavedLocation>
|
||||
{
|
||||
getMockLocation()
|
||||
};
|
||||
}
|
||||
|
||||
private SavedLocation getMockLocation()
|
||||
{
|
||||
return new SavedLocation() {ID = 1, Name = "Some Weird Storage Place"};
|
||||
}
|
||||
}
|
||||
}
|
||||
+595
@@ -0,0 +1,595 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using LCU.API.Collections.CollectionsApiLib.Models;
|
||||
using LCU.API.Collections.RepoApi.Configuration;
|
||||
using LCU.API.Collections.RepoApi.DataAccess;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models.Settings;
|
||||
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
||||
using LCU.Shared.Collections.RepoApiLib.Repositories.Settings;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class SettingsServiceTest
|
||||
{
|
||||
private Mock<IAccountTypeRepository> _mockAccountTypeRepository;
|
||||
private Mock<IAllowedStatusChangeRepository> _mockAllowedStatusChangeRepository;
|
||||
private Mock<IBodyStyleRepository> _mockBodyStyleRepository;
|
||||
private Mock<ICleaningLevelRepository> _mockCleaningLevelRepository;
|
||||
private Mock<ICollateralTypeRepository> _mockCollateralTypeRepository;
|
||||
private Mock<ICollateralTypeToVehicleTypeRepository> _mockCollateralTypeToVehicleTypeRepository;
|
||||
private Mock<IHoldStatusRepository> _mockHoldStatusRepository;
|
||||
private Mock<ILoanCategoryRepository> _mockLoanCategoryRepository;
|
||||
private Mock<ILocationTypeRepository> _mockLocationTypeRepository;
|
||||
private Mock<IVehicleTypeRepository> _mockVehicleTypeRepository;
|
||||
private Mock<IExternalUserRepository> _mockExternalUserRepository;
|
||||
private Mock<IRepoCompanyRepository> _mockRepoCompanyRepository;
|
||||
private Mock<ICollectionsDao> _mockCollectionsDao;
|
||||
private Mock<IUnitOfWork> _mockUnitOfWork;
|
||||
private Mock<IMemoryCache> _memoryCache;
|
||||
private RepoApiConfiguration _configuration;
|
||||
|
||||
private List<AccountType> accountTypes = new List<AccountType>
|
||||
{
|
||||
new AccountType()
|
||||
};
|
||||
|
||||
private List<AllowedStatusChange> allowedStatusChanges = new List<AllowedStatusChange>
|
||||
{
|
||||
new AllowedStatusChange()
|
||||
};
|
||||
|
||||
private List<BodyStyle> bodyStyles = new List<BodyStyle>
|
||||
{
|
||||
new BodyStyle()
|
||||
};
|
||||
|
||||
List<CleaningLevel> cleaningLevels = new List<CleaningLevel>
|
||||
{
|
||||
new CleaningLevel()
|
||||
};
|
||||
|
||||
private List<CollateralType> collateralTypes = new List<CollateralType>
|
||||
{
|
||||
new CollateralType()
|
||||
};
|
||||
|
||||
|
||||
private List<CollateralTypeToVehicleType> collateralTypeToVehicleTypes = new List<CollateralTypeToVehicleType>
|
||||
{
|
||||
new CollateralTypeToVehicleType()
|
||||
};
|
||||
|
||||
private List<HoldStatus> holdStatuses = new List<HoldStatus>
|
||||
{
|
||||
new HoldStatus()
|
||||
};
|
||||
|
||||
private List<LoanCategory> loanCategories = new List<LoanCategory>
|
||||
{
|
||||
new LoanCategory()
|
||||
};
|
||||
|
||||
private List<LocationType> locationTypes = new List<LocationType>
|
||||
{
|
||||
new LocationType()
|
||||
};
|
||||
|
||||
private List<VehicleType> vehicleTypes = new List<VehicleType>
|
||||
{
|
||||
new VehicleType()
|
||||
};
|
||||
|
||||
private List<BranchEntry> branchSet = new List<BranchEntry>
|
||||
{
|
||||
new BranchEntry() { BranchId = "5", BranchName = "Mars" }
|
||||
};
|
||||
|
||||
private List<ExternalUser> externalUserSet = new List<ExternalUser>
|
||||
{
|
||||
new ExternalUser() { Id = 10, Code = "jdoe", Name = "John Doe" }
|
||||
};
|
||||
|
||||
private List<RepoCompany> RepoCompanies = new List<RepoCompany>
|
||||
{
|
||||
new RepoCompany() { ID = 5, ReferenceId = 555 }
|
||||
};
|
||||
|
||||
private readonly List<string> _transactionTypeCodes = new List<string> { "TEST" };
|
||||
private readonly string _transactionTypeCodeQueryPrefix = "TESTPREFIX";
|
||||
private readonly string _transactionHistoryParameterDateFormat = "yyyy-MM-dd";
|
||||
private readonly int _transactionHistoryStartDateOffset = 120;
|
||||
|
||||
public SettingsServiceTest()
|
||||
{
|
||||
_mockAccountTypeRepository = new Mock<IAccountTypeRepository>();
|
||||
_mockAllowedStatusChangeRepository = new Mock<IAllowedStatusChangeRepository>();
|
||||
_mockBodyStyleRepository = new Mock<IBodyStyleRepository>();
|
||||
_mockCleaningLevelRepository = new Mock<ICleaningLevelRepository>();
|
||||
_mockCollateralTypeRepository = new Mock<ICollateralTypeRepository>();
|
||||
_mockCollateralTypeToVehicleTypeRepository = new Mock<ICollateralTypeToVehicleTypeRepository>();
|
||||
_mockHoldStatusRepository = new Mock<IHoldStatusRepository>();
|
||||
_mockLoanCategoryRepository = new Mock<ILoanCategoryRepository>();
|
||||
_mockLocationTypeRepository = new Mock<ILocationTypeRepository>();
|
||||
_mockVehicleTypeRepository = new Mock<IVehicleTypeRepository>();
|
||||
_mockExternalUserRepository = new Mock<IExternalUserRepository>();
|
||||
_mockRepoCompanyRepository = new Mock<IRepoCompanyRepository>();
|
||||
_mockCollectionsDao = new Mock<ICollectionsDao>();
|
||||
_mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
_memoryCache = new Mock<IMemoryCache>();
|
||||
_configuration = new RepoApiConfiguration
|
||||
{
|
||||
TransactionTypeCodes = _transactionTypeCodes,
|
||||
TransactionTypeCodeQueryPrefix = _transactionTypeCodeQueryPrefix,
|
||||
TransactionHistoryParameterDateFormat = _transactionHistoryParameterDateFormat,
|
||||
TransactionHistoryStartDateOffset = _transactionHistoryStartDateOffset
|
||||
};
|
||||
|
||||
_mockAccountTypeRepository.Setup(x => x.ListAllAsync()).ReturnsAsync(accountTypes);
|
||||
_mockAllowedStatusChangeRepository.Setup(x => x.ListAllAsync()).ReturnsAsync(allowedStatusChanges);
|
||||
_mockBodyStyleRepository.Setup(x => x.ListAllAsync()).ReturnsAsync(bodyStyles);
|
||||
_mockCleaningLevelRepository.Setup(x => x.ListAllAsync()).ReturnsAsync(cleaningLevels);
|
||||
_mockCollateralTypeRepository.Setup(x => x.ListAllAsync()).ReturnsAsync(collateralTypes);
|
||||
_mockCollateralTypeToVehicleTypeRepository.Setup(x => x.ListAllAsync())
|
||||
.ReturnsAsync(collateralTypeToVehicleTypes);
|
||||
_mockHoldStatusRepository.Setup(x => x.ListAllAsync()).ReturnsAsync(holdStatuses);
|
||||
_mockLoanCategoryRepository.Setup(x => x.ListAllAsync()).ReturnsAsync(loanCategories);
|
||||
_mockLocationTypeRepository.Setup(x => x.ListAllAsync()).ReturnsAsync(locationTypes);
|
||||
_mockVehicleTypeRepository.Setup(x => x.ListAllAsync()).ReturnsAsync(vehicleTypes);
|
||||
_mockExternalUserRepository.Setup(x => x.ListAsync()).ReturnsAsync(externalUserSet);
|
||||
_mockRepoCompanyRepository.Setup(x => x.ListAsync()).ReturnsAsync(RepoCompanies);
|
||||
_mockCollectionsDao.Setup(x => x.RetrieveBranchSetAsync()).ReturnsAsync(branchSet);
|
||||
}
|
||||
|
||||
private SettingsService BuildTestSettingsService()
|
||||
{
|
||||
return new SettingsService
|
||||
(
|
||||
_mockAccountTypeRepository.Object,
|
||||
_mockAllowedStatusChangeRepository.Object,
|
||||
_mockBodyStyleRepository.Object,
|
||||
_mockCleaningLevelRepository.Object,
|
||||
_mockCollateralTypeRepository.Object,
|
||||
_mockCollateralTypeToVehicleTypeRepository.Object,
|
||||
_mockHoldStatusRepository.Object,
|
||||
_mockLoanCategoryRepository.Object,
|
||||
_mockLocationTypeRepository.Object,
|
||||
_mockVehicleTypeRepository.Object,
|
||||
_mockExternalUserRepository.Object,
|
||||
_mockRepoCompanyRepository.Object,
|
||||
_mockUnitOfWork.Object,
|
||||
_memoryCache.Object,
|
||||
_mockCollectionsDao.Object,
|
||||
_configuration
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ListSettings_Ok()
|
||||
{
|
||||
// arrange service instance
|
||||
var service = BuildTestSettingsService();
|
||||
|
||||
// act
|
||||
var result = await service.ListAllSettingsAsync();
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
|
||||
Assert.Single(result.AccountTypes);
|
||||
Assert.True(accountTypes.SequenceEqual(result.AccountTypes));
|
||||
|
||||
Assert.Single(result.AllowedStatusChanges);
|
||||
Assert.True(allowedStatusChanges.SequenceEqual(result.AllowedStatusChanges));
|
||||
|
||||
Assert.Single(result.BodyStyles);
|
||||
Assert.True(bodyStyles.SequenceEqual(result.BodyStyles));
|
||||
|
||||
Assert.Single(result.CleaningLevels);
|
||||
Assert.True(cleaningLevels.SequenceEqual(result.CleaningLevels));
|
||||
|
||||
Assert.Single(result.CollateralTypes);
|
||||
Assert.True(collateralTypes.SequenceEqual(result.CollateralTypes));
|
||||
|
||||
Assert.Single(result.CollateralTypesToVehicleTypes);
|
||||
Assert.True(collateralTypeToVehicleTypes.SequenceEqual(result.CollateralTypesToVehicleTypes));
|
||||
|
||||
Assert.Single(result.HoldStatuses);
|
||||
Assert.True(holdStatuses.SequenceEqual(result.HoldStatuses));
|
||||
|
||||
Assert.Single(result.LoanCategories);
|
||||
Assert.True(loanCategories.SequenceEqual(result.LoanCategories));
|
||||
|
||||
Assert.Single(result.LocationTypes);
|
||||
Assert.True(locationTypes.SequenceEqual(result.LocationTypes));
|
||||
|
||||
Assert.Single(result.VehicleTypes);
|
||||
Assert.True(vehicleTypes.SequenceEqual(result.VehicleTypes));
|
||||
|
||||
Assert.Single(result.BranchSet);
|
||||
Assert.True(branchSet.SequenceEqual(result.BranchSet));
|
||||
|
||||
Assert.Single(result.RepoCompanies);
|
||||
Assert.True(RepoCompanies.SequenceEqual(result.RepoCompanies));
|
||||
|
||||
Assert.Single(result.TransactionTypeCodes);
|
||||
Assert.True(_transactionTypeCodes.SequenceEqual(result.TransactionTypeCodes));
|
||||
|
||||
Assert.Equal(_transactionHistoryParameterDateFormat.ToUpper(), result.TransactionHistoryParameterDateFormat);
|
||||
|
||||
Assert.Equal(_transactionTypeCodeQueryPrefix, result.TransactionTypeCodeQueryPrefix);
|
||||
|
||||
Assert.Equal(_transactionHistoryStartDateOffset, result.TransactionHistoryStartDateOffset);
|
||||
|
||||
Assert.NotNull((result.RepoTypeMap));
|
||||
Assert.Equal(5, result.RepoTypeMap.Count);
|
||||
Assert.Equal(RepoType.Involuntary.ToString(), result.RepoTypeMap.GetValueOrDefault((int)RepoType.Involuntary));
|
||||
Assert.Equal(RepoType.Voluntary.ToString(), result.RepoTypeMap.GetValueOrDefault((int)RepoType.Voluntary));
|
||||
Assert.Equal(RepoType.Skip.ToString(), result.RepoTypeMap.GetValueOrDefault((int)RepoType.Skip));
|
||||
Assert.Equal(RepoType.PreSkip.ToString(), result.RepoTypeMap.GetValueOrDefault((int)RepoType.PreSkip));
|
||||
Assert.Equal(RepoType.Unknown.ToString(), result.RepoTypeMap.GetValueOrDefault((int)RepoType.Unknown));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Save_Account_Type_OK()
|
||||
{
|
||||
var type = new AccountType();
|
||||
_mockAccountTypeRepository.Setup(x => x.ListAllAsync()).ReturnsAsync(new List<AccountType> { type });
|
||||
|
||||
// arrange
|
||||
var service = BuildTestSettingsService();
|
||||
|
||||
// act
|
||||
var result = await service.SaveAsync(type);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(type, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Save_Allowed_Status_Change_OK()
|
||||
{
|
||||
var statusChange = new AllowedStatusChange();
|
||||
_mockAllowedStatusChangeRepository.Setup(x => x.ListAllAsync())
|
||||
.ReturnsAsync(new List<AllowedStatusChange> { statusChange });
|
||||
|
||||
// arrange
|
||||
var service = BuildTestSettingsService();
|
||||
|
||||
// act
|
||||
var result = await service.SaveAsync(statusChange);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(statusChange, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Save_Body_Style_OK()
|
||||
{
|
||||
var bodyStyle = new BodyStyle();
|
||||
_mockBodyStyleRepository.Setup(x => x.ListAllAsync()).ReturnsAsync(new List<BodyStyle> { bodyStyle });
|
||||
|
||||
// arrange
|
||||
var service = BuildTestSettingsService();
|
||||
|
||||
// act
|
||||
var result = await service.SaveAsync(bodyStyle);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(bodyStyle, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Save_Cleaning_Level_OK()
|
||||
{
|
||||
var cleaningLevel = new CleaningLevel();
|
||||
_mockCleaningLevelRepository.Setup(x => x.ListAllAsync())
|
||||
.ReturnsAsync(new List<CleaningLevel> { cleaningLevel });
|
||||
|
||||
// arrange
|
||||
var service = BuildTestSettingsService();
|
||||
|
||||
// act
|
||||
var result = await service.SaveAsync(cleaningLevel);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(cleaningLevel, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Save_Collateral_Type_OK()
|
||||
{
|
||||
var collateralType = new CollateralType();
|
||||
_mockCollateralTypeRepository.Setup(x => x.ListAllAsync())
|
||||
.ReturnsAsync(new List<CollateralType> { collateralType });
|
||||
|
||||
// arrange
|
||||
var service = BuildTestSettingsService();
|
||||
|
||||
// act
|
||||
var result = await service.SaveAsync(collateralType);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(collateralType, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Save_Collateral_Type_To_Vehicle_Type_OK()
|
||||
{
|
||||
var collateralToVehicle = new CollateralTypeToVehicleType();
|
||||
_mockCollateralTypeToVehicleTypeRepository.Setup(x => x.ListAllAsync())
|
||||
.ReturnsAsync(new List<CollateralTypeToVehicleType> { collateralToVehicle });
|
||||
|
||||
// arrange
|
||||
var service = BuildTestSettingsService();
|
||||
|
||||
// act
|
||||
var result = await service.SaveAsync(collateralToVehicle);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(collateralToVehicle, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Save_Hold_Status_OK()
|
||||
{
|
||||
var holdStatus = new HoldStatus();
|
||||
_mockHoldStatusRepository.Setup(x => x.ListAllAsync()).ReturnsAsync(new List<HoldStatus> { holdStatus });
|
||||
|
||||
// arrange
|
||||
var service = BuildTestSettingsService();
|
||||
|
||||
// act
|
||||
var result = await service.SaveAsync(holdStatus);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(holdStatus, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Save_Loan_Category_OK()
|
||||
{
|
||||
var loanCategory = new LoanCategory();
|
||||
_mockLoanCategoryRepository.Setup(x => x.ListAllAsync())
|
||||
.ReturnsAsync(new List<LoanCategory> { loanCategory });
|
||||
|
||||
// arrange
|
||||
var service = BuildTestSettingsService();
|
||||
|
||||
// act
|
||||
var result = await service.SaveAsync(loanCategory);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(loanCategory, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Save_Location_Type_OK()
|
||||
{
|
||||
var locationType = new LocationType();
|
||||
_mockLocationTypeRepository.Setup(x => x.ListAllAsync())
|
||||
.ReturnsAsync(new List<LocationType> { locationType });
|
||||
|
||||
// arrange
|
||||
var service = BuildTestSettingsService();
|
||||
|
||||
// act
|
||||
var result = await service.SaveAsync(locationType);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(locationType, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Save_Vehicle_Type_OK()
|
||||
{
|
||||
var vehicleType = new VehicleType();
|
||||
_mockVehicleTypeRepository.Setup(x => x.ListAllAsync()).ReturnsAsync(new List<VehicleType> { vehicleType });
|
||||
|
||||
// arrange
|
||||
var service = BuildTestSettingsService();
|
||||
|
||||
// act
|
||||
var result = await service.SaveAsync(vehicleType);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(vehicleType, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Account_Type_OK()
|
||||
{
|
||||
var type = new AccountType();
|
||||
_mockAccountTypeRepository.Setup(x => x.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(type);
|
||||
type.Description = "New description";
|
||||
|
||||
// arrange
|
||||
var service = BuildTestSettingsService();
|
||||
|
||||
// act
|
||||
var result = await service.UpdateAsync(type);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("New description", result.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Allowed_Status_Change_OK()
|
||||
{
|
||||
var statusChange = new AllowedStatusChange();
|
||||
_mockAllowedStatusChangeRepository.Setup(x => x.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(statusChange);
|
||||
statusChange.AllowedChangeStatus = "New status";
|
||||
|
||||
// arrange
|
||||
var service = BuildTestSettingsService();
|
||||
|
||||
// act
|
||||
var result = await service.UpdateAsync(statusChange);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("New status", result.AllowedChangeStatus);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Body_Style_OK()
|
||||
{
|
||||
var bodyStyle = new BodyStyle();
|
||||
_mockBodyStyleRepository.Setup(x => x.FindByIdAsync(It.IsAny<string>())).ReturnsAsync(bodyStyle);
|
||||
bodyStyle.Description = "New description";
|
||||
|
||||
// arrange
|
||||
var service = BuildTestSettingsService();
|
||||
|
||||
// act
|
||||
var result = await service.UpdateAsync(bodyStyle);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("New description", result.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Cleaning_Level_OK()
|
||||
{
|
||||
var cleaningLevel = new CleaningLevel();
|
||||
_mockCleaningLevelRepository.Setup(x => x.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(cleaningLevel);
|
||||
cleaningLevel.Description = "New description";
|
||||
|
||||
// arrange
|
||||
var service = BuildTestSettingsService();
|
||||
|
||||
// act
|
||||
var result = await service.UpdateAsync(cleaningLevel);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("New description", result.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Collateral_Type_OK()
|
||||
{
|
||||
var collateralType = new CollateralType();
|
||||
_mockCollateralTypeRepository.Setup(x => x.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(collateralType);
|
||||
collateralType.Description = "New description";
|
||||
|
||||
// arrange
|
||||
var service = BuildTestSettingsService();
|
||||
|
||||
// act
|
||||
var result = await service.UpdateAsync(collateralType);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("New description", result.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Collateral_Type_To_Vehicle_Type_OK()
|
||||
{
|
||||
var collateralToVehicle = new CollateralTypeToVehicleType();
|
||||
_mockCollateralTypeToVehicleTypeRepository.Setup(x => x.FindByIdAsync(It.IsAny<int>()))
|
||||
.ReturnsAsync(collateralToVehicle);
|
||||
collateralToVehicle.VehicleTypeId = 42;
|
||||
|
||||
// arrange
|
||||
var service = BuildTestSettingsService();
|
||||
|
||||
// act
|
||||
var result = await service.UpdateAsync(collateralToVehicle);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(42, result.VehicleTypeId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Hold_Status_OK()
|
||||
{
|
||||
var holdStatus = new HoldStatus();
|
||||
_mockHoldStatusRepository.Setup(x => x.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(holdStatus);
|
||||
holdStatus.Description = "New description";
|
||||
|
||||
// arrange
|
||||
var service = BuildTestSettingsService();
|
||||
|
||||
// act
|
||||
var result = await service.UpdateAsync(holdStatus);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("New description", result.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Loan_Category_OK()
|
||||
{
|
||||
var loanCategory = new LoanCategory();
|
||||
_mockLoanCategoryRepository.Setup(x => x.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(loanCategory);
|
||||
loanCategory.CategoryName = "New name";
|
||||
|
||||
// arrange
|
||||
var service = BuildTestSettingsService();
|
||||
|
||||
// act
|
||||
var result = await service.UpdateAsync(loanCategory);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("New name", result.CategoryName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Location_Type_OK()
|
||||
{
|
||||
var locationType = new LocationType();
|
||||
_mockLocationTypeRepository.Setup(x => x.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(locationType);
|
||||
locationType.Description = "New description";
|
||||
|
||||
// arrange
|
||||
var service = BuildTestSettingsService();
|
||||
|
||||
// act
|
||||
var result = await service.UpdateAsync(locationType);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("New description", result.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Vehicle_Type_OK()
|
||||
{
|
||||
var vehicleType = new VehicleType();
|
||||
_mockVehicleTypeRepository.Setup(x => x.FindByIdAsync(It.IsAny<string>())).ReturnsAsync(vehicleType);
|
||||
vehicleType.Description = "New description";
|
||||
|
||||
// arrange
|
||||
var service = BuildTestSettingsService();
|
||||
|
||||
// act
|
||||
var result = await service.UpdateAsync(vehicleType);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("New description", result.Description);
|
||||
}
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.API.Collections.CollectionsApiLib.Models;
|
||||
using LCU.API.Collections.RepoApi.Exceptions;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class StatusServiceTests
|
||||
{
|
||||
|
||||
[Theory]
|
||||
[InlineData(RepoStatus.REHO, "REHO")]
|
||||
[InlineData(RepoStatus.RECA, "RECA")]
|
||||
[InlineData(RepoStatus.O4R, "O4R")]
|
||||
[InlineData(RepoStatus.REPO, "REPO")]
|
||||
[InlineData(RepoStatus.REDEEMED, "REDEEMED")]
|
||||
[InlineData(RepoStatus.SOLD, "SOLD")]
|
||||
[InlineData(RepoStatus.NOTACTIVE, "SOLD")]
|
||||
public void MapsProperRepoStatus(RepoStatus oldStatus, string status)
|
||||
{
|
||||
var result = StatusService.ConvertStatus(oldStatus);
|
||||
Assert.Equal(result, status);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StatusServiceThrowsOnUnknown()
|
||||
{
|
||||
Assert.Throws<MissingRequirementException>(() => { StatusService.ConvertStatus(RepoStatus.UNKNOWN); });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+192
@@ -0,0 +1,192 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
using Moq;
|
||||
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
||||
using RabbitMQ.Client;
|
||||
using LCU.API.Collections.RepoApi.Services;
|
||||
using LCU.API.Collections.RepoApi.Exceptions;
|
||||
using LCU.Shared.Collections.RepoApiLib.Models;
|
||||
using System.Threading.Tasks;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace LCU.API.Collections.RepoApiTests.Services
|
||||
{
|
||||
public class VehicleFloorPricingParameterServiceTest
|
||||
{
|
||||
[Fact]
|
||||
public async void ListAll_Exception()
|
||||
{
|
||||
var _mockFloorPricingParamRepo = new Mock<IVehicleFloorPricingParametersRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockFloorPricingParamRepo.Setup(repo => repo.ListAllAsync()).ThrowsAsync(new Exception("oops"));
|
||||
VehicleFloorPricingParametersService vehicleFloorPricingService = new VehicleFloorPricingParametersService(_mockFloorPricingParamRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await vehicleFloorPricingService.ListAll());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ListAll_OK()
|
||||
{
|
||||
var _mockFloorPricingParamRepo = new Mock<IVehicleFloorPricingParametersRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockFloorPricingParamRepo.Setup(repo => repo.ListAllAsync()).ReturnsAsync(new List<VehicleFloorPricingParameters>() { new VehicleFloorPricingParameters() { } });
|
||||
VehicleFloorPricingParametersService vehicleFloorPricingService = new VehicleFloorPricingParametersService(_mockFloorPricingParamRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
|
||||
var res = await vehicleFloorPricingService.ListAll();
|
||||
Assert.Single(res);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Exception()
|
||||
{
|
||||
var _mockFloorPricingParamRepo = new Mock<IVehicleFloorPricingParametersRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockFloorPricingParamRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ThrowsAsync(new Exception("oops"));
|
||||
VehicleFloorPricingParametersService vehicleFloorPricingService = new VehicleFloorPricingParametersService(_mockFloorPricingParamRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await vehicleFloorPricingService.Get(5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Ok()
|
||||
{
|
||||
var _mockFloorPricingParamRepo = new Mock<IVehicleFloorPricingParametersRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockFloorPricingParamRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(new VehicleFloorPricingParameters() { Id = 5 }) ;
|
||||
VehicleFloorPricingParametersService vehicleFloorPricingService = new VehicleFloorPricingParametersService(_mockFloorPricingParamRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
var res = await vehicleFloorPricingService.Get(5);
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(5, res.Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Null_Exception()
|
||||
{
|
||||
var _mockFloorPricingParamRepo = new Mock<IVehicleFloorPricingParametersRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockFloorPricingParamRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).Returns(Task.FromResult<VehicleFloorPricingParameters>(null));
|
||||
VehicleFloorPricingParametersService vehicleFloorPricingService = new VehicleFloorPricingParametersService(_mockFloorPricingParamRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<NotFoundException>(async () => await vehicleFloorPricingService.Get(5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateAsync_Existing_Null()
|
||||
{
|
||||
VehicleFloorPricingParameters parameters = new VehicleFloorPricingParameters {
|
||||
Id = 5,
|
||||
LowCondition = 1,
|
||||
HighCondition = 5,
|
||||
NADAFirstValue = "101.1",
|
||||
NADASecondValue = "202.2",
|
||||
MMRAdjustedValue = "303.3",
|
||||
PercentageOf = 10,
|
||||
ValuationServiceType = 5
|
||||
};
|
||||
|
||||
var _mockFloorPricingParamRepo = new Mock<IVehicleFloorPricingParametersRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockFloorPricingParamRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).Returns(Task.FromResult<VehicleFloorPricingParameters>(null));
|
||||
_mockFloorPricingParamRepo.Setup(repo => repo.Update(It.Is<VehicleFloorPricingParameters>(param => param.Id == 5)));
|
||||
|
||||
VehicleFloorPricingParametersService vehicleFloorPricingService = new VehicleFloorPricingParametersService(_mockFloorPricingParamRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<NotFoundException>(async () => await vehicleFloorPricingService.UpdateAsync(parameters));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateAsync_Ok()
|
||||
{
|
||||
VehicleFloorPricingParameters parameters = new VehicleFloorPricingParameters
|
||||
{
|
||||
Id = 5,
|
||||
LowCondition = 1,
|
||||
HighCondition = 3,
|
||||
NADAFirstValue = "101.1",
|
||||
NADASecondValue = "202.2",
|
||||
MMRAdjustedValue = "303.3",
|
||||
PercentageOf = 10,
|
||||
ValuationServiceType = 4
|
||||
};
|
||||
|
||||
var _mockFloorPricingParamRepo = new Mock<IVehicleFloorPricingParametersRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockFloorPricingParamRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(parameters);
|
||||
_mockFloorPricingParamRepo.Setup(repo => repo.Update(It.Is<VehicleFloorPricingParameters>(param => param.Id == 5 && param.NADAFirstValue == "101.1")));
|
||||
VehicleFloorPricingParametersService vehicleFloorPricingService = new VehicleFloorPricingParametersService(_mockFloorPricingParamRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
var res = await vehicleFloorPricingService.UpdateAsync(parameters);
|
||||
Assert.NotNull(res);
|
||||
Assert.Equal(1, res.LowCondition);
|
||||
Assert.Equal(3, res.HighCondition);
|
||||
Assert.Equal("101.1", res.NADAFirstValue);
|
||||
Assert.Equal("202.2", res.NADASecondValue);
|
||||
Assert.Equal("303.3", res.MMRAdjustedValue);
|
||||
Assert.Equal(10, res.PercentageOf);
|
||||
Assert.Equal(4, res.ValuationServiceType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateAsync_Existing_Exception()
|
||||
{
|
||||
VehicleFloorPricingParameters parameters = new VehicleFloorPricingParameters
|
||||
{
|
||||
Id = 5,
|
||||
LowCondition = 1,
|
||||
HighCondition = 5,
|
||||
NADAFirstValue = "101.1",
|
||||
NADASecondValue = "202.2",
|
||||
MMRAdjustedValue = "303.3",
|
||||
PercentageOf = 10,
|
||||
ValuationServiceType = 5
|
||||
};
|
||||
|
||||
var _mockFloorPricingParamRepo = new Mock<IVehicleFloorPricingParametersRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockFloorPricingParamRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).ThrowsAsync(new Exception("oops"));
|
||||
_mockFloorPricingParamRepo.Setup(repo => repo.Update(It.Is<VehicleFloorPricingParameters>(param => param.Id == 5)));
|
||||
|
||||
VehicleFloorPricingParametersService vehicleFloorPricingService = new VehicleFloorPricingParametersService(_mockFloorPricingParamRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await vehicleFloorPricingService.UpdateAsync(parameters));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateAsync_Update_Exception()
|
||||
{
|
||||
VehicleFloorPricingParameters parameters = new VehicleFloorPricingParameters
|
||||
{
|
||||
Id = 5,
|
||||
LowCondition = 1,
|
||||
HighCondition = 5,
|
||||
NADAFirstValue = "101.1",
|
||||
NADASecondValue = "202.2",
|
||||
MMRAdjustedValue = "303.3",
|
||||
PercentageOf = 10,
|
||||
ValuationServiceType = 5
|
||||
};
|
||||
|
||||
var _mockFloorPricingParamRepo = new Mock<IVehicleFloorPricingParametersRepository>();
|
||||
var _mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_mockFloorPricingParamRepo.Setup(repo => repo.FindByIdAsync(It.IsAny<int>())).Returns(Task.FromResult<VehicleFloorPricingParameters>(parameters));
|
||||
_mockFloorPricingParamRepo.Setup(repo => repo.Update(It.Is<VehicleFloorPricingParameters>(param => param.Id == 5))).Throws(new Exception("oops"));
|
||||
|
||||
VehicleFloorPricingParametersService vehicleFloorPricingService = new VehicleFloorPricingParametersService(_mockFloorPricingParamRepo.Object, _mockUnitOfWork.Object);
|
||||
|
||||
await Assert.ThrowsAsync<ServerErrorException>(async () => await vehicleFloorPricingService.UpdateAsync(parameters));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user