Пример #1
0
        void TestMethodAPIs()
        {
            Log("");
            Log("Testing methods...");

            currentTest = "TestMethods.StaticLog(\"test\", fail: false)";
            Expect(() => TestMethods.StaticLog("test", fail: false));

            currentTest = "TestMethods.StaticEcho(\"test\", fail: false)";
            ExpectResult("test", () => TestMethods.StaticEcho("test", fail: false));

            currentTest = "TestMethods.StaticLog(\"test\", fail: true)";
            ExpectException(() => TestMethods.StaticLog("test", fail: true));

            currentTest = "TestMethods.StaticEcho(\"test\", fail: true)";
            ExpectException(() => TestMethods.StaticEcho("test", fail: true));

            var testMethodsInstance = new TestMethods();

            currentTest = "testMethodsInstance.Log(\"test\", fail: false)";
            Expect(() => testMethodsInstance.Log("test", fail: false));

            currentTest = "testMethodsInstance.Echo(\"test\", fail: false)";
            ExpectResult("test", () => testMethodsInstance.Echo("test", fail: false));

            currentTest = "testMethodsInstance.Log(\"test\", fail: true)";
            ExpectException(() => testMethodsInstance.Log("test", fail: true));

            currentTest = "testMethodsInstance.Echo(\"test\", fail: true)";
            ExpectException(() => testMethodsInstance.Echo("test", fail: true));

            var testData = new TestStruct();

            testData.Value = new DateTimeOffset(new DateTime(2016, 6, 6));

            currentTest = "testMethodsInstance.EchoData({}, fail: false)";
            ExpectResult(() => testMethodsInstance.EchoData(testData, false),
                         result => testData.Value == result?.Value);

            TestStruct[] testDataArray = new[] { new TestStruct(), new TestStruct() };
            testDataArray[0].Value = new DateTimeOffset(new DateTime(2016, 6, 7));
            testDataArray[1].Value = new DateTimeOffset(new DateTime(2016, 6, 8));

            currentTest = "testMethodsInstance.EchoDataList([{},{}], fail: false)";
            ExpectResult(() => testMethodsInstance.EchoDataList(testDataArray, false),
                         result => 2 == result?.Count &&
                         testDataArray[0].Value == result[0].Value &&
                         testDataArray[1].Value == result[1].Value);
        }
Пример #2
0
        void TestDispose()
        {
            Log("");
            Log("Testing dispose...");

            currentTest = "(proxy-by-value type)";
            TestStruct testStruct = new TestStruct();

            Assert(!(testStruct is IDisposable), "should not be disposable");

            currentTest = "dispose()";
            TestMethods testMethods        = new TestMethods();
            IDisposable disposableInstance = testMethods;

            Expect(() => testMethods.Dispose());

            currentTest = "(calling method on disposed instance)";
            ExpectException(() => testMethods.EchoNullableInt(1));
        }