Contains() static public méthode

Asserts that a string is found within another string.
static public Contains ( string expected, string actual ) : void
expected string The expected string
actual string The string to be examined
Résultat void
        public virtual void Formatter_iterates_IEnumerable_property_when_its_actual_type_is_an_array_of_objects()
        {
            Formatter <Node> .RegisterForMembers();

            var node = new Node
            {
                Id    = "1",
                Nodes =
                    new[]
                {
                    new Node {
                        Id = "1.1"
                    },
                    new Node {
                        Id = "1.2"
                    },
                    new Node {
                        Id = "1.3"
                    },
                }
            };

            var output = node.ToLogString();

            StringAssert.Contains("1.1", output);
            StringAssert.Contains("1.2", output);
            StringAssert.Contains("1.3", output);
        }
        public void Formatter_iterates_IEnumerable_property_when_its_reflected_type_is_array()
        {
            Log.Formatters.RegisterPropertiesFormatter <Node>();

            var node = new Node
            {
                Id         = "1",
                NodesArray =
                    new[]
                {
                    new Node {
                        Id = "1.1"
                    },
                    new Node {
                        Id = "1.2"
                    },
                    new Node {
                        Id = "1.3"
                    },
                }
            };

            var output = node.ToLogString();

            StringAssert.Contains("1.1", output);
            StringAssert.Contains("1.2", output);
            StringAssert.Contains("1.3", output);
        }
        private static void AssertStringContains(AssertionException result, string expectedMessage, string lambdaDescription)
        {
            StringAssertEx.Contains(lambdaDescription, result.Message);
            var replace = result.Message.Replace(lambdaDescription, "");

            StringAssertEx.Contains(expectedMessage, replace);
        }
        public void AddTeacher_WhenTeacherIsNull_ShouldThrowArgumentNullException()
        {
            var      id          = 100;
            ITeacher nullTeacher = null;

            var ex = Assert.Throws <ArgumentNullException>(() => SchoolSystemEngine.AddTeacher(id, nullTeacher));

            StringAssert.Contains("cannot be null or empty", ex.Message);
        }
        public void AddTeacher_WhenIdIsInvalid_ShouldThrowArgumentOutOfRangeException()
        {
            var invalidID     = -1;
            var mockedTeacher = new Mock <ITeacher>();

            var ex = Assert.Throws <ArgumentOutOfRangeException>(() => SchoolSystemEngine.AddTeacher(invalidID, mockedTeacher.Object));

            StringAssert.Contains("cannot be less than 0!", ex.Message);
        }
        public void AddStudent_WhenStudentIsNull_ShouldThrowArgumentNullException()
        {
            var      id          = 100;
            IStudent nullStudent = null;

            var ex = Assert.Throws <ArgumentNullException>(() => SchoolSystemEngine.AddStudent(id, nullStudent));

            StringAssert.Contains("cannot be null or empty", ex.Message);
        }
Exemple #7
0
        public virtual void Log_WithParams_comment_appears_in_output()
        {
            var writer   = new StringWriter();
            var fortyone = 41;

            using (Log.Events().Subscribe(e => writer.Write(e.ToLogString())))
            {
                Log.WithParams(() => new { fortyone }).Write("a message");
            }

            StringAssert.Contains("a message", writer.ToString());
        }
        public void Success_and_failure_messages_can_be_configured_separately()
        {
            var plan = new ValidationPlan <string>
            {
                Validate.That <string>(s => s.As("value").Length.As("length") > 3.As("min"))
                .WithErrorMessage("Fail! Your string {value} is only {length} characters.")
                .WithSuccessMessage("Win! '{value}' is more than {min} characters.")
            };

            var failure = plan.Execute("hi").Evaluations.Single();
            var success = plan.Execute("hello").Evaluations.Single();

            StringAssert.Contains("Fail!", failure.Message);
            StringAssert.Contains("Win!", success.Message);
        }
Exemple #9
0
        public virtual void Log_WithParams_automatically_generates_custom_formatter_for_reference_type()
        {
            var writer = new StringWriter();

            Log.Formatters.RegisterPropertiesFormatter <FileInfo>();
            const int anInt    = 23;
            var       fileInfo = new FileInfo(@"c:\temp\testfile.txt");

            using (Log.Events().Subscribe(e => writer.Write(e.ToLogString())))
                using (TestHelper.LogToConsole())
                {
                    Log.WithParams(() => new { anInt, fileInfo }).Write("a message");
                }

            StringAssert.Contains(@"Directory = c:\temp", writer.ToString());
        }
Exemple #10
0
        public virtual void Log_WithParams_automatically_generates_custom_formatter_for_array()
        {
            var writer = new StringWriter();
            var myInts = new[] { 2222, 3333, 4444 };

            using (Log.Events().Subscribe(e => writer.Write(e.ToLogString())))
            {
                Log.WithParams(() => new { myInts }).Write("a message");
            }

            var output = writer.ToString();

            StringAssert.Contains("2222", output);
            StringAssert.Contains("3333", output);
            StringAssert.Contains("4444", output);
            StringAssert.DoesNotContain(myInts.ToString(), output);
        }
Exemple #11
0
        public void Parameter_logging_can_be_disabled_per_class()
        {
            var log = new StringWriter();

            Extension <Boundaries> .DisableFor <InheritedWidget>();

            using (Log.Events().Subscribe(e => log.Write(e.ToLogString())))
            {
                var w  = new Widget();
                var iw = new InheritedWidget();
                w.DoStuff("should be in log");
                iw.DoStuff("should not be in log");
            }

            StringAssert.Contains("should be in log", log.ToString());
            StringAssert.DoesNotContain("should not be in log", log.ToString());
        }
Exemple #12
0
        public void Exception_WithData_two_anonymous_type_objects_are_added_with_two_keys()
        {
            int fortyone = 41;
            var string42 = "42";

            var exception = new Exception();

            exception.WithData(new { fortyone = fortyone }).WithData(new { string42 });

            Assert.That(exception.Data.Count, Is.EqualTo(2));

            var exceptionData = exception.Data["ItsLog_ExceptionData_"].ToString();

            StringAssert.Contains(string.Format("fortyone = {0}", fortyone), exceptionData);

            exceptionData = exception.Data["ItsLog_ExceptionData_2"].ToString();
            StringAssert.Contains(string.Format("string42 = {0}", string42), exceptionData);
        }
Exemple #13
0
        public virtual void Log_WithParams_correctly_outputs_value_types()
        {
            var writer   = new StringWriter();
            var forty    = "40";
            var fortyone = 41;

            using (Log.Events().Subscribe(e => writer.Write(e.ToLogString())))
            {
                Log.WithParams(() => new { forty, fortyone }).Write("a message");
            }

            var output = writer.ToString();

            StringAssert.Contains("forty", output);
            StringAssert.Contains("40", output);
            StringAssert.Contains("fortyone", output);
            Assert.IsTrue(output.Contains("41"));
        }
        public virtual void LogActivity_trace_outputs_updated_parameter_values()
        {
            var log = "";

            var anInt   = 1;
            var aString = "a";

            using (TestHelper.OnEntryPosted(e => log += e.ToLogString()))
                using (var activity = Log.Enter(() => new { anInt, aString }))
                {
                    StringAssert.Contains("anInt = 1", log);
                    StringAssert.Contains("aString = a", log);

                    anInt   = 2;
                    aString = "b";

                    activity.Trace("here i am");

                    StringAssert.Contains("anInt = 2", log);
                    StringAssert.Contains("aString = b", log);
                }
        }
Exemple #15
0
        public void Exception_WithData_anonymous_type_object_is_added_as_string()
        {
            var writer       = new StringWriter();
            var writerString = "This is writer.ToString()";

            writer.Write(writerString);
            var    string42   = "42";
            int    fortyone   = 41;
            string stringNull = null;

            var exception = new Exception();

            exception.WithData(new { fortyone = fortyone, string42, stringNull, writer.Encoding, writerString = writer.ToString() });

            Assert.That(exception.Data.Count, Is.EqualTo(1));

            var exceptionData = exception.Data["ItsLog_ExceptionData_"].ToString();

            StringAssert.Contains(string.Format("fortyone = {0}", fortyone), exceptionData);
            StringAssert.Contains(string.Format("string42 = {0}", string42), exceptionData);
            StringAssert.Contains("stringNull = [null]", exceptionData);
            StringAssert.Contains(string.Format("writerString = {0}", writerString), exceptionData);
        }