Beispiel #1
0
 protected override void EstablishContext()
 {
     _expectedMappedObject = new TestTargetClass();
     _source = new object();
     Dependency <IDoMapper>().Stub(mapper => mapper.DoMap <object, TestTargetClass>(Arg.Is(_source)))
     .Return(_expectedMappedObject);
 }
Beispiel #2
0
        public static void TestThree()
        {
            MethodInfo target       = typeof(TestTargetClass).GetMethod("target");
            MethodInfo replacement  = typeof(UnitTests).GetMethod("targetHook");
            MethodInfo target2      = typeof(UnitTests).GetMethod("staticTest");
            MethodInfo replacement2 = typeof(UnitTests).GetMethod("staticTestHook");

            HookManager     hook    = new HookManager();
            TestTargetClass persist = new TestTargetClass();

            //test control
            Assert.Equals(persist.target(false), "TestTargetClass");
            Assert.Equals(staticTest(), 4950);

            //test
            Assert.ExceptionSafe(() => hook.Hook(target, replacement), "hook1 threw exception");
            Assert.ExceptionSafe(() => hook.Hook(target2, replacement2), "hook2 threw exception");
            Assert.Equals(persist.target(true), "TESTTARGETCLASSHOOKED");
            Assert.Equals(staticTest(), 4951);

            //unhook test
            Assert.ExceptionSafe(() => hook.Unhook(target), "unhook threw exception");

            //test control
            Assert.Equals(persist.target(true), "TESTTARGETCLASS");
            Assert.Equals(staticTest(), 4951);

            //cleanup
            Assert.ExceptionSafe(() => hook.Unhook(target2), "unhook threw exception");
            Assert.Equals(staticTest(), 4950);
        }
 protected override void EstablishContext()
 {
     _expectedMappedObject = new TestTargetClass();
     _source = new object();
     Dependency<IDoMapper>().Stub(mapper => mapper.DoMap<object,TestTargetClass>(Arg.Is(_source)))
         .Return(_expectedMappedObject);
 }
Beispiel #4
0
        public void GetOutTaxAmountTest2()
        {
            var context = getTestData();

            try
            {
                // メソッドの実行結果を取得する
                var expected = TestTargetClass.GetOutTaxAmount(context.amount, context.taxRate);
                // 実行結果と期待値を比較する
                Assert.AreEqual(expected, context.actualTaxAmount);

                // 結果をDebug出力する
                writeExecLog(context.no, "TaxAmount", context.actualTaxAmount, expected, true);
            }
            catch (Exception ex)
            {
                // 例外が発生した場合
                // Exceptionの型が想定通りか
                Assert.IsTrue(ex.GetType().Name == context.actualException);
                // Exceptionのメッセージ内容が想定通りか(改行を除去して比較)
                Assert.AreEqual(ex.Message.Replace("\r\n", ""), context.actualMessage);

                // 結果をDebug出力する
                writeExecLog(context.no, "Exception", context.actualException, ex.GetType().Name, true);
                writeExecLog(context.no, "Message", context.actualMessage, ex.Message.Replace("\r\n", ""), false);
            }
        }
Beispiel #5
0
        public void GetOutTaxAmount_ExceptionTest2()
        {
            decimal amount  = 1000;
            decimal taxRate = 10;    // 現在の消費税率10%だから10って渡す人がいるんだよね

            // メソッドの実行結果を取得する
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => TestTargetClass.GetOutTaxAmount(amount, taxRate));
        }
Beispiel #6
0
        //Test hook
        public static string targetHook(TestTargetClass t, bool isUpperCase)
        {
            string s = t.GetType().Name + "HOOKED";

            if (isUpperCase)
            {
                s = s.ToUpper();
            }
            return(s);
        }
Beispiel #7
0
        public void GetOutTaxAmount_ExceptionTest1()
        {
            decimal amount  = -1000;   // 人にお金を渡して税金分返ってくるなんて事はないよ?
            decimal taxRate = 0.10m;
            decimal actual  = 1000 * 0.1m;

            // メソッドの実行結果を取得する
            var expected = TestTargetClass.GetOutTaxAmount(amount, taxRate);

            Assert.AreEqual(expected, actual);
        }
