public void ExpressionEntityTypeAnonymizer_Constants_ReferenceEquality()
        {
            var q = new Qux {
                Baz = 42
            };
            var t = new Tuple <Qux, Qux>(q, q);

            var eta = new ExpressionEntityTypeAnonymizer();

            var res = eta.Apply(Expression.Constant(t));

            Assert.IsNotNull(res);
            Assert.IsTrue(res.Type.IsGenericType);
            Assert.AreEqual(typeof(Tuple <,>), res.Type.GetGenericTypeDefinition());

            var a1 = res.Type.GetGenericArguments()[0];
            var a2 = res.Type.GetGenericArguments()[1];

            Assert.AreEqual(a1, a2);

            Assert.AreEqual(ExpressionType.Constant, res.NodeType);
            var c = (ConstantExpression)res;
            var o = c.Value;

            var t1 = res.Type.GetProperty("Item1").GetValue(o);
            var t2 = res.Type.GetProperty("Item2").GetValue(o);

            Assert.AreSame(t1, t2);

            Assert.AreEqual(42, t1.GetType().GetProperty("baz").GetValue(t1));
        }
        public void ExpressionSlimEntityTypeRecordizer_Constants_Equal()
        {
            var q = new Qux {
                Baz = 42
            };
            var t = new Tuple <Qux, Qux>(q, q);

            var res = Roundtrip(Expression.Constant(t));

            Assert.IsNotNull(res);
            Assert.IsTrue(res.Type.IsGenericType);
            Assert.AreEqual(typeof(Tuple <,>), res.Type.GetGenericTypeDefinition());

            var a1 = res.Type.GetGenericArguments()[0];
            var a2 = res.Type.GetGenericArguments()[1];

            Assert.AreEqual(a1, a2);

            Assert.AreEqual(ExpressionType.Constant, res.NodeType);
            var c = (ConstantExpression)res;
            var o = c.Value;

            var t1 = res.Type.GetProperty("Item1").GetValue(o);
            var t2 = res.Type.GetProperty("Item2").GetValue(o);

            Assert.IsTrue(ObjectComparator.CreateInstance().Equals(t1, t2));

            Assert.AreEqual(42, t1.GetType().GetProperty("baz").GetValue(t1));
        }
예제 #3
0
 public static extern void root(ref Foo_u32 a,
                                ref Baz_i32 b,
                                ref Taz c,
                                Tazz d,
                                ref Tazzz e,
                                ref Tazzzz f,
                                ref Qux g);
예제 #4
0
 public void TestUncompilableCode()
 {
     new ForceCreationOfInterface().Dispose();
     new InheritsProtectedVirtualFromSecondaryBase().Dispose();
     new InheritanceBuffer().Dispose();
     new HasProtectedVirtual().Dispose();
     new Proprietor(5).Dispose();
     using (var foo = new Foo())
     {
         var isNoParams = foo.IsNoParams;
         foo.SetNoParams();
     }
     // TODO: remove when the bug in question is fixed
     if (Type.GetType("Mono.Runtime") != null)
     {
         Assert.Fail("Crashes with Mono because of a problem with marshalling arrays: https://gist.github.com/tritao/7e62c71ffe57d6bc326e");
     }
     else
     {
         using (var qux = new Qux())
         {
             new Bar(qux).Dispose();
         }
     }
 }
예제 #5
0
 public void TestUncompilableCode()
 {
     new ForceCreationOfInterface().Dispose();
     new InheritsProtectedVirtualFromSecondaryBase().Dispose();
     new InheritanceBuffer().Dispose();
     new HasProtectedVirtual().Dispose();
     new Proprietor(5).Dispose();
     using (var testOverrideFromSecondaryBase = new TestOverrideFromSecondaryBase())
     {
         testOverrideFromSecondaryBase.function();
         var ok = false;
         testOverrideFromSecondaryBase.function(ref ok);
         var property = testOverrideFromSecondaryBase.property;
         testOverrideFromSecondaryBase.VirtualMember();
     }
     using (var foo = new Foo())
     {
         var isNoParams = foo.IsNoParams;
         foo.SetNoParams();
     }
     using (var hasOverride = new HasOverrideOfHasPropertyWithDerivedType())
         hasOverride.CauseRenamingError();
     using (var qux = new Qux())
     {
         new Bar(qux).Dispose();
     }
     using (ComplexType complexType = TestFlag.Flag1)
     {
     }
     using (var typeMappedWithOperator = new TypeMappedWithOperator())
     {
         int i = typeMappedWithOperator | 5;
     }
 }
예제 #6
0
 public void TestUncompilableCode()
 {
     new ForceCreationOfInterface().Dispose();
     new InheritsProtectedVirtualFromSecondaryBase().Dispose();
     new InheritanceBuffer().Dispose();
     new HasProtectedVirtual().Dispose();
     new Proprietor(5).Dispose();
     using (var testOverrideFromSecondaryBase = new TestOverrideFromSecondaryBase())
     {
         testOverrideFromSecondaryBase.function();
         var ok = false;
         testOverrideFromSecondaryBase.function(ref ok);
         var property = testOverrideFromSecondaryBase.property;
         testOverrideFromSecondaryBase.VirtualMember();
     }
     using (var foo = new Foo())
     {
         var isNoParams = foo.IsNoParams;
         foo.SetNoParams();
     }
     using (var hasOverride = new HasOverrideOfHasPropertyWithDerivedType())
         hasOverride.CauseRenamingError();
     using (var qux = new Qux())
     {
         new Bar(qux).Dispose();
     }
     using (ComplexType complexType = TestFlag.Flag1)
     {
     }
     using (var typeMappedWithOperator = new TypeMappedWithOperator())
     {
         int i = typeMappedWithOperator | 5;
     }
 }
예제 #7
0
    public void TestProperties()
    {
        var proprietor = new Proprietor();

        Assert.That(proprietor.Parent, Is.EqualTo(0));
        proprietor.Value = 20;
        Assert.That(proprietor.Value, Is.EqualTo(20));
        proprietor.Prop = 50;
        Assert.That(proprietor.Prop, Is.EqualTo(50));
        using (var qux = new Qux())
        {
            using (var p = new P((IQux)qux)
            {
                Value = 20
            })
            {
                Assert.That(p.Value, Is.EqualTo(30));
                p.Prop = 50;
                Assert.That(p.Prop, Is.EqualTo(150));

                using (var complexType = new ComplexType())
                {
                    p.ComplexType = complexType;
                    Assert.That(p.ComplexType.Check(), Is.EqualTo(5));
                }

                Assert.That(p.Test, Is.True);
                Assert.That(p.IsBool, Is.False);
            }
        }
    }
예제 #8
0
    public Foo(T obj, Qux qux)
    {
        var baz = obj as Baz;
        var bar = obj as Bar;

        Active      = baz != null && baz.Active || bar != null && bar.Active;
        this.FooQux = string.Format("{0} - {1}", qux.ID, qux.Name);
    }
        void InitScene()
        {
            _foo = new GameObject().AddComponent <Foo>();

            _bar  = _foo.gameObject.AddComponent <Bar>();
            _qux1 = _foo.gameObject.AddComponent <Qux>();
            _qux2 = _foo.gameObject.AddComponent <Qux>();
        }
        public void WhenTheTypesAreUnrelatedButTheSourceTypeImlementsIConvertibleReturnsAFuncThatReturnsTheResultOfACallToConvertChangeType()
        {
            var f = ConvertFuncFactory.GetConvertFunc(typeof(Qux), typeof(Foo));

            var qux = new Qux();

            Assert.That(f(qux), Is.InstanceOf<Foo>());
        }
예제 #11
0
        public void WhenTheTypesAreUnrelatedButTheSourceTypeImlementsIConvertibleReturnsAFuncThatReturnsTheResultOfACallToConvertChangeType()
        {
            var f = ConvertFuncFactory.GetConvertFunc(typeof(Qux), typeof(Foo));

            var qux = new Qux();

            Assert.That(f(qux), Is.InstanceOf <Foo>());
        }
