/// <summary>
 /// Instantiate using the <see cref="DefaultIndention"/> and the <see cref="CurlyBraceStyle"/>
 /// </summary>
 public Configuration(
     string indentIncrement = DefaultIndention,
     TestFrameworkAreEqualsMethod areEqualsMethod = null)
 {
     IndentIncrement   = indentIncrement;
     OutputFormatter   = new CurlyBraceStyle(this);
     AreEqualsMethod   = areEqualsMethod;
     NewLineDefinition = Environment.NewLine;
 }
        /// <summary>
        /// Configure how to call AreEquals in the unit testing framework of your choice.
        /// Only set this field if you are using the <see cref="Stateprinter.Assert"/> functionality.
        /// </summary>
        public Configuration SetAreEqualsMethod(TestFrameworkAreEqualsMethod areEqualsMethod)
        {
            if (areEqualsMethod == null)
            {
                throw new ArgumentNullException("areEqualsMethod");
            }
            AreEqualsMethod = areEqualsMethod;

            return(configuration);
        }
        public Configuration SetAreEqualsMethod(Action <string, string, string, object[]> nunitAreEqualsMethod)
        {
            if (nunitAreEqualsMethod == null)
            {
                throw new ArgumentNullException("nunitAreEqualsMethod");
            }
            AreEqualsMethod = new TestFrameworkAreEqualsMethod((actual, expected, message) => nunitAreEqualsMethod(actual, expected, message, NoArg));

            return(configuration);
        }
 /// <summary>
 /// Instantiate using the <see cref="DefaultIndention"/> and the <see cref="CurlyBraceStyle"/>
 /// </summary>
 public Configuration(
     string indentIncrement = DefaultIndention,
     TestFrameworkAreEqualsMethod areEqualsMethod = null)
 {
     IndentIncrement      = indentIncrement;
     OutputFormatter      = new CurlyBraceStyle(this);
     AreEqualsMethod      = areEqualsMethod;
     NewLineDefinition    = Environment.NewLine;
     LegacyBehaviour      = new LegacyBehaviour();
     AutomaticTestRewrite = (x) => false;
 }
        /// <summary>
        /// Return a configuration which covers most usages.
        /// The configuration returned can be further remolded by adding additional handlers.
        ///
        /// Eg. add a <see cref="PublicFieldsHarvester"/> to restrict the printed state to only public fields.
        /// </summary>
        public static Configuration GetStandardConfiguration(TestFrameworkAreEqualsMethod areEqualsMethod)
        {
            if (areEqualsMethod == null)
            {
                throw new ArgumentNullException("areEqualsMethod");
            }

            return(GetStandardConfiguration(
                       Configuration.DefaultIndention,
                       areEqualsMethod: areEqualsMethod));
        }
Beispiel #6
0
        /// <summary>
        /// Instantiate using the <see cref="DefaultIndention"/> and the <see cref="CurlyBraceStyle"/>
        /// </summary>
        public Configuration(
            string indentIncrement = DefaultIndention,
            TestFrameworkAreEqualsMethod areEqualsMethod = null)
        {
            IndentIncrement = indentIncrement;
            OutputFormatter = new CurlyBraceStyle(this);
            NewLineDefinition = Environment.NewLine;
            LegacyBehaviour = new LegacyBehaviour();

            Test = new TestingBehaviour(this);
            Test.SetAutomaticTestRewrite(x => false);
            Test.SetAssertMessageCreator(new DefaultAssertMessage().Create);

            if(areEqualsMethod != null)
                Test.SetAreEqualsMethod(areEqualsMethod);
        }
        /// <summary>
        /// Instantiate using the <see cref="DefaultIndention"/> and the <see cref="CurlyBraceStyle"/>
        /// </summary>
        public Configuration(
            string indentIncrement = DefaultIndention,
            TestFrameworkAreEqualsMethod areEqualsMethod = null)
        {
            IndentIncrement   = indentIncrement;
            OutputFormatter   = new CurlyBraceStyle(this);
            NewLineDefinition = Environment.NewLine;
            LegacyBehaviour   = new LegacyBehaviour();

            Test = new TestingBehaviour(this);
            Test.SetAutomaticTestRewrite(x => false);
            Test.SetAssertMessageCreator(new DefaultAssertMessage().Create);

            if (areEqualsMethod != null)
            {
                Test.SetAreEqualsMethod(areEqualsMethod);
            }
        }
        /// <summary>
        /// Return a configuration which covers most usages.
        /// The configuration returned can be further remolded by adding additional handlers.
        ///
        /// Eg. add a <see cref="PublicFieldsHarvester"/> to restrict the printed state to only public fields.
        /// </summary>
        public static Configuration GetStandardConfiguration(
            string indentIncrement = Configuration.DefaultIndention,
            TestFrameworkAreEqualsMethod areEqualsMethod = null)
        {
            var cfg = new Configuration(indentIncrement, areEqualsMethod);

            // valueconverters
            cfg.Add(new StandardTypesConverter(cfg));
            cfg.Add(new StringConverter());
            cfg.Add(new DateTimeConverter(cfg));
            cfg.Add(new EnumConverter());

            // harvesters
            cfg.Add(new AllFieldsHarvester());

            // outputformatters
            cfg.OutputFormatter = new CurlyBraceStyle(cfg);

            return(cfg);
        }
