private void AddReferenceIfNeeded(IVBProject project, IUnitTestSettings settings) { switch (settings.BindingMode) { case BindingMode.EarlyBinding: _interaction.EnsureProjectReferencesUnitTesting(project); return; case BindingMode.LateBinding: return; case BindingMode.DualBinding: var precompile = _argumentsProvider.UserDefinedCompilationArguments(project.ProjectId); if (precompile is null) { return; } var setting = precompile.FirstOrDefault(option => option.Key.Equals(LateBindDirectiveName, StringComparison.CurrentCultureIgnoreCase)); if (!string.IsNullOrEmpty(setting.Key) && setting.Value != 0) { _interaction.EnsureProjectReferencesUnitTesting(project); } return; default: throw new ArgumentOutOfRangeException(); } }
private string GetTestModule(IUnitTestSettings settings) { var assertType = string.Format("Rubberduck.{0}AssertClass", settings.AssertMode == AssertMode.StrictAssert ? string.Empty : "Permissive"); var assertDeclaredAs = DeclarationFormatFor(AssertFieldDeclarationFormat, assertType, settings); const string fakesType = "Rubberduck.FakesProvider"; var fakesDeclaredAs = DeclarationFormatFor(FakesFieldDeclarationFormat, fakesType, settings); var formattedModuleTemplate = string.Format(_testModuleEmptyTemplate, assertDeclaredAs, fakesDeclaredAs); if (settings.ModuleInit) { var assertBinding = InstantiationFormatFor(assertType, settings); var assertSetAs = $"Set Assert = {assertBinding}"; var fakesBinding = InstantiationFormatFor(fakesType, settings); var fakesSetAs = $"Set Fakes = {fakesBinding}"; formattedModuleTemplate += string.Format(_moduleInit, assertSetAs, fakesSetAs); } if (settings.MethodInit) { formattedModuleTemplate += _methodInit; } return(formattedModuleTemplate); }
private string InstantiationFormatFor(string type, IUnitTestSettings settings) { const string EarlyBoundInstantiationFormat = "New {0}"; const string LateBoundInstantiationFormat = "CreateObject(\"{0}\")"; return(string.Format(settings.BindingMode == BindingMode.EarlyBinding ? EarlyBoundInstantiationFormat : LateBoundInstantiationFormat, type)); }
private string GetTestModule(IUnitTestSettings settings) { var assertClass = settings.AssertMode == AssertMode.StrictAssert ? string.Empty : "Permissive"; var moduleBinding = settings.BindingMode == BindingMode.EarlyBinding ? string.Format(ModuleEarlyBinding, assertClass) : ModuleLateBinding; var formattedModuleTemplate = string.Format(TestModuleEmptyTemplate, FolderAnnotation, moduleBinding); if (settings.ModuleInit) { var lateBindingString = string.Format(ModuleInitLateBinding, settings.AssertMode == AssertMode.StrictAssert ? string.Empty : "Permissive"); formattedModuleTemplate += string.Format(_moduleInit, settings.BindingMode == BindingMode.EarlyBinding ? string.Empty : lateBindingString); } if (settings.MethodInit) { formattedModuleTemplate += _methodInit; } return(formattedModuleTemplate); }
private string DeclarationFormatFor(string declarationFormat, string type, IUnitTestSettings settings) { return(string.Format(declarationFormat, settings.BindingMode == BindingMode.EarlyBinding ? type : "Object")); }