public void GeneratedAssemblyBuilderWithAssemblyInfoSucceeds() { var builder = new GeneratedAssemblyBuilder(); builder.WithAssemblyName(Guid.NewGuid().ToString("N")) .WithAssemblyInfo("company", "productName", "1.0.0.0", "description") .InCurrentDirectory() .WithClass("TestClassActivator").InNamespace("PRI.Activators") .ImplementsInterface <ISimple>() .WithMethod("SimpleMethod") .WithReturnType(typeof(void)) .WithInstruction(new NullaryInstruction(OpCodes.Ret)) .CommitMethod() .WithMethod("Create") .WithReturnType(typeof(Customer)) .WithInstruction(new UnaryInstruction(OpCodes.Newobj, typeof(Customer).GetConstructor(Type.EmptyTypes))) .WithLocal(typeof(Customer)) .WithInstruction(new NullaryInstruction(OpCodes.Stloc_0)) .WithInstruction(new NullaryInstruction(OpCodes.Ldloc_0)) .WithInstruction(new NullaryInstruction(OpCodes.Ret)) .WithParameter() .WithType(typeof(int)) .CommitParameter() .CommitMethod() .CommitType() .SaveAssembly(); var results = new List <ValidationResult>(); builder.TryValidate(results); var filePath = Path.Combine(builder.Directory, builder.Name + ".dll"); Assert.True(File.Exists(filePath)); File.Delete(filePath); }
public void GeneratedAssemblyBuilderTypeInRootNamespaceSucceeds() { /*builder.WithAssemblyName(.WithUniqueName) * .InDirectory * .WithAssemblyInfo * .WithClass(name) * .Public * .InterfaceImplementations.Add * .BaseClass */ var builder = new GeneratedAssemblyBuilder(); builder.WithAssemblyName(Guid.NewGuid().ToString("N")) .InCurrentDirectory() .WithClass("TestClassActivator") .WithMethod("Create") .WithReturnType(typeof(Customer)) .WithInstruction(new UnaryInstruction(OpCodes.Newobj, typeof(Customer).GetConstructor(Type.EmptyTypes))) .WithLocal(typeof(Customer)) .WithInstruction(new NullaryInstruction(OpCodes.Stloc_0)) .WithInstruction(new NullaryInstruction(OpCodes.Ldloc_0)) .WithInstruction(new NullaryInstruction(OpCodes.Ret)) .WithParameter("number") .WithType(typeof(int)) .CommitParameter() .CommitMethod() .CommitType().SaveAssembly(); var results = new List <ValidationResult>(); builder.TryValidate(results); var filePath = Path.Combine(builder.Directory, builder.Name + ".dll"); Assert.True(File.Exists(filePath)); File.Delete(filePath); }
public void WithNullDirectoryThrows() { var builder = new GeneratedAssemblyBuilder(); var ex = Assert.Throws <ValidationException>(() => builder.WithAssemblyName(Guid.NewGuid().ToString("N")) .SaveAssembly() ); Assert.Equal("Directory is null.", ex.Message); }
public void WithBadNameThrows() { var builder = new GeneratedAssemblyBuilder(); var path = $"x{Path.GetInvalidFileNameChars()[0]}x"; var ex = Assert.Throws <ValidationException>(() => { builder .WithAssemblyName(path) .InCurrentDirectory() .SaveAssembly(); }); Assert.Equal($"Assembly name {path} contains invalid characters.", ex.Message); }
public IGeneratedAssemblyBuilder WithAssemblyName(string assemblyName) { _wrappedBuilder.WithAssemblyName(assemblyName); return(this); }