Esempio n. 1
0
 public void Test_01_InternalClass_Static()
 {
     Assert.That(InternalClass.Field_Static, Is.EqualTo("Value"));
     Assert.That(InternalClass.Property_Static, Is.EqualTo("Value"));
     //Assert.That( InternalClass.Event_Static, Is.Null );
     Assert.That(InternalClass.Method_Static(), Is.EqualTo("Value"));
 }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var publicClass   = new PublicClass();
            var internalClass = new InternalClass();

            Console.ReadLine();
        }
Esempio n. 3
0
        public void MockInternalClass()
        {
            MockRepository mocker            = new MockRepository();
            InternalClass  mockInternalClass = mocker.StrictMock <InternalClass>();

            Assert.NotNull(mockInternalClass);
        }
Esempio n. 4
0
        public void TestFormat() {
            Assert.ExpectAsserts(1);

            InternalClass testee = new InternalClass();
            string s = testee.Format(0);
            Assert.AreEqual(s, "0", "Expected '0' for result.");
        }
Esempio n. 5
0
        public void MockInternalClass()
        {
            InternalClass mockInternalClass = MockRepository.Mock <InternalClass>();

            mockInternalClass.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);
            Assert.NotNull(mockInternalClass);
        }
Esempio n. 6
0
        public void PropertyValue()
        {
            var obj = new InternalClass()
            {
                Id   = 1,
                Name = "haha"
            };

            var id = obj.GetPropertyValue <int>("Id");

            Assert.AreEqual(obj.Id, id);

            var name = obj.GetPropertyValue <string>("Name");

            Assert.AreEqual(obj.Name, name);


            var id2   = 2;
            var name2 = "heihei";


            obj.SetPropertyValue("Id", id2);
            Assert.AreEqual(obj.Id, id2);

            obj.SetPropertyValue("Name", name2);
            Assert.AreEqual(obj.Name, name2);


            //id = obj.GetPropertyValue<int>("id");
            //Assert.AreEqual(obj.Id, id);

            //name = obj.GetPropertyValue<string>("Name");
            //Assert.AreEqual(obj.Name, name);
        }
        public TestClass()
        {
            var publicClass = new PublicClass();

            publicClass.PublicProp = 1;
            //publicClass.PrivateProp = 2;
            //publicClass.ProtectedProp = 3;
            publicClass.InternalProp          = 4;
            publicClass.ProtectedInternalProp = 5;
            //publicClass.PrivateProtectedProp = 6;

            // var privateClass = new PrivateClass();
            //var protectedClass = new ProtectedClass();

            var internalClass = new InternalClass();

            internalClass.PublicProp = 1;
            //internalClass.PrivateProp = 2;
            //internalClass.ProtectedProp = 3;
            internalClass.InternalProp          = 4;
            internalClass.ProtectedInternalProp = 5;
            //internalClass.PrivateProtectedProp = 6;

            var protectedInternalClass = new PublicClass.ProtectedInternalClass();

            protectedInternalClass.PublicProp = 1;
            //protectedInternalClass.PrivateProp = 2;
            //protectedInternalClass.ProtectedProp = 3;
            protectedInternalClass.InternalProp          = 4;
            protectedInternalClass.ProtectedInternalProp = 5;
            //protectedInternalClass.PrivateProtectedProp = 6;

            // var PrivateProtectedClass = new PrivateProtectedClass();
        }
 public ExternalClass(int number)
 {
     IClass = new InternalClass()
     {
         SomeNumber = number
     };
 }
Esempio n. 9
0
        public void TestParse() {
            Assert.ExpectAsserts(1);

            InternalClass testee = new InternalClass();
            int i = testee.Parse("0");
            Assert.AreEqual(i, 0, "Expected 0 for result.");
        }
Esempio n. 10
0
        public Manager(string firstName, string lastName, int age, Position position) : this(firstName, lastName)
        {
            Age      = age;
            Position = position;

            internalClass = new InternalClass();
        }
Esempio n. 11
0
        private void ProcessInternalMacro(InternalClass klass, MacroStatement node)
        {
            TypeDefinition macroDefinition = klass.TypeDefinition;

            if (MacroDefinitionContainsMacroApplication(macroDefinition, node))
            {
                ProcessingError(CompilerErrorFactory.InvalidMacro(node, klass));
                return;
            }

            var  macroCompiler = My <MacroCompiler> .Instance;
            bool firstTry      = !macroCompiler.AlreadyCompiled(macroDefinition);
            Type macroType     = macroCompiler.Compile(macroDefinition);

            if (macroType == null)
            {
                if (firstTry)
                {
                    ProcessingError(CompilerErrorFactory.AstMacroMustBeExternal(node, klass));
                }
                else
                {
                    RemoveCurrentNode();
                }
                return;
            }
            ProcessMacro(macroType, node);
        }
