Skip to content

Instantly share code, notes, and snippets.

@AlexZeitler
Created January 27, 2011 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexZeitler/798238 to your computer and use it in GitHub Desktop.
Save AlexZeitler/798238 to your computer and use it in GitHub Desktop.
BDD Learning Tests mit BehaviorConfigs
Ich habe ein COM Interop Szenario. Um das Verhalten des API kennen zu lernen, habe ich Learning Tests / Specs geschrieben, die aber eine OLE-Verbindung zur laufenden App benötigen.
Es müssen z.B. Dokumente in der App geladen werden. Da häufig gleiche Dokumente benötigt werden, sollen diese in BehaviorConfigs ausgelagert werden. Da die BehaviorConfigs teilweise voneinander abhängen (schlecht, aber derzeit nicht anders lösbar), muß EstablishContext der jeweiligen BehaviorConfig vor dem Instanzieren der nächsten BehaviorConfig erledigt sein.
public class EmptyAssemblyAsActiveDocument : IBehaviorConfig {
public void EstablishContext(IDependencyAccessor accessor) {
string applicationDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string tempFolder = Path.Combine(applicationDataFolder, "Temp");
DirectoryInfo directoryInfo = new DirectoryInfo(tempFolder);
if (!directoryInfo.Exists) {
Directory.CreateDirectory(tempFolder);
}
string assemblyPath = string.Format("{0}\\test.sldasm", tempFolder);
ISldWorks solidWorks = new SolidWorksOleConnector().Connect(new SolidWorksVersion2009());
AssemblyCreator assemblyCreator =
new AssemblyCreator(solidWorks);
assemblyCreator.CreateEmptyAssembly(assemblyPath);
}
public void PrepareSut(object sut) {
}
public void Cleanup(object sut) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment