예제 #1
0
 public void TestStaticClasses()
 {
     Assert.That(TestStaticClass.Add(1, 2), Is.EqualTo(3));
     Assert.That(TestStaticClass.OneTwoThree, Is.EqualTo(123));
     Assert.That(TestStaticClassDerived.Foo(), Is.EqualTo(0));
     TestNotStaticClass.StaticFunction();
 }
예제 #2
0
        public void UnloadNotLoadObj()
        {
            onDestroyResult = string.Empty;
            var c   = MakeDriver();
            var obj = new TestStaticClass();

            c.Detach(obj);
            Assert.AreEqual(string.Empty, onDestroyResult);
        }
예제 #3
0
        public void UnloadNotLoadObj()
        {
            onDestroyResult = string.Empty;
            var c   = MakeDriver();
            var d   = c.Make <IMonoDriver>() as CatLib.MonoDriver.MonoDriver;
            var obj = new TestStaticClass();

            d.Detach(obj);
            Assert.AreEqual(string.Empty, onDestroyResult);
        }
예제 #4
0
    public void TestStaticClasses()
    {
        Type staticClassType = typeof(TestStaticClass);

        // Only static class can be both abstract and sealed
        Assert.IsTrue(staticClassType.IsAbstract && staticClassType.IsSealed);
        Assert.That(TestStaticClass.Add(1, 2), Is.EqualTo(3));
        Assert.That(TestStaticClass.OneTwoThree, Is.EqualTo(123));
        Assert.That(TestStaticClassDerived.Foo, Is.EqualTo(0));
        TestNotStaticClass.StaticFunction.GetHashCode();
    }
예제 #5
0
        /// "Smoke" tests for flapigen dotnet backend.
        /// Note, that some function does not return anything. They are called here just to verify, that there are no crashes.
        public void TestAll()
        {
            TestStaticClass.Hello();
            TestStaticClass.PrintNumber(123);
            Assert.Equal(3, TestStaticClass.Add(1, 2));
            Assert.Equal("Concatenated String", TestStaticClass.Concat("Concatenated ", "String"));
            Assert.Equal("Concatenated str", TestStaticClass.Concat("Concatenated ", "str"));

            var obj = new TestClass();

            Assert.Equal(0, obj.Get());
            obj.Increment();
            Assert.Equal(1, obj.Get());
            obj.Add(3);
            obj.Print();
            Assert.Equal(4, obj.Get());

            TestStaticClass.TestObjByValue(obj);

            var vec = new List <int>();

            vec.Add(1);
            vec.Add(2);

            TestStaticClass.PrintVecLen(vec);
            var new_vec = TestStaticClass.GetVec();

            Assert.Equal(3, new_vec.Count);
            Assert.Equal(5, new_vec[0]);
            Assert.Equal(6, new_vec[1]);
            Assert.Equal(7, new_vec[2]);

            Assert.Equal(0, TestStaticClass.MaybeReturnClass(new Option <string>("asdf")).Value.Get());
            Assert.False(TestStaticClass.MaybeAddOne(new Option <int>()).IsSome);

            // This shouldn't throw.
            TestStaticClass.TryCreateObjectOk();
            // But this one should.
            Assert.Throws <flapigen_test_dotnet.Error>(() => TestStaticClass.TryCreateObjectErr());

            var arc_mutex = new TestArcMutex();

            arc_mutex.Inc();
            Assert.Equal("1", arc_mutex.ToString());
            Assert.Equal("1", TestArcMutex.ToStringArc(arc_mutex));

            Assert.Equal(TestEnum.A, TestStaticClass.ReverseEnum(TestEnum.B));

            var tuple = TestStaticClass.GetTuple();

            Assert.Equal(0, tuple.Item1);
            Assert.Equal("0", tuple.Item2);
        }
예제 #6
0
    public void TestGenericSetupDefaultNegativeIncorrectExpression()
    {
        var body = Expression.Block(
            Expression.Add(Expression.Constant(1), Expression.Constant(2)),
            Expression.Constant(3));
        var lambda = Expression.Lambda <Action>(body);

        Assert.Throws <Exception>(() => Mock.SetupDefault(lambda, () =>
        {
            TestStaticClass.TestMethodReturn1WithoutParameters();
        }));
    }
예제 #7
0
        public void RepeatLoadTest()
        {
            var c   = MakeDriver();
            var obj = new TestStaticClass();

            c.Attach(obj);

            ExceptionAssert.Throws <RuntimeException>(() =>
            {
                c.Attach(obj);
            });
        }
예제 #8
0
    public void TestNestedThrowsMockWithDifferentFunctionsParentAfterChild()
    {
        Mock.Setup(() => TestStaticClass.TestMethodReturn1WithoutParameters(), () =>
        {
            Mock.Setup(() => TestStaticClass.TestMethodReturnWithParameter(2), () =>
            {
                Assert.Throws <ArgumentNullException>(() => TestStaticClass.TestMethodReturnWithParameter(2));
            }).Throws(typeof(ArgumentNullException));

            Assert.Throws <Exception>(() => TestStaticClass.TestMethodReturn1WithoutParameters());
        }).Throws(typeof(Exception));
    }
