コード例 #1
0
        public void GetPathTwoLevelsGenerics()
        {
            var intActuals1  = PropertyPathParser.GetPath <Fake <int>, int>(x => x.Next.Value);
            var intExpecteds = new[] { typeof(Fake <int>).GetProperty(nameof(Fake <int> .Next), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), typeof(Level <int>).GetProperty(nameof(Level <int> .Value), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) };

            CollectionAssert.AreEqual(intExpecteds, intActuals1);

            var intActuals2 = PropertyPathParser.GetPath <Fake <int>, int>(x => x.Next.Value);

            Assert.AreSame(intActuals1, intActuals2);

            var intFake     = new Fake <int>();
            var intActuals3 = PropertyPathParser.GetPath(() => intFake.Next.Value);

            Assert.AreSame(intActuals1, intActuals3);

            var doubleActuals1  = PropertyPathParser.GetPath <Fake <double>, double>(x => x.Next.Value);
            var doubleExpecteds = new[] { typeof(Fake <double>).GetProperty(nameof(Fake <double> .Next), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), typeof(Level <double>).GetProperty(nameof(Level <double> .Value), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) };

            CollectionAssert.AreEqual(doubleExpecteds, doubleActuals1);

            var doubleActuals2 = PropertyPathParser.GetPath <Fake <double>, double>(x => x.Next.Value);

            Assert.AreSame(doubleActuals1, doubleActuals2);
            Assert.AreNotSame(intActuals1, doubleActuals2);

            var doubleFake     = new Fake <double>();
            var doubleActuals3 = PropertyPathParser.GetPath(() => doubleFake.Next.Value);

            Assert.AreSame(doubleActuals1, doubleActuals3);
            Assert.AreNotSame(intActuals1, doubleActuals2);
        }
コード例 #2
0
        public void GetPathTwoLevelsGenerics()
        {
            var intActuals1  = PropertyPathParser.GetPath <Fake <int>, int>(x => x.Next.Value);
            var intExpecteds = new[] { typeof(Fake <int>).GetProperty("Next"), typeof(Level <int>).GetProperty("Value") };

            CollectionAssert.AreEqual(intExpecteds, intActuals1);

            var intActuals2 = PropertyPathParser.GetPath <Fake <int>, int>(x => x.Next.Value);

            Assert.AreSame(intActuals1, intActuals2);

            var intFake     = new Fake <int>();
            var intActuals3 = PropertyPathParser.GetPath(() => intFake.Next.Value);

            Assert.AreSame(intActuals1, intActuals3);

            var doubleActuals1  = PropertyPathParser.GetPath <Fake <double>, double>(x => x.Next.Value);
            var doubleExpecteds = new[] { typeof(Fake <double>).GetProperty("Next"), typeof(Level <double>).GetProperty("Value") };

            CollectionAssert.AreEqual(doubleExpecteds, doubleActuals1);

            var doubleActuals2 = PropertyPathParser.GetPath <Fake <double>, double>(x => x.Next.Value);

            Assert.AreSame(doubleActuals1, doubleActuals2);
            Assert.AreNotSame(intActuals1, doubleActuals2);

            var doubleFake     = new Fake <double>();
            var doubleActuals3 = PropertyPathParser.GetPath(() => doubleFake.Next.Value);

            Assert.AreSame(doubleActuals1, doubleActuals3);
            Assert.AreNotSame(intActuals1, doubleActuals2);
        }
コード例 #3
0
        public void GetPathOneItemFuncOfTOneItemNoThis()
        {
#pragma warning disable SA1101 // Prefix local calls with this
            var properties1 = PropertyPathParser.GetPath(() => IsTrue);
#pragma warning restore SA1101 // Prefix local calls with this
            CollectionAssert.AreEqual(new[] { this.GetType().GetProperty("IsTrue") }, properties1);
            var properties2 = PropertyPathParser.GetPath(() => this.IsTrue);
            Assert.AreSame(properties1, properties2);
        }
コード例 #4
0
        public void GetPathOneItemFuncOfTOneItemWithThis()
        {
            var properties1 = PropertyPathParser.GetPath(() => this.IsTrue);

            CollectionAssert.AreEqual(new[] { this.GetType().GetProperty("IsTrue") }, properties1);
            var properties2 = PropertyPathParser.GetPath(() => this.IsTrue);

            Assert.AreSame(properties1, properties2);
        }
コード例 #5
0
        public void ReadOnlyCollectionAndReadOnlyObservableCollectionCount()
        {
            var actuals1 = PropertyPathParser.GetPath <ReadOnlyObservableCollection <int>, int>(x => x.Count);

            CollectionAssert.AreEqual(new[] { typeof(ReadOnlyObservableCollection <int>).GetProperty("Count") }, actuals1);
            var actuals2 = PropertyPathParser.GetPath <ReadOnlyCollection <int>, int>(f => f.Count);

            CollectionAssert.AreEqual(new[] { typeof(ReadOnlyCollection <int>).GetProperty("Count") }, actuals2);
        }
コード例 #6
0
        public void GetPathOneItemFuncOfTOneItemNoThis()
        {
#pragma warning disable SA1101 // Prefix local calls with this
            var properties1 = PropertyPathParser.GetPath(() => IsTrue);
#pragma warning restore SA1101 // Prefix local calls with this
            CollectionAssert.AreEqual(new[] { this.GetType().GetProperty(nameof(this.IsTrue), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) }, properties1);
            var properties2 = PropertyPathParser.GetPath(() => this.IsTrue);
            Assert.AreSame(properties1, properties2);
        }
コード例 #7
0
        public void GetPathOneItem3()
        {
            var properties1 = PropertyPathParser.GetPath(() => this.IsTrue);

            CollectionAssert.AreEqual(new[] { this.GetType().GetProperty(nameof(this.IsTrue), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) }, properties1);
            var properties2 = PropertyPathParser.GetPath <PropertyPathParserTests, bool>(x => x.IsTrue);

            Assert.AreSame(properties1, properties2);
        }
コード例 #8
0
        public void ReadOnlyCollectionAndReadOnlyObservableCollectionCount()
        {
            var actuals1 = PropertyPathParser.GetPath <ReadOnlyObservableCollection <int>, int>(x => x.Count);

            CollectionAssert.AreEqual(new[] { typeof(ReadOnlyObservableCollection <int>).GetProperty(nameof(ReadOnlyCollection <int> .Count), BindingFlags.Public | BindingFlags.Instance) }, actuals1);
            var actuals2 = PropertyPathParser.GetPath <ReadOnlyCollection <int>, int>(f => f.Count);

            CollectionAssert.AreEqual(new[] { typeof(ReadOnlyCollection <int>).GetProperty(nameof(ReadOnlyCollection <int> .Count), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) }, actuals2);
        }
コード例 #9
0
        public void GetPathOneItem3()
        {
            var properties1 = PropertyPathParser.GetPath(() => this.IsTrue);

            CollectionAssert.AreEqual(new[] { this.GetType().GetProperty("IsTrue") }, properties1);
            var properties2 = PropertyPathParser.GetPath <PropertyPathParserTests, bool>(x => x.IsTrue);

            Assert.AreSame(properties1, properties2);
        }
コード例 #10
0
        /// <summary>
        /// Returns the name of a property provided as a property expression.
        /// </summary>
        /// <typeparam name="TItem">
        /// Type of the item.
        /// </typeparam>
        /// <typeparam name="TValue">
        /// Type of the property.
        /// </typeparam>
        /// <param name="property">
        /// Property expression on the the form () =&gt; Instance.Property.
        /// </param>
        /// <returns>
        /// Returns the simple name of the property.
        /// </returns>
        public static string Property <TItem, TValue>(Expression <Func <TItem, TValue> > property)
        {
            if (property is null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            var path = PropertyPathParser.GetPath(property);

            return(path[path.Count - 1].Name);
        }
コード例 #11
0
        /// <summary>
        /// Returns the name of a property provided as a property expression.
        /// </summary>
        /// <typeparam name="T">
        /// Type of the property.
        /// </typeparam>
        /// <param name="property">
        /// Property expression on the the form () =&gt; Instance.Property.
        /// </param>
        /// <param name="allowNestedProperty">
        /// Throw an exception if the provided path is a multi level path (e.g. a.b)
        /// </param>
        /// <returns>
        /// Returns the simple name of the property.
        /// </returns>
        //// ReSharper disable once UnusedParameter.Global
        public static string Property <T>(Expression <Func <T> > property, bool allowNestedProperty = false)
        {
            var path = PropertyPathParser.GetPath(property);

            if (path.Count > 1 && !allowNestedProperty)
            {
                throw new ArgumentException("Trying to get the name of a nested property: " + string.Join(".", path.Select(x => x.Name)));
            }

            return(path[path.Count - 1].Name);
        }
コード例 #12
0
        public void GetPathTwoLevels2()
        {
            var actuals1  = PropertyPathParser.GetPath <Fake, bool>(x => x.Next.IsTrue);
            var expected1 = new[] { typeof(Fake).GetProperty("Next"), typeof(Level).GetProperty("IsTrue") };

            CollectionAssert.AreEqual(expected1, actuals1);

            var actuals2  = PropertyPathParser.GetPath <Fake, string>(fake => fake.Next.Name);
            var expected2 = new[] { typeof(Fake).GetProperty("Next"), typeof(Level).GetProperty("Name") };

            CollectionAssert.AreEqual(expected2, actuals2);
        }
コード例 #13
0
        public void GetPathTwoLevels2()
        {
            var actuals1  = PropertyPathParser.GetPath <Fake, bool>(x => x.Next.IsTrue);
            var expected1 = new[] { typeof(Fake).GetProperty(nameof(Fake.Next), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), typeof(Level).GetProperty(nameof(Level.IsTrue), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) };

            CollectionAssert.AreEqual(expected1, actuals1);

            var actuals2  = PropertyPathParser.GetPath <Fake, string>(fake => fake.Next.Name);
            var expected2 = new[] { typeof(Fake).GetProperty(nameof(Fake.Next), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), typeof(Level).GetProperty(nameof(Level.Name), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) };

            CollectionAssert.AreEqual(expected2, actuals2);
        }
コード例 #14
0
        public void GetPathFromMock()
        {
            var fake     = Mock.Of <IReadOnlyObservableCollection <int> >();
            var actuals  = PropertyPathParser.GetPath(() => fake.Count);
            var expected = typeof(IReadOnlyCollection <int>).GetProperty(nameof(IReadOnlyCollection <int> .Count), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

            Assert.NotNull(expected);
            Assert.AreEqual(1, actuals.Count);
            Assert.AreEqual(expected.Name, actuals[0].Name);
            Assert.AreEqual(expected.PropertyType, actuals[0].PropertyType);
            Assert.AreEqual(expected.DeclaringType, actuals[0].DeclaringType);
            Assert.AreEqual(expected.GetMethod, actuals[0].GetMethod);
            Assert.AreEqual(typeof(IReadOnlyObservableCollection <int>), actuals[0].ReflectedType);
        }
コード例 #15
0
        public void GetPathOneLevel()
        {
            var actuals1 = PropertyPathParser.GetPath <Fake, bool>(x => x.IsTrue);

            CollectionAssert.AreEqual(new[] { typeof(Fake).GetProperty(nameof(Fake.IsTrue), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) }, actuals1);
            var actuals2 = PropertyPathParser.GetPath <Fake, bool>(f => f.IsTrue);

            Assert.AreSame(actuals1, actuals2);

            var fake     = new Fake();
            var actuals3 = PropertyPathParser.GetPath(() => fake.IsTrue);

            Assert.AreSame(actuals1, actuals3);
        }
コード例 #16
0
        public void GetPathsOneLevel()
        {
            var fake       = new Fake();
            var fakeIsTrue = new[] { typeof(Fake).GetProperty("IsTrue") };

            CollectionAssert.AreEqual(fakeIsTrue, PropertyPathParser.GetPath <Fake, bool>(x => x.IsTrue));
            CollectionAssert.AreEqual(fakeIsTrue, PropertyPathParser.GetPath(() => fake.IsTrue));

            CollectionAssert.AreEqual(new[] { typeof(Fake).GetProperty("Name") }, PropertyPathParser.GetPath <Fake, string>(x => x.Name));
            CollectionAssert.AreEqual(new[] { typeof(PropertyPathParserTests).GetProperty("IsTrue") }, PropertyPathParser.GetPath <PropertyPathParserTests, bool>(x => x.IsTrue));
            CollectionAssert.AreEqual(fakeIsTrue, PropertyPathParser.GetPath <Fake, bool>(x => x.IsTrue));
            CollectionAssert.AreEqual(new[] { typeof(Fake).GetProperty("Name") }, PropertyPathParser.GetPath <Fake, string>(x => x.Name));
            CollectionAssert.AreEqual(new[] { typeof(PropertyPathParserTests).GetProperty("IsTrue") }, PropertyPathParser.GetPath <PropertyPathParserTests, bool>(x => x.IsTrue));
        }
コード例 #17
0
        public void GetPathOneAndTwoLevels()
        {
            var actuals1 = PropertyPathParser.GetPath <Fake, Level>(x => x.Next);

            CollectionAssert.AreEqual(new[] { typeof(Fake).GetProperty(nameof(Fake.Next), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) }, actuals1);

            var actuals2 = PropertyPathParser.GetPath <Fake, int>(f => f.Next.Value1);

            CollectionAssert.AreEqual(new[] { typeof(Fake).GetProperty(nameof(Fake.Next), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), typeof(Level).GetProperty(nameof(Level.Value1), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) }, actuals2);

            var actuals3 = PropertyPathParser.GetPath <Fake, int>(f => f.Next.Value2);

            CollectionAssert.AreEqual(new[] { typeof(Fake).GetProperty(nameof(Fake.Next), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), typeof(Level).GetProperty(nameof(Level.Value2), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) }, actuals3);
        }
コード例 #18
0
        public void GetPathsOneLevel()
        {
            var fake       = new Fake();
            var fakeIsTrue = new[] { typeof(Fake).GetProperty(nameof(Fake.IsTrue), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) };

            CollectionAssert.AreEqual(fakeIsTrue, PropertyPathParser.GetPath <Fake, bool>(x => x.IsTrue));
            CollectionAssert.AreEqual(fakeIsTrue, PropertyPathParser.GetPath(() => fake.IsTrue));

            CollectionAssert.AreEqual(new[] { typeof(Fake).GetProperty(nameof(Fake.Name), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) }, PropertyPathParser.GetPath <Fake, string>(x => x.Name));
            CollectionAssert.AreEqual(new[] { typeof(PropertyPathParserTests).GetProperty(nameof(this.IsTrue), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) }, PropertyPathParser.GetPath <PropertyPathParserTests, bool>(x => x.IsTrue));
            CollectionAssert.AreEqual(fakeIsTrue, PropertyPathParser.GetPath <Fake, bool>(x => x.IsTrue));
            CollectionAssert.AreEqual(new[] { typeof(Fake).GetProperty(nameof(Fake.Name), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) }, PropertyPathParser.GetPath <Fake, string>(x => x.Name));
            CollectionAssert.AreEqual(new[] { typeof(PropertyPathParserTests).GetProperty(nameof(this.IsTrue), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) }, PropertyPathParser.GetPath <PropertyPathParserTests, bool>(x => x.IsTrue));
        }
コード例 #19
0
        public void GetPathOneLevelGeneric()
        {
            var actuals1 = PropertyPathParser.GetPath <Level <int>, int>(x => x.Value);

            CollectionAssert.AreEqual(new[] { typeof(Level <int>).GetProperty("Value") }, actuals1);
            var actuals2 = PropertyPathParser.GetPath <Level <int>, int>(f => f.Value);

            Assert.AreSame(actuals1, actuals2);

            var fake     = new Level <int>();
            var actuals3 = PropertyPathParser.GetPath(() => fake.Value);

            Assert.AreSame(actuals1, actuals3);
        }
コード例 #20
0
        public void GetPathOneLevelGeneric()
        {
            var actuals1 = PropertyPathParser.GetPath <Level <int>, int>(x => x.Value);

            CollectionAssert.AreEqual(new[] { typeof(Level <int>).GetProperty(nameof(Level <int> .Value), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) }, actuals1);
            var actuals2 = PropertyPathParser.GetPath <Level <int>, int>(f => f.Value);

            Assert.AreSame(actuals1, actuals2);

            var fake     = new Level <int>();
            var actuals3 = PropertyPathParser.GetPath(() => fake.Value);

            Assert.AreSame(actuals1, actuals3);
        }
コード例 #21
0
        public void GetPathOneAndTwoLevels()
        {
            var actuals1 = PropertyPathParser.GetPath <Fake, Level>(x => x.Next);

            CollectionAssert.AreEqual(new[] { typeof(Fake).GetProperty("Next") }, actuals1);

            var actuals2 = PropertyPathParser.GetPath <Fake, int>(f => f.Next.Value1);

            CollectionAssert.AreEqual(new[] { typeof(Fake).GetProperty("Next"), typeof(Level).GetProperty("Value1") }, actuals2);

            var actuals3 = PropertyPathParser.GetPath <Fake, int>(f => f.Next.Value2);

            CollectionAssert.AreEqual(new[] { typeof(Fake).GetProperty("Next"), typeof(Level).GetProperty("Value2") }, actuals3);
        }
コード例 #22
0
        public void ReadOnlyObservableCollectionCount()
        {
            var actuals1 = PropertyPathParser.GetPath <ReadOnlyObservableCollection <int>, int>(x => x.Count);

            CollectionAssert.AreEqual(new[] { typeof(ReadOnlyObservableCollection <int>).GetProperty(nameof(ReadOnlyCollection <int> .Count), BindingFlags.Public | BindingFlags.Instance) }, actuals1);
            var actuals2 = PropertyPathParser.GetPath <ReadOnlyObservableCollection <int>, int>(f => f.Count);

            Assert.AreSame(actuals1, actuals2);

            var ints     = new ReadOnlyObservableCollection <int>(new ObservableCollection <int>());
            var actuals3 = PropertyPathParser.GetPath(() => ints.Count);

            Assert.AreSame(actuals1, actuals3);
        }
コード例 #23
0
        public void GetPathOneLevel()
        {
            var actuals1 = PropertyPathParser.GetPath <Fake, bool>(x => x.IsTrue);

            CollectionAssert.AreEqual(new[] { typeof(Fake).GetProperty("IsTrue") }, actuals1);
            var actuals2 = PropertyPathParser.GetPath <Fake, bool>(f => f.IsTrue);

            Assert.AreSame(actuals1, actuals2);

            var fake     = new Fake();
            var actuals3 = PropertyPathParser.GetPath(() => fake.IsTrue);

            Assert.AreSame(actuals1, actuals3);
        }
コード例 #24
0
        public void GetPathTwoLevels()
        {
            var actuals1 = PropertyPathParser.GetPath <Fake, bool>(x => x.Next.IsTrue);
            var expected = new[] { typeof(Fake).GetProperty("Next"), typeof(Level).GetProperty("IsTrue") };

            CollectionAssert.AreEqual(expected, actuals1);

            var actuals2 = PropertyPathParser.GetPath <Fake, bool>(f => f.Next.IsTrue);

            Assert.AreSame(actuals1, actuals2);

            var fake     = new Fake();
            var actuals3 = PropertyPathParser.GetPath(() => fake.Next.IsTrue);

            Assert.AreSame(actuals1, actuals3);
        }
コード例 #25
0
        public void GetPathTwoLevelsGeneric()
        {
            var actuals1 = PropertyPathParser.GetPath <Fake <int>, int>(x => x.Next.Value);
            var expected = new[] { typeof(Fake <int>).GetProperty(nameof(Fake <int> .Next), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), typeof(Level <int>).GetProperty(nameof(Level <int> .Value), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) };

            CollectionAssert.AreEqual(expected, actuals1);

            var actuals2 = PropertyPathParser.GetPath <Fake <int>, int>(x => x.Next.Value);

            Assert.AreSame(actuals1, actuals2);

            var fake     = new Fake <int>();
            var actuals3 = PropertyPathParser.GetPath(() => fake.Next.Value);

            Assert.AreSame(actuals1, actuals3);
        }
コード例 #26
0
        public void GetPathTwoLevels()
        {
            var actuals1 = PropertyPathParser.GetPath <Fake, bool>(x => x.Next.IsTrue);
            var expected = new[] { typeof(Fake).GetProperty(nameof(Fake.Next), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), typeof(Level).GetProperty(nameof(Level.IsTrue), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) };

            CollectionAssert.AreEqual(expected, actuals1);

            var actuals2 = PropertyPathParser.GetPath <Fake, bool>(f => f.Next.IsTrue);

            Assert.AreSame(actuals1, actuals2);

            var fake     = new Fake();
            var actuals3 = PropertyPathParser.GetPath(() => fake.Next.IsTrue);

            Assert.AreSame(actuals1, actuals3);
        }
コード例 #27
0
        public void GetPathTwoLevelsGeneric()
        {
            var actuals1 = PropertyPathParser.GetPath <Fake <int>, int>(x => x.Next.Value);
            var expected = new[] { typeof(Fake <int>).GetProperty("Next"), typeof(Level <int>).GetProperty("Value") };

            CollectionAssert.AreEqual(expected, actuals1);

            var actuals2 = PropertyPathParser.GetPath <Fake <int>, int>(x => x.Next.Value);

            Assert.AreSame(actuals1, actuals2);

            var fake     = new Fake <int>();
            var actuals3 = PropertyPathParser.GetPath(() => fake.Next.Value);

            Assert.AreSame(actuals1, actuals3);
        }
コード例 #28
0
        public void FakeOfReadOnlyObservableCollectionCount()
        {
            var actuals1 = PropertyPathParser.GetPath <Fake <ReadOnlyObservableCollection <int> >, int>(x => x.Value.Count);
            var expected = new[]
            {
                typeof(Fake <ReadOnlyObservableCollection <int> >).GetProperty(nameof(Fake <ReadOnlyObservableCollection <int> > .Value), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
                typeof(ReadOnlyObservableCollection <int>).GetProperty(nameof(ReadOnlyCollection <int> .Count), BindingFlags.Public | BindingFlags.Instance),
            };

            CollectionAssert.AreEqual(expected, actuals1);
            var actuals2 = PropertyPathParser.GetPath <Fake <ReadOnlyObservableCollection <int> >, int>(f => f.Value.Count);

            Assert.AreSame(actuals1, actuals2);

            var ints     = new Fake <ReadOnlyObservableCollection <int> >();
            var actuals3 = PropertyPathParser.GetPath(() => ints.Value.Count);

            Assert.AreSame(actuals1, actuals3);
        }
コード例 #29
0
        public void FakeOfReadOnlyObservableCollectionCount()
        {
            var actuals1 = PropertyPathParser.GetPath <Fake <ReadOnlyObservableCollection <int> >, int>(x => x.Value.Count);
            var expected = new[]
            {
                typeof(Fake <ReadOnlyObservableCollection <int> >).GetProperty("Value"),
                typeof(ReadOnlyObservableCollection <int>).GetProperty("Count")
            };

            CollectionAssert.AreEqual(expected, actuals1);
            var actuals2 = PropertyPathParser.GetPath <Fake <ReadOnlyObservableCollection <int> >, int>(f => f.Value.Count);

            Assert.AreSame(actuals1, actuals2);

            var ints     = new Fake <ReadOnlyObservableCollection <int> >();
            var actuals3 = PropertyPathParser.GetPath(() => ints.Value.Count);

            Assert.AreSame(actuals1, actuals3);
        }
コード例 #30
0
        public void GetPathOneLevelGenerics()
        {
            var intActuals1 = PropertyPathParser.GetPath <Level <int>, int>(x => x.Value);

            CollectionAssert.AreEqual(new[] { typeof(Level <int>).GetProperty(nameof(Level <int> .Value), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) }, intActuals1);
            var doubleActuals1 = PropertyPathParser.GetPath <Level <double>, double>(x => x.Value);

            CollectionAssert.AreEqual(new[] { typeof(Level <double>).GetProperty(nameof(Level <double> .Value), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) }, doubleActuals1);
            Assert.AreNotSame(intActuals1, doubleActuals1);

            var intLevel    = new Level <int>();
            var intActuals2 = PropertyPathParser.GetPath(() => intLevel.Value);

            Assert.AreSame(intActuals1, intActuals2);

            var doubleLevel    = new Level <double>();
            var doubleActuals2 = PropertyPathParser.GetPath(() => doubleLevel.Value);

            Assert.AreSame(doubleActuals1, doubleActuals2);
        }