private CanCreateContactRequest CreateRequest(ContactType newType, int minExistingEmail = 0, int minExistingPhone = 0) { var contactRetailsRequest = _fixture.Build <ContactDetailsRequestObject>() .With(x => x.ContactInformation, CreateContactInformation(newType)) .Create(); var existingContacts = _fixture.Build <ContactDetails>() .With(x => x.TargetId, contactRetailsRequest.TargetId) .CreateMany(3).ToList(); if (minExistingEmail > 0) { existingContacts.AddRange(_fixture.Build <ContactDetails>() .With(x => x.TargetId, contactRetailsRequest.TargetId) .With(x => x.ContactInformation, CreateContactInformation(ContactType.email)) .CreateMany(minExistingEmail)); } if (minExistingPhone > 0) { existingContacts.AddRange(_fixture.Build <ContactDetails>() .With(x => x.TargetId, contactRetailsRequest.TargetId) .With(x => x.ContactInformation, CreateContactInformation(ContactType.phone)) .CreateMany(minExistingPhone)); } return(new CanCreateContactRequest() { Request = contactRetailsRequest, ExistingContacts = existingContacts }); }
public void ServiceReturnsBadRequestWithTooManyExistingContactDetails(ContactType newType) { this.Given(g => _contactDetailsFixture.GivenANewContactRequest(newType)) .And(h => _contactDetailsFixture.GivenMaxContactDetailsAlreadyExist(_contactDetailsFixture.ContactRequestObject.TargetId)) .When(w => _steps.WhenTheCreateContactEndpointIsCalled(_contactDetailsFixture.ContactRequestObject)) .Then(t => _steps.ThenBadRequestIsReturned()) .And(t => _steps.ThenTheResponseIncludesValidationErrorsForTooManyContacts()) .BDDfy(); }
public void ContactTypeShouldNotErrorWithFerwerThanMaxContacts(ContactType type) { // Arrange var model = CreateRequest(type); // Act var result = _sut.TestValidate(model); // Assert result.ShouldNotHaveValidationErrorFor(x => x.ExistingContacts); }
public void CreateContactTooManyExistingThrows(ContactType newType) { // Arrange var contactInfo = CreateContactInformation(newType); var request = _fixture.Build <ContactDetailsRequestObject>() .With(x => x.TargetId, _targetId) .With(x => x.ContactInformation, contactInfo) .Create(); _mockGateway.Setup(x => x.GetContactDetailsByTargetId(It.IsAny <ContactQueryParameter>())) .ReturnsAsync(CreateTooManyExistingContacts()); // Act Func <Task <ContactDetailsResponseObject> > func = async() => await _classUnderTest.ExecuteAsync(request, _token).ConfigureAwait(false); // Assert var typeString = Enum.GetName(typeof(ContactType), newType); func.Should().Throw <ValidationException>().WithMessage($"*Cannot create {typeString} contact record for targetId {_targetId} as the " + "maximum for that type (5) has already been reached*"); }
private ContactInformation CreateContactInformation(ContactType newType) { return(_fixture.Build <ContactInformation>() .With(x => x.ContactType, newType) .Create()); }
private static string FormatErrorMessage(ContactType type, int maxAllowed, Guid targetId) { var typeString = Enum.GetName(typeof(ContactType), type); return($"Cannot create {typeString} contact record for targetId {targetId} as the maximum for that type ({maxAllowed}) has already been reached."); }