public void BuyPracticeModel_WhenHowDidYouHearAboutUsDetailIsInvalid_DoesNotAddErrorToValidationResults(string testData)
        {
            var sut = CreateRandomBuyPracticeModel();
            var validationResults = ModelValidator.Validate(sut);

            Assert.False(validationResults.Any());

            sut.HowDidYouHearAboutUsDetail = testData;

            validationResults = ModelValidator.Validate(sut);
            Assert.False(validationResults.Any());
        }
        public void BuyPracticeModel_WhenContactLastNameIsInvalid_AddsErrorToValidationResults(string testData)
        {
            var sut = CreateRandomBuyPracticeModel();
            var validationResults = ModelValidator.Validate(sut);

            Assert.False(validationResults.Any());

            sut.ContactLastName = testData;

            validationResults = ModelValidator.Validate(sut);
            Assert.True(validationResults.Count == 1);
        }
        [InlineData("10000000.01")] // To large
        public void BuyPracticeModel_WhenMaxPurchaseAmountIsInvalid_AddsErrorToValidationResults(string testValue)
        {
            var sut = CreateRandomBuyPracticeModel();
            var validationResults = ModelValidator.Validate(sut);

            Assert.False(validationResults.Any());

            sut.MaxPurchaseAmount = decimal.Parse(testValue);

            validationResults = ModelValidator.Validate(sut);
            Assert.True(validationResults.Count == 1);
        }
        public void BuyPracticeModel_WhenAdditionalNotesIsInvalid_DoesNotAddErrorToValidationResults(string testData)
        {
            var sut = CreateRandomBuyPracticeModel();
            var validationResults = ModelValidator.Validate(sut);

            Assert.False(validationResults.Any());

            sut.AdditionalNotes = testData;

            validationResults = ModelValidator.Validate(sut);
            Assert.False(validationResults.Any());
        }
        [InlineData(1_001)] // To large
        public void BuyPracticeModel_WhenMinOperatoryCountIsInvalid_AddsErrorToValidationResults(int?testValue)
        {
            var sut = CreateRandomBuyPracticeModel();
            var validationResults = ModelValidator.Validate(sut);

            Assert.False(validationResults.Any());

            sut.MinOperatoryCount = testValue;

            validationResults = ModelValidator.Validate(sut);
            Assert.True(validationResults.Count == 1);
        }
        public void BuyPracticeModel_WhenMaxPurchaseAmountIsNull_AddsErrorToValidationResults()
        {
            var sut = CreateRandomBuyPracticeModel();
            var validationResults = ModelValidator.Validate(sut);

            Assert.False(validationResults.Any());

            sut.MaxPurchaseAmount = null;

            validationResults = ModelValidator.Validate(sut);
            Assert.True(validationResults.Count == 1);
        }
        [InlineData("(234) 567-8901")]    // (###) ###-#### format
        public void BuyPracticeModel_WhenPhoneNumberIsValid_DoesNotAddErrorToValidationResults(string phone)
        {
            var sut = CreateRandomBuyPracticeModel();
            var validationResults = ModelValidator.Validate(sut);

            Assert.False(validationResults.Any());

            sut.ContactPhoneNumber = phone;

            validationResults = ModelValidator.Validate(sut);
            Assert.False(validationResults.Any());
        }
        public void BuyPracticeModel_WhenIsDoctorWillingToStayOnAfterTransitionIsNull_AddsErrorToValidationResults()
        {
            var sut = CreateRandomBuyPracticeModel();
            var validationResults = ModelValidator.Validate(sut);

            Assert.False(validationResults.Any());

            sut.IsDoctorWillingToStayOnAfterTransition = null;

            validationResults = ModelValidator.Validate(sut);
            Assert.True(validationResults.Count == 1);
        }
Exemplo n.º 9
0
        public static void CreateModel_WhenPracticeLocationIsInvalid_AddsErrorToValidationResults(string testData)
        {
            var sut = CreateRandomCreateModel();
            var validationResults = ModelValidator.Validate(sut);

            Assert.False(validationResults.Any());

            sut.PracticeLocation = testData;

            validationResults = ModelValidator.Validate(sut);
            Assert.True(validationResults.Count == 1);
        }