Beispiel #9
0
        public void AreEquals_WhenConfigured()
        {
            string called_expected = null, called_actual = null, called_msg = null;
            TestFrameworkAreEqualsMethod assertMth = (exp, act, msg) =>
            {
                called_expected = exp;
                called_actual   = act;
                called_msg      = msg;
            };

            var cfg = ConfigurationHelper.GetStandardConfiguration(assertMth);
            var printer = new Stateprinter(cfg);

            // without "
            printer.Assert.AreEqual("a", "b");
            Assert.AreEqual("a", called_expected);
            Assert.AreEqual("b", called_actual);
            Assert.AreEqual("\r\n\r\nProposed output for unit test:\r\nvar expected = \"b\";\r\n", called_msg);

            // with  "
            printer.Assert.AreEqual("c", "\"e\"");
            Assert.AreEqual("c", called_expected);
            Assert.AreEqual("\"e\"", called_actual);
            Assert.AreEqual("\r\n\r\nProposed output for unit test:\r\nvar expected = @\"\"\"e\"\"\";\r\n", called_msg);


            // without "
            printer.Assert.That("aa", Is.EqualTo("bb"));
            Assert.AreEqual("bb", called_expected);
            Assert.AreEqual("aa", called_actual);
            Assert.AreEqual("\r\n\r\nProposed output for unit test:\r\nvar expected = \"aa\";\r\n", called_msg);

            // with  "
            printer.Assert.That("\"cc\"", Is.EqualTo("ee"));
            Assert.AreEqual("ee", called_expected);
            Assert.AreEqual("\"cc\"", called_actual);
            Assert.AreEqual("\r\n\r\nProposed output for unit test:\r\nvar expected = @\"\"\"cc\"\"\";\r\n", called_msg);
        }
 public Configuration SetAreEqualsMethod(TestFrameworkAreEqualsMethod areEqualsMethod)
 {
     return(Test.SetAreEqualsMethod(areEqualsMethod));
 }
Beispiel #11
0
 internal Asserter(Stateprinter printer)
 {
     this.assert  = printer.Configuration.AreEqualsMethod;
     this.printer = printer;
 }
Beispiel #12
0
 public Configuration SetAreEqualsMethod(TestFrameworkAreEqualsMethod areEqualsMethod)
 {
     return Test.SetAreEqualsMethod(areEqualsMethod);
 }
        /// <summary>
        /// Configure how to call AreEquals in the unit testing framework of your choice. 
        /// Only set this field if you are using the <see cref="Stateprinter.Assert"/> functionality.
        /// </summary>
        public Configuration SetAreEqualsMethod(TestFrameworkAreEqualsMethod areEqualsMethod)
        {
            if (areEqualsMethod == null)
                throw new ArgumentNullException("areEqualsMethod");
            AreEqualsMethod = areEqualsMethod;

            return configuration;
        }