public void GetClone_Class_Cloned()
 {
     var source = new SimpleClass() { Property = 10, _field = 3 };
     var target = CloneFactory.GetClone(source);
     Assert.AreEqual(source.Property, target.Property);
     Assert.AreEqual(source._field, target._field);
 }
 public void TestSimpleObject()
 {
     var nodeContainer = new NodeContainer();
     var instance = new SimpleClass { Member1 = 3, Member2 = new SimpleClass() };
     var rootNode = nodeContainer.GetOrCreateNode(instance);
     var visitor = new TestVisitor();
     visitor.Visit(rootNode);
     var expectedNodes = new[]
     {
         rootNode,
         rootNode.TryGetChild(nameof(SimpleClass.Member1)),
         rootNode.TryGetChild(nameof(SimpleClass.Member2)),
         rootNode.TryGetChild(nameof(SimpleClass.Member2)).Target,
         rootNode.TryGetChild(nameof(SimpleClass.Member2)).Target.TryGetChild(nameof(SimpleClass.Member1)),
         rootNode.TryGetChild(nameof(SimpleClass.Member2)).Target.TryGetChild(nameof(SimpleClass.Member2)),
     };
     var expectedPaths = new[]
     {
         new GraphNodePath(rootNode),
         new GraphNodePath(rootNode).PushMember(nameof(SimpleClass.Member1)),
         new GraphNodePath(rootNode).PushMember(nameof(SimpleClass.Member2)),
         new GraphNodePath(rootNode).PushMember(nameof(SimpleClass.Member2)).PushTarget(),
         new GraphNodePath(rootNode).PushMember(nameof(SimpleClass.Member2)).PushTarget().PushMember(nameof(SimpleClass.Member1)),
         new GraphNodePath(rootNode).PushMember(nameof(SimpleClass.Member2)).PushTarget().PushMember(nameof(SimpleClass.Member2)),
     };
     VerifyNodesAndPath(expectedNodes, expectedPaths, visitor);
 }
		public void CopyTo()
		{
			ViewFactory<SimpleClass> factory = ViewFactory<SimpleClass>.IList();
			IList<SimpleClass> list = factory.List;

			list.Add(new SimpleClass(100, "aaa", new DateTime(1970, 1, 1)));
			list.Add(new SimpleClass(80, "bbb", new DateTime(1980, 12, 12)));
			list.Add(new SimpleClass(60, "ccc", new DateTime(1975, 6, 6)));

			SimpleClass[] array = new SimpleClass[3];
			((ICollection)factory.View).CopyTo(array, 0);

			SimpleClass item = array[0];
			Assert.IsNotNull(item);
			Assert.AreEqual(100, item.IntegerValue);
			Assert.AreEqual("aaa", item.StringValue);
			Assert.AreEqual(new DateTime(1970, 1, 1), item.DateTimeValue);

			item = array[1];
			Assert.AreEqual(80, item.IntegerValue);
			Assert.AreEqual("bbb", item.StringValue);
			Assert.AreEqual(new DateTime(1980, 12, 12), item.DateTimeValue);

			item = array[2];
			Assert.AreEqual(60, item.IntegerValue);
			Assert.AreEqual("ccc", item.StringValue);
			Assert.AreEqual(new DateTime(1975, 6, 6), item.DateTimeValue);
		}
    public static void Main()
    {
        SimpleStruct ss = new SimpleStruct();
        ss.X = 5;
        ss.DisplayX();

        SS si = (SS) ss;
        si.X = 90;
        si.DisplayX();
        
        ss =  (SimpleStruct) si ;
        ss.X = 5;
        ss.DisplayX();
        
        SimpleClass ss1 = new SimpleClass();
        ss1.X = 5;
        ss1.DisplayX();
        
        try {
        ss1 =  (SimpleClass) si ;
        ss1.X = 5;
        ss1.DisplayX();
        } 
        catch(Exception)
        {
        	Console.WriteLine("Failed to cast");
        }
        

    }
        public void CrossoverTest()
        {
            var obj = new SimpleClass();
            var generator = new Generator<SimpleClass>();
            CodeExpression<SimpleClass> leftTree = generator.BuildRandomExpressionTree();
            CodeExpression<SimpleClass> rightTree = generator.BuildRandomExpressionTree();

            Trace.WriteLine("Vor dem Crossover");
            Trace.WriteLine("-----------------");
            Trace.WriteLine("");
            Trace.WriteLine("Tree links:");
            Trace.WriteLine(leftTree);

            Trace.WriteLine("");
            Trace.WriteLine("Tree rechts:");
            Trace.WriteLine(rightTree);

            generator.Crossover(ref leftTree, ref rightTree);

            Trace.WriteLine("");
            Trace.WriteLine("Nach dem Crossover");
            Trace.WriteLine("------------------");
            Trace.WriteLine("");
            Trace.WriteLine("Tree links:");
            Trace.WriteLine(leftTree);

            Trace.WriteLine("");
            Trace.WriteLine("Tree rechts:");
            Trace.WriteLine(rightTree);
        }
    public static SimpleClass delegate_test_class(SimpleClass
ss)
    {
        if
        (ss
        ==
        null)
        return
        null;
        if
        (!
        (!ss.a
        &&
        ss.b
        &&
        !ss.c
        &&
        ss.d
        ==
        "TEST"))
        return
        null;
        SimpleClass
        res
        =
        ss;
        return
        res;
    }