Exemplo n.º 10
0
        public static void CreateModel_WhenLinkedInAccountIsNotValidUrl_AddsErorrToValidationResults(string linkedInUrl)
        {
            var sut = CreateRandomCreateModel();
            var validationResults = ModelValidator.Validate(sut);

            Assert.False(validationResults.Any());

            sut.LinkedInAccount = linkedInUrl;

            validationResults = ModelValidator.Validate(sut);
            Assert.True(validationResults.Count == 1);
        }
Exemplo n.º 11
0
        public void CreateModel_WhenDoctorSpecialtyIsInvalid_DoesNotAddErrorToValidationResults(string testData)
        {
            var sut = CreateRandomCreateModel();
            var validationResults = ModelValidator.Validate(sut);

            Assert.False(validationResults.Any());

            sut.Specialty = testData;

            validationResults = ModelValidator.Validate(sut);
            Assert.False(validationResults.Any());
        }
        [InlineData("A@b@[email protected]")] //only one @ is allowed
        public void BuyPracticeModel_WhenContactEmailIsInvalid_AddsErrorToValidationResults(string email)
        {
            var sut = CreateRandomBuyPracticeModel();
            var validationResults = ModelValidator.Validate(sut);

            Assert.False(validationResults.Any());

            sut.ContactEmail = email;

            validationResults = ModelValidator.Validate(sut);
            Assert.True(validationResults.Count == 1);
        }
Exemplo n.º 13
0
        public void ValidateDemoPatient()
        {
            var s = this.GetType().Assembly.GetManifestResourceStream("Hl7.Fhir.Test.patient-example.xml");

            var patient = FhirParser.ParseResource(XmlReader.Create(s));

            ICollection <ValidationResult> dummy = new List <ValidationResult>();

            ModelValidator.Validate(patient);

            Assert.IsTrue(ModelValidator.TryValidate(patient, dummy));
        }
Exemplo n.º 14
0
        [InlineData("*****@*****.**")]    //more than 10 characters for domain
        public void CreateModel_WhenContactEmailIsValid_DoesNotAddErrorToValidationResults(string email)
        {
            var sut = CreateRandomCreateModel();
            var validationResults = ModelValidator.Validate(sut);

            Assert.False(validationResults.Any());

            sut.ContactEmail = email;

            validationResults = ModelValidator.Validate(sut);
            Assert.False(validationResults.Any());
        }
Exemplo n.º 15
0
 public void ValidateTest_Positive_EmptyObject()
 {
     try
     {
         var modelState = ModelValidator.Validate(new object());
         Assert.IsTrue(modelState.IsValid);
     }
     catch (Exception)
     {
         Assert.Fail();
     }
 }
Exemplo n.º 16
0
        public void TimeEntryModel_Invalid_Hours(int hours)
        {
            // Arrange
            var model = new TimeEntryModel();

            model.Hours = hours;
            // Act
            var results = ModelValidator.Validate(model);

            // Assert
            results.Count(o => o.ErrorMessage == Resources.Error_Index_Hours_RangeError).Should().Be(1, "because hours field in the model is invalid");
        }
Exemplo n.º 17
0
        public void TitleTooShort()
        {
            var trash = new Trash
            {
                Title   = "Tit",
                AddTime = DateTime.Now,
                Content = "content",
            };
            var result = ModelValidator.Validate(trash);

            Assert.AreEqual(1, result.Count);
        }
Exemplo n.º 18
0
        public void CreateModel_WhenJobRequirementsIsInvalid_AddsErrorToValidationResults(string testData)
        {
            var sut = CreateRandomCreateModel();
            var validationResults = ModelValidator.Validate(sut);

            Assert.False(validationResults.Any());

            sut.JobRequirements = testData;

            validationResults = ModelValidator.Validate(sut);
            Assert.True(validationResults.Count == 1);
        }
Exemplo n.º 19
0
        public void Should_Work_Faster_After_FirstValidation()
        {
            // Arrange
            var model = new ValidationTestModel();

            // Act
            var duration1 = GetActionDuration(() => ModelValidator.Validate(model));
            var duration2 = GetActionDuration(() => ModelValidator.Validate(model));

            // Assert
            Assert.True(duration1 > duration2);
        }