Esempio n. 12
0
        GetAssemblyInformationalVersionOfObject_UsedInternalObject_ReturnsInformationalVersionOfTestAssembly()
        {
            var instance = new InternalClass();
            var version  = instance.GetAssemblyInformationalVersionOfObject();

            version.Should().Be("1.0.0", "Current version of the test assembly is expected.");
        }
Esempio n. 13
0
        public void Test()
        {
            /* by default class inaccessible due to protection level */
            /* watch assembly InternalVisibleTo attribute */
            var internalClassVariable = new InternalClass();

            Assert.Equal(1, 1);
        }
Esempio n. 14
0
    private void SomeMethod()
    {
        //InternalClass can only be created by methods of ParentClass
        var ic = new InternalClass();

        ic.PublicMethod();          //Internally visible
        ic.PrivateMethod();         //Invalid, not accessible
    }
Esempio n. 15
0
    public async Task CanInvokeMethodThatReturnsTaskOfInternalClass()
    {
        // JSON RPC cannot invoke non-public members. A public member cannot have Task<NonPublicType> result.
        // Though it can have result of just Task type, and return a Task<NonPublicType>, and dev hub supports that.
        InternalClass result = await this.clientRpc.InvokeAsync <InternalClass>(nameof(Server.MethodThatReturnsTaskOfInternalClass));

        Assert.NotNull(result);
    }
Esempio n. 16
0
        public void TestParse()
        {
            Assert.ExpectAsserts(1);

            InternalClass testee = new InternalClass();
            int           i      = testee.Parse("0");

            Assert.AreEqual(i, 0, "Expected 0 for result.");
        }
Esempio n. 17
0
        public void TestFormat()
        {
            Assert.ExpectAsserts(1);

            InternalClass testee = new InternalClass();
            string        s      = testee.Format(0);

            Assert.AreEqual(s, "0", "Expected '0' for result.");
        }
Esempio n. 18
0
        public void PublicClass_PrivateMethod()
        {
            _internalClass = new InternalClass();
            _publicClass   = new PublicClass();

            var internalInstance = new InternalClass();

            Assert.AreEqual("PublicMethod", _publicClass.PrivateMethod(_internalClass));
        }
            public void CreateNavigationPropertySetter_creates_a_setter_delegate_for_non_public_reference_property_with_base_setter()
            {
                var target = new InternalClass();
                var entity = new ClassWithoutSetters();

                DelegateFactory.CreateNavigationPropertySetter(
                    typeof(ClassWithoutSetters),
                    typeof(ClassWithoutSetters).GetProperty("InternalNavProperty", BindingFlags.Instance | BindingFlags.NonPublic))(entity, target);

                Assert.Same(target, entity.InternalNavProperty);
            }
            public void CreateNavigationPropertySetter_creates_a_setter_delegate_for_non_public_reference_property_with_base_setter()
            {
                var target = new InternalClass();
                var entity = new ClassWithoutSetters();

                DelegateFactory.CreateNavigationPropertySetter(
                    typeof(ClassWithoutSetters),
                    typeof(ClassWithoutSetters).GetAnyProperty("InternalNavProperty"))(entity, target);

                Assert.Same(target, entity.InternalNavProperty);
            }
            public void CreateNavigationPropertySetter_creates_a_setter_delegate_for_non_public_reference_property()
            {
                var target = new InternalClass();
                var entity = new PublicClass1();

                DelegateFactory.CreateNavigationPropertySetter(
                    typeof(PublicClass1),
                    typeof(PublicClass1).GetDeclaredProperty("InternalNavProperty"))(entity, target);

                Assert.Same(target, entity.InternalNavProperty);
            }
Esempio n. 22
0
        private void ProcessInternalMacro(InternalClass klass, MacroStatement node)
        {
            Type macroType = new MacroCompiler(Context).Compile(klass);

            if (null == macroType)
            {
                Errors.Add(CompilerErrorFactory.AstMacroMustBeExternal(node, klass.FullName));
                return;
            }
            ProcessMacro(macroType, node);
        }