Beispiel #7
0
		static void Main (string[] args)
		{
			var v = ObjCRuntime.Dlfcn.dlopen (GetCurrentExecutingDirectory () + "/SimpleClass.dylib", 0);

			NSApplication.Init ();
			SimpleClass c = new SimpleClass ();
			Console.WriteLine (c.DoIt());
		}
        public void TestExecuteMethod()
        {
            SimpleClass simpleClass = new SimpleClass();
            Assert.IsFalse(simpleClass.MethodCalled);

            ReflectionUtilities.ExecuteMethod(simpleClass, "MyMethod");
            Assert.IsTrue(simpleClass.MethodCalled);
        }
        public void ToViewModel_Simple_Class()
        {
            var model = new SimpleClass { A = 5, B = "test" };

            var json = Knockout.ToViewModel(model);

            Assert.AreEqual("{\"A\":ko.observable(5),\"B\":ko.observable(\"test\")}", json.ToJson());
        }
Beispiel #10
0
        public void BuildNullObject6()
        {
            UnityContainer uc = new UnityContainer();
            SimpleClass myObject = new SimpleClass();
            uc.BuildUp(myObject, String.Empty);

            Assert.AreNotEqual(uc.Resolve<SimpleClass>(), myObject);
        }
        public void GetBindingInstance_should_return_instance_specified_through_SetBindingInstance()
        {
            var scenarioContext = CreateScenarioContext();

            var expectedInstance = new SimpleClass();
            scenarioContext.SetBindingInstance(typeof(SimpleClass), expectedInstance);
            var result = scenarioContext.GetBindingInstance(typeof(SimpleClass));
            result.Should().Be(expectedInstance);
        }
        public void TestExecuteMethod_WithReturnValue()
        {
            SimpleClass simpleClass = new SimpleClass();
            Assert.IsFalse(simpleClass.MethodCalled);

            var returnValue = ReflectionUtilities.ExecuteMethod(simpleClass, "MyMethodWithReturn");
            Assert.IsTrue(simpleClass.MethodCalled);
            Assert.IsTrue(Convert.ToBoolean(returnValue));
        }
            public void PacksDefinedClassCorrectly()
            {
                var toPack = new SimpleClass {A = true};
                var expected = new List<byte> {0xA1, 0x81, 0x41, (byte) Markers.True}; //1 fields


                var actual = Packers.Map.Pack(toPack);
                actual.Should().Equal(expected);
            }
Beispiel #14
0
        public void TestReadonly()
        {
            SimpleClass instance = new SimpleClass();

            int value = 100;
            instance.m_array[0] = value;

            Assert.AreEqual(value, instance.m_array[0]);
        }
        public void GenerateExpressionTree()
        {
            var obj = new SimpleClass();
            var generator = new Generator<SimpleClass>();
            var func = generator.BuildRandomExpressionTree();
            Trace.WriteLine(func);

            func.Execute(obj);
        }