Beispiel #8
0
        public void GetOutTaxAmountTest()
        {
            decimal amount  = 1000;
            decimal taxRate = 0.10m;    // 現在の消費税率10%
            decimal actual  = 1000 * 0.1m;

            // 最大値とか最小値とか境界値のテストをしたいから
            // ここでamountの値とか変えて何度も実行したらいいか!
            // ってやっちゃダメです。

            // メソッドの実行結果を取得する
            var expected = TestTargetClass.GetOutTaxAmount(amount, taxRate);

            Assert.AreEqual(expected, actual);
        }
Beispiel #9
0
        public void GetOutTaxAmount_ExceptionTest3()
        {
            decimal amount        = 1000;
            decimal taxRate       = 10; // 現在の消費税率10%だから10って渡す人がいるんだよね
            string  actualMessage = "税率は0.01~0.99の間で指定してください\r\nパラメーター名:taxRate";

            try
            {
                // メソッドの実行結果を取得する
                var expected = TestTargetClass.GetOutTaxAmount(amount, taxRate);
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.GetType() == typeof(ArgumentOutOfRangeException));
                Assert.AreEqual(ex.Message, actualMessage);
            }
        }
Beispiel #10
0
 protected override void Because()
 {
     _mapped = _source.MapFromTo <object, TestTargetClass>();
 }
Beispiel #11
0
        public void GetOutTaxAmountTest()
        {
            #region テストデータ取得
            string  no = TestContext.DataRow["No"].ToString();
            decimal amount;
            decimal taxRate;
            decimal actualTaxAmount;
            string  actualException = TestContext.DataRow["Exception"].ToString();
            string  actualMessage   = TestContext.DataRow["ExceptionMessage"].ToString();
            // テストデータの型が正しくない場合はテスト失敗
            if (!decimal.TryParse(TestContext.DataRow["Amount"].ToString(), out amount))
            {
                Assert.Fail("amountが数値ではありません");
            }
            if (!decimal.TryParse(TestContext.DataRow["TaxRate"].ToString(), out taxRate))
            {
                Assert.Fail("taxRateが数値ではありません");
            }
            if (!decimal.TryParse(TestContext.DataRow["TaxAmount"].ToString(), out actualTaxAmount))
            {
                Assert.Fail("actualTaxAmountが数値ではありません");
            }
            #endregion
            try
            {
                // メソッドの実行結果を取得する
                var expected = TestTargetClass.GetOutTaxAmount(amount, taxRate);
                // 実行結果と期待値を比較する
                Assert.AreEqual(expected, actualTaxAmount);

                // 結果をDebug出力する
                var msg = string.Format("{0},{1},{2},{3},{4}"
                                        , no
                                        , "TaxAmount"
                                        , actualTaxAmount
                                        , expected
                                        , actualTaxAmount == expected
                                        );
                Debug.WriteLine("No,項目名,期待値,実行結果,期待値と実行結果の比較");
                Debug.WriteLine(msg);
            }
            catch (Exception ex)
            {
                // 例外が発生した場合
                // Exceptionの型が想定通りか
                Assert.IsTrue(ex.GetType().Name == actualException);
                // Exceptionのメッセージ内容が想定通りか(改行を除去して比較)
                Assert.AreEqual(ex.Message.Replace("\r\n", ""), actualMessage);

                // 結果をDebug出力する
                Debug.WriteLine("No,項目名,期待値,実行結果,期待値と実行結果の比較");
                var msg = string.Format("{0},{1},{2},{3},{4}"
                                        , no
                                        , "Exception"
                                        , actualException
                                        , ex.GetType().Name
                                        , actualException == ex.GetType().Name
                                        );
                Debug.WriteLine(msg);
                msg = string.Format("{0},{1},{2},{3},{4}"
                                    , no
                                    , "Message"
                                    , actualMessage
                                    , ex.Message.Replace("\r\n", "")
                                    , actualMessage == ex.Message.Replace("\r\n", "")
                                    );
                Debug.WriteLine(msg);
            }
        }
 protected override void Because()
 {
     _mapped = _source.MapFromTo<object,TestTargetClass>();
 }