Beispiel #1
0
    public ExampleClass2 RunAnotherFunction(string ExampleString)
    {
        ExampleClass2 instance = new ExampleClass2();

        instance.UpperString = ExampleString.ToUpper();
        return(instance);
    }
Beispiel #2
0
        public void BasicMap2T()
        {
            ICoffeeMapper mapper         = CreateMapperWithExampleMapping();
            ExampleClass1 exampleObject1 = GetObject1();
            ExampleClass2 result         = mapper.Map <ExampleClass1, ExampleClass2>(exampleObject1);

            Assert.AreEqual(exampleObject1.A, result.A);
        }
Beispiel #3
0
        public void Clean_should_clean_complex_classes()
        {
            var guid = Guid.NewGuid();

            var objectToClear1 = new ExampleClass()
            {
                Integer          = 5,
                IntegerCloneable = 5,
                Strign           = "text",
                StrignCloneable  = "text",
                Double           = 1.2,
                DoubleCloneable  = 1.2
            };

            var objectToClear2 = new ExampleClass2()
            {
                Integer          = 5,
                IntegerCloneable = 5
            };

            var objectToClear3 = new ExampleClass3()
            {
                Guid          = guid,
                GuidCloneable = guid
            };

            var objectToClear = new ExampleClass4()
            {
                Guid          = guid,
                GuidCloneable = guid,

                ExampleClass  = objectToClear1,
                ExampleClass2 = objectToClear2,
                ExampleClass3 = objectToClear3
            };

            CloneCleaner.Clean(objectToClear);

            Assert.That(objectToClear.Guid, Is.EqualTo(Guid.Empty));
            Assert.That(objectToClear.GuidCloneable, Is.EqualTo(guid));

            Assert.That(objectToClear.ExampleClass.Integer, Is.EqualTo(0));
            Assert.That(objectToClear.ExampleClass.IntegerCloneable, Is.EqualTo(5));
            Assert.That(objectToClear.ExampleClass.Strign, Is.Null);
            Assert.That(objectToClear.ExampleClass.StrignCloneable, Is.EqualTo("text"));
            Assert.That(objectToClear.ExampleClass.Double, Is.EqualTo(0));
            Assert.That(objectToClear.ExampleClass.DoubleCloneable, Is.EqualTo(1.2));

            Assert.That(objectToClear.ExampleClass2.Integer, Is.Null);
            Assert.That(objectToClear.ExampleClass2.IntegerCloneable, Is.EqualTo(5));

            Assert.That(objectToClear.ExampleClass3.Guid, Is.EqualTo(Guid.Empty));
            Assert.That(objectToClear.ExampleClass3.GuidCloneable, Is.EqualTo(guid));
        }
Beispiel #4
0
        public void BasicMap0T()
        {
            ICoffeeMapper mapper         = CreateMapperWithExampleMapping();
            ExampleClass1 exampleObject1 = GetObject1();
            object        objResult      = mapper.Map(exampleObject1, typeof(ExampleClass1), typeof(ExampleClass2));

            Assert.IsInstanceOfType(objResult, typeof(ExampleClass2));
            ExampleClass2 result = (ExampleClass2)objResult;

            Assert.AreEqual(exampleObject1.A, result.A);
        }
Beispiel #5
0
        public void Clean_should_set_null_for_nullable_type()
        {
            var objectToClear = new ExampleClass2()
            {
                Integer          = 5,
                IntegerCloneable = 5
            };

            CloneCleaner.Clean(objectToClear);

            Assert.That(objectToClear.Integer, Is.Null);
            Assert.That(objectToClear.IntegerCloneable, Is.EqualTo(5));
        }
Beispiel #6
0
        public void ClassMappingWithoutAutoDiscoversBasicProperty()
        {
            ClassMappingInstructionHolder mappingInstructions = new ClassMappingInstructionHolder();

            mappingInstructions.AddMapping <ExampleClass1, ExampleClass2>(new ClassMappingInstructionOptions {
                AutoAddPropertiesWithSameName = false
            });
            ICoffeeMapper mapper         = new CoffeeMapper(mappingInstructions);
            ExampleClass1 exampleObject1 = GetObject1();
            ExampleClass2 result         = mapper.Map <ExampleClass2>(exampleObject1);

            Assert.AreEqual(null, result.A);
        }
        public void TestCreateAction2b()
        {
            string  n   = nameof(ExampleClass2.Increment);
            Action2 inc = Accelerator.CreateAction2(typeof(ExampleClass2).GetMethod(n, new[] { typeof(int) }));

            var o = new ExampleClass2();

            o.Increment(1);
            Assert.AreEqual(1, o.Value);
            inc(o, 3);
            Assert.AreEqual(4, o.Value);
            inc(o, 11);
            Assert.AreEqual(15, o.Value);
        }
        public void TestCreateAction1b()
        {
            string  n   = nameof(ExampleClass2.Increment);
            Action1 inc = Accelerator.CreateAction1(typeof(ExampleClass2).GetMethod(n, Type.EmptyTypes));

            var o = new ExampleClass2();

            o.Increment();
            Assert.AreEqual(1, o.Value);
            inc(o);
            Assert.AreEqual(2, o.Value);
            inc(o);
            inc(o);
            Assert.AreEqual(4, o.Value);
        }
Beispiel #9
0
        public void TestCreateFunction1c()
        {
            string     n            = nameof(ExampleClass2.AppendTextAndGet);
            MethodInfo m            = typeof(ExampleClass2).GetMethod(n, Type.EmptyTypes);
            Func1      appendAndGet = Accelerator.CreateFunction1(m);

            var o = new ExampleClass2();

            Assert.AreEqual(null, o.Text);
            o.Text = "ABC";
            Assert.AreEqual("ABCtext", o.AppendTextAndGet());
            Assert.AreEqual("ABCtext", o.Text);
            Assert.AreEqual("ABCtexttext", appendAndGet(o));
            Assert.AreEqual("ABCtexttext", o.Text);
        }
Beispiel #10
0
        public void TestCreateFunction2a()
        {
            string     n         = nameof(ExampleClass2.IncrementAndGet);
            MethodInfo m         = typeof(ExampleClass2).GetMethod(n, new Type[] { typeof(int) });
            Func2      incAndGet = Accelerator.CreateFunction2(m);

            var o = new ExampleClass2();

            Assert.AreEqual(0, o.Value);
            Assert.AreEqual(1, o.IncrementAndGet(1));
            Assert.AreEqual(1, o.Value);
            Assert.AreEqual(3, (int)incAndGet(o, 2));
            Assert.AreEqual(3, o.Value);
            Assert.AreEqual(6, (int)incAndGet(o, 3));
            Assert.AreEqual(6, o.Value);
        }
Beispiel #11
0
 public ExampleClass(ExampleClass2 testClass2)
 {
     this.testClass2 = testClass2;
     myString        = "Constructed";
 }