Beispiel #16
0
        public void I_want_some_nifty_helpers_to_make_generics_useful()
        {
            SimpleClass testClass = new SimpleClass();

            SingleGenericClass<Guid> single = new SingleGenericClass<Guid>(Guid.NewGuid());
            DoubleGenericClass<SingleGenericClass<Guid>, Guid> argument = new DoubleGenericClass<SingleGenericClass<Guid>, Guid>(single, single.Key);

            Generic.Call(testClass, x => x.DoubleGenericMethod<object, object>(null), argument);
        }
    public static int delegate_test_class_out(out SimpleClass ss)
    {
        ss = new SimpleClass ();
        ss.a = true;
        ss.b = false;
        ss.c = true;
        ss.d = "RES";

        return 0;
    }
Beispiel #18
0
                public void Takes_Properties()
                {
                    var properties = new [] { "Property1", "Property2" };
                    var target = new SimpleClass { Property1 = "Property1", Property2 = 32 };

                    var line = Sugar.ComposeLine<SimpleClass>(SerializeMethod.CSV,
                            properties, target);

                    Assert.Equal("Property1,32", line);
                }
Beispiel #19
0
        public void BuildNullObject7()
        {
            UnityContainer uc = new UnityContainer();
            SimpleClass myObject1 = new SimpleClass();
            SimpleClass myObject2 = new SimpleClass();
            uc.BuildUp(myObject1, String.Empty);
            uc.BuildUp(myObject2, (string)null);

            Assert.AreNotEqual(uc.Resolve<SimpleClass>(), myObject2);
        }
        public void LoggingToolkit_Methods_LogsMethodEnter()
        {
            SimpleClass s = new SimpleClass();
            s.MethodWith1Argument("asd");

            Thread.Sleep( 100 ); //Make sure method is executed

            string output = OutputString.ToString();
            StringAssert.Contains("Entering: PostSharp.Toolkit.Integration.Tests.SimpleClass.MethodWith1Argument(string stringArg = \"asd\")", output);
        }
Beispiel #21
0
                public void Ignores_Case()
                {
                    var properties = new [] { "PROPERTY1" };
                    var target = new SimpleClass { Property1 = "Property1", Property2 = 32 };

                    var line = Sugar.ComposeLine<SimpleClass>(SerializeMethod.FixedWidth,
                            properties, target);

                    Assert.Equal("Property1", line);
                }
Beispiel #22
0
		public void IndexOfItemNotInList()
		{
			ViewFactory<SimpleClass> factory = ViewFactory<SimpleClass>.IList();
			IList<SimpleClass> list = factory.List;

			list.Add(new SimpleClass(100, "aaa", new DateTime(1970, 1, 1)));
			SimpleClass bbb = new SimpleClass(80, "bbb", new DateTime(1980, 12, 12));
			list.Add(new SimpleClass(60, "ccc", new DateTime(1975, 6, 6)));

			Assert.AreEqual(-1, factory.View.IndexOf(bbb));
		}
Beispiel #23
0
                public void Inner_Properties()
                {
                    var properties = new [] { "Property3.Property1" };
                    var target = new SimpleClass { Property1 = "Property1", Property2 = 32,
                        Property3 = new InnerClass { Property1 = "Property3" } };

                    var line = Sugar.ComposeLine<SimpleClass>(SerializeMethod.CSV,
                            properties, target);

                    Assert.Equal("Property3", line);
                }
        public void InjectDependencies_ShouldPopulateInterfacePropertyOnObject_GivenTheInterfaceIsRegisteredWithTheContainer()
        {
            var container = new WindsorContainer();
            container.Register(Component.For<IService>().ImplementedBy<ServiceImpl>());

            var objectWithDependencies = new SimpleClass();
            container.Kernel.InjectDependencies(objectWithDependencies);
            container.Kernel.ReleaseDependencies(objectWithDependencies);

            Assert.That(objectWithDependencies.Dependency, Is.InstanceOf<ServiceImpl>());
        }
        public void FirstIntegrationTest()
        {
            //arrange
            string expected = "F#";
            SimpleClass sc = new SimpleClass();

            //act
            var result = sc.X;
            OutputWriter.WriteLine("result: {0}", result);
            //assert
            result.Should().Be(expected);
        }
        private static void Main()
        {
            SimpleClass myTest = new SimpleClass();
            Type myType = typeof(SimpleClass);

            object[] myAttributes = myType.GetCustomAttributes(false);

            foreach (VersionAttribute item in myAttributes)
            {
                Console.WriteLine("{0} {1}", item, item.Version);
            }
        }
        public void Trace_OnException_PrintsException()
        {
            SimpleClass s = new SimpleClass();

            try
            {
                s.MethodThrowsException();
            }
            catch { }

            string output = OutputString.ToString();

            StringAssert.Contains("System.Exception: This is an exception", output);
        }
        public void Multiple()
        {
            var source  = new SimpleClass();
            var patched = new SimpleClass()
            {
                Integer2 = 7, String2 = "Something"
            };

            var diff = DiffBuilder.Build(source, patched);

            Assert.True(JObject.DeepEquals(
                            JObject.Parse("{Integer2: 7, String2:'Something'}"),
                            diff));
        }
