This repository has been archived by the owner on Jan 17, 2024. It is now read-only.
forked from 18F/dol-whd-14c
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from AppliedIS/unittests-backend
add test coverage
- Loading branch information
Showing
15 changed files
with
665 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
DOL.WHD.Section14c.Test/Domain/Models/Identity/ApplicationUserTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Security.Claims; | ||
using System.Threading.Tasks; | ||
using DOL.WHD.Section14c.Domain.Models; | ||
using DOL.WHD.Section14c.Domain.Models.Identity; | ||
using Microsoft.AspNet.Identity; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
|
||
namespace DOL.WHD.Section14c.Test.Domain.Models.Identity | ||
{ | ||
[TestClass] | ||
public class ApplicationUserTests | ||
{ | ||
[TestMethod] | ||
public async Task GenerateUserIdentityAsync_AddsEINClaim() | ||
{ | ||
// Arrange | ||
var ein = "30-1234567"; | ||
var identity = new ClaimsIdentity(); | ||
var userStoreMock = new Mock<IUserStore<ApplicationUser>>(); | ||
var userManagerMock = new Mock<UserManager<ApplicationUser>>(userStoreMock.Object); | ||
userManagerMock.Setup(x => x.CreateIdentityAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).ReturnsAsync(identity); | ||
|
||
var roleStoreMock = new Mock<IRoleStore<ApplicationRole>>(); | ||
var roleManagerMock = new Mock<RoleManager<ApplicationRole>>(roleStoreMock.Object); | ||
|
||
var user = new ApplicationUser(); | ||
user.Organizations = new List<OrganizationMembership> | ||
{ | ||
new OrganizationMembership { EIN = ein, IsAdmin = true} | ||
}; | ||
|
||
// Act | ||
var result = await user.GenerateUserIdentityAsync(userManagerMock.Object, roleManagerMock.Object, null); | ||
|
||
Assert.AreEqual(ein, result.Claims.Single(x => x.Type == "EIN").Value); | ||
} | ||
|
||
[TestMethod] | ||
public async Task GenerateUserIdentityAsync_AddsSubmitApplicationClaim() | ||
{ | ||
// Arrange | ||
var identity = new ClaimsIdentity(); | ||
var userStoreMock = new Mock<IUserStore<ApplicationUser>>(); | ||
var userManagerMock = new Mock<UserManager<ApplicationUser>>(userStoreMock.Object); | ||
userManagerMock.Setup(x => x.CreateIdentityAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).ReturnsAsync(identity); | ||
|
||
var roleStoreMock = new Mock<IRoleStore<ApplicationRole>>(); | ||
var roleManagerMock = new Mock<RoleManager<ApplicationRole>>(roleStoreMock.Object); | ||
|
||
var user = new ApplicationUser(); | ||
|
||
// Act | ||
var result = await user.GenerateUserIdentityAsync(userManagerMock.Object, roleManagerMock.Object, null); | ||
|
||
Assert.IsTrue(result.HasClaim(x => x.Type == ApplicationClaimTypes.SubmitApplication)); | ||
} | ||
|
||
[TestMethod] | ||
public async Task GenerateUserIdentityAsync_AddsRoleBasedClaim() | ||
{ | ||
// Arrange | ||
var identity = new ClaimsIdentity(); | ||
var userStoreMock = new Mock<IUserStore<ApplicationUser>>(); | ||
var userManagerMock = new Mock<UserManager<ApplicationUser>>(userStoreMock.Object); | ||
userManagerMock.Setup(x => x.CreateIdentityAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).ReturnsAsync(identity); | ||
|
||
var roles = new List<ApplicationRole> | ||
{ | ||
new ApplicationRole | ||
{ | ||
Id = Roles.SystemAdministrator, | ||
RoleFeatures = new List<RoleFeature> | ||
{ | ||
new RoleFeature { Feature = new Feature { Key = ApplicationClaimTypes.ModifyAccount}} | ||
} | ||
} | ||
}; | ||
var roleStoreMock = new Mock<IRoleStore<ApplicationRole>>(); | ||
var roleManagerMock = new Mock<RoleManager<ApplicationRole>>(roleStoreMock.Object); | ||
roleManagerMock.Setup(x => x.Roles).Returns(roles.AsQueryable()); | ||
|
||
var user = new ApplicationUser(); | ||
user.Roles.Add(new ApplicationUserRole { RoleId = Roles.SystemAdministrator}); | ||
|
||
// Act | ||
var result = await user.GenerateUserIdentityAsync(userManagerMock.Object, roleManagerMock.Object, null); | ||
|
||
Assert.IsTrue(result.HasClaim(x => x.Type == ApplicationClaimTypes.ModifyAccount)); | ||
} | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
DOL.WHD.Section14c.Test/Domain/Models/Submission/ApplicationSubmissionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using DOL.WHD.Section14c.Domain.Models.Submission; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace DOL.WHD.Section14c.Test.Domain.Models.Submission | ||
{ | ||
[TestClass] | ||
public class ApplicationSubmissionTests | ||
{ | ||
[TestMethod] | ||
public void ApplicationSubmission_PublicProperties() | ||
{ | ||
//Arrange | ||
var ein = "30-1234567"; | ||
var applicationTypeId = 1; | ||
var applicationType = new Response {Id = applicationTypeId}; | ||
var hasPreviousApplication = true; | ||
var hasPreviousCertificate = true; | ||
var certificateNumber = "xxxxxxx"; | ||
var establishmentTypeId = new List<int> {7, 8, 9}; | ||
var contactName = "Test Name"; | ||
var contactPhone = "123-456-7890"; | ||
var contactFax = "123-456-7890"; | ||
var contactEmail = "foo@bar.com"; | ||
var employer = new EmployerInfo(); | ||
var payTypeId = 21; | ||
var payType = new Response {Id = payTypeId}; | ||
var hourlyWageInfo = new HourlyWageInfo(); | ||
var pieceRateWageInfo = new PieceRateWageInfo(); | ||
var totalNumWorkSites = 5; | ||
var workSites = new List<WorkSite>(); | ||
var wioa = new WIOA(); | ||
|
||
//Act | ||
var model = new ApplicationSubmission | ||
{ | ||
EIN = ein, | ||
ApplicationTypeId = applicationTypeId, | ||
ApplicationType = applicationType, | ||
HasPreviousApplication = hasPreviousApplication, | ||
HasPreviousCertificate = hasPreviousCertificate, | ||
CertificateNumber = certificateNumber, | ||
EstablishmentTypeId = establishmentTypeId, | ||
ContactName = contactName, | ||
ContactPhone = contactPhone, | ||
ContactFax = contactFax, | ||
ContactEmail = contactEmail, | ||
Employer = employer, | ||
PayTypeId = payTypeId, | ||
PayType = payType, | ||
HourlyWageInfo = hourlyWageInfo, | ||
PieceRateWageInfo = pieceRateWageInfo, | ||
TotalNumWorkSites = totalNumWorkSites, | ||
WorkSites = workSites, | ||
WIOA = wioa | ||
}; | ||
|
||
Assert.AreEqual(ein, model.EIN); | ||
Assert.AreEqual(applicationTypeId, model.ApplicationTypeId); | ||
Assert.AreEqual(applicationType, model.ApplicationType); | ||
Assert.AreEqual(hasPreviousApplication, model.HasPreviousApplication); | ||
Assert.AreEqual(hasPreviousCertificate, model.HasPreviousCertificate); | ||
Assert.AreEqual(certificateNumber, model.CertificateNumber); | ||
Assert.AreEqual(establishmentTypeId[0], model.EstablishmentType.ElementAt(0).EstablishmentTypeId); | ||
Assert.AreEqual(establishmentTypeId[1], model.EstablishmentType.ElementAt(1).EstablishmentTypeId); | ||
Assert.AreEqual(establishmentTypeId[2], model.EstablishmentType.ElementAt(2).EstablishmentTypeId); | ||
Assert.AreEqual(contactName, model.ContactName); | ||
Assert.AreEqual(contactPhone, model.ContactPhone); | ||
Assert.AreEqual(contactFax, model.ContactFax); | ||
Assert.AreEqual(contactEmail, model.ContactEmail); | ||
Assert.AreEqual(employer, model.Employer); | ||
Assert.AreEqual(payTypeId, model.PayTypeId); | ||
Assert.AreEqual(payType, model.PayType); | ||
Assert.AreEqual(hourlyWageInfo, model.HourlyWageInfo); | ||
Assert.AreEqual(pieceRateWageInfo, model.PieceRateWageInfo); | ||
Assert.AreEqual(totalNumWorkSites, model.TotalNumWorkSites); | ||
Assert.AreEqual(workSites, model.WorkSites); | ||
Assert.AreEqual(wioa, model.WIOA); | ||
} | ||
|
||
[TestMethod] | ||
public void ApplicationSubmission_Handles_Null_EstablishmentId() | ||
{ | ||
// Arrange | ||
var model = new ApplicationSubmission { EstablishmentTypeId = null}; | ||
Assert.IsNull(model.EstablishmentType); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
DOL.WHD.Section14c.Test/Domain/Models/Submission/EmployeeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using DOL.WHD.Section14c.Domain.Models.Submission; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace DOL.WHD.Section14c.Test.Domain.Models.Submission | ||
{ | ||
[TestClass] | ||
public class EmployeeTests | ||
{ | ||
[TestMethod] | ||
public void Employee_PublicProperties() | ||
{ | ||
var name = "Employee Name"; | ||
var primaryDisabilityId = 39; | ||
var primaryDisability = new Response {Id = primaryDisabilityId}; | ||
var primaryDisabilityOther = "primaryDisabilityOther"; | ||
var workType = "workType"; | ||
var numJobs = 3; | ||
var avgWeeklyHours = 41.5; | ||
var avgHourlyEarnings = 3.55; | ||
var prevailingWage = 5.05; | ||
var productivityMeasure = 500.55; | ||
var commensurateWageRate = "commensurateWageRate"; | ||
var totalHours = 500118.55; | ||
var workAtOtherSite = true; | ||
|
||
var model = new Employee | ||
{ | ||
Name = name, | ||
PrimaryDisabilityId = primaryDisabilityId, | ||
PrimaryDisability = primaryDisability, | ||
PrimaryDisabilityOther = primaryDisabilityOther, | ||
WorkType = workType, | ||
NumJobs = numJobs, | ||
AvgWeeklyHours = avgWeeklyHours, | ||
AvgHourlyEarnings = avgHourlyEarnings, | ||
PrevailingWage = prevailingWage, | ||
ProductivityMeasure = productivityMeasure, | ||
CommensurateWageRate = commensurateWageRate, | ||
TotalHours = totalHours, | ||
WorkAtOtherSite = workAtOtherSite | ||
}; | ||
|
||
Assert.AreEqual(name, model.Name); | ||
Assert.AreEqual(primaryDisabilityId, model.PrimaryDisabilityId); | ||
Assert.AreEqual(primaryDisability, model.PrimaryDisability); | ||
Assert.AreEqual(primaryDisabilityOther, model.PrimaryDisabilityOther); | ||
Assert.AreEqual(workType, model.WorkType); | ||
Assert.AreEqual(numJobs, model.NumJobs); | ||
Assert.AreEqual(avgWeeklyHours, model.AvgWeeklyHours); | ||
Assert.AreEqual(avgHourlyEarnings, model.AvgHourlyEarnings); | ||
Assert.AreEqual(prevailingWage, model.PrevailingWage); | ||
Assert.AreEqual(productivityMeasure, model.ProductivityMeasure); | ||
Assert.AreEqual(commensurateWageRate, model.CommensurateWageRate); | ||
Assert.AreEqual(totalHours, model.TotalHours); | ||
Assert.AreEqual(workAtOtherSite, model.WorkAtOtherSite); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ion14c.Test/Domain/Models/Submission/EmployerInfoProvidingFacilitiesDeductionTypeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using DOL.WHD.Section14c.Domain.Models.Submission; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace DOL.WHD.Section14c.Test.Domain.Models.Submission | ||
{ | ||
[TestClass] | ||
public class EmployerInfoProvidingFacilitiesDeductionTypeTests | ||
{ | ||
[TestMethod] | ||
public void EmployerInfoProvidingFacilitiesDeductionType_PublicProperties() | ||
{ | ||
var employerInfoId = Guid.NewGuid(); | ||
var employerInfo = new EmployerInfo {Id = employerInfoId}; | ||
var providingFacilitiesDeductionTypeId = 30; | ||
var providingFacilitiesDeductionType = new Response {Id = providingFacilitiesDeductionTypeId}; | ||
|
||
var model = new EmployerInfoProvidingFacilitiesDeductionType | ||
{ | ||
EmployerInfoId = employerInfoId, | ||
EmployerInfo = employerInfo, | ||
ProvidingFacilitiesDeductionTypeId = providingFacilitiesDeductionTypeId, | ||
ProvidingFacilitiesDeductionType = providingFacilitiesDeductionType | ||
}; | ||
|
||
Assert.AreEqual(employerInfoId, model.EmployerInfoId); | ||
Assert.AreEqual(employerInfo, model.EmployerInfo); | ||
Assert.AreEqual(providingFacilitiesDeductionTypeId, model.ProvidingFacilitiesDeductionTypeId); | ||
Assert.AreEqual(providingFacilitiesDeductionType, model.ProvidingFacilitiesDeductionType); | ||
} | ||
} | ||
} |
Oops, something went wrong.