Esempio n. 23
0
        public void InternalClassWithInternalEnum()
        {
            InternalClass expected = new InternalClass
            {
                EnumProperty = InternalEnum.Two,
            };

            byte[]        bytes  = MessagePackSerializer.Serialize(expected, StandardResolverAllowPrivate.Options);
            InternalClass actual = MessagePackSerializer.Deserialize <InternalClass>(bytes, StandardResolverAllowPrivate.Options);

            Assert.Equal(expected.EnumProperty, actual.EnumProperty);
        }
            public void CreatePropertySetter_creates_a_setter_delegate_for_a_non_public_property_with_base_setter()
            {
                var target = new InternalClass();
                var entity = new ClassWithoutSetters();

                DelegateFactory.CreatePropertySetter(
                    typeof(ClassWithoutSetters),
                    typeof(ClassWithoutSetters).GetProperty("InternalNavProperty", BindingFlags.Instance | BindingFlags.NonPublic),
                    allowNull: true)(entity, target);

                Assert.Same(target, entity.InternalNavProperty);
            }
Esempio n. 25
0
 private void CollectModulesForBaseTypes(CompileUnit unit, TypeDefinition node)
 {
     foreach (TypeReference baseType in node.BaseTypes)
     {
         InternalClass internalClass = baseType.Entity as InternalClass;
         if (internalClass == null)
         {
             continue;
         }
         GetModuleFor(unit, internalClass.TypeDefinition);
     }
 }
Esempio n. 26
0
        void CheckAmbiguousVariableNames(Method node)
        {
            if (null == node.DeclaringType || null == node.DeclaringType.Entity)
            {
                return;
            }
            InternalClass klass = node.DeclaringType.Entity as InternalClass;

            if (null == klass || null == klass.BaseType)
            {
                return;
            }

            if (Parameters.DisabledWarnings.Contains("BCW0025"))
            {
                return;
            }

            klass = klass.BaseType as InternalClass;
            foreach (Local local in node.Locals)
            {
                if (null == local.Entity || ((InternalLocal)local.Entity).IsExplicit)
                {
                    continue;
                }

                //check in the cache if variable is safe (the frequent case)
                if (_safeVars.Contains(local.Name))
                {
                    return;
                }

                //navigate down the base types
                bool safe = true;
                while (null != klass)
                {
                    Field field = klass.TypeDefinition.Members[local.Name] as Field;
                    if (null != field && field.IsPrivate)
                    {
                        safe = false;
                        Warnings.Add(CompilerWarningFactory.AmbiguousVariableName(local, local.Name, klass.Name));
                        break;                         //no need to go further down
                    }
                    klass = klass.BaseType as InternalClass;
                }

                if (safe)                 //this var is safe for all methods of the current type
                {
                    _safeVars.Add(local.Name);
                }
            }
        }
Esempio n. 27
0
        private void ProcessMacro(IType macroType, MacroStatement node)
        {
            ExternalType type = macroType as ExternalType;

            if (null == type)
            {
                InternalClass klass = (InternalClass)macroType;
                ProcessInternalMacro(klass, node);
                return;
            }

            ProcessMacro(type.ActualType, node);
        }
Esempio n. 28
0
        private void ProcessMacro(IType macroType, MacroStatement node)
        {
            var externalType = macroType as ExternalType;

            if (externalType == null)
            {
                InternalClass internalType = (InternalClass)macroType;
                ProcessInternalMacro(internalType, node);
                return;
            }

            ProcessMacro(externalType.ActualType, node);
        }
            public void CreatePropertyGetter_creates_getter_delegate_for_non_public_reference_type_property()
            {
                var target = new InternalClass();

                Assert.Same(
                    target,
                    DelegateFactory.CreatePropertyGetter(
                        typeof(PublicClass1),
                        typeof(PublicClass1).GetDeclaredProperty("InternalNavProperty"))(
                        new PublicClass1
                {
                    InternalNavProperty = target
                }));
            }
            public void CreatePropertyGetter_creates_getter_delegate_for_non_public_reference_type_property()
            {
                var target = new InternalClass();

                Assert.Same(
                    target,
                    DelegateFactory.CreatePropertyGetter(
                        typeof(PublicClass1),
                        typeof(PublicClass1).GetProperty("InternalNavProperty", BindingFlags.NonPublic | BindingFlags.Instance))(
                        new PublicClass1
                {
                    InternalNavProperty = target
                }));
            }
        public void Serializable()
        {
            var svc = new SerializableService();
            var obj = new InternalClass();

            obj.Field = 123;
            obj.Name  = "Test";

            var bytes = svc.Serialize(obj);

            var newObj = svc.Deserialize <InternalClass>(bytes);

            Assert.IsInstanceOfType(newObj, typeof(InternalClass));
            Assert.AreEqual(obj.Field, newObj.Field);
            Assert.AreEqual(obj.Name, newObj.Name);
        }