Beispiel #29
0
    public static int delegate_test_byval_class_inout(SimpleClass ss)
    {
        if ((ss.a != false) || (ss.b != true) || (ss.c != false) || (ss.d != "FOO"))
        {
            return(1);
        }

        ss.a = true;
        ss.b = false;
        ss.c = true;
        ss.d = "RES";

        return(0);
    }
        public void NullToValue()
        {
            var source  = new SimpleClass();
            var patched = new SimpleClass()
            {
                String1 = "value"
            };

            var diff = DiffBuilder.Build(source, patched);

            Assert.True(JObject.DeepEquals(
                            JObject.Parse("{String1:'value'}"),
                            diff));
        }
        public void ValueToNull()
        {
            var source  = new SimpleClass();
            var patched = new SimpleClass()
            {
                String2 = null
            };

            var diff = DiffBuilder.Build(source, patched);

            Assert.True(JObject.DeepEquals(
                            JObject.Parse("{String2:null}"),
                            diff));
        }
Beispiel #32
0
            public void PacksDefinedClassCorrectly()
            {
                var toPack = new SimpleClass {
                    A = true
                };
                var expected = new List <byte> {
                    0xA1, 0x81, 0x41, Markers.True
                };                                                              //1 fields


                var actual = Packers.Map.Pack(toPack);

                actual.Should().Equal(expected);
            }
Beispiel #33
0
            public void UnpacksDefinedClass_WithProperty()
            {
                var expected = new SimpleClass {
                    A = true
                };
                var toUnpack = new List <byte> {
                    0xA1, 0x81, 0x41, Markers.True
                };                                                              //1 fields


                var actual = Packers.Map.Unpack <SimpleClass>(toUnpack.ToArray());

                actual.ShouldBeEquivalentTo(expected);
            }
Beispiel #34
0
        public void IndexOf()
        {
            var factory = ViewFactory <SimpleClass> .IList();

            var list = factory.List;

            list.Add(new SimpleClass(100, "aaa", new DateTime(1970, 1, 1)));
            var bbb = new SimpleClass(80, "bbb", new DateTime(1980, 12, 12));

            list.Add(bbb);
            list.Add(new SimpleClass(60, "ccc", new DateTime(1975, 6, 6)));

            Assert.AreEqual(1, ((IList)factory.View).IndexOf(bbb));
        }
