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(); }
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>(); }
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>(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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>(); }
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(); }