예제 #1
0
        public void IsIgnoredReturnsFalseWhenNoMatchOnConstructorArguments()
        {
            var configuration       = Substitute.For <IBuildConfiguration>();
            var constructorResolver = Substitute.For <IConstructorResolver>();

            var instance = new Optionals(Guid.NewGuid().ToString())
            {
                Value = Guid.NewGuid().ToString()
            };
            var propertyInfo = instance.GetType().GetProperty(nameof(Optionals.Value)) !;
            var args         = new object?[]
            {
                Guid.NewGuid().ToString()
            };
            var constructor = instance.GetType().GetConstructor(new[] { typeof(string) });

            configuration.ConstructorResolver.Returns(constructorResolver);
            constructorResolver.Resolve(typeof(Optionals), args).Returns(constructor);

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            var actual = sut.IsIgnored(configuration, instance, propertyInfo, args);

            actual.Should().BeFalse();
        }
예제 #2
0
        public void IsIgnoredThrowsExceptionWithNullInstance()
        {
            var configuration = Model.UsingDefaultConfiguration();
            var propertyInfo  = typeof(Person).GetProperty(nameof(Person.Address)) !;

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            Action action = () => sut.IsIgnored(configuration, null !, propertyInfo, null !);

            action.Should().Throw <ArgumentNullException>();
        }
예제 #3
0
        public void IsIgnoredThrowsExceptionWithNullPropertyInfo()
        {
            var configuration = Model.UsingDefaultConfiguration();
            var instance      = new Person();

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            Action action = () => sut.IsIgnored(configuration, instance, null !, null !);

            action.Should().Throw <ArgumentNullException>();
        }
예제 #4
0
        public void IsIgnoredReturnsTrueWhenIgnoreRuleMatched()
        {
            var configuration = Model.UsingDefaultConfiguration() !.AddIgnoreRule <Person>(x => x.Address !);
            var instance      = new Person();
            var propertyInfo  = typeof(Person).GetProperty(nameof(Person.Address)) !;

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            var actual = sut.IsIgnored(configuration, instance, propertyInfo, null !);

            actual.Should().BeTrue();
        }
예제 #5
0
        public void IsIgnoredReturnsFalseWhenPropertyNotIgnoredAndNullArgumentsProvided()
        {
            var configuration = Model.UsingDefaultConfiguration();
            var instance      = new Person();
            var propertyInfo  = typeof(Person).GetProperty(nameof(Person.Address)) !;

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            var actual = sut.IsIgnored(configuration, instance, propertyInfo, null !);

            actual.Should().BeFalse();
        }
예제 #6
0
        public void IsIgnoredReturnsFalseWhenIgnoreRulesAreEmpty()
        {
            var configuration = Model.UsingDefaultConfiguration();
            var instance      = Model.Create <WithConstructorParameters>() !;

            var propertyInfo = typeof(WithConstructorParameters).GetProperty(nameof(WithConstructorParameters.Id)) !;

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            var actual = sut.IsIgnored(configuration, instance, propertyInfo, null !);

            actual.Should().BeFalse();
        }
예제 #7
0
        public void IsIgnoredReturnsTrueForIndexerProperty()
        {
            var configuration = Substitute.For <IBuildConfiguration>();
            var items         = new List <int>();
            var instance      = new ReadOnlyCollection <int>(items);
            var type          = typeof(ReadOnlyCollection <int>);
            var propertyInfo  = type.GetProperties().First(x => x.GetIndexParameters().Length > 0);

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            var actual = sut.IsIgnored(configuration, instance, propertyInfo, null !);

            actual.Should().BeTrue();
        }
예제 #8
0
        public void IsIgnoredReturnsFalseWhenPropertyRelatesToNullParameter()
        {
            var configuration = Model.UsingDefaultConfiguration();
            var instance      = Model.Create <WithConstructorParameters>() !;
            var args          = new object?[]
            {
                null !, new Company(), instance.Id, instance.RefNumber, instance.Number, instance.Value
            };

            var propertyInfo = typeof(WithConstructorParameters).GetProperty(nameof(WithConstructorParameters.First)) !;

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            var actual = sut.IsIgnored(configuration, instance, propertyInfo, args);

            actual.Should().BeFalse();
        }
예제 #9
0
        public void IsIgnoredReturnsTrueWhenParametersMatchPropertyValueType()
        {
            var configuration = Model.UsingDefaultConfiguration();
            var instance      = Model.Create <WithConstructorParameters>() !;
            var args          = new object?[]
            {
                instance.First, instance.Id, instance.RefNumber, instance.Number, instance.Value
            };

            var propertyInfo = typeof(WithConstructorParameters).GetProperty(nameof(WithConstructorParameters.Number)) !;

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            var actual = sut.IsIgnored(configuration, instance, propertyInfo, args);

            actual.Should().BeTrue();
        }