Beispiel #35
0
            private void returns_intercepted_parameters_as_string_when_GenericWithRepeatedGenericParameterReturnInterceptedOutParameters_is_called()
            {
                Execute(() =>
                {
                    var instance      = new InterceptGenericMethodsClass <int, string>();
                    var interceptedP1 = 2;
                    var interceptedP2 = new SimpleStruct(2);
                    var interceptedP3 = new SimpleClass(2);
                    var interceptedP4 = new[] { 1, 2 };
                    var interceptedP5 = new[] { new SimpleStruct(1), new SimpleStruct(2) };
                    var interceptedP6 = new[] { new SimpleClass(1), new SimpleClass(2) };
                    var interceptedP7 = new List <int> {
                        1, 2
                    };
                    var interceptedP8 = new List <SimpleStruct> {
                        new SimpleStruct(1), new SimpleStruct(2)
                    };
                    var interceptedP9 = new List <SimpleClass> {
                        new SimpleClass(1), new SimpleClass(2)
                    };

                    int out1;
                    SimpleStruct out2;
                    SimpleClass out3;
                    int[] out4;
                    SimpleStruct[] out5;
                    SimpleClass[] out6;
                    List <int> out7;
                    List <SimpleStruct> out8;
                    List <SimpleClass> out9;
                    instance.GenericWithRepeatedGenericParameterReturnInterceptedOutParameters <SimpleClass, SimpleStruct>(out out1, out out2, out out3, out out4, out out5, out out6, out out7, out out8, out out9);

                    Assert.Equal(interceptedP1, out1);
                    Assert.Equal(interceptedP2.Value, out2.Value);
                    Assert.Equal(interceptedP3.Value, out3.Value);
                    Assert.Equal(interceptedP4[0], out4[0]);
                    Assert.Equal(interceptedP4[1], out4[1]);
                    Assert.Equal(interceptedP5[0].Value, out5[0].Value);
                    Assert.Equal(interceptedP5[1].Value, out5[1].Value);
                    Assert.Equal(interceptedP6[0].Value, out6[0].Value);
                    Assert.Equal(interceptedP6[1].Value, out6[1].Value);
                    Assert.Equal(interceptedP7[0], out7[0]);
                    Assert.Equal(interceptedP7[1], out7[1]);
                    Assert.Equal(interceptedP8[0].Value, out8[0].Value);
                    Assert.Equal(interceptedP8[1].Value, out8[1].Value);
                    Assert.Equal(interceptedP9[0].Value, out9[0].Value);
                    Assert.Equal(interceptedP9[1].Value, out9[1].Value);
                });
            }
Beispiel #36
0
                public void Inner_Properties()
                {
                    var properties = new [] { "Property3.Property1" };
                    var target     = new SimpleClass {
                        Property1 = "Property1", Property2 = 32,
                        Property3 = new InnerClass {
                            Property1 = "Property3"
                        }
                    };

                    var line = Sugar.ComposeLine <SimpleClass>(SerializeMethod.CSV,
                                                               properties, target);

                    Assert.Equal("Property3", line);
                }
        public void GetBindingInstance_should_return_instance_through_BindingInstanceResolver()
        {
            var expectedInstance = new SimpleClass();

            var scenarioContext = CreateScenarioContext(registerGlobalMocks: (globalContainer =>
            {
                var bindingInstanceResolverMock = new Mock<IBindingInstanceResolver>();
                bindingInstanceResolverMock.Setup(m => m.ResolveBindingInstance(typeof(SimpleClass), It.IsAny<IObjectContainer>()))
                    .Returns(expectedInstance);
                globalContainer.RegisterInstanceAs(bindingInstanceResolverMock.Object);
            }));

            var result = scenarioContext.GetBindingInstance(typeof(SimpleClass));
            result.Should().Be(expectedInstance);
        }
Beispiel #38
0
        public void ComplexCopyTest()
        {
            var simple = new SimpleClass()
            {
                Primitive = 1, Str = "apollo ssc"
            };
            var obj = new ComplexClass {
                Reference = simple
            };
            var copy = obj.Copy();

            Check.That(obj).IsNotEqualTo(copy);
            Check.That(obj.Reference).IsNotEqualTo(copy.Reference);
            Check.That(obj.Reference.Str).IsEqualTo("apollo ssc");
        }
Beispiel #39
0
        public void ContainsItemInList()
        {
            var factory = ViewFactory <SimpleClass> .IList();

            var list = factory.List;
            var view = factory.View;

            list.Add(new SimpleClass(100, "aaa", new DateTime(1970, 1, 1)));
            var bbb = new SimpleClass(80, "bbb", new DateTime(1980, 12, 12));

            list.Add(bbb);
            list.Add(new SimpleClass(60, "ccc", new DateTime(1975, 6, 6)));

            Assert.IsTrue(view.Contains(bbb));
        }
Beispiel #40
0
        static void Main(string[] args)
        {
            SimpleClass simpleClass = new SimpleClass();

            MyDelegate handler1 = simpleClass.Method1;
            MyDelegate handler2 = simpleClass.Method2;
            // Статический метод.
            MyDelegate handler3 = SimpleClass.Method3;

            MyDelegate handler4 = handler1 + handler2 + handler3;

            handler4();

            Console.ReadLine();
        }
