public ProfileManager Clone() { var clone = new ProfileManager { DefaultProfileName = DefaultProfileName }; clone.ImportFrom(this); return clone; }
public void Import_the_default_does_not_impact_the_source() { var source = new ProfileManager(); var sourceInstance = new ConfiguredInstance(typeof (AWidget)); source.SetDefault(typeof (IWidget), sourceInstance); var destination = new ProfileManager(); destination.ImportFrom(source); destination.SetDefault(typeof (IWidget), new ObjectInstance(new AWidget())); Assert.AreSame(sourceInstance, source.GetDefault(typeof (IWidget))); }
public void Import_an_instance_from_the_default_profile() { var source = new ProfileManager(); var sourceInstance = new ConfiguredInstance(typeof (AWidget)); source.SetDefault(PROFILE, typeof (IWidget), sourceInstance); var destination = new ProfileManager(); destination.DefaultProfileName = PROFILE; destination.ImportFrom(source); Assert.AreSame(sourceInstance, destination.GetDefault(typeof (IWidget))); }
public static InstanceFactory CreateFactoryForFamily(PluginFamily family, ProfileManager profileManager) { family.Seal(); var factory = new InstanceFactory(family); Instance instance = family.GetDefaultInstance(); if(instance != null) { profileManager.SetDefault(family.PluginType, instance); } return factory; }
public void Import_a_default_when_the_destination_already_has_an_active_profile() { var source = new ProfileManager(); var sourceInstance = new ConfiguredInstance(typeof (AWidget)); source.SetDefault(PROFILE, typeof (IWidget), sourceInstance); var destination = new ProfileManager(); destination.SetDefault(PROFILE, typeof (Rule), new ConfiguredInstance(typeof (ColorRule))); destination.CurrentProfile = PROFILE; destination.ImportFrom(source); Assert.AreSame(sourceInstance, destination.GetDefault(typeof (IWidget))); }
public void Throw_280_if_requesting_an_invalid_profile() { try { var manager = new ProfileManager(); manager.CurrentProfile = "some profile that does not exist"; Assert.Fail("Should have thrown error"); } catch (StructureMapException ex) { Assert.AreEqual(280, ex.ErrorCode); } }
public void Import_the_default_for_a_profile_make_sure_overriding_the_destination_does_not_impact_the_source() { var source = new ProfileManager(); var profileInstance = new ConfiguredInstance(typeof (AWidget)); source.SetDefault(PROFILE, typeof (IWidget), profileInstance); var destination = new ProfileManager(); destination.ImportFrom(source); // Source should be unchanged when destination IS changed destination.SetDefault(PROFILE, typeof (IWidget), new ObjectInstance(new AWidget())); Assert.AreSame(profileInstance, source.GetDefault(typeof (IWidget), PROFILE)); }
public void Import_a_default_for_a_profile_in_destination_will_override_existing_default_in_that_profile() { var source = new ProfileManager(); var sourceInstance = new ConfiguredInstance(typeof (AWidget)); source.SetDefault(PROFILE, typeof (IWidget), sourceInstance); // Fill in value before the ImportFrom var destination = new ProfileManager(); var destinationInstance = new ObjectInstance(new AWidget()); destination.SetDefault(PROFILE, typeof (IWidget), destinationInstance); destination.ImportFrom(source); Assert.AreSame(sourceInstance, destination.GetDefault(typeof (IWidget), PROFILE)); }
public void ImportFrom(ProfileManager source) { foreach (var pair in source._profiles) { Profile fromProfile = pair.Value; Profile toProfile = getProfile(pair.Key); fromProfile.Merge(toProfile); } source._default.Merge(_default); setProfileDefaults(new GraphLog()); CurrentProfile = CurrentProfile; }
public ProfileBuilder(PluginGraph pluginGraph) { _pluginGraph = pluginGraph; _profileManager = pluginGraph.ProfileManager; }
public static InstanceFactory CreateFactoryForType(Type concreteType, ProfileManager profileManager) { return CreateFactoryForFamily(new PluginFamily(concreteType), profileManager); }
public PluginFamily CreateTemplatedFamily(Type templatedType, ProfileManager profileManager) { Type basicType = templatedType.GetGenericTypeDefinition(); if (_families.Has(basicType)) { PluginFamily basicFamily = _families[basicType]; Type[] templatedParameterTypes = templatedType.GetGenericArguments(); PluginFamily templatedFamily = basicFamily.CreateTemplatedClone(templatedParameterTypes); PluginFamily family = templatedFamily; profileManager.CopyDefaults(basicType, templatedType, family); return family; } else { return null; } }
public void Import_the_default_for_a_profile_that_is_not_in_the_destination() { var source = new ProfileManager(); var profileInstance = new ConfiguredInstance(typeof (AWidget)); source.SetDefault(PROFILE, typeof (IWidget), profileInstance); var destination = new ProfileManager(); destination.ImportFrom(source); Assert.AreSame(profileInstance, destination.GetDefault(typeof (IWidget), PROFILE)); }
public void Import_the_default_if_it_is_completely_missing() { var source = new ProfileManager(); var sourceInstance = new ConfiguredInstance(typeof (AWidget)); source.SetDefault(typeof (IWidget), sourceInstance); var destination = new ProfileManager(); destination.ImportFrom(source); Assert.AreSame(sourceInstance, destination.GetDefault(typeof (IWidget))); }