Exemplo n.º 20
0
        public virtual async Task <bool> Add(string attachmentPath, string args)
        {
            ModelValidator validator = new ModelValidator();

            if (validator.Validate(this))
            {
                using (var client = new HttpClient())
                {
                    var serializedProduct = JsonConvert.SerializeObject(this, new JsonSerializerSettings {
                        DateFormatString = "yyyy-MM-ddTHH:mm:ss.fff"
                    });
                    string url = Secrets.ApiAddress + $"Create{typeof(T).Name}?token=" + Secrets.TenantToken + $"&{typeof(T).Name}Json={serializedProduct}" + "&UserId=" + RuntimeSettings.UserId;
                    MultipartFormDataContent content = new MultipartFormDataContent();
                    //var body = new StringContent(serializedProduct, Encoding.UTF8, "application/json");

                    try
                    {
                        using (var fileStream = System.IO.File.OpenRead(attachmentPath))
                        {
                            var           fileInfo = new FileInfo(attachmentPath);
                            StreamContent fcontent = new StreamContent(fileStream);
                            fcontent.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
                            fcontent.Headers.Add("Content-Disposition", "form-data; name=\"file\"; filename=\"" + fileInfo.Name + "\"");
                            content.Add(fcontent, "file", fileInfo.Name);
                            var result = await client.PostAsync(new Uri(url), content);

                            if (result.IsSuccessStatusCode)
                            {
                                var rString = await result.Content.ReadAsStringAsync();

                                AddedItem = rString;
                                return(true);
                            }
                            else
                            {
                                MessageBox.Show("Serwer zwrócił błąd przy próbie utworzenia rekordu. Wiadomość: " + result.ReasonPhrase, "Nieudane żądanie", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return(false);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show($"Błąd. Stack trace={ex.ToString()}", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 21
0
        public void IsValid_ValidNif_True(string validNif)
        {
            var model = new NifModelDummy
            {
                MyProperty1 = validNif,
                MyProperty2 = validNif
            };

            var(isValid, validationResults) = ModelValidator.Validate(model);

            Assert.True(isValid);
            Assert.Empty(validationResults);
        }
        public void IsValid_NotEmpty_True(int[] items)
        {
            var model = new NotEmptyCollectionModelDummy
            {
                MyProperty1 = items,
                MyProperty2 = items
            };

            var(isValid, validationResults) = ModelValidator.Validate(model);

            Assert.True(isValid);
            Assert.Empty(validationResults);
        }
Exemplo n.º 23
0
        public void ContainsKeyTest()
        {
            var model = new CollectionMinLengthFakeModel
            {
                Collection = new List <int> {
                    1, 2
                }                                 //should use three or more elements
            };

            var modelState = ModelValidator.Validate(model);

            Assert.IsTrue(modelState.ContainsKey("Collection"));
        }
        public void IsValid_ValidEmail_True()
        {
            var model = new EmailModelDummy
            {
                MyProperty1 = "*****@*****.**",
                MyProperty2 = "*****@*****.**"
            };

            var(isValid, validationResults) = ModelValidator.Validate(model);

            Assert.True(isValid);
            Assert.Empty(validationResults);
        }
        public void IsValid_InvalidEmail_False(string invalidEmail)
        {
            var model = new EmailModelDummy
            {
                MyProperty1 = invalidEmail,
                MyProperty2 = invalidEmail
            };

            var(isValid, validationResults) = ModelValidator.Validate(model);

            Assert.False(isValid);
            Assert.Equal("Invalid e-mail address: MyProperty1.", validationResults[0].ErrorMessage);
            Assert.Equal("The e-mail should be valid.", validationResults[1].ErrorMessage);
        }
Exemplo n.º 26
0
 public void ValidateTest_Negative_Null()
 {
     try
     {
         var modelState = ModelValidator.Validate(null);
     }
     catch (ArgumentNullException)
     {
     }
     catch (Exception)
     {
         Assert.Fail();
     }
 }
Exemplo n.º 27
0
        public void NameFirstLetterNotUpper()
        {
            var bin = new Bin
            {
                Trash             = new List <Trash>(),
                Id                = 1,
                Description       = "Description",
                Name              = "bin",
                ApplicationUserId = "1",
            };
            var result = ModelValidator.Validate(bin);

            Assert.AreEqual(1, result.Count);
        }
Exemplo n.º 28
0
        public void DescriptionTooShort()
        {
            var bin = new Bin
            {
                Trash             = new List <Trash>(),
                Id                = 1,
                Description       = "Den",
                Name              = "Bin",
                ApplicationUserId = "1",
            };
            var result = ModelValidator.Validate(bin);

            Assert.AreEqual(1, result.Count);
        }
Exemplo n.º 29
0
        public void EmailValidationShouldFailWithErrorCode()
        {
            var target = new ModelValidator(_reflectionService);

            var complexModel = new ComplexModel("notavalidmail", "bbbbbbbbbbb");

            var validationResult = target.Validate(complexModel);

            var errorCode = validationResult[0]
                            .ErrorCodes[0];

            Assert.AreEqual(FieldValidationErrorCode.EmailAddress, errorCode);
            Assert.IsFalse(validationResult[0].IsValid);
        }
Exemplo n.º 30
0
        public void IsValid_InvalidNif_False(string invalidNif)
        {
            var model = new NifModelDummy
            {
                MyProperty1 = invalidNif,
                MyProperty2 = invalidNif
            };

            var(isValid, validationResults) = ModelValidator.Validate(model);

            Assert.False(isValid);
            Assert.Equal("Invalid NIF: MyProperty1.", validationResults[0].ErrorMessage);
            Assert.Equal("The nif should be valid.", validationResults[1].ErrorMessage);
        }
Exemplo n.º 31
0
        public void Validate_WithNoValidators_ShouldBeTrue()
        {
            var factory = new Mock<IValidatorFactory>();

            factory.Setup(x => x.Create(It.IsAny<Customer>(), It.IsAny<string>())).Throws<Exception>();

            var sut = new ModelValidator(factory.Object);

            Should.Throw<Exception>(() => { var result = sut.Validate(new Customer()); });

        }
Exemplo n.º 32
0
        public void Validate_With_ShouldBeFalse()
        {
            var validator = new Mock<IValidator<Customer>>();

            validator.Setup(x => x.Validate(It.IsAny<Customer>())).Returns(new ValidationResult(new [] {new ValidationFailure(""), }));

            var factory = new Mock<IValidatorFactory>();

            factory.Setup(x => x.Create(It.IsAny<Customer>(), It.IsAny<string>())).Returns(new IValidator<Customer>[] { validator.Object });

            var sut = new ModelValidator(factory.Object);

            var result = sut.Validate(new Customer());

            result.IsValid.ShouldBeFalse();

            result.Errors.Count.ShouldBe(1);
        }
Exemplo n.º 33
0
        public void Validate_WithNullValidators_ShouldBeTrue()
        {
            var factory = new Mock<IValidatorFactory>();

            factory.Setup(x => x.Create(It.IsAny<Customer>(), It.IsAny<string>())).Returns((IValidator<Customer>[])null);

            var sut = new ModelValidator(factory.Object);

            var result = sut.Validate(new Customer());

            result.ShouldNotBeNull();

            result.IsValid.ShouldBeTrue();
        }
Exemplo n.º 34
0
        public void Validate_WithRuleNameAndContext_ShouldBeValid()
        {
            var validator = new Mock<IValidator<Customer>>();

            validator.Setup(x => x.Validate(It.IsAny<Customer>(), It.Is<object>(o => true))).Returns(new ValidationResult());

            var factory = new Mock<IValidatorFactory>();

            factory.Setup(x => x.Create(It.IsAny<Customer>(), It.IsAny<string>())).Returns(new IValidator<Customer>[] { validator.Object });

            var sut = new ModelValidator(factory.Object);

            var result = sut.Validate(new Customer(), "rulename", new { });

            result.IsValid.ShouldBe(true);
        }