Beispiel #41
0
        public void ContainsItemInList()
        {
            ViewFactory <SimpleClass> factory = ViewFactory <SimpleClass> .IList();

            IList <SimpleClass>          list = factory.List;
            ObjectListView <SimpleClass> view = factory.View;

            list.Add(new SimpleClass(100, "aaa", new DateTime(1970, 1, 1)));
            SimpleClass bbb = new SimpleClass(80, "bbb", new DateTime(1980, 12, 12));

            list.Add(bbb);
            list.Add(new SimpleClass(60, "ccc", new DateTime(1975, 6, 6)));

            Assert.IsTrue(((IList)view).Contains(bbb));
        }
        public void ShouldRecordMasterListKeys()
        {
            SimpleClass[] masterList = new SimpleClass[19];

            objectBuilder.Construct(Arg.Any <int>()).Returns(new SimpleClass());

            declaration = new RangeDeclaration <SimpleClass>(listBuilderImpl, objectBuilder, 9, 10);
            declaration.Construct();

            declaration.AddToMaster(masterList);

            Assert.That(declaration.MasterListAffectedIndexes.Count, Is.EqualTo(2));
            Assert.That(declaration.MasterListAffectedIndexes[0], Is.EqualTo(9));
            Assert.That(declaration.MasterListAffectedIndexes[1], Is.EqualTo(10));
        }
        public void Create()
        {
            this.Initialize();
            var simple = new SimpleClass().CreateProxy(this.DebugContext, this);

            simple.Hook();
            simple.DoNotHook();
            simple.Hook();

            var hooks = this.Counts["Hook"];

            Assert.Equal(2, hooks.BeforeCount);
            Assert.Equal(2, hooks.AfterCount);
            Assert.Equal(0, hooks.AfterExceptionCount);
        }
Beispiel #44
0
        public async Task ValidClassIsValidWithCustomRulesForAsync()
        {
            var simple = new SimpleClass {
                Number = 2, Text = "A value"
            };
            var complex = new ComplexClass {
                Id = Guid.NewGuid(), Child = simple
            };
            var validator = new ComplexClassValidator(new SimpleClassValidator()) as Core.Validators.IValidator <ComplexClass>;
            var result    = await validator?.ValidateAsync(complex, ComplexClassValidator.RuleSetName);

            validator.Should().NotBeNull("because the base validator should impleent the base IValidator<T> contract");
            result.Should().NotBeNull("because a set should be returned even for valid objects");
            result.Should().HaveCount(0, "because a valid object should have no errors");
        }
Beispiel #45
0
            private void returns_original_parameters_as_string_when_GenericWithRepeatedGenericParameterReturnOriginalParametersAsString_is_called()
            {
                Execute(() =>
                {
                    var instance = new InterceptGenericMethodsClass <int, string>();
                    var p1       = 1;
                    var p2       = new SimpleStruct(1);
                    var p3       = new SimpleClass(1);
                    var expected = Helper.AsString(p1, p2, p3);

                    var result = instance.GenericWithRepeatedGenericParameterReturnOriginalParametersAsString <SimpleClass, SimpleStruct>(p1, p2, p3);

                    Assert.Equal(expected, result);
                });
            }
        public void AfterConstructionOf_PropertySetter_NullValue()
        {
            var builder = new Builder(1)
                          .For <SimpleClass>()
                          .Set(c => c.StringProperty, (string)null)
                          .Set(c => c.StringField, (string)null)
            ;
            SimpleClass newClass = null;

            Assert.DoesNotThrow(() => newClass = builder.Build <SimpleClass>());

            Assert.IsNotNull(newClass);
            Assert.IsNull(newClass.StringProperty);
            Assert.IsNull(newClass.StringField);
        }
        public void Run()
        {
            Type         t     = typeof(SimpleClass);
            BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public |
                                 BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;

            MemberInfo[] members = t.GetMembers(flags);
            Console.WriteLine($"Type {t.Name} has {members.Length} members: ");
            foreach (var member in members)
            {
                string access = "";
                string stat   = "";
                var    method = member as MethodBase;
                if (method != null)
                {
                    if (method.IsPublic)
                    {
                        access = " Public";
                    }
                    else if (method.IsPrivate)
                    {
                        access = " Private";
                    }
                    else if (method.IsFamily)
                    {
                        access = " Protected";
                    }
                    else if (method.IsAssembly)
                    {
                        access = " Internal";
                    }
                    else if (method.IsFamilyOrAssembly)
                    {
                        access = " Protected Internal ";
                    }
                    if (method.IsStatic)
                    {
                        stat = " Static";
                    }
                }
                var output = $"{member.Name} ({member.MemberType}): {access}{stat}, Declared by {member.DeclaringType}";
                Console.WriteLine(output);
            }

            SimpleClass sc = new SimpleClass();

            Console.WriteLine(sc.ToString());
        }
        public void Store_two_objects_one_commited_one_reverted()
        {
            var a = new SimpleClass();

            a.Name  = "abc";
            a.Value = 3;

            var b = new SimpleClass();

            b.Name  = "def";
            b.Value = 6;

            using (var odb = OdbFactory.Open(DbName))
            {
                odb.Store(a);
                odb.Commit();
                odb.Store(b);
                odb.Rollback();
            }

            using (var odb = OdbFactory.Open(DbName))
            {
                var items = odb.QueryAndExecute <SimpleClass>();
                Assert.That(items.Count, Is.EqualTo(1));

                var item = items.GetFirst();
                Assert.That(item.Name, Is.EqualTo("abc"));
                Assert.That(item.Value, Is.EqualTo(3));
            }

            using (var odb = OdbFactory.Open(DbName))
            {
                var item = odb.QueryAndExecute <SimpleClass>().GetFirst();
                item.Name = "ghi";
                odb.Store(item);
                odb.Commit();
                item.Value = 9;
                odb.Store(item);
                odb.Rollback();
            }

            using (var odb = OdbFactory.Open(DbName))
            {
                var item = odb.QueryAndExecute <SimpleClass>().GetFirst();
                Assert.That(item.Name, Is.EqualTo("ghi"));
                Assert.That(item.Value, Is.EqualTo(3));
            }
        }