예제 #10
0
        public void IsIgnoredReturnsFalseWhenParametersDoNotMatchPropertyValueType()
        {
            var configuration = Model.UsingDefaultConfiguration();
            var instance      = Model.Create <WithConstructorParameters>() !;
            var args          = new object?[]
            {
                instance.First, Guid.NewGuid(), null !, int.MinValue, false
            };

            var propertyInfo = typeof(WithConstructorParameters).GetProperty(nameof(WithConstructorParameters.Number)) !;

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            var actual = sut.IsIgnored(configuration, instance, propertyInfo, args);

            actual.Should().BeFalse();
        }
예제 #11
0
        IsIgnoredReturnsFalseWhenPropertyContainsNullAndPropertyTypeCannotBeCreatedForEqualityChecking()
        {
            var configuration = Model.UsingDefaultConfiguration();
            var instance      = Model.Create <ReadOnlyModelParent>() !.Set(x => x.Child = null !);
            var args          = new object?[]
            {
                Guid.NewGuid()
            };

            var propertyInfo = typeof(ReadOnlyModelParent).GetProperty(nameof(ReadOnlyModelParent.Child)) !;

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            var actual = sut.IsIgnored(configuration, instance, propertyInfo, args);

            actual.Should().BeFalse();
        }
예제 #12
0
        public void IsIgnoredReturnsFalseWhenParameterDoesNotMatchReferencePropertyWithNameMatch()
        {
            var configuration = Model.UsingDefaultConfiguration();
            var value         = new Person();
            var model         = new ClassMatchingNameWrapper <Person>(value);
            var propertyInfo  =
                typeof(ClassMatchingNameWrapper <Person>).GetProperty(nameof(ClassMatchingNameWrapper <Person> .Value)) !;
            var args = new object?[]
            {
                new Person()
            };

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            var actual = sut.IsIgnored(configuration, model, propertyInfo, args);

            actual.Should().BeFalse();
        }
예제 #13
0
        public void IsIgnoredReturnsTrueWhenParameterMatchesValueTypePropertyWithNameMatch()
        {
            var configuration = Model.UsingDefaultConfiguration();
            var value         = Environment.TickCount;
            var model         = new StructMatchingNameWrapper <int>(value);
            var propertyInfo  =
                typeof(StructMatchingNameWrapper <int>).GetProperty(nameof(StructMatchingNameWrapper <int> .Value)) !;
            var args = new object?[]
            {
                value
            };

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            var actual = sut.IsIgnored(configuration, model, propertyInfo, args);

            actual.Should().BeTrue();
        }
예제 #14
0
        public void IsIgnoredReturnsTrueWhenParameterMatchesStringPropertyWithNameMatch()
        {
            var configuration = Model.UsingDefaultConfiguration();
            var value         = Guid.NewGuid().ToString();
            var model         = new ClassMatchingNameWrapper <string>(value);
            var propertyInfo  =
                typeof(ClassMatchingNameWrapper <string>).GetProperty(nameof(ClassMatchingNameWrapper <string> .Value)) !;
            var args = new object?[]
            {
                value
            };

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            var actual = sut.IsIgnored(configuration, model, propertyInfo, args);

            actual.Should().BeTrue();
        }
예제 #15
0
        public void IsIgnoredReturnsFalseWhenParameterDoesNotMatchValueTypePropertyWithNameMismatch()
        {
            var configuration = Model.UsingDefaultConfiguration();
            var item          = Environment.TickCount;
            var model         = new StructMismatchingNameWrapper <int>(item);
            var propertyInfo  =
                typeof(StructMismatchingNameWrapper <int>).GetProperty(nameof(StructMismatchingNameWrapper <int> .Value)) !;
            var args = new object?[]
            {
                Guid.NewGuid().ToString()
            };

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            var actual = sut.IsIgnored(configuration, model, propertyInfo, args);

            actual.Should().BeFalse();
        }
예제 #16
0
        public void IsIgnoredThrowsExceptionWhenConstructorNotFound()
        {
            var configuration = Substitute.For <IBuildConfiguration>();
            var instance      = new Optionals(Guid.NewGuid().ToString())
            {
                Value = Guid.NewGuid().ToString()
            };
            var propertyInfo = instance.GetType().GetProperty(nameof(Optionals.Value)) !;
            var args         = new object?[]
            {
                Guid.NewGuid().ToString(),
                Guid.NewGuid().ToString()
            };

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            Action action = () => sut.IsIgnored(configuration, instance, propertyInfo, args);

            action.Should().Throw <MissingMemberException>();
        }
예제 #17
0
        public void IsIgnoredReturnsFalseWhenParameterMatchesStructPropertyWithNameMismatch()
        {
            var configuration = Model.UsingDefaultConfiguration();
            var item          = new StructModel {
                FirstName = Guid.NewGuid().ToString()
            };
            var model        = new StructMismatchingNameWrapper <StructModel>(item);
            var propertyInfo =
                typeof(StructMismatchingNameWrapper <StructModel>).GetProperty(
                    nameof(StructMismatchingNameWrapper <StructModel> .Value)) !;
            var args = new object?[]
            {
                item
            };

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            var actual = sut.IsIgnored(configuration, model, propertyInfo, args);

            actual.Should().BeFalse();
        }