public void ProvidersAreCheckedDependingOnTheConfigureAttributePrecedence() { // Arrange var provider1 = new GoodMockConfigurationMethodProvider(); var provider2 = new GoodMockConfigurationMethodProvider2(); provider1.ConfigureAttributeTypesSupported = new Type[] { typeof(HighPrecedenceConfigureAttribute) }; provider2.ConfigureAttributeTypesSupported = new Type[] { typeof(LowPrecedenceConfigureAttribute) }; Configure.TheEnvironment.AddConfigurationMethod(provider1); Configure.TheEnvironment.AddConfigurationMethod(provider2); int provider1Step = 0; int provider2Step = 0; int callCount = 0; provider1.TryPopulateBehaviour = (configurationInstance, propertyInfo, attribute) => { if (provider1Step != 0) { Assert.Fail(); } provider1Step = ++callCount; return false; }; provider2.TryPopulateBehaviour = (configurationInstance, propertyInfo, attribute) => { if (provider2Step != 0) { Assert.Fail(); } provider2Step = ++callCount; return false; }; // Action var configuration1 = Configure.Get<IPrecedenceTestConfiguration>(); // No Provider to be called. Assert.AreEqual(2, callCount); Assert.AreEqual(1, provider1Step); Assert.AreEqual(2, provider2Step); }
public void CorrectProviderIsCalledDependingOnConfigureAttributeType() { // Arrange var provider1 = new GoodMockConfigurationMethodProvider(); var provider2 = new GoodMockConfigurationMethodProvider2(); Configure.TheEnvironment.AddConfigurationMethod(provider1); Configure.TheEnvironment.AddConfigurationMethod(provider2); int provider1CallCount = 0; int provider2CallCount = 0; provider1.TryPopulateBehaviour = (configurationInstance, propertyInfo, attribute) => { provider1CallCount++; return true; }; provider2.TryPopulateBehaviour = (configurationInstance, propertyInfo, attribute) => { provider2CallCount++; return true; }; // Action provider1CallCount = 0; provider2CallCount = 0; var configuration1 = Configure.Get<IMyTestConfiguration>(); // No Provider to be called. Assert.AreEqual(0, provider1CallCount); Assert.AreEqual(0, provider2CallCount); provider1CallCount = 0; provider2CallCount = 0; var configuration2 = Configure.Get<IMyTestConfiguration2>(); // Expect provider 2 to be called. Assert.AreEqual(1, provider1CallCount); Assert.AreEqual(0, provider2CallCount); provider1CallCount = 0; provider2CallCount = 0; var configuration3 = Configure.Get<IMyTestConfiguration3>(); // Expect both to be called Assert.AreEqual(1, provider1CallCount); Assert.AreEqual(1, provider2CallCount); }
public void ProviderSupportConfigureAttributeType() { // Arrange // By Initializing the environment. var configurationProvider = new GoodMockConfigurationMethodProvider(); configurationProvider.ConfigureAttributeTypesSupported = new[] { typeof(ConfigureGoodMockAttribute) }; // Action & Assert TestDelegate testDelegate = () => Configure.TheEnvironment.AddConfigurationMethod(configurationProvider); ; Assert.DoesNotThrow(testDelegate); }
public void CorrectValuesArePassedToProvider() { // Arrange // By Initializing the environment. var configurationProvider = new GoodMockConfigurationMethodProvider(); Configure.TheEnvironment.AddConfigurationMethod(configurationProvider); configurationProvider.TryPopulateBehaviour = (configurationInstance, propertyInfo, attribute) => { Assert.IsNotNull(configurationInstance); Assert.IsInstanceOf<IMyTestConfiguration2>(configurationInstance); Assert.IsNotNull(propertyInfo); Assert.AreEqual("TestValue3", propertyInfo.Name); Assert.AreEqual(typeof(IMyTestConfiguration2), propertyInfo.DeclaringType); Assert.IsNotNull(attribute); Assert.IsInstanceOf<ConfigureGoodMockAttribute>(attribute); Assert.Pass(); return true; }; // Action var configuration = Configure.Get<IMyTestConfiguration2>(); // Assert Assert.Fail(); }
public void ProviderMustSupportAtLeastOneConfigureAttributeType() { // Arrange // By Initializing the environment. var configurationProvider = new GoodMockConfigurationMethodProvider(); configurationProvider.ConfigureAttributeTypesSupported = new Type[] { }; // Action & Assert TestDelegate testDelegate = () => Configure.TheEnvironment.AddConfigurationMethod(configurationProvider); ; Assert.Throws<ProviderMustSupportAtLeastOneConfigureAttributeType>(testDelegate); }