Beispiel #49
0
        public void ShouldPreserveIdentity()
        {
            var str     = "This is a string";
            var simple1 = new SimpleClass {
                Str = str
            };
            var simple2 = new SimpleClass {
                Str = str
            };
            var container = new SimpleContainer {
                First = simple1, Second = simple2
            };
            var copy = SerializerClone(container);

            Assert.AreSame(copy.First.Str, copy.Second.Str);
        }
        public void ShouldRecordMasterListKeys()
        {
            SimpleClass[] masterList = new SimpleClass[19];

            using (mocks.Record())
                objectBuilder.Expect(x => x.Construct(Arg <int> .Is.Anything)).Return(new SimpleClass()).Repeat.Times(2);

            declaration = new RangeDeclaration <SimpleClass>(listBuilderImpl, objectBuilder, 9, 10);
            declaration.Construct();

            declaration.AddToMaster(masterList);

            Assert.That(declaration.MasterListAffectedIndexes.Count, Is.EqualTo(2));
            Assert.That(declaration.MasterListAffectedIndexes[0], Is.EqualTo(9));
            Assert.That(declaration.MasterListAffectedIndexes[1], Is.EqualTo(10));
        }
Beispiel #51
0
    public static SimpleClass delegate_test_class(SimpleClass ss)
    {
        if (ss == null)
        {
            return(null);
        }

        if (!(!ss.a && ss.b && !ss.c && ss.d == "TEST"))
        {
            return(null);
        }

        SimpleClass res = ss;

        return(res);
    }
        public void Log4Net_OnException_PrintsException()
        {
            SimpleClass s = new SimpleClass();

            try
            {
                s.MethodThrowsException();
            }
            catch
            {
            }

            string output = OutputString.ToString();

            StringAssert.Contains("An exception occurred:\nSystem.Exception", output);
        }
        public void ShouldRecordMasterListKeys()
        {
            SimpleClass[] masterList = new SimpleClass[19];


            objectBuilder.BuilderSettings.Returns(builderSettings);
            objectBuilder.Construct(Arg.Any <int>()).Returns(new SimpleClass());

            declaration = new GlobalDeclaration <SimpleClass>(listBuilderImpl, objectBuilder);
            declaration.Construct();

            declaration.AddToMaster(masterList);
            declaration.MasterListAffectedIndexes.Count.ShouldBe(2);
            declaration.MasterListAffectedIndexes[0].ShouldBe(0);
            declaration.MasterListAffectedIndexes[1].ShouldBe(1);
        }
            private void returns_intercepted_parameters_as_string_when_ReturnInterceptedParametersAsString_is_called()
            {
                Execute(() =>
                {
                    var instance      = new InterceptGenericMethodsWithConstraintsClass <InheritsFromSimpleClass, SimpleClass>();
                    var interceptedP1 = new InheritsFromSimpleClass(2);
                    var interceptedP2 = new SimpleClass(2);
                    var expected      = Helper.AsString(interceptedP1, interceptedP2);

                    var originalP1 = new InheritsFromSimpleClass(1);
                    var originalP2 = new SimpleClass(1);
                    var result     = instance.ReturnInterceptedParametersAsString(originalP1, originalP2);

                    Assert.Equal(expected, result);
                });
            }
Beispiel #55
0
	public static int delegate_test_class_byref (ref SimpleClass ss)
	{
		if (ss == null)
			return -1;

		if (!ss.a && ss.b && !ss.c && ss.d == "TEST") {
			ss.a = true;
			ss.b = false;
			ss.c = true;
			ss.d = "RES";

			return 0;
		}

		return 1;
	}
            private void returns_original_parameters_as_string_when_GenericReturnOriginalParametersAsString_is_called()
            {
                Execute(() =>
                {
                    var instance = new InterceptGenericMethodsWithConstraintsClass <InheritsFromSimpleClass, SimpleClass>();
                    var p1       = new InheritsFromSimpleClass(1);
                    var p2       = new SimpleClass(1);
                    var p3       = new SimpleStruct(1);
                    var p4       = new SimpleClass(1);
                    var expected = Helper.AsString(p1, p2, p3, p4);

                    var result = instance.GenericReturnOriginalParametersAsString <SimpleStruct, SimpleClass>(p1, p2, p3, p4);

                    Assert.Equal(expected, result);
                });
            }
Beispiel #57
0
        public void ItemGet()
        {
            ViewFactory <SimpleClass> factory = ViewFactory <SimpleClass> .IList();

            IList <SimpleClass> list = factory.List;

            list.Add(new SimpleClass(100, "aaa", new DateTime(1970, 1, 1)));
            SimpleClass bbb = new SimpleClass(80, "bbb", new DateTime(1980, 12, 12));

            list.Add(bbb);
            list.Add(new SimpleClass(60, "ccc", new DateTime(1975, 6, 6)));

            SimpleClass item = factory.View[1];

            Assert.AreEqual(bbb, item);
        }
 public void TestExecuteMethodDoesntExist()
 {
     //---------------Set up test pack-------------------
     SimpleClass simpleClass = new SimpleClass();
     //---------------Execute Test ----------------------
     try
     {
         ReflectionUtilities.ExecuteMethod(simpleClass, "InvalidMethod");
         Assert.Fail("Expected to throw an Exception");
     }
         //---------------Test Result -----------------------
     catch (Exception ex)
     {
         StringAssert.Contains("Virtual method call for 'InvalidMethod' does not exist for object of type 'SimpleClass'", ex.Message);
     }
 }
 public void Test_SetPropertyValue_ThatThrowsError_ShouldRethrowError()
 {
     //---------------Set up test pack-------------------
     SimpleClass simpleClass = new SimpleClass();
     //---------------Execute Test ----------------------
     try
     {
         ReflectionUtilities.SetPropertyValue(simpleClass, "MyPropWithException", true);
         Assert.Fail("Expected to throw an HabaneroApplicationException");
     }
         //---------------Test Result -----------------------
     catch (HabaneroApplicationException ex)
     {
         StringAssert.Contains("Error setting public property 'MyPropWithException' for object of type 'SimpleClass'", ex.Message);
         Assert.IsInstanceOf<ArgumentNullException>(ex.InnerException);
         StringAssert.Contains("Value cannot be null", ex.InnerException.Message);
     }
 }
        public void MutationTest()
        {
            var obj = new SimpleClass();
            var generator = new Generator<SimpleClass>();
            CodeExpression<SimpleClass> tree = generator.BuildRandomExpressionTree();

            Trace.WriteLine("Vor der Mutation");
            Trace.WriteLine("----------------");
            Trace.WriteLine("");
            Trace.WriteLine(tree);

            generator.Mutate(ref tree);

            Trace.WriteLine("");
            Trace.WriteLine("Nach der Mutation");
            Trace.WriteLine("-----------------");
            Trace.WriteLine("");
            Trace.WriteLine(tree);
        }