Exemple #1
0
        public bool Matches(object actualViewModel)
        {
            foreach (var property in actualViewModel.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                if (property.IsReadonly())
                {
                    continue;
                }

                var expectedValue          = property.GetValue(_expectedViewModel, null);
                var viewModelPropertyValue = property.GetValue(actualViewModel, null);

                if (!property.PropertyType.IsValueType && property.PropertyType != typeof(string) && !typeof(IEnumerable).IsAssignableFrom(property.PropertyType))
                {
                    IsSame.ViewModelAs(expectedValue, viewModelPropertyValue);
                    continue;
                }

                if (expectedValue is IEnumerable && !(expectedValue as IEnumerable).Cast <object>().Any())
                {
                    viewModelPropertyValue.ShouldBeNull(customMessage: $"View model property: {property.Name}");
                }
                else
                {
                    viewModelPropertyValue.ShouldBe(expectedValue, $"View model property: {property.Name}");
                }
            }

            return(true);
        }
        public override bool Matches(object actualViewModel)
        {
            foreach (var property in actualViewModel.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                if (property.IsReadonly())
                    continue;
                var expectedValue = property.GetValue(_expectedViewModel, null);
                var actualValue = property.GetValue(actualViewModel, null);

                if (!property.PropertyType.IsValueType && property.PropertyType != typeof(string) && !typeof(IEnumerable).IsAssignableFrom(property.PropertyType))
                {
                    Assert.That(actualValue, IsSame.ViewModelAs(expectedValue));
                    continue;
                }

                if (expectedValue is IEnumerable && !(expectedValue as IEnumerable).Cast<object>().Any())
                    Assert.That(actualValue, Is.Null.Or.Empty);
                else
                    Assert.That(actualValue, Is.EqualTo(expectedValue), property.Name);
            }

            return true;
        }