-
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.
Create ContactChannelCreationValidatorTests.cs
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
GetIntoTeachingApiTests/Models/Crm/Validators/ContactChannelCreationValidatorTests.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,62 @@ | ||
using System; | ||
using System.Linq; | ||
using FluentAssertions; | ||
using FluentValidation.TestHelper; | ||
using GetIntoTeachingApi.Models; | ||
using GetIntoTeachingApi.Models.Crm; | ||
using GetIntoTeachingApi.Models.Crm.Validators; | ||
using GetIntoTeachingApi.Services; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace GetIntoTeachingApiTests.Models.Crm.Validators | ||
{ | ||
public class ContactChannelCreationValidatorTests | ||
{ | ||
private readonly ContactChannelCreationValidator _validator; | ||
private readonly Mock<IStore> _mockStore; | ||
|
||
public ContactChannelCreationValidatorTests() | ||
{ | ||
_mockStore = new Mock<IStore>(); | ||
_validator = new ContactChannelCreationValidator(_mockStore.Object); | ||
} | ||
|
||
[Fact] | ||
public void Validate_WhenValid_HasNoErrors() | ||
{ | ||
var mockPickListItem = new PickListItem { Id = 123 }; | ||
|
||
_mockStore | ||
.Setup(mock => mock.GetPickListItems("dfe_contactchannelcreation", "dfe_creationchannelsource")) | ||
.Returns(new[] { mockPickListItem }.AsQueryable()); | ||
|
||
_mockStore | ||
.Setup(mock => mock.GetPickListItems("dfe_contactchannelcreation", "dfe_creationchannelservice")) | ||
.Returns(new[] { mockPickListItem }.AsQueryable()); | ||
|
||
_mockStore | ||
.Setup(mock => mock.GetPickListItems("dfe_contactchannelcreation", "dfe_creationchannelactivities")) | ||
.Returns(new[] { mockPickListItem }.AsQueryable()); | ||
|
||
var contactChannelCreation = new ContactChannelCreation() | ||
{ | ||
CreationChannelSourceId = mockPickListItem.Id, | ||
CreationChannelServiceId = mockPickListItem.Id, | ||
CreationChannelActivityId = mockPickListItem.Id, | ||
}; | ||
|
||
var result = _validator.TestValidate(contactChannelCreation); | ||
|
||
result.IsValid.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void Validate_ChannelIdIsInvalid_HasError() | ||
{ | ||
var result = _validator.TestValidate(new ContactChannelCreation() { CreationChannelSourceId = 123 }); | ||
|
||
result.ShouldHaveValidationErrorFor(r => r.CreationChannelSourceId); | ||
} | ||
} | ||
} |