public void ShouldMakeNullableTypeTest() { ReflectionFascade reflectionFascade; Type conversionType; Type nullableType; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance <IDataTypeFascade>(); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); conversionType = typeof(int); nullableType = reflectionFascade.MakeNullableType(conversionType); Assert.AreEqual(typeof(int?), nullableType); conversionType = typeof(int?); nullableType = reflectionFascade.MakeNullableType(conversionType); Assert.AreEqual(typeof(int?), nullableType); conversionType = typeof(IDisposable); nullableType = reflectionFascade.MakeNullableType(conversionType); Assert.AreEqual(typeof(IDisposable), nullableType); }
public void ShouldFailOnNoMatchingConstructorTest() { TransientActivatorAutoWiringDependencyResolution transientActivatorAutoWiringDependencyResolution; IDependencyManager mockDependencyManager; IReflectionFascade mockReflectionFascade; Type activatorType; object result; MockFactory mockFactory; string _unusedString = null; bool _unusedBoolean = false; Type _unusedType = null; ConstructorInfo _unusedConstructorInfo = null; mockFactory = new MockFactory(); mockDependencyManager = mockFactory.CreateInstance <IDependencyManager>(); mockReflectionFascade = mockFactory.CreateInstance <IReflectionFascade>(); // TODO: reflection to fascade classes IReflectionFascade stubReflectionFascade; stubReflectionFascade = new ReflectionFascade(new DataTypeFascade()); mockReflectionFascade = stubReflectionFascade; activatorType = typeof(MockAmbiguousCtorMatchDependantObject); //Expect.On(mockReflectionFascade).Exactly(4).Method(x => x.GetOneAttribute<DependencyInjectionAttribute>(_unusedConstructorInfo)).WithAnyArguments().Will(Return.Value<DependencyInjectionAttribute>((DependencyInjectionAttribute)null)); transientActivatorAutoWiringDependencyResolution = new TransientActivatorAutoWiringDependencyResolution(mockReflectionFascade, activatorType); Assert.AreEqual(DependencyLifetime.Transient, transientActivatorAutoWiringDependencyResolution.DependencyLifetime); result = transientActivatorAutoWiringDependencyResolution.Resolve(mockDependencyManager, typeof(object), "boaty_mcboatface_NO_MATCH_right?"); }
private static void AddTrustedDependencies(IDependencyManager dependencyManager) { IDataTypeFascade dataTypeFascade; IReflectionFascade reflectionFascade; IConfigurationRoot configurationRoot; IAppConfigFascade appConfigFascade; IAssemblyInformationFascade assemblyInformationFascade; if ((object)dependencyManager == null) { throw new ArgumentNullException(nameof(dependencyManager)); } dataTypeFascade = new DataTypeFascade(); reflectionFascade = new ReflectionFascade(dataTypeFascade); configurationRoot = LoadAppConfigFile(APP_CONFIG_FILE_NAME); appConfigFascade = new AppConfigFascade(configurationRoot, dataTypeFascade); assemblyInformationFascade = new AssemblyInformationFascade(reflectionFascade, Assembly.GetEntryAssembly()); dependencyManager.AddResolution <IConfigurationRoot>(string.Empty, false, new SingletonWrapperDependencyResolution <IConfigurationRoot>(new InstanceDependencyResolution <IConfigurationRoot>(configurationRoot))); dependencyManager.AddResolution <IDataTypeFascade>(string.Empty, false, new SingletonWrapperDependencyResolution <IDataTypeFascade>(new InstanceDependencyResolution <IDataTypeFascade>(dataTypeFascade))); dependencyManager.AddResolution <IReflectionFascade>(string.Empty, false, new SingletonWrapperDependencyResolution <IReflectionFascade>(new InstanceDependencyResolution <IReflectionFascade>(reflectionFascade))); dependencyManager.AddResolution <IAppConfigFascade>(string.Empty, false, new SingletonWrapperDependencyResolution <IAppConfigFascade>(new InstanceDependencyResolution <IAppConfigFascade>(appConfigFascade))); dependencyManager.AddResolution <IAssemblyInformationFascade>(string.Empty, false, new SingletonWrapperDependencyResolution <IAssemblyInformationFascade>(new InstanceDependencyResolution <IAssemblyInformationFascade>(assemblyInformationFascade))); }
public void ShouldGetErrors() { ReflectionFascade reflectionFascade; MockException mockException; string message; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance <IDataTypeFascade>(); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); try { try { throw new InvalidOperationException("ioe.collected.outer", new DivideByZeroException("dbze.collected.inner")); } catch (Exception ex) { mockException = new MockException("me.outer", new BadImageFormatException("bie.inner")); mockException.CollectedExceptions.Add(ex); throw mockException; } } catch (Exception ex) { message = reflectionFascade.GetErrors(ex, 0); Console.WriteLine(message); } }
public void ShouldGetAttributeTest() { ReflectionFascade reflectionFascade; MockSingleTestAttibute sta; Type targetType; MethodInfo methodInfo; ParameterInfo parameterInfo; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; targetType = typeof(MockTestAttributedClass); var _targetType = targetType.GetTypeInfo(); mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance <IDataTypeFascade>(); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); sta = reflectionFascade.GetOneAttribute <MockSingleTestAttibute>(_targetType.Module); Assert.IsNotNull(sta); Assert.AreEqual(int.MinValue, sta.Value); sta = reflectionFascade.GetOneAttribute <MockSingleTestAttibute>(_targetType.Assembly); Assert.IsNotNull(sta); Assert.AreEqual(int.MaxValue, sta.Value); sta = reflectionFascade.GetOneAttribute <MockSingleTestAttibute>(targetType); Assert.IsNotNull(sta); Assert.AreEqual(1, sta.Value); methodInfo = targetType.GetMethod(nameof(MockTestAttributedClass.MyMethod)); Assert.IsNotNull(methodInfo); sta = reflectionFascade.GetOneAttribute <MockSingleTestAttibute>(methodInfo); Assert.IsNotNull(sta); Assert.AreEqual(2, sta.Value); parameterInfo = methodInfo.GetParameters().Single(p => p.Name == "obj"); Assert.IsNotNull(parameterInfo); sta = reflectionFascade.GetOneAttribute <MockSingleTestAttibute>(parameterInfo); Assert.IsNotNull(sta); Assert.AreEqual(4, sta.Value); parameterInfo = methodInfo.ReturnParameter; Assert.IsNotNull(parameterInfo); sta = reflectionFascade.GetOneAttribute <MockSingleTestAttibute>(parameterInfo); Assert.IsNotNull(sta); Assert.AreEqual(8, sta.Value); }
public void ShouldFailOnCreateNullDataType() { IReflectionFascade reflectionFascade; IDataTypeFascade mockDataTypeFascade; mockDataTypeFascade = null; reflectionFascade = new ReflectionFascade(mockDataTypeFascade); }
public void ShouldFailOnNullValueCreateTest() { DynamicValueTokenReplacementStrategy tokenReplacementStrategy; Func <string[], object> value; value = null; // TODO - MOCK THIS IDataTypeFascade mockDataTypeFascade = new DataTypeFascade(); IReflectionFascade mockReflectionFascade = new ReflectionFascade(mockDataTypeFascade); tokenReplacementStrategy = new DynamicValueTokenReplacementStrategy(mockDataTypeFascade, mockReflectionFascade, value); }
public void ShouldFailOnMultiDefinedGetAttributeTest() { ReflectionFascade reflectionFascade; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance <IDataTypeFascade>(); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); reflectionFascade.GetOneAttribute <MockMultipleTestAttibute>(typeof(MockTestAttributedClass)); }
public void ShouldFailOnNullConversionTypeMakeNullableTypeTest() { ReflectionFascade reflectionFascade; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance <IDataTypeFascade>(); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); reflectionFascade.MakeNullableType(null); }
public void ShouldFailOnNullTargetGetZeroAttributesTest() { ReflectionFascade reflectionFascade; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance <IDataTypeFascade>(); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); reflectionFascade.GetZeroAttributes <MockMultipleTestAttibute>(null); }
public void ShouldGetNoAttributesTest() { ReflectionFascade reflectionFascade; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance <IDataTypeFascade>(); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); reflectionFascade.GetZeroAttributes <AssemblyDescriptionAttribute>(typeof(MockTestAttributedClass)); }
public void ShouldCreateAndEvaluateTest() { TransientActivatorAutoWiringDependencyResolution transientActivatorAutoWiringDependencyResolution; IDependencyManager mockDependencyManager; IReflectionFascade mockReflectionFascade; Type activatorType; object result; MockFactory mockFactory; string _unusedString = null; bool _unusedBoolean = false; Type _unusedType = null; ConstructorInfo _unusedConstructorInfo = null; mockFactory = new MockFactory(); mockDependencyManager = mockFactory.CreateInstance <IDependencyManager>(); mockReflectionFascade = mockFactory.CreateInstance <IReflectionFascade>(); // TODO: reflection to fascade classes IReflectionFascade stubReflectionFascade; stubReflectionFascade = new ReflectionFascade(new DataTypeFascade()); mockReflectionFascade = stubReflectionFascade; activatorType = typeof(MockDependantObject); //Expect.On(mockReflectionFascade).Exactly(4).Method(x => x.GetOneAttribute<DependencyInjectionAttribute>(_unusedConstructorInfo)).WithAnyArguments().Will(Return.Value<DependencyInjectionAttribute>((DependencyInjectionAttribute)null)); Expect.On(mockDependencyManager).One.Method(m => m.ResolveDependency(_unusedType, _unusedString, _unusedBoolean)).With(typeof(MockDependantObject), "named_dep_obj", true).Will(Return.Value(new MockDependantObject("left"))); Expect.On(mockDependencyManager).One.Method(m => m.ResolveDependency(_unusedType, _unusedString, _unusedBoolean)).With(typeof(MockDependantObject), string.Empty, true).Will(Return.Value(new MockDependantObject("right"))); transientActivatorAutoWiringDependencyResolution = new TransientActivatorAutoWiringDependencyResolution(mockReflectionFascade, activatorType); Assert.AreEqual(DependencyLifetime.Transient, transientActivatorAutoWiringDependencyResolution.DependencyLifetime); result = transientActivatorAutoWiringDependencyResolution.Resolve(mockDependencyManager, typeof(object), string.Empty); Assert.IsNotNull(result); Assert.IsInstanceOf <MockDependantObject>(result); Assert.IsNotNull(((MockDependantObject)result).Text); Assert.AreEqual(string.Empty, ((MockDependantObject)result).Text); Assert.IsNotNull(((MockDependantObject)result).Left); Assert.IsNotNull(((MockDependantObject)result).Right); Assert.AreEqual("left", ((MockDependantObject)result).Left.Text); Assert.AreEqual("right", ((MockDependantObject)result).Right.Text); transientActivatorAutoWiringDependencyResolution.Dispose(); mockFactory.VerifyAllExpectationsHaveBeenMet(); }
public void ShouldFailOnNullTokenReplStratsCreateTest() { Tokenizer tokenizer; MockFactory mockFactory; IDictionary <string, ITokenReplacementStrategy> mockTokenReplacementStrategies; mockFactory = new MockFactory(); mockTokenReplacementStrategies = null; // TODO - MOCK THIS IDataTypeFascade mockDataTypeFascade = new DataTypeFascade(); IReflectionFascade mockReflectionFascade = new ReflectionFascade(mockDataTypeFascade); tokenizer = new Tokenizer(mockDataTypeFascade, mockReflectionFascade, mockTokenReplacementStrategies, true); mockFactory.VerifyAllExpectationsHaveBeenMet(); }
public void ShouldGetNullAttributeTest() { ReflectionFascade reflectionFascade; MockMultipleTestAttibute ta; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance <IDataTypeFascade>(); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); ta = reflectionFascade.GetOneAttribute <MockMultipleTestAttibute>(typeof(Exception)); Assert.IsNull(ta); }
public void ShouldGetEmptyAttributesTest() { ReflectionFascade reflectionFascade; MockMultipleTestAttibute[] tas; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance <IDataTypeFascade>(); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); tas = reflectionFascade.GetAllAttributes <MockMultipleTestAttibute>(typeof(Exception)); Assert.IsNotNull(tas); Assert.IsEmpty(tas); }
public void ShouldGetAttributesTest() { ReflectionFascade reflectionFascade; MockMultipleTestAttibute[] tas; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance <IDataTypeFascade>(); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); tas = reflectionFascade.GetAllAttributes <MockMultipleTestAttibute>(typeof(MockTestAttributedClass)); Assert.IsNotNull(tas); Assert.AreEqual(2, tas.Length); }
public void ShouldCreateAndEvaluateSelectorKeyTest() { TransientActivatorAutoWiringDependencyResolution <MockDependantObject> transientActivatorAutoWiringDependencyResolution; IDependencyManager mockDependencyManager; IReflectionFascade mockReflectionFascade; MockDependantObject result; MockFactory mockFactory; string _unusedString = null; bool _unusedBoolean = false; Type _unusedType = null; mockFactory = new MockFactory(); mockDependencyManager = mockFactory.CreateInstance <IDependencyManager>(); mockReflectionFascade = mockFactory.CreateInstance <IReflectionFascade>(); // TODO: reflection to fascade classes IReflectionFascade stubReflectionFascade; stubReflectionFascade = new ReflectionFascade(new DataTypeFascade()); mockReflectionFascade = stubReflectionFascade; Expect.On(mockDependencyManager).One.Method(m => m.ResolveDependency(_unusedType, _unusedString, _unusedBoolean)).With(typeof(MockDependantObject), string.Empty, true).Will(Return.Value(new MockDependantObject("both"))); transientActivatorAutoWiringDependencyResolution = new TransientActivatorAutoWiringDependencyResolution <MockDependantObject>(mockReflectionFascade); Assert.AreEqual(DependencyLifetime.Transient, transientActivatorAutoWiringDependencyResolution.DependencyLifetime); result = transientActivatorAutoWiringDependencyResolution.Resolve(mockDependencyManager, "named_dep_obj"); Assert.IsNotNull(result); Assert.IsInstanceOf <MockDependantObject>(result); Assert.IsNotNull(result.Text); Assert.AreEqual(string.Empty, result.Text); Assert.IsNotNull(result.Left); Assert.IsNotNull(result.Right); Assert.AreEqual("both", result.Left.Text); Assert.AreEqual("both", result.Right.Text); transientActivatorAutoWiringDependencyResolution.Dispose(); mockFactory.VerifyAllExpectationsHaveBeenMet(); }
public void ShouldCreateTest() { Tokenizer tokenizer; MockFactory mockFactory; IDictionary <string, ITokenReplacementStrategy> mockTokenReplacementStrategies; mockFactory = new MockFactory(); mockTokenReplacementStrategies = mockFactory.CreateInstance <IDictionary <string, ITokenReplacementStrategy> >(); // TODO - MOCK THIS IDataTypeFascade mockDataTypeFascade = new DataTypeFascade(); IReflectionFascade mockReflectionFascade = new ReflectionFascade(mockDataTypeFascade); tokenizer = new Tokenizer(mockDataTypeFascade, mockReflectionFascade, mockTokenReplacementStrategies, true); Assert.IsNotNull(tokenizer); Assert.IsNotNull(tokenizer.TokenReplacementStrategies); Assert.IsTrue(tokenizer.StrictMatching); mockFactory.VerifyAllExpectationsHaveBeenMet(); }
public void ShouldCreateAndEvaluateTest() { DynamicValueTokenReplacementStrategy tokenReplacementStrategy; Func <string[], object> value; object result; value = p => int.Parse(p[0]) + 1; // TODO - MOCK THIS IDataTypeFascade mockDataTypeFascade = new DataTypeFascade(); IReflectionFascade mockReflectionFascade = new ReflectionFascade(mockDataTypeFascade); tokenReplacementStrategy = new DynamicValueTokenReplacementStrategy(mockDataTypeFascade, mockReflectionFascade, value); Assert.IsNotNull(tokenReplacementStrategy); Assert.IsNotNull(tokenReplacementStrategy.Method); result = tokenReplacementStrategy.Evaluate(new string[] { "10" }); Assert.IsNotNull(result); Assert.AreEqual(11, result); }
public void ShouldExpandTokensLooseMatchingTest() { Tokenizer tokenizer; MockFactory mockFactory; IDictionary <string, ITokenReplacementStrategy> mockTokenReplacementStrategies; ITokenReplacementStrategy mockTokenReplacementStrategy; ITokenReplacementStrategy _unusedTokenReplacementStrategy = null; string _unusedString = null; string[] _unusedStrings = null; string tokenizedValue; string expandedValue; string expectedValue; mockFactory = new MockFactory(); mockTokenReplacementStrategies = mockFactory.CreateInstance <IDictionary <string, ITokenReplacementStrategy> >(); mockTokenReplacementStrategy = mockFactory.CreateInstance <ITokenReplacementStrategy>(); Expect.On(mockTokenReplacementStrategies).One.Method(x => x.TryGetValue(_unusedString, out _unusedTokenReplacementStrategy)).With(new EqualMatcher("myValueSemanticToken"), new AndMatcher(new ArgumentsMatcher.OutMatcher(), new AlwaysMatcher(true, string.Empty))).Will(new SetNamedParameterAction("value", mockTokenReplacementStrategy), Return.Value(true)); Expect.On(mockTokenReplacementStrategy).One.Method(x => x.Evaluate(_unusedStrings)).With(new EqualMatcher(null)).WillReturn("testValue"); Expect.On(mockTokenReplacementStrategies).One.Method(x => x.TryGetValue(_unusedString, out _unusedTokenReplacementStrategy)).With(new EqualMatcher("myFunctionSemanticToken0"), new AndMatcher(new ArgumentsMatcher.OutMatcher(), new AlwaysMatcher(true, string.Empty))).Will(new SetNamedParameterAction("value", mockTokenReplacementStrategy), Return.Value(true)); Expect.On(mockTokenReplacementStrategy).One.Method(x => x.Evaluate(_unusedStrings)).With(new EqualMatcher(new string[] { })).WillReturn("testValue"); Expect.On(mockTokenReplacementStrategies).One.Method(x => x.TryGetValue(_unusedString, out _unusedTokenReplacementStrategy)).With(new EqualMatcher("myFunctionSemanticToken1"), new AndMatcher(new ArgumentsMatcher.OutMatcher(), new AlwaysMatcher(true, string.Empty))).Will(new SetNamedParameterAction("value", mockTokenReplacementStrategy), Return.Value(true)); Expect.On(mockTokenReplacementStrategy).One.Method(x => x.Evaluate(_unusedStrings)).With(new EqualMatcher(new string[] { "a", })).WillReturn("testValue"); Expect.On(mockTokenReplacementStrategies).One.Method(x => x.TryGetValue(_unusedString, out _unusedTokenReplacementStrategy)).With(new EqualMatcher("myFunctionSemanticToken2"), new AndMatcher(new ArgumentsMatcher.OutMatcher(), new AlwaysMatcher(true, string.Empty))).Will(new SetNamedParameterAction("value", mockTokenReplacementStrategy), Return.Value(true)); Expect.On(mockTokenReplacementStrategy).One.Method(x => x.Evaluate(_unusedStrings)).With(new EqualMatcher(new string[] { "a", "b" })).WillReturn("testValue"); Expect.On(mockTokenReplacementStrategies).One.Method(x => x.TryGetValue(_unusedString, out _unusedTokenReplacementStrategy)).With(new EqualMatcher("myUnkSemanticToken"), new AndMatcher(new ArgumentsMatcher.OutMatcher(), new AlwaysMatcher(true, string.Empty))).Will(new SetNamedParameterAction("value", null), Return.Value(false)); Expect.On(mockTokenReplacementStrategies).One.Method(x => x.TryGetValue(_unusedString, out _unusedTokenReplacementStrategy)).With(new EqualMatcher("myErrSemanticToken"), new AndMatcher(new ArgumentsMatcher.OutMatcher(), new AlwaysMatcher(true, string.Empty))).Will(new SetNamedParameterAction("value", mockTokenReplacementStrategy), Return.Value(true)); Expect.On(mockTokenReplacementStrategy).One.Method(x => x.Evaluate(_unusedStrings)).With(new EqualMatcher(null)).Will(Throw.Exception(new Exception())); Expect.On(mockTokenReplacementStrategies).One.Method(x => x.TryGetValue(_unusedString, out _unusedTokenReplacementStrategy)).With(new EqualMatcher("a"), new AndMatcher(new ArgumentsMatcher.OutMatcher(), new AlwaysMatcher(true, string.Empty))).Will(new SetNamedParameterAction("value", mockTokenReplacementStrategy), Return.Value(true)); Expect.On(mockTokenReplacementStrategy).One.Method(x => x.Evaluate(_unusedStrings)).With(new EqualMatcher(null)).WillReturn(string.Empty); Expect.On(mockTokenReplacementStrategies).One.Method(x => x.TryGetValue(_unusedString, out _unusedTokenReplacementStrategy)).With(new EqualMatcher("b"), new AndMatcher(new ArgumentsMatcher.OutMatcher(), new AlwaysMatcher(true, string.Empty))).Will(new SetNamedParameterAction("value", mockTokenReplacementStrategy), Return.Value(true)); Expect.On(mockTokenReplacementStrategy).One.Method(x => x.Evaluate(_unusedStrings)).With(new EqualMatcher(null)).WillReturn(string.Empty); Expect.On(mockTokenReplacementStrategies).One.Method(x => x.TryGetValue(_unusedString, out _unusedTokenReplacementStrategy)).With(new EqualMatcher("c"), new AndMatcher(new ArgumentsMatcher.OutMatcher(), new AlwaysMatcher(true, string.Empty))).Will(new SetNamedParameterAction("value", mockTokenReplacementStrategy), Return.Value(true)); Expect.On(mockTokenReplacementStrategy).One.Method(x => x.Evaluate(_unusedStrings)).With(new EqualMatcher(null)).WillReturn(string.Empty); Expect.On(mockTokenReplacementStrategies).One.Method(x => x.TryGetValue(_unusedString, out _unusedTokenReplacementStrategy)).With(new EqualMatcher("d"), new AndMatcher(new ArgumentsMatcher.OutMatcher(), new AlwaysMatcher(true, string.Empty))).Will(new SetNamedParameterAction("value", mockTokenReplacementStrategy), Return.Value(true)); Expect.On(mockTokenReplacementStrategy).One.Method(x => x.Evaluate(_unusedStrings)).With(new EqualMatcher(null)).Will(Throw.Exception(new Exception())); // TODO - MOCK THIS IDataTypeFascade mockDataTypeFascade = new DataTypeFascade(); IReflectionFascade mockReflectionFascade = new ReflectionFascade(mockDataTypeFascade); tokenizer = new Tokenizer(mockDataTypeFascade, mockReflectionFascade, mockTokenReplacementStrategies, false); tokenizedValue = string.Empty; expandedValue = tokenizer.ExpandTokens(tokenizedValue); expectedValue = string.Empty; Assert.AreEqual(expectedValue, expandedValue); tokenizedValue = "...{myNoSemanticToken}..."; expandedValue = tokenizer.ExpandTokens(tokenizedValue); expectedValue = "...{myNoSemanticToken}..."; Assert.AreEqual(expectedValue, expandedValue); tokenizedValue = "...${myValueSemanticToken}..."; expandedValue = tokenizer.ExpandTokens(tokenizedValue); expectedValue = "...testValue..."; Assert.AreEqual(expectedValue, expandedValue); tokenizedValue = "...${myFunctionSemanticToken0()}..."; expandedValue = tokenizer.ExpandTokens(tokenizedValue); expectedValue = "...testValue..."; Assert.AreEqual(expectedValue, expandedValue); tokenizedValue = "...${myFunctionSemanticToken1(`a`)}..."; expandedValue = tokenizer.ExpandTokens(tokenizedValue); expectedValue = "...testValue..."; Assert.AreEqual(expectedValue, expandedValue); tokenizedValue = "...${myFunctionSemanticToken2(`a`, `b`)}..."; expandedValue = tokenizer.ExpandTokens(tokenizedValue); expectedValue = "...testValue..."; Assert.AreEqual(expectedValue, expandedValue); tokenizedValue = "...${myUnkSemanticToken}..."; expandedValue = tokenizer.ExpandTokens(tokenizedValue); expectedValue = "...${myUnkSemanticToken}..."; Assert.AreEqual(expectedValue, expandedValue); tokenizedValue = "...${myErrSemanticToken}..."; expandedValue = tokenizer.ExpandTokens(tokenizedValue); expectedValue = "...${myErrSemanticToken}..."; Assert.AreEqual(expectedValue, expandedValue); tokenizedValue = "...${a}...${c}...${b}...${d}..."; expandedValue = tokenizer.ExpandTokens(tokenizedValue); expectedValue = "............${d}..."; Assert.AreEqual(expectedValue, expandedValue); Assert.IsNotNull(tokenizer.OrderedPreviousExpansionTokens); Assert.AreEqual("a,b,c,d", string.Join(",", tokenizer.OrderedPreviousExpansionTokens)); mockFactory.VerifyAllExpectationsHaveBeenMet(); }
public void ShouldAssociativeOnlyGetLogicalPropertyTypeTest() { ReflectionFascade reflectionFascade; Dictionary<string, object> mockObject; string propertyName; Type propertyType; bool result; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; string _unusedString = null; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance<IDataTypeFascade>(); Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With((object)null).Will(Return.Value(true)); Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With(string.Empty).Will(Return.Value(true)); Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With("FirstName").Will(Return.Value(false)); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); // null, null mockObject = null; propertyName = null; result = reflectionFascade.GetLogicalPropertyType(mockObject, propertyName, out propertyType); Assert.IsFalse(result); Assert.IsNull(propertyType); // null, "" mockObject = null; propertyName = string.Empty; result = reflectionFascade.GetLogicalPropertyType(mockObject, propertyName, out propertyType); Assert.IsFalse(result); Assert.IsNull(propertyType); // null, "PropName" mockObject = null; propertyName = "FirstName"; result = reflectionFascade.GetLogicalPropertyType(mockObject, propertyName, out propertyType); Assert.IsFalse(result); Assert.IsNull(propertyType); // !null, null mockObject = new Dictionary<string, object>(); propertyName = null; result = reflectionFascade.GetLogicalPropertyType(mockObject, propertyName, out propertyType); Assert.IsFalse(result); Assert.IsNull(propertyType); // !null, "" mockObject = new Dictionary<string, object>(); propertyName = string.Empty; result = reflectionFascade.GetLogicalPropertyType(mockObject, propertyName, out propertyType); Assert.IsFalse(result); Assert.IsNull(propertyType); // !null, "PropName" mockObject = new Dictionary<string, object>(); mockObject["FirstName"] = "john"; propertyName = "FirstName"; result = reflectionFascade.GetLogicalPropertyType(mockObject, propertyName, out propertyType); Assert.IsTrue(result); Assert.IsNotNull(propertyType); Assert.AreEqual(typeof(string), propertyType); mockFactory.VerifyAllExpectationsHaveBeenMet(); }
public void ShouldFailOnMultiDefinedGetAttributeTest() { ReflectionFascade reflectionFascade; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance<IDataTypeFascade>(); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); reflectionFascade.GetOneAttribute<MockMultipleTestAttibute>(typeof(MockTestAttributedClass)); }
public void ShouldReflectionOnlySetLogicalPropertyValueTest() { ReflectionFascade reflectionFascade; MockObject mockObject; string propertyName; object propertyValue; bool result; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; string _unusedString = null; object _unusedObject = null; Type _unusedType = null; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance<IDataTypeFascade>(); Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With((object)null).Will(Return.Value(true)); Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With(string.Empty).Will(Return.Value(true)); Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With("FirstName").Will(Return.Value(false)); Expect.On(mockDataTypeFascade).Exactly(2).Method(m => m.ChangeType(_unusedObject, _unusedType)).WithAnyArguments().Will(Return.Value(null)); Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With("NoGetter").Will(Return.Value(false)); Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With("NoSetter").Will(Return.Value(false)); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); propertyValue = null; // null, null mockObject = null; propertyName = null; result = reflectionFascade.SetLogicalPropertyValue(mockObject, propertyName, propertyValue); Assert.IsFalse(result); Assert.IsNull(propertyValue); // null, "" mockObject = null; propertyName = string.Empty; result = reflectionFascade.SetLogicalPropertyValue(mockObject, propertyName, propertyValue); Assert.IsFalse(result); Assert.IsNull(propertyValue); // null, "PropName" mockObject = null; propertyName = "FirstName"; result = reflectionFascade.SetLogicalPropertyValue(mockObject, propertyName, propertyValue); Assert.IsFalse(result); Assert.IsNull(propertyValue); // !null, null mockObject = new MockObject(); propertyName = null; result = reflectionFascade.SetLogicalPropertyValue(mockObject, propertyName, propertyValue); Assert.IsFalse(result); Assert.IsNull(propertyValue); // !null, "" mockObject = new MockObject(); propertyName = string.Empty; result = reflectionFascade.SetLogicalPropertyValue(mockObject, propertyName, propertyValue); Assert.IsFalse(result); Assert.IsNull(propertyValue); // !null, "PropName" mockObject = new MockObject(); propertyName = "FirstName"; propertyValue = "john"; result = reflectionFascade.SetLogicalPropertyValue(mockObject, propertyName, propertyValue); Assert.IsTrue(result); Assert.IsNotNull(propertyValue); Assert.AreEqual("john", propertyValue); // !null, "PropName:PropName!!!getter" mockObject = new MockObject(); propertyName = "NoGetter"; propertyValue = "john"; result = reflectionFascade.SetLogicalPropertyValue(mockObject, propertyName, propertyValue); Assert.IsTrue(result); Assert.IsNotNull(propertyValue); Assert.AreEqual("john", propertyValue); // !null, "PropName:PropName!!!setter" mockObject = new MockObject(); mockObject.FirstName = "john"; propertyName = "NoSetter"; result = reflectionFascade.SetLogicalPropertyValue(mockObject, propertyName, propertyValue); Assert.IsFalse(result); }
public void ShouldFailOnNullConversionTypeMakeNullableTypeTest() { ReflectionFascade reflectionFascade; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance<IDataTypeFascade>(); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); reflectionFascade.MakeNullableType(null); }
public void ShouldGetAttributeTest() { ReflectionFascade reflectionFascade; MockSingleTestAttibute sta; Type targetType; MethodInfo methodInfo; ParameterInfo parameterInfo; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; targetType = typeof(MockTestAttributedClass); var _targetType = targetType.GetTypeInfo(); mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance<IDataTypeFascade>(); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); sta = reflectionFascade.GetOneAttribute<MockSingleTestAttibute>(_targetType.Module); Assert.IsNotNull(sta); Assert.AreEqual(int.MinValue, sta.Value); sta = reflectionFascade.GetOneAttribute<MockSingleTestAttibute>(_targetType.Assembly); Assert.IsNotNull(sta); Assert.AreEqual(int.MaxValue, sta.Value); sta = reflectionFascade.GetOneAttribute<MockSingleTestAttibute>(targetType); Assert.IsNotNull(sta); Assert.AreEqual(1, sta.Value); methodInfo = targetType.GetMethod(nameof(MockTestAttributedClass.MyMethod)); Assert.IsNotNull(methodInfo); sta = reflectionFascade.GetOneAttribute<MockSingleTestAttibute>(methodInfo); Assert.IsNotNull(sta); Assert.AreEqual(2, sta.Value); parameterInfo = methodInfo.GetParameters().Single(p => p.Name == "obj"); Assert.IsNotNull(parameterInfo); sta = reflectionFascade.GetOneAttribute<MockSingleTestAttibute>(parameterInfo); Assert.IsNotNull(sta); Assert.AreEqual(4, sta.Value); parameterInfo = methodInfo.ReturnParameter; Assert.IsNotNull(parameterInfo); sta = reflectionFascade.GetOneAttribute<MockSingleTestAttibute>(parameterInfo); Assert.IsNotNull(sta); Assert.AreEqual(8, sta.Value); }
public void ShouldGetAttributesTest() { ReflectionFascade reflectionFascade; MockMultipleTestAttibute[] tas; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance<IDataTypeFascade>(); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); tas = reflectionFascade.GetAllAttributes<MockMultipleTestAttibute>(typeof(MockTestAttributedClass)); Assert.IsNotNull(tas); Assert.AreEqual(2, tas.Length); }
public void ShouldGetEmptyAttributesTest() { ReflectionFascade reflectionFascade; MockMultipleTestAttibute[] tas; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance<IDataTypeFascade>(); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); tas = reflectionFascade.GetAllAttributes<MockMultipleTestAttibute>(typeof(Exception)); Assert.IsNotNull(tas); Assert.IsEmpty(tas); }
public void ShouldAssociativeOnlyGetLogicalPropertyTypeTest() { ReflectionFascade reflectionFascade; Dictionary <string, object> mockObject; string propertyName; Type propertyType; bool result; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; string _unusedString = null; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance <IDataTypeFascade>(); Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With((object)null).Will(Return.Value(true)); Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With(string.Empty).Will(Return.Value(true)); Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With("FirstName").Will(Return.Value(false)); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); // null, null mockObject = null; propertyName = null; result = reflectionFascade.GetLogicalPropertyType(mockObject, propertyName, out propertyType); Assert.IsFalse(result); Assert.IsNull(propertyType); // null, "" mockObject = null; propertyName = string.Empty; result = reflectionFascade.GetLogicalPropertyType(mockObject, propertyName, out propertyType); Assert.IsFalse(result); Assert.IsNull(propertyType); // null, "PropName" mockObject = null; propertyName = "FirstName"; result = reflectionFascade.GetLogicalPropertyType(mockObject, propertyName, out propertyType); Assert.IsFalse(result); Assert.IsNull(propertyType); // !null, null mockObject = new Dictionary <string, object>(); propertyName = null; result = reflectionFascade.GetLogicalPropertyType(mockObject, propertyName, out propertyType); Assert.IsFalse(result); Assert.IsNull(propertyType); // !null, "" mockObject = new Dictionary <string, object>(); propertyName = string.Empty; result = reflectionFascade.GetLogicalPropertyType(mockObject, propertyName, out propertyType); Assert.IsFalse(result); Assert.IsNull(propertyType); // !null, "PropName" mockObject = new Dictionary <string, object>(); mockObject["FirstName"] = "john"; propertyName = "FirstName"; result = reflectionFascade.GetLogicalPropertyType(mockObject, propertyName, out propertyType); Assert.IsTrue(result); Assert.IsNotNull(propertyType); Assert.AreEqual(typeof(string), propertyType); mockFactory.VerifyAllExpectationsHaveBeenMet(); }
public void ShouldGetErrors() { ReflectionFascade reflectionFascade; MockException mockException; string message; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance<IDataTypeFascade>(); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); try { try { throw new InvalidOperationException("ioe.collected.outer", new DivideByZeroException("dbze.collected.inner")); } catch (Exception ex) { mockException = new MockException("me.outer", new BadImageFormatException("bie.inner")); mockException.CollectedExceptions.Add(ex); throw mockException; } } catch (Exception ex) { message = reflectionFascade.GetErrors(ex, 0); Console.WriteLine(message); } }
public void ShouldGetNoAttributesTest() { ReflectionFascade reflectionFascade; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance<IDataTypeFascade>(); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); reflectionFascade.GetZeroAttributes<AssemblyDescriptionAttribute>(typeof(MockTestAttributedClass)); }
public void ShouldGetNullAttributesWithInvalidTargetTest() { ReflectionFascade reflectionFascade; MockMultipleTestAttibute[] tas; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance<IDataTypeFascade>(); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); tas = reflectionFascade.GetAllAttributes<MockMultipleTestAttibute>(int.MaxValue); Assert.IsNull(tas); }
public void ShouldReflectionOnlySetLogicalPropertyValueTest() { ReflectionFascade reflectionFascade; MockObject mockObject; string propertyName; object propertyValue; bool result; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; string _unusedString = null; object _unusedObject = null; Type _unusedType = null; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance <IDataTypeFascade>(); Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With((object)null).Will(Return.Value(true)); Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With(string.Empty).Will(Return.Value(true)); Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With("FirstName").Will(Return.Value(false)); Expect.On(mockDataTypeFascade).Exactly(2).Method(m => m.ChangeType(_unusedObject, _unusedType)).WithAnyArguments().Will(Return.Value(null)); Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With("NoGetter").Will(Return.Value(false)); Expect.On(mockDataTypeFascade).One.Method(m => m.IsNullOrWhiteSpace(_unusedString)).With("NoSetter").Will(Return.Value(false)); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); propertyValue = null; // null, null mockObject = null; propertyName = null; result = reflectionFascade.SetLogicalPropertyValue(mockObject, propertyName, propertyValue); Assert.IsFalse(result); Assert.IsNull(propertyValue); // null, "" mockObject = null; propertyName = string.Empty; result = reflectionFascade.SetLogicalPropertyValue(mockObject, propertyName, propertyValue); Assert.IsFalse(result); Assert.IsNull(propertyValue); // null, "PropName" mockObject = null; propertyName = "FirstName"; result = reflectionFascade.SetLogicalPropertyValue(mockObject, propertyName, propertyValue); Assert.IsFalse(result); Assert.IsNull(propertyValue); // !null, null mockObject = new MockObject(); propertyName = null; result = reflectionFascade.SetLogicalPropertyValue(mockObject, propertyName, propertyValue); Assert.IsFalse(result); Assert.IsNull(propertyValue); // !null, "" mockObject = new MockObject(); propertyName = string.Empty; result = reflectionFascade.SetLogicalPropertyValue(mockObject, propertyName, propertyValue); Assert.IsFalse(result); Assert.IsNull(propertyValue); // !null, "PropName" mockObject = new MockObject(); propertyName = "FirstName"; propertyValue = "john"; result = reflectionFascade.SetLogicalPropertyValue(mockObject, propertyName, propertyValue); Assert.IsTrue(result); Assert.IsNotNull(propertyValue); Assert.AreEqual("john", propertyValue); // !null, "PropName:PropName!!!getter" mockObject = new MockObject(); propertyName = "NoGetter"; propertyValue = "john"; result = reflectionFascade.SetLogicalPropertyValue(mockObject, propertyName, propertyValue); Assert.IsTrue(result); Assert.IsNotNull(propertyValue); Assert.AreEqual("john", propertyValue); // !null, "PropName:PropName!!!setter" mockObject = new MockObject(); mockObject.FirstName = "john"; propertyName = "NoSetter"; result = reflectionFascade.SetLogicalPropertyValue(mockObject, propertyName, propertyValue); Assert.IsFalse(result); }
public void ShouldFailOnNullTargetGetZeroAttributesTest() { ReflectionFascade reflectionFascade; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance<IDataTypeFascade>(); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); reflectionFascade.GetZeroAttributes<MockMultipleTestAttibute>(null); }
public void ShouldMakeNullableTypeTest() { ReflectionFascade reflectionFascade; Type conversionType; Type nullableType; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance<IDataTypeFascade>(); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); conversionType = typeof(int); nullableType = reflectionFascade.MakeNullableType(conversionType); Assert.AreEqual(typeof(int?), nullableType); conversionType = typeof(int?); nullableType = reflectionFascade.MakeNullableType(conversionType); Assert.AreEqual(typeof(int?), nullableType); conversionType = typeof(IDisposable); nullableType = reflectionFascade.MakeNullableType(conversionType); Assert.AreEqual(typeof(IDisposable), nullableType); }
public void ShouldGetNullAttributeTest() { ReflectionFascade reflectionFascade; MockMultipleTestAttibute ta; MockFactory mockFactory; IDataTypeFascade mockDataTypeFascade; mockFactory = new MockFactory(); mockDataTypeFascade = mockFactory.CreateInstance<IDataTypeFascade>(); reflectionFascade = new ReflectionFascade(mockDataTypeFascade); ta = reflectionFascade.GetOneAttribute<MockMultipleTestAttibute>(typeof(Exception)); Assert.IsNull(ta); }