Пример #1
0
        public void given_valid_person_when_trying_to_validate_should_return_true_and_empty_results()
        {
			var results = new List<ValidationResult>();
            var complexPerson = new PersonWithBuiltInValidation{FirstName = "Todd", LastName = "Meinershagen", EmailAddress = "*****@*****.**"};
            complexPerson.TryValidate(results).Should().BeTrue();
			results.Should().BeEmpty();

            var simplePerson = new PersonWithCustomValidation { FirstName = "Todd", LastName = "Meinershagen", EmailAddress = "*****@*****.**" };
            simplePerson.TryValidate(results).Should().BeTrue();
			results.Should().BeEmpty();
        }
Пример #2
0
        public void given_valid_person_when_comparing_difference_in_validation_execution_time_for_a_million_executions_should_be_less_than_1_second()
        {
            var range = Enumerable.Range(1, 1000000).ToList();

            Action testBuiltInMethod = () => 
                range.ForEach(x =>
                {
                    var person = new PersonWithBuiltInValidation
                    {
                        FirstName = "Todd",
                        LastName = "Meinershagen",
                        EmailAddress = "*****@*****.**"
                    };
                    person.Validate();
                });

            var builtInWatch = new Stopwatch();
            builtInWatch.Start();
            testBuiltInMethod();
            builtInWatch.Stop();
            

            Action testCustomMethod = () =>
                range.ForEach(x =>
                {
                    var person = new PersonWithCustomValidation
                    {
                        FirstName = "Todd",
                        LastName = "Meinershagen",
                        EmailAddress = "*****@*****.**"
                    };
                    person.TryValidate();
                });


            var customWatch = new Stopwatch();
            customWatch.Start();
            testCustomMethod();
            customWatch.Stop();

            customWatch.Elapsed.Subtract(builtInWatch.Elapsed).Should().BeLessThan(TimeSpan.FromSeconds(1));
        }