Exemplo n.º 1
0
        private static void CtorSetTests()
        {
            QUnit.Module("CtorSetTests");

            QUnit.Test("Simple string property CtorSet initialisation", assert =>
            {
                var x = new SomethingWithStringId("abc");
                assert.Equal(x.Id, "abc");
            });

            QUnit.Test("Simple string property CtorSet initialisation on 'Plain' autoProperty", assert =>
            {
                var x = new SomethingWithPlainAutoPropertyStringId("abc");
                assert.Equal(x.Id, "abc");
            });

            QUnit.Test("CtorSet may not be called outside of the constructor (only works if CtorSet is set consistently within the constructor)", assert =>
            {
#pragma warning disable CtorSet // CtorSet should only be used in specific circumstances - suppress this, we're testing the runtime error handling
                var x = new SomethingWithStringId("abc");
                assert.Throws(
                    () => x.CtorSet(_ => _.Id, "abc"),
                    "CtorSet should throw if called outside of the constructor (since it should only be called once per property and the constructor should call it for all properties)"
                    );
            });
#pragma warning restore CtorSet // CtorSet should only be used in specific circumstances
        }
Exemplo n.º 2
0
        private static void CtorSetTests()
        {
            QUnit.Module("CtorSetTests");

            QUnit.Test("Simple string property CtorSet initialisation", assert =>
            {
                var x = new SomethingWithStringId("abc");
                assert.Equal(x.Id, "abc");
            });

            QUnit.Test("Simple string property CtorSet initialisation on 'Plain' autoProperty", assert =>
            {
                var x = new SomethingWithPlainAutoPropertyStringId("abc");
                assert.Equal(x.Id, "abc");
            });

            QUnit.Test("CtorSet may not be called outside of the constructor (only works if CtorSet is set consistently within the constructor)", assert =>
            {
                var x = new SomethingWithStringId("abc");
                assert.Throws(
                    () => x.CtorSet(_ => _.Id, "abc"),
                    "CtorSet should throw if called outside of the constructor (since it should only be called once per property and the constructor should call it for all properties)"
                    );
            });
        }