예제 #9
0
            public void ThePropertiesShouldBeCopied()
            {
                dynamic person = new
                {
                    Name = "Chris",
                    Age  = 42,
                };

                TestStaticClass result = DynamicToStatic.ToStatic <TestStaticClass>(person);

                result.ShouldHave().AllPropertiesBut(@class => @class.Birthday).EqualTo(person);
            }
예제 #10
0
        public void OnDestroyTest()
        {
            var c   = MakeDriver();
            var obj = new TestStaticClass();

            c.Attach(obj);

            updateResult = string.Empty;
            c.OnDestroy();
            c.Update();

            Assert.AreEqual(string.Empty, updateResult);
        }
예제 #11
0
    public async Task TestSetupReturnsMethodsReturnTaskAsync()
    {
        var originalResult = await TestStaticClass.TestMethodReturnTaskWithoutParametersAsync();

        Assert.AreEqual(1, originalResult);
        var expectedResult = 2;

        Mock.Setup(typeof(TestStaticClass), nameof(TestStaticClass.TestMethodReturnTaskWithoutParametersAsync), async() =>
        {
            var actualResult = await TestStaticClass.TestMethodReturnTaskWithoutParametersAsync();
            Assert.AreEqual(expectedResult, actualResult);
        }).Returns(Task.FromResult(expectedResult));
    }
예제 #12
0
        public void RepeatLoadTest()
        {
            var c   = MakeDriver();
            var d   = c.Make <IMonoDriver>() as CatLib.MonoDriver.MonoDriver;
            var obj = new TestStaticClass();

            d.Attach(obj);

            ExceptionAssert.Throws <RuntimeException>(() =>
            {
                d.Attach(obj);
            });
        }
예제 #13
0
    public async Task TestGenericSetupReturnsAsyncMethodsReturnTaskAsync()
    {
        var originalResult = await TestStaticClass.TestMethodReturnTaskWithoutParametersAsync();

        Assert.AreEqual(1, originalResult);
        var expectedResult = 2;

        Mock.Setup(() => TestStaticClass.TestMethodReturnTaskWithoutParametersAsync(), async() =>
        {
            var actualResult = await TestStaticClass.TestMethodReturnTaskWithoutParametersAsync();
            Assert.AreEqual(expectedResult, actualResult);
        }).ReturnsAsync(expectedResult);
    }
예제 #14
0
    public void TestNestedThrowsReturnTest()
    {
        const int expectedChildResult = 2;

        Mock.Setup(() => TestStaticClass.TestMethodReturn1WithoutParameters(), () =>
        {
            Assert.Throws <Exception>(() => TestStaticClass.TestMethodReturn1WithoutParameters());
            Mock.Setup(() => TestStaticClass.TestMethodReturn1WithoutParameters(), () =>
            {
                var actualChildResult = TestStaticClass.TestMethodReturn1WithoutParameters();
                Assert.AreEqual(expectedChildResult, actualChildResult);
            }).Returns(expectedChildResult);
        }).Throws <Exception>();
    }
예제 #15
0
        public void OnDestroyTest()
        {
            var c   = MakeDriver();
            var d   = c.Make <IMonoDriver>() as CatLib.MonoDriver.MonoDriver;
            var obj = new TestStaticClass();

            d.Attach(obj);

            updateResult = string.Empty;
            d.OnDestroy();
            d.Update();

            Assert.AreEqual(string.Empty, updateResult);
        }
예제 #16
0
    public void TestGenericSetupReturnsWithTestMethodReturn1WithoutParameters()
    {
        var originalResult = TestStaticClass.TestMethodReturn1WithoutParameters();
        var expectedResult = 2;

        Mock.Setup(
            () => TestStaticClass.TestMethodReturn1WithoutParameters(),
            () =>
        {
            var actualResult = TestStaticClass.TestMethodReturn1WithoutParameters();

            Assert.AreNotEqual(originalResult, actualResult);
            Assert.AreEqual(expectedResult, actualResult);
        })
        .Returns(expectedResult);
    }
예제 #17
0
    public void TestNestedInChildCallbackMockWithDifferentFunctions()
    {
        const int expectedParentResult = 2;
        const int expectedChildResult  = 3;

        Mock.Setup(() => TestStaticClass.TestMethodReturn1WithoutParameters(), () =>
        {
            Mock.Setup(() => TestStaticClass.TestMethodReturnWithParameter(2), () =>
            {
                var actualChildResult = TestStaticClass.TestMethodReturnWithParameter(2);
                Assert.AreEqual(expectedChildResult, actualChildResult);
                var actualParentResult = TestStaticClass.TestMethodReturn1WithoutParameters();
                Assert.AreEqual(expectedParentResult, actualParentResult);
            }).Callback(() => expectedChildResult);
        }).Callback(() => expectedParentResult);
    }
예제 #18
0
    public void TestNestedInChildReturnThrowsMockWithDifferentFunctions()
    {
        const int expectedParentResult = 2;

        Mock.Setup(() => TestStaticClass.TestMethodReturn1WithoutParameters(), () =>
        {
            Mock.Setup(() => TestStaticClass.TestMethodReturnWithParameter(2), () =>
            {
                var actualParentResult = TestStaticClass.TestMethodReturn1WithoutParameters();
                Assert.AreEqual(expectedParentResult, actualParentResult);
                Assert.Throws <Exception>(() => TestStaticClass.TestMethodReturnWithParameter(2));
                actualParentResult = TestStaticClass.TestMethodReturn1WithoutParameters();
                Assert.AreEqual(expectedParentResult, actualParentResult);
            }).Throws <Exception>();
        }).Returns(expectedParentResult);
    }
예제 #19
0
    public void TestNestedReturnMock()
    {
        const int expectedParentResult = 2;
        const int expectedChildResult  = 3;

        Mock.Setup(() => TestStaticClass.TestMethodReturn1WithoutParameters(), () =>
        {
            var actualParentResult = TestStaticClass.TestMethodReturn1WithoutParameters();
            Assert.AreEqual(expectedParentResult, actualParentResult);
            Mock.Setup(() => TestStaticClass.TestMethodReturn1WithoutParameters(), () =>
            {
                var actualChildResult = TestStaticClass.TestMethodReturn1WithoutParameters();
                Assert.AreEqual(expectedChildResult, actualChildResult);
            }).Returns(expectedChildResult);
        }).Returns(expectedParentResult);
    }
예제 #20
0
    public void TestReturnsWithTestMethodOutParameter()
    {
        var originalResult = TestStaticClass.TestMethodReturn1WithOutParameter(out _);
        var expectedResult = 2;

        Mock.Setup(
            typeof(TestStaticClass),
            nameof(TestStaticClass.TestMethodReturn1WithOutParameter),
            () =>
        {
            var actualResult = TestStaticClass.TestMethodReturn1WithOutParameter(out _);

            Assert.AreNotEqual(originalResult, actualResult);
            Assert.AreEqual(expectedResult, actualResult);
        })
        .Returns(expectedResult);
    }
예제 #21
0
    public void TestFuncCallback()
    {
        var originalResult = TestStaticClass.TestMethodReturn1WithoutParameters();
        var expectedResult = 2;

        Assert.AreNotEqual(expectedResult, originalResult);

        Mock.Setup(typeof(TestStaticClass), nameof(TestStaticClass.TestMethodReturn1WithoutParameters), () =>
        {
            var actualResult = TestStaticClass.TestMethodReturn1WithoutParameters();
            Assert.AreEqual(expectedResult, actualResult);
        }).Callback(() =>
        {
            var x = expectedResult;
            return(x);
        });
    }
예제 #22
0
    public static int StartTest(string info)
    {
        DebugHelper.InitLog(true);

        Debug.LogError(" == 223 中午 == +-*x&!@$#$()_+<>?{}|ff ~ " + info);

        TestStaticClass.StartTest(1);

        var obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);

        //obj.AddComponent<TestDelegate>();
        obj.AddComponent <TestLoader>();
        obj.AddComponent <TestBehaviourScript>();
        //obj.AddComponent<TestException>();

        return(123);
    }
예제 #23
0
    public void TestGenericSetupReturnsWithTestMethodReturnInstanceObject()
    {
        var originalResult = TestStaticClass.TestMethodReturnReferenceObject();
        var expectedResult = new TestInstance
        {
            IntProperty    = 1,
            ObjectProperty = new object()
        };

        Mock.Setup(
            () => TestStaticClass.TestMethodReturnReferenceObject(),
            () =>
        {
            var actualResult = TestStaticClass.TestMethodReturnReferenceObject();

            Assert.AreNotEqual(originalResult, actualResult);
            Assert.AreEqual(expectedResult, actualResult);
        })
        .Returns(expectedResult);
    }
예제 #24
0
    static void StartTest()
    {
        var ptr = ScriptEngine.GetFuncPointer();

        MonoBind.InitBind(ptr);

        DebugHelper.InitLog(true);

        Debug.LogError(" ========223 中午 ==== +-*x&!@$#$()_+<>?{}|ff ~");

        TestStaticClass.StartTest(1);

        TestCube();

        var obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);

        //obj.AddComponent<TestDelegate>();
        obj.AddComponent <TestLoader>();
        obj.AddComponent <TestBehaviourScript>();
        //obj.AddComponent<TestException>();
    }
예제 #25
0
 public void TestStaticClasses()
 {
     Assert.That(TestStaticClass.Add(1, 2), Is.EqualTo(3));
 }
예제 #26
0
 public void TestGenericSetup()
 {
     Mock.Setup(() => TestStaticClass.TestMethodReturn1WithoutParameters(), () => { });
 }
예제 #27
0
 public void OnEntry_Called_For_StaticMethod_In_StaticClass()
 {
     TestStaticClass.StaticMethod();
     Assert.True(callsBag.Contains("StaticClass_StaticMethod"));
 }
예제 #28
0
 public void TestStaticClasses()
 {
     Assert.That(TestStaticClass.Add(1, 2), Is.EqualTo(3));
     Assert.That(TestStaticClassDerived.Foo(), Is.EqualTo(0));
 }