Esempio n. 32
0
            public void Foo()
            {
                AccessModifiersTestClass sample231 = new AccessModifiersTestClass();

                sample231.ProperyPublic = -1;

                // InternalsVisibleTo
                SomeSamples.Chapter2.InternalClass internalClass = new InternalClass();

                PublicClass publicClass = new PublicClass();

                PublicClass.ProtectedInternalClass protectedInternalClass = new PublicClass.ProtectedInternalClass();
                PublicClass.PublicClassInner       publicClassInner       = new PublicClass.PublicClassInner();
                PublicClass.IPublicInterface       publicInterface;
                PublicClass.PublicEnum             publicEnum;
            }
Esempio n. 33
0
        static void Main(string[] args)
        {
            double doubleValInfo = double.PositiveInfinity;
            var    internalClass = new InternalClass()
            {
                Name = "wai rock", Value = doubleValInfo
            };

            var json = new JavaScriptSerializer().Serialize(internalClass);

            Console.WriteLine(json);

            var newton = JsonConvert.SerializeObject(internalClass);

            Console.WriteLine(newton);

            Console.Read();
        }
Esempio n. 34
0
 public int SomeMethod()
 {
     var obj = new InternalClass();
     return new PublicClass().InternalMethod();
 }
Esempio n. 35
0
        private void ProcessInternalMacro(InternalClass klass, MacroStatement node)
        {
            TypeDefinition macroDefinition = klass.TypeDefinition;

            if (MacroDefinitionContainsMacroApplication(macroDefinition, node))
            {
                ProcessingError(CompilerErrorFactory.InvalidMacro(node, klass.FullName));
                return;
            }

            bool firstTry = ! MacroCompiler.AlreadyCompiled(macroDefinition);
            Type macroType = new MacroCompiler(Context).Compile(macroDefinition);
            if (null == macroType)
            {
                if (firstTry)
                {
                    ProcessingError(CompilerErrorFactory.AstMacroMustBeExternal(node, klass.FullName));
                }
                else
                {
                    RemoveCurrentNode();
                }
                return;
            }
            ProcessMacro(macroType, node);
        }
            public void CreatePropertyGetter_creates_getter_delegate_for_non_public_reference_type_property()
            {
                var target = new InternalClass();

                Assert.Same(
                    target,
                    DelegateFactory.CreatePropertyGetter(
                        typeof(PublicClass1),
                        typeof(PublicClass1).GetProperty("InternalNavProperty", BindingFlags.NonPublic | BindingFlags.Instance))(
                            new PublicClass1
                                {
                                    InternalNavProperty = target
                                }));
            }
            public void CreatePropertySetter_creates_a_setter_delegate_for_a_non_public_property()
            {
                var target = new InternalClass();
                var entity = new PublicClass1();

                DelegateFactory.CreatePropertySetter(
                    typeof(PublicClass1),
                    typeof(PublicClass1).GetProperty("InternalNavProperty", BindingFlags.Instance | BindingFlags.NonPublic),
                    allowNull: true)(entity, target);

                Assert.Same(target, entity.InternalNavProperty);
            }
Esempio n. 38
0
        private void ProcessInternalMacro(InternalClass klass, MacroStatement node)
        {
            TypeDefinition macroDefinition = klass.TypeDefinition;
            if (MacroDefinitionContainsMacroApplication(macroDefinition, node))
            {
                ProcessingError(CompilerErrorFactory.InvalidMacro(node, klass));
                return;
            }

            var macroCompiler = My<MacroCompiler>.Instance;
            bool firstTry = !macroCompiler.AlreadyCompiled(macroDefinition);
            Type macroType = macroCompiler.Compile(macroDefinition);
            if (macroType == null)
            {
                if (firstTry)
                    ProcessingError(CompilerErrorFactory.AstMacroMustBeExternal(node, klass));
                else
                    RemoveCurrentNode();
                return;
            }
            ProcessMacro(macroType, node);
        }