public void Resolve_WithAttributedType_ReturnsValue() { var resolver = new StandardExodataResolver(); var value = resolver.TryResolve(CommonExodata.Description).For <TestSubject>(); Assert.AreEqual("Test Subject", value); }
public void Resolve_WithModuleProvidedMatchingBinding_ReturnsValue() { var resolver = new StandardExodataResolver(new TestExodataBindingModule()); int value = resolver.TryResolve(StringExodata.MaxLength).Get(); Assert.AreEqual(42, value); }
public void Resolve_WithSpecificContext_YieldsSpecificContextualExodataSurrogateExodata() { var resolver = new StandardExodataResolver(); BaseTestSubjectExodataSurrogate.ShouldYieldInstanceExodata = true; Assert.AreEqual("Specific Contextual Member Description", resolver.TryResolve(CommonExodata.Description).Given("Context").For <TestSubject>(x => x.FirstName)); }
public void Resolve_WithSurrogate_ReturnsValue() { var resolver = new StandardExodataResolver(); var value = resolver.TryResolve(StringExodata.MaxLength).For <TestSubject>(x => x.MiddleName); Assert.AreEqual(74088, value); }
public void Resolve_WithModuleThatOverridesAttributeExodata_ReturnsValue() { var resolver = new StandardExodataResolver(new TestExodataBindingModule()); var value = resolver.TryResolve(CommonExodata.Description).For <TestSubject>(); Assert.AreEqual("Overridden Description", value); }
public void Resolve_WithAttributedFieldForBaseExodataClass_ReturnsValue() { var resolver = new StandardExodataResolver(); var allExodata = resolver.TryResolve(CommonExodata.All).For <TestSubject>(x => x.LastName); Assert.IsNotNull(allExodata); Assert.AreEqual("Last Name", allExodata.Description); }
public void Resolve_WithAttributedField_ReturnsValue() { var resolver = new StandardExodataResolver(); var allExodata = resolver.TryResolve(StringExodata.All).For <TestSubject>(x => x.LastName); Assert.AreEqual(7, allExodata.MinimumLength); Assert.AreEqual(1764, allExodata.MaximumLength); Assert.AreEqual("Last Name", allExodata.Description); }
public void Get_ByTypeOnly_UsesTypeDeclaration() { var resolver = new StandardExodataResolver(); resolver.Bind(ExodataDeclaration <int> .TypeDeclaration, 42); ExodataDeclaration.SetResolver(resolver); Assert.AreEqual(42, ExodataDeclaration.Get <int>()); }
public void Resolve_AgainstArbitraryInstance_YieldsAttributeExodata() { var resolver = new StandardExodataResolver(); BaseTestSubjectExodataSurrogate.ShouldYieldInstanceExodata = false; var value = resolver.TryResolve(CommonExodata.Description).For(new TestSubject()); Assert.AreEqual("Test Subject", value); }
public void Resolve_WithSpecificInstanceAgainstMember_YieldsExodataSurrogateMetadata() { var resolver = new StandardExodataResolver(); BaseTestSubjectExodataSurrogate.ShouldYieldInstanceExodata = true; var value = resolver.TryResolve(CommonExodata.Description).For(BaseTestSubjectExodataSurrogate.Subject, x => x.FirstName); Assert.AreEqual("Special Member Description", value); }
public void Resolve_AgainstArbitraryDerivedInstance_YieldsSurrogateExodata() { var resolver = new StandardExodataResolver(); BaseTestSubjectExodataSurrogate.ShouldYieldInstanceExodata = true; var value = resolver.TryResolve(CommonExodata.Description).For(new DerivedTestSubject()); Assert.AreEqual("Surrogate Description", value); }
public void Resolve_AgainstSpecificInstanceWhenPredicateReturnsFalse_YieldsAttributeExodata() { var resolver = new StandardExodataResolver(); BaseTestSubjectExodataSurrogate.ShouldYieldInstanceExodata = false; var value = resolver.TryResolve(CommonExodata.Description).For(BaseTestSubjectExodataSurrogate.Subject); Assert.AreEqual("Test Subject", value); }
public void Resolve_AgainstSpecificInstance_WorksCorrectly() { var resolver = new StandardExodataResolver(); BaseTestSubjectExodataSurrogate.ShouldYieldInstanceExodata = true; var value = resolver.TryResolve(CommonExodata.Description).For(BaseTestSubjectExodataSurrogate.Subject); Assert.AreEqual("Special Instance Description", value); }
public void Resolve_WithMultipleMembers_YieldsExodata() { var resolver = new StandardExodataResolver(); resolver.Bind(IntegerExodata.MinValue) .For <DateTime>(x => x.Day, x => x.Month) .To(42); Assert.AreEqual(42, resolver.TryResolve(IntegerExodata.MinValue).For <DateTime>(x => x.Day)); Assert.AreEqual(42, resolver.TryResolve(IntegerExodata.MinValue).For <DateTime>(x => x.Month)); }
public void ValidateValue_WithoutValidValue_ThrowsException() { var betweenOneAndTen = new ComparableExodataDeclaration <int>(1, 10, 5); var resolver = new StandardExodataResolver(); resolver.Bind(betweenOneAndTen, 42); ExodataDeclaration.SetResolver(resolver); Assert.Throws <ExodataValidationException <int> >(() => betweenOneAndTen.Get()); }
public void ValidateValue_WithValidValue_DoesNotThrowException() { var betweenOneAndTen = new ComparableExodataDeclaration <int>(1, 10, 5); var resolver = new StandardExodataResolver(); resolver.Bind(betweenOneAndTen, 7); ExodataDeclaration.SetResolver(resolver); Assert.AreEqual(7, betweenOneAndTen.Get()); }
public void Resolve_ThruImplicitCastOperator_ReturnsValue() { var resolver = new StandardExodataResolver(); resolver.Bind(StringExodata.MaxLength, 42); ExodataDeclaration.SetResolver(resolver); int value = StringExodata.MaxLength; Assert.AreEqual(42, value); }
public void TryResolve_AfterUnloadingModule_ReturnsNoValue() { var module = new TestExodataBindingModule(); var resolver = new StandardExodataResolver(module); Maybe <int> value = resolver.TryResolve(StringExodata.MaxLength).TryGet(); Assert.IsTrue(value == 42); resolver.UnloadModule(module); value = resolver.TryResolve(StringExodata.MaxLength).TryGet(); Assert.IsTrue(value == Maybe <int> .NoValue); }
public void Resolve_WithDerivedInstance_YieldsMostDerivedBindingsExodata() { var resolver = new StandardExodataResolver(); resolver.Bind(CommonExodata.Description) .For <DerivedTestSubject>() .To("Derived Surrogate Description"); BaseTestSubjectExodataSurrogate.ShouldYieldInstanceExodata = true; var value = resolver.TryResolve(CommonExodata.Description).For(new DerivedTestSubject()); Assert.AreEqual("Derived Surrogate Description", value); }
public void Get_WithValidArguments_ReturnsExodataResolverResults() { var maxLength = new ExodataDeclaration <int>(7); var resolver = new StandardExodataResolver(); resolver.Bind(maxLength) .For <string>() .To(42); ExodataDeclaration.SetResolver(resolver); var value = maxLength.For <string>(); Assert.AreEqual(42, value); }
public void Get_WithNoExodataResolver_UsesResolverFromIoc() { var maxLength = new ExodataDeclaration <int>(7); var exodataResolver = new StandardExodataResolver(); exodataResolver.Bind(maxLength) .For <string>() .To(42); Ioc.SetDependencyResolver(new DependencyResolver(symbol => symbol.ToMaybe().OfType <IDependencySymbol>().Where(x => x.DependencyType == typeof(IExodataResolver)).Select(x => (object)exodataResolver))); var value = maxLength.For <string>(); Assert.AreEqual(42, value); }
public void Resolve_WithAttributedProperty_ReturnsValue() { var resolver = new StandardExodataResolver(); var minLength = resolver.TryResolve(StringExodata.MinLength).For <TestSubject>(x => x.FirstName); Assert.AreEqual(21, minLength); var maxLength = resolver.TryResolve(StringExodata.MaxLength).For <TestSubject>(x => x.FirstName); Assert.AreEqual(84, maxLength); var description = resolver.TryResolve(CommonExodata.Description).For <TestSubject>(x => x.FirstName); Assert.AreEqual("First Name", description); }
public void Resolve_UsesIocToCreateSurrogates() { bool executed = false; Ioc.SetDependencyResolver(new DependencyResolver(x => x .ToMaybe() .OfType <IDependencySymbol>() .Where(y => typeof(BaseTestSubjectExodataSurrogate).IsAssignableFrom(y.DependencyType)) .Select(y => Activator.CreateInstance(y.DependencyType)) .OnValue(y => executed = true))); var resolver = new StandardExodataResolver(); var value = resolver.TryResolve(StringExodata.MaxLength).For <TestSubject>(x => x.MiddleName); Assert.AreEqual(74088, value); Assert.IsTrue(executed); }
public ModuleExodataBindingSource(StandardExodataResolver parent) { Guard.NotNull(parent, "parent"); _Parent = parent; }
public void Resolve_WithSimpleStaticBinding_YieldsExodataSurrogateExodata() { var resolver = new StandardExodataResolver(); Assert.AreEqual("A string...", resolver.TryResolve(CommonExodata.Description).For <string>()); }