コード例 #1
0
        public void ValidateCredentials_ReturnsAuthenticationError_WhenApiKeyIsNotEmptyAndServerIdIsEmpty()
        {
            //Arrange
            const int serverId  = int.MinValue;
            var       apiKey    = RandomHelper.RandomString();
            var       validator = new SendValidator();

            //Act
            var actual = validator.ValidateCredentials(serverId, apiKey);

            //Assert
            Assert.AreEqual(SendResult.AuthenticationValidationFailed, actual.Result);
        }
コード例 #2
0
        public void HasFromAddress_ReturnsFalse_WhenFromRecipientIsNull()
        {
            //Arrange
            var message = new BasicMessage {
                From = null
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.HasFromAddress(message);

            //Assert
            Assert.IsFalse(actual);
        }
コード例 #3
0
        public void HasApiTemplate_ReturnsFalse_WhenApiTemplateIsMinValue()
        {
            //Arrange
            var message = new BasicMessage {
                ApiTemplate = int.MinValue
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.HasApiTemplate(message);

            //Assert
            Assert.IsFalse(actual);
        }
コード例 #4
0
        public void ValidateRecipients_BulkMessage_ReturnsNoRecipients_WhenToIsEmpty()
        {
            //Arrange
            var message = new BulkMessage {
                To = new List <IBulkRecipient>()
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.ValidateRecipients(message);

            //Assert
            Assert.AreEqual(SendResult.RecipientValidationMissingTo, actual.Result);
        }
コード例 #5
0
        public void HasSubject_ReturnsTrue_WhenSubjectIsNotEmpty()
        {
            //Arrange
            var message = new BasicMessage {
                Subject = RandomHelper.RandomString()
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.HasSubject(message);

            //Assert
            Assert.IsTrue(actual);
        }
コード例 #6
0
        public void FindInvalidRecipients_ListOfBulkRecipient_ReturnsList_WhenInvalidRecipientsFound()
        {
            //Arrange
            var message = new List <IBulkRecipient> {
                new BulkRecipient(RandomHelper.RandomString())
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.FindInvalidRecipients(message);

            //Assert
            Assert.AreEqual(1, actual.Count);
        }
コード例 #7
0
        public void ValidateIMessageBase_ReturnsMessageValidationEmptySubject_WhenSubjectIsEmpty()
        {
            //Arrange
            var message = new BasicMessage {
                Subject = string.Empty
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.ValidateIMessageBase(message);

            //Assert
            Assert.AreEqual(SendResult.MessageValidationEmptySubject, actual);
        }
コード例 #8
0
        public void FindInvalidRecipients_ListOfBulkRecipient_ReturnsNull_WhenNoInvalidRecipientsFound()
        {
            //Arrange
            var message = new List <IBulkRecipient> {
                new BulkRecipient(RandomHelper.RandomEmail())
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.FindInvalidRecipients(message);

            //Assert
            Assert.IsNull(actual);
        }
コード例 #9
0
        public void HasSubject_ReturnsFalse_WhenSubjectIsEmpty()
        {
            //Arrange
            var message = new BasicMessage {
                Subject = string.Empty
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.HasSubject(message);

            //Assert
            Assert.IsFalse(actual);
        }
コード例 #10
0
        public void HasValidCustomHeaders_ReturnsFalse_WhenKeyIsEmptyAndValueIsNotEmpty()
        {
            //Arrange
            var customHeaders = new List <ICustomHeader>
            {
                new CustomHeader(string.Empty, RandomHelper.RandomString())
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.HasValidCustomHeaders(customHeaders);

            //Assert
            Assert.IsFalse(actual);
        }
コード例 #11
0
        public void HasValidCustomHeaders_ReturnsTrue_WhenDictionaryIsValid()
        {
            //Arrange
            var customHeaders = new List <ICustomHeader>
            {
                new CustomHeader(RandomHelper.RandomString(), RandomHelper.RandomString())
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.HasValidCustomHeaders(customHeaders);

            //Assert
            Assert.IsTrue(actual);
        }
コード例 #12
0
        public void HasApiTemplate_ReturnsTrue_WhenApiTemplateIsNotMinValue()
        {
            //Arrange
            var message = new BasicMessage
            {
                ApiTemplate = RandomHelper.RandomInt(1, 10)
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.HasApiTemplate(message);

            //Assert
            Assert.IsTrue(actual);
        }
コード例 #13
0
        public void HasFromAddress_ReturnsTrue_WhenFromRecipientIsNotEmpty()
        {
            //Arrange
            var message = new BasicMessage
            {
                From = new EmailAddress(RandomHelper.RandomEmail())
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.HasFromAddress(message);

            //Assert
            Assert.IsTrue(actual);
        }
コード例 #14
0
        public void ValidateRecipients_BulkMessage_ReturnsTooManyRecipients_WhenToHasToManyRecipients()
        {
            //Arrange
            var validator = new SendValidator();
            var message   = new BulkMessage
            {
                To = RandomHelper.RandomListOfBulkRecipients(validator.MaximumRecipientsPerMessage + 1)
            };

            //Act
            var actual = validator.ValidateRecipients(message);

            //Assert
            Assert.AreEqual(SendResult.RecipientValidationMaxExceeded, actual.Result);
        }
コード例 #15
0
        public void HasValidCustomHeaders_ReturnsFalse_WhenKeyAndValueAreEmpty()
        {
            //Arrange
            var customHeaders = new List <ICustomHeader>
            {
                new CustomHeader(string.Empty, string.Empty)
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.HasValidCustomHeaders(customHeaders);

            //Assert
            Assert.IsFalse(actual);
        }
コード例 #16
0
        public void ValidateIMessageBase_ReturnsEmailAddressValidationInvalidFrom_WhenFromRecipientIsInvalid()
        {
            //Arrange
            var message = new BasicMessage
            {
                Subject = RandomHelper.RandomString(),
                From    = new EmailAddress("$$##%%")
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.ValidateIMessageBase(message);

            //Assert
            Assert.AreEqual(SendResult.EmailAddressValidationInvalidFrom, actual);
        }
コード例 #17
0
        public void ValidateIMessageBase_ReturnsMessageValidationEmptyMessage_WhenSubjectAndFromRecipientAndAllBodyFieldsAreEmpty()
        {
            //Arrange
            var message = new BasicMessage
            {
                Subject = RandomHelper.RandomString(),
                From    = new EmailAddress(RandomHelper.RandomEmail())
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.ValidateIMessageBase(message);

            //Assert
            Assert.AreEqual(SendResult.MessageValidationEmptyMessage, actual);
        }
コード例 #18
0
        public void ValidateIMessageBase_ReturnsSuccess_WhenSubjectAndFromRecipientAndApiTemplateIsNotEmpty()
        {
            //Arrange
            var message = new BasicMessage
            {
                Subject     = RandomHelper.RandomString(),
                From        = new EmailAddress(RandomHelper.RandomEmail()),
                ApiTemplate = RandomHelper.RandomInt()
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.ValidateIMessageBase(message);

            //Assert
            Assert.AreEqual(SendResult.Success, actual);
        }
コード例 #19
0
        public void ValidateRecipients_BasicMessage_ReturnsSuccess_WhenBccIsNotEmpty()
        {
            //Arrange
            var message = new BasicMessage
            {
                Bcc = new List <IEmailAddress> {
                    new EmailAddress(RandomHelper.RandomEmail())
                }
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.ValidateRecipients(message);

            //Assert
            Assert.AreEqual(SendResult.Success, actual.Result);
        }
コード例 #20
0
        public void HasMessageBody_ReturnsFalse_WhenHtmlBodyAndPlainTextBodyAndApiTemplateIsEmpty()
        {
            //Arrange
            var message = new BasicMessage
            {
                HtmlBody      = string.Empty,
                PlainTextBody = string.Empty,
                ApiTemplate   = null
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.HasMessageBody(message);

            //Assert
            Assert.IsFalse(actual);
        }
コード例 #21
0
        public void FeeIsRequired()
        {
            // Arrange
            SendAction.Fee = null;

            // Act
            ValidationResult validationResult = SendValidator.Validate(SendAction);

            // Assert
            validationResult.IsValid.ShouldBe(false);
            validationResult.Errors.Count.ShouldBe(1);
            ValidationFailure validationFailure = validationResult.Errors[0];

            validationFailure.PropertyName.ShouldBe(nameof(SendAction.Fee));
            validationFailure.ErrorCode.ShouldBe(nameof(NotEmptyValidator));
            validationFailure.Severity.ShouldBe(Severity.Error);
        }
コード例 #22
0
        public void GetFullRecipientCount_BasicMessage_ReturnsGT0_WhenOnlyBccRecipientsHasOneValue()
        {
            //Arrange
            var message = new BasicMessage
            {
                Bcc = new List <IEmailAddress> {
                    new EmailAddress(RandomHelper.RandomEmail())
                }
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.GetFullRecipientCount(message);

            //Assert
            Assert.IsTrue(actual > 0);
        }
コード例 #23
0
        public void HasMessageBody_ReturnsTrue_WhenApiTemplateIsNotEmptyAndPlainTextBodyAndHtmlBodyIsEmpty()
        {
            //Arrange
            var message = new BasicMessage
            {
                HtmlBody      = string.Empty,
                PlainTextBody = string.Empty,
                ApiTemplate   = RandomHelper.RandomInt()
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.HasMessageBody(message);

            //Assert
            Assert.IsTrue(actual);
        }
コード例 #24
0
        public void HasInvalidRecipients_IBulkMessage_ReturnsListOfOne_WhenToHasOneInvalid()
        {
            //Arrange
            var message = new BulkMessage
            {
                To = new List <IBulkRecipient> {
                    new BulkRecipient(RandomHelper.RandomString())
                }
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.HasInvalidRecipients(message);

            //Assert
            Assert.AreEqual(1, actual.Count);
        }
コード例 #25
0
        public void ValidateRecipients_BasicMessage_ReturnsTooManyRecipients_WhenToAndCcAndBccCombinedHasToManyRecipients()
        {
            //Arrange
            var validator = new SendValidator();
            var message   = new BasicMessage
            {
                To  = RandomHelper.RandomListOfRecipients(validator.MaximumRecipientsPerMessage / 2),
                Cc  = RandomHelper.RandomListOfRecipients(validator.MaximumRecipientsPerMessage / 2),
                Bcc = RandomHelper.RandomListOfRecipients(validator.MaximumRecipientsPerMessage / 2)
            };

            //Act
            var actual = validator.ValidateRecipients(message);

            //Assert
            Assert.AreEqual(SendResult.RecipientValidationMaxExceeded, actual.Result);
        }
コード例 #26
0
        public void HasInvalidRecipients_IBasicMessage_ReturnsListOfOne_WhenBccHasOneInvalid()
        {
            //Arrange
            var message = new BasicMessage
            {
                Bcc = new List <IEmailAddress> {
                    new EmailAddress(RandomHelper.RandomString())
                }
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.HasInvalidRecipients(message);

            //Assert
            Assert.AreEqual(1, actual.Count);
        }
コード例 #27
0
        public void NativeAmountMustBeGreaterThanZero()
        {
            // Arrange
            SendAction.NativeAmount = "0000";

            // Act

            ValidationResult validationResult = SendValidator.Validate(SendAction);

            // Assert
            validationResult.IsValid.ShouldBe(false);
            validationResult.Errors.Count.ShouldBe(1);
            ValidationFailure validationFailure = validationResult.Errors[0];

            validationFailure.PropertyName.ShouldBe(nameof(SendAction.NativeAmount));
            validationFailure.ErrorCode.ShouldBe(nameof(PredicateValidator));
            validationFailure.Severity.ShouldBe(Severity.Error);
        }
コード例 #28
0
        public void WalletMustExist()
        {
            SendAction.EdgeCurrencyWalletId = "x";

            // Act

            ValidationResult validationResult = SendValidator.Validate(SendAction);

            // Assert
            validationResult.IsValid.ShouldBe(false);
            validationResult.Errors.Count.ShouldBe(1);

            ValidationFailure validationFailure = validationResult.Errors[0];

            validationFailure.PropertyName.ShouldBe(nameof(SendAction.EdgeCurrencyWalletId));
            validationFailure.ErrorCode.ShouldBe(nameof(PredicateValidator));
            validationFailure.Severity.ShouldBe(Severity.Error);
        }
コード例 #29
0
        public void DestinationAddressMustBeValid()
        {
            // Arrange

            SendAction.DestinationAddress = "ThisIsNotValid";

            // Act
            ValidationResult validationResult = SendValidator.Validate(SendAction);

            // Assert
            validationResult.IsValid.ShouldBe(false);
            validationResult.Errors.Count.ShouldBe(1);
            ValidationFailure validationFailure = validationResult.Errors[0];

            validationFailure.PropertyName.ShouldBe(nameof(SendAction.DestinationAddress));
            validationFailure.ErrorCode.ShouldBe(nameof(PredicateValidator));
            validationFailure.Severity.ShouldBe(Severity.Error);
        }
コード例 #30
0
        public void DestinationAddressIsRequired()
        {
            // Arrange

            SendAction.DestinationAddress = "";

            // Act
            ValidationResult validationResult = SendValidator.Validate(SendAction);

            // Assert
            validationResult.IsValid.ShouldBe(false);
            validationResult.Errors.Count.ShouldBeGreaterThan(0);
            ValidationFailure validationFailure = validationResult.Errors
                                                  .First(aValidationFailure => aValidationFailure.ErrorCode == nameof(NotEmptyValidator));

            validationFailure.PropertyName.ShouldBe(nameof(SendAction.DestinationAddress));
            validationFailure.ErrorCode.ShouldBe(nameof(NotEmptyValidator));
            validationFailure.Severity.ShouldBe(Severity.Error);
        }