예제 #12
0
        public void Setup1()
        {
            _foo = new GameObject().AddComponent <Foo>();

            _bar  = _foo.gameObject.AddComponent <Bar>();
            _qux1 = _foo.gameObject.AddComponent <Qux>();
            _qux2 = _foo.gameObject.AddComponent <Qux>();
        }
        public void WhenTheTypesAreUnrelatedButTheSourceTypeImplementsIConvertibleReturnsAFuncThatReturnsTheResultOfACallToConvertChangeButWhenThatCallThrowsAnExceptionReturnTheInputObject()
        {
            var f = ConvertFuncFactory.GetConvertFunc(typeof(Qux), typeof(Bar));

            var qux = new Qux();

            Assert.That(f(qux), Is.InstanceOf<Qux>());
        }
예제 #14
0
        public void WhenTheTypesAreUnrelatedButTheSourceTypeImplementsIConvertibleReturnsAFuncThatReturnsTheResultOfACallToConvertChangeButWhenThatCallThrowsAnExceptionReturnTheInputObject()
        {
            var f = ConvertFuncFactory.GetConvertFunc(typeof(Qux), typeof(Bar));

            var qux = new Qux();

            Assert.That(f(qux), Is.InstanceOf <Qux>());
        }
예제 #15
0
 public void TestFixedArrays()
 {
     Qux qux = new Qux(null);
     var array = new[] { 1, 2, 3 };
     qux.Array = array;
     for (int i = 0; i < qux.Array.Length; i++)
         Assert.That(array[i], Is.EqualTo(qux.Array[i]));
 }
예제 #16
0
    public void TestUncompilableCode()
    {
#pragma warning disable 0168 // warning CS0168: The variable `foo' is declared but never used
#pragma warning disable 0219 // warning CS0219: The variable `foo' is assigned but its value is never used

        ALLCAPS_UNDERSCORES a;
        using (var testRenaming = new TestRenaming())
        {
            testRenaming.name();
            testRenaming.Name();
            testRenaming.Property.GetHashCode();
        }
        new ForceCreationOfInterface().Dispose();
        new InheritsProtectedVirtualFromSecondaryBase().Dispose();
        new InheritanceBuffer().Dispose();
        new HasProtectedVirtual().Dispose();
        new Proprietor(5).Dispose();
        using (var testOverrideFromSecondaryBase = new TestOverrideFromSecondaryBase())
        {
            testOverrideFromSecondaryBase.function();
            var ok = false;
            testOverrideFromSecondaryBase.function(ref ok);
            var property = testOverrideFromSecondaryBase.property;
            testOverrideFromSecondaryBase.VirtualMember();
        }
        using (var foo = new Foo())
        {
            var isNoParams = foo.IsNoParams;
            foo.SetNoParams();
            foo.Width = 5;
            using (var hasSecondaryBaseWithAbstractWithDefaultArg = new HasSecondaryBaseWithAbstractWithDefaultArg())
            {
                hasSecondaryBaseWithAbstractWithDefaultArg.Abstract();
                hasSecondaryBaseWithAbstractWithDefaultArg.AbstractWithNoDefaultArg(foo);
            }
        }
        using (var hasOverride = new HasOverrideOfHasPropertyWithDerivedType())
            hasOverride.CauseRenamingError();
        using (var qux = new Qux())
        {
            new Bar(qux).Dispose();
        }
        using (ComplexType complexType = TestFlag.Flag1)
        {
        }
        using (var typeMappedWithOperator = new TypeMappedWithOperator())
        {
            int i = typeMappedWithOperator | 5;
        }
        using (Base <int> @base = new DerivedFromSpecializationOfUnsupportedTemplate())
        {
        }

        CSharp.CSharp.FunctionInsideInlineNamespace();

#pragma warning restore 0168
#pragma warning restore 0219
    }
예제 #17
0
    public void TestFixedArrays()
    {
        Qux qux   = new Qux((Foo)null);
        var array = new[] { 1, 2, 3 };

        qux.Array = array;
        for (int i = 0; i < qux.Array.Length; i++)
        {
            Assert.That(array[i], Is.EqualTo(qux.Array[i]));
        }
    }
예제 #18
0
        public void TestLazyInstanceInjectorFail()
        {
            Qux.WasInjected = false;

            var qux = new Qux();

            Container.BindInstance(qux);

            Assert.That(!Qux.WasInjected);
            Initialize();
            Assert.That(!Qux.WasInjected);
        }
예제 #19
0
 public bool Equals(Qux other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(other.Value == Value);
 }
예제 #20
0
        public void ClassicCpsRewriter_Basics13()
        {
            Expression <Func <string> > f = () => Qux.Bar <string>("Hello, CPS!");

            var r = new ClassicCpsRewriter().Rewrite(f);

            var res = default(string);

            r.Compile()(s => res = s);

            Assert.AreEqual("Hello, CPS!", res);
        }
            public void WhenTheObjectIsNotAnIDictionaryOfStringToAnythingCopiesPropertyValuesToNewDictionary()
            {
                var qux = new Qux
                {
                    Foo = new MyInt32(123)
                };

                var result = _converter.Convert(qux);

                Assert.That(result.Count, Is.EqualTo(1));
                Assert.That(result["Foo"], Is.InstanceOf <MyInt32>());
                Assert.That(result["Foo"].Value, Is.EqualTo(123));
            }
예제 #22
0
 public void TestCopyCtor()
 {
     Qux q1 = new Qux();
     for (int i = 0; i < q1.Array.Length; i++)
     {
         q1.Array[i] = i;
     }
     Qux q2 = new Qux(q1);
     for (int i = 0; i < q2.Array.Length; i++)
     {
         Assert.AreEqual(q1.Array[i], q2.Array[i]);
     }
 }
예제 #23
0
        public void SetExtendedPropertiesMapsStringOtherDictionaryItemsToExtendedProperties()
        {
            var logEntry = new LogEntry("Hello, world!", LogLevel.Error);

            var foo = new Qux(123);
            var bar = new Qux(456);

            logEntry.SetExtendedProperties(new Dictionary <string, Qux> {
                { nameof(foo), foo }, { nameof(bar), bar }
            });

            logEntry.ExtendedProperties[nameof(foo)].Should().BeSameAs(foo);
            logEntry.ExtendedProperties[nameof(bar)].Should().BeSameAs(bar);
        }
예제 #24
0
 public void TakeRefToPointerToObject()
 {
     using (Foo foo = new Foo {
         A = 25
     })
     {
         Foo returnedFoo = CSharp.CSharp.TakeReturnReferenceToPointer(foo);
         Assert.That(returnedFoo.A, Is.EqualTo(foo.A));
         using (Qux qux = new Qux())
         {
             Assert.That(qux.TakeReferenceToPointer(foo), Is.EqualTo(foo.A));
         }
     }
 }
        public IEnumerator TestLazyInstanceInjectorFail()
        {
            PreInstall();
            Qux.WasInjected = false;

            var qux = new Qux();

            Container.BindInstance(qux);

            Assert.That(!Qux.WasInjected);
            PostInstall();
            Assert.That(!Qux.WasInjected);
            yield break;
        }
        public void CanRoundTripClassWithReadOnlyPropertyOfTypeIEnumerableOfCustomType()
        {
            var qux = new Qux(new[] { new Corge { Value = "abc" }, new Corge { Value = "xyz" } });

            var serializer = new XmlSerializer<Qux>(o => o.Indent());

            var xml = serializer.Serialize(qux);

            var roundTrip = serializer.Deserialize(xml);

            Assert.That(roundTrip.Corges.Count(), Is.EqualTo(qux.Corges.Count()));
            Assert.That(roundTrip.Corges.First().Value, Is.EqualTo(qux.Corges.First().Value));
            Assert.That(roundTrip.Corges.Last().Value, Is.EqualTo(qux.Corges.Last().Value));
        }
예제 #27
0
    public void TestCopyCtor()
    {
        Qux q1 = new Qux();

        for (int i = 0; i < q1.Array.Length; i++)
        {
            q1.Array[i] = i;
        }
        Qux q2 = new Qux(q1);

        for (int i = 0; i < q2.Array.Length; i++)
        {
            Assert.AreEqual(q1.Array[i], q2.Array[i]);
        }
    }
예제 #28
0
    public void TestUncompilableCode()
    {
        ALLCAPS_UNDERSCORES a;

        using (var testRenaming = new TestRenaming())
        {
            testRenaming.name();
            testRenaming.Name();
            testRenaming.Property.GetHashCode();
        }
        new ForceCreationOfInterface().Dispose();
        new InheritsProtectedVirtualFromSecondaryBase().Dispose();
        new InheritanceBuffer().Dispose();
        new HasProtectedVirtual().Dispose();
        new Proprietor(5).Dispose();
        using (var testOverrideFromSecondaryBase = new TestOverrideFromSecondaryBase())
        {
            testOverrideFromSecondaryBase.function();
            var ok = false;
            testOverrideFromSecondaryBase.function(ref ok);
            var property = testOverrideFromSecondaryBase.property;
            testOverrideFromSecondaryBase.VirtualMember();
        }
        using (var foo = new Foo())
        {
            var isNoParams = foo.IsNoParams;
            foo.SetNoParams();
            foo.Width = 5;
            using (var hasSecondaryBaseWithAbstractWithDefaultArg = new HasSecondaryBaseWithAbstractWithDefaultArg())
            {
                hasSecondaryBaseWithAbstractWithDefaultArg.Abstract();
                hasSecondaryBaseWithAbstractWithDefaultArg.AbstractWithNoDefaultArg(foo);
            }
        }
        using (var hasOverride = new HasOverrideOfHasPropertyWithDerivedType())
            hasOverride.CauseRenamingError();
        using (var qux = new Qux())
        {
            new Bar(qux).Dispose();
        }
        using (ComplexType complexType = TestFlag.Flag1)
        {
        }
        using (var typeMappedWithOperator = new TypeMappedWithOperator())
        {
            int i = typeMappedWithOperator | 5;
        }
    }
예제 #29
0
        public void TestInstanceMethodHandler()
        {
            Container.DeclareSignal <FooSignal>();

            var qux = new Qux();

            Container.BindSignal <FooSignal>()
            .ToMethod <Qux>(x => x.OnFoo).From(b => b.FromInstance(qux));
            Container.ResolveRoots();

            var signalBus = Container.Resolve <SignalBus>();

            Assert.That(!qux.HasRecievedSignal);
            signalBus.Fire <FooSignal>();
            Assert.That(qux.HasRecievedSignal);
        }
예제 #30
0
        public void DeleteOwner()
        {
            ISession s = OpenSession();
            Qux      q = new Qux();

            s.Save(q);
            Fum  f1   = new Fum(FumKey("f1"));
            Fum  f2   = new Fum(FumKey("f2"));
            ISet dict = new HashedSet();

            dict.Add(f1);
            dict.Add(f2);
            IList list = new ArrayList();

            list.Add(f1);
            list.Add(f2);
            f1.FumString = "f1";
            f2.FumString = "f2";
            q.Fums       = dict;
            q.MoreFums   = list;
            s.Save(f1);
            s.Save(f2);
            s.Flush();
            s.Close();

            s = OpenSession();
            ITransaction t = s.BeginTransaction();

            q = (Qux)s.Load(typeof(Qux), q.Key, LockMode.Upgrade);
            s.Lock(q, LockMode.Upgrade);
            s.Delete(q);
            t.Commit();
            s.Close();

            s    = OpenSession();
            t    = s.BeginTransaction();
            list = s.CreateQuery("from fum in class NHibernate.DomainModel.Fum where not fum.FumString='FRIEND'").List();
            Assert.AreEqual(2, list.Count, "deleted owner");
            s.Lock(list[0], LockMode.Upgrade);
            s.Lock(list[1], LockMode.Upgrade);
            foreach (object obj in list)
            {
                s.Delete(obj);
            }
            t.Commit();
            s.Close();
        }
예제 #31
0
 public void TestUncompilableCode()
 {
     ALLCAPS_UNDERSCORES a;
     using (var testRenaming = new TestRenaming())
     {
         testRenaming.name();
         testRenaming.Name();
         testRenaming.Property.GetHashCode();
     }
     new ForceCreationOfInterface().Dispose();
     new InheritsProtectedVirtualFromSecondaryBase().Dispose();
     new InheritanceBuffer().Dispose();
     new HasProtectedVirtual().Dispose();
     new Proprietor(5).Dispose();
     using (var testOverrideFromSecondaryBase = new TestOverrideFromSecondaryBase())
     {
         testOverrideFromSecondaryBase.function();
         var ok = false;
         testOverrideFromSecondaryBase.function(ref ok);
         var property = testOverrideFromSecondaryBase.property;
         testOverrideFromSecondaryBase.VirtualMember();
     }
     using (var foo = new Foo())
     {
         var isNoParams = foo.IsNoParams;
         foo.SetNoParams();
         foo.Width = 5;
         using (var hasSecondaryBaseWithAbstractWithDefaultArg = new HasSecondaryBaseWithAbstractWithDefaultArg())
         {
             hasSecondaryBaseWithAbstractWithDefaultArg.Abstract();
             hasSecondaryBaseWithAbstractWithDefaultArg.AbstractWithNoDefaultArg(foo);
         }
     }
     using (var hasOverride = new HasOverrideOfHasPropertyWithDerivedType())
         hasOverride.CauseRenamingError();
     using (var qux = new Qux())
     {
         new Bar(qux).Dispose();
     }
     using (ComplexType complexType = TestFlag.Flag1)
     {
     }
     using (var typeMappedWithOperator = new TypeMappedWithOperator())
     {
         int i = typeMappedWithOperator | 5;
     }
 }
예제 #32
0
        public async Task DeleteOwnerAsync()
        {
            ISession s = OpenSession();
            Qux      q = new Qux();

            await(s.SaveAsync(q));
            Fum f1 = new Fum(FumKey("f1"));
            Fum f2 = new Fum(FumKey("f2"));

            f1.FumString = "f1";
            f2.FumString = "f2";
            q.Fums       = new HashSet <Fum> {
                f1, f2
            };
            q.MoreFums = new List <Fum> {
                f1, f2
            };
            await(s.SaveAsync(f1));
            await(s.SaveAsync(f2));
            await(s.FlushAsync());
            s.Close();

            s = OpenSession();
            ITransaction t = s.BeginTransaction();

            q = (Qux)await(s.LoadAsync(typeof(Qux), q.Key, LockMode.Upgrade));
            await(s.LockAsync(q, LockMode.Upgrade));
            await(s.DeleteAsync(q));
            await(t.CommitAsync());
            s.Close();

            s = OpenSession();
            t = s.BeginTransaction();
            var list = await(s.CreateQuery("from fum in class NHibernate.DomainModel.Fum where not fum.FumString='FRIEND'").ListAsync());

            Assert.AreEqual(2, list.Count, "deleted owner");
            await(s.LockAsync(list[0], LockMode.Upgrade));
            await(s.LockAsync(list[1], LockMode.Upgrade));
            foreach (object obj in list)
            {
                await(s.DeleteAsync(obj));
            }
            await(t.CommitAsync());
            s.Close();
        }
        public void CanRoundTripClassWithReadOnlyPropertyOfTypeIEnumerableOfCustomType()
        {
            var qux = new Qux(new[] { new Corge {
                                          Value = "abc"
                                      }, new Corge {
                                          Value = "xyz"
                                      } });

            var serializer = new XmlSerializer <Qux>(o => o.Indent());

            var xml = serializer.Serialize(qux);

            var roundTrip = serializer.Deserialize(xml);

            Assert.That(roundTrip.Corges.Count(), Is.EqualTo(qux.Corges.Count()));
            Assert.That(roundTrip.Corges.First().Value, Is.EqualTo(qux.Corges.First().Value));
            Assert.That(roundTrip.Corges.Last().Value, Is.EqualTo(qux.Corges.Last().Value));
        }
예제 #34
0
    public Foo(T obj, Qux qux)
    {
        //this.Active = obj.Active;
        var fooProps = GetType().GetProperties().ToList();
        var tProps   = typeof(T).GetProperties()
                       .Where(p =>
        {
            var w = fooProps.FirstOrDefault(f => f.Name == p.Name);
            return(w != null);
        }).ToList();

        foreach (var propertyInfo in tProps)
        {
            var val = propertyInfo.GetValue(obj);
            fooProps.First(e => e.Name == propertyInfo.Name).SetValue(this, val);
        }
        this.FooQux = string.Format("{0} - {1}", qux.ID, qux.Name);
    }
    public Foo(T obj, IEnumerable <Qux> quxs, string quxPropName)
    {
        var fooProps = GetType().GetProperties().ToList();
        var tProps   = typeof(T).GetProperties()
                       .Where(p =>
        {
            var w = fooProps.FirstOrDefault(f => f.Name == p.Name);
            return(w != null);
        }).ToList();

        foreach (var propertyInfo in tProps)
        {
            var val = propertyInfo.GetValue(obj, null);
            fooProps.First(e => e.Name == propertyInfo.Name).SetValue(this, val, null);
        }
        int id  = (int)typeof(T).GetProperty(quxPropName).GetValue(obj, null);
        Qux qux = quxs.Single(q => q.ID == id);

        this.FooQux = string.Format("{0} - {1}", qux.ID, qux.Name);
    }
예제 #36
0
        public void TestExceptions()
        {
            var qux1 = new Qux();
            var qux2 = new Qux();

            try
            {
                using (var block = DisposeBlock.Spawn())
                {
                    block.Add(qux1);
                    block.Add(qux2);
                    throw new Exception();
                }
            }
            catch
            {
            }

            Assert.That(qux1.WasDisposed);
            Assert.That(qux2.WasDisposed);
        }
예제 #37
0
        public void CompositeIDCollections()
        {
            ISession s    = OpenSession();
            Fum      fum1 = new Fum(FumKey("fum1"));
            Fum      fum2 = new Fum(FumKey("fum2"));

            fum1.FumString = "fee fo fi";
            fum2.FumString = "fee fo fi";
            s.Save(fum1);
            s.Save(fum2);
            Qux q = new Qux();

            s.Save(q);
            ISet  dict = new HashedSet();
            IList list = new ArrayList();

            dict.Add(fum1);
            dict.Add(fum2);
            list.Add(fum1);
            q.Fums        = dict;
            q.MoreFums    = list;
            fum1.QuxArray = new Qux[] { q };
            s.Flush();
            s.Close();

            s = OpenSession();
            q = (Qux)s.Load(typeof(Qux), q.Key);
            Assert.AreEqual(2, q.Fums.Count, "collection of fums");
            Assert.AreEqual(1, q.MoreFums.Count, "collection of fums");
            Assert.AreSame(q, ((Fum)q.MoreFums[0]).QuxArray[0], "unkeyed composite id collection");
            IEnumerator enumer = q.Fums.GetEnumerator();

            enumer.MoveNext();
            s.Delete((Fum)enumer.Current);
            enumer.MoveNext();
            s.Delete((Fum)enumer.Current);
            s.Delete(q);
            s.Flush();
            s.Close();
        }
예제 #38
0
    public void TestProperties()
    {
        var proprietor = new Proprietor();
        Assert.That(proprietor.Parent, Is.EqualTo(0));
        proprietor.Value = 20;
        Assert.That(proprietor.Value, Is.EqualTo(20));
        proprietor.Prop = 50;
        Assert.That(proprietor.Prop, Is.EqualTo(50));
        using (var qux = new Qux())
        {
            using (var p = new P((IQux) qux) { Value = 20 })
            {
                Assert.That(p.Value, Is.EqualTo(30));
                p.Prop = 50;
                Assert.That(p.Prop, Is.EqualTo(150));

                using (var complexType = new ComplexType())
                {
                    p.ComplexType = complexType;
                    Assert.That(p.ComplexType.Check(), Is.EqualTo(5));
                }

                Assert.That(p.Test, Is.True);
                Assert.That(p.IsBool, Is.False);
            }
        }
    }
        public void ConditionalCall_Compile_Ref()
        {
            var p = Expression.Parameter(typeof(Qux));
            var q = new Qux();

            var m1 = CSharpExpression.ConditionalCall(p, typeof(Qux).GetMethod("X"));
            var f1 = Expression.Lambda<Func<Qux, int?>>(m1, p);
            var d1 = f1.Compile();

            Assert.AreEqual(42, d1(q));
            Assert.IsNull(d1(null));

            var m2 = CSharpExpression.ConditionalCall(p, typeof(Qux).GetMethod("N"));
            var f2 = Expression.Lambda<Func<Qux, int?>>(m2, p);
            var d2 = f2.Compile();

            Assert.AreEqual(42, d2(q));
            Assert.IsNull(d2(null));

            var m3 = CSharpExpression.ConditionalCall(p, typeof(Qux).GetMethod("S"));
            var f3 = Expression.Lambda<Func<Qux, string>>(m3, p);
            var d3 = f3.Compile();

            Assert.AreEqual("bar", d3(q));
            Assert.IsNull(d3(null));

            var m4 = CSharpExpression.ConditionalCall(p, typeof(Qux).GetMethod("V"));
            var f4 = Expression.Lambda<Action<Qux>>(m4, p);
            var d4 = f4.Compile();

            d4(q); // does not throw
        }
            public void WhenTheObjectIsNotAnIDictionaryOfStringToAnythingCopiesPropertyValuesToNewDictionary()
            {
                var qux = new Qux
                {
                    Foo = new MyInt32(123)
                };

                var result = _converter.Convert(qux);

                Assert.That(result.Count, Is.EqualTo(1));
                Assert.That(result["Foo"], Is.InstanceOf<MyInt32>());
                Assert.That(result["Foo"].Value, Is.EqualTo(123));
            }
예제 #41
0
 public void TestUncompilableCode()
 {
     new ForceCreationOfInterface().Dispose();
     new InheritsProtectedVirtualFromSecondaryBase().Dispose();
     new InheritanceBuffer().Dispose();
     new HasProtectedVirtual().Dispose();
     new Proprietor(5).Dispose();
     using (var foo = new Foo())
     {
         var isNoParams = foo.IsNoParams;
         foo.SetNoParams();
     }
     // TODO: remove when the bug in question is fixed
     if (Type.GetType("Mono.Runtime") != null)
     {
         Assert.Fail("Crashes with Mono because of a problem with marshalling arrays: https://gist.github.com/tritao/7e62c71ffe57d6bc326e");
     }
     else
     {
         using (var qux = new Qux())
         {
             new Bar(qux).Dispose();
         }
     }
 }
        public void ConditionalMember_Compile_Field_Ref()
        {
            var p = Expression.Parameter(typeof(Qux));
            var q = new Qux();

            var m1 = CSharpExpression.ConditionalField(p, "Y");
            var f1 = Expression.Lambda<Func<Qux, int?>>(m1, p);
            var d1 = f1.Compile();

            Assert.AreEqual(42, d1(q));
            Assert.IsNull(d1(null));

            var m2 = CSharpExpression.ConditionalField(p, "O");
            var f2 = Expression.Lambda<Func<Qux, int?>>(m2, p);
            var d2 = f2.Compile();

            Assert.AreEqual(42, d2(q));
            Assert.IsNull(d2(null));

            var m3 = CSharpExpression.ConditionalField(p, "T");
            var f3 = Expression.Lambda<Func<Qux, string>>(m3, p);
            var d3 = f3.Compile();

            Assert.AreEqual("bar", d3(q));
            Assert.IsNull(d3(null));
        }
예제 #43
0
 public void TestUncompilableCode()
 {
     new ForceCreationOfInterface().Dispose();
     new InheritsProtectedVirtualFromSecondaryBase().Dispose();
     new InheritanceBuffer().Dispose();
     new HasProtectedVirtual().Dispose();
     new Proprietor(5).Dispose();
     using (var foo = new Foo())
     {
         var isNoParams = foo.IsNoParams;
         foo.SetNoParams();
     }
     using (var hasOverride = new HasOverrideOfHasPropertyWithDerivedType())
         hasOverride.CauseRenamingError();
     // TODO: remove when the bug in question is fixed
     if (Type.GetType("Mono.Runtime") != null)
     {
         Assert.Fail("Crashes with Mono because of a problem with marshalling arrays: https://gist.github.com/tritao/7e62c71ffe57d6bc326e");
     }
     else
     {
         using (var qux = new Qux())
         {
             new Bar(qux).Dispose();
         }
     }
     using (ComplexType complexType = TestFlag.Flag1)
     {
     }
     using (var typeMappedWithOperator = new TypeMappedWithOperator())
     {
         int i = typeMappedWithOperator | 5;
     }
 }
예제 #44
0
 public bool Equals(Qux other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return other.Value == Value; }