public void GivenoneFurnaceType_WhenAssemblyEmitted_TypeCanBeCastedToIFurnaceObjectType() { //Assign const string assemblyName = "TestAssemblyName"; Sut.AddFurnaceType(BaseNamespace + "ClassOne"); TypeFinder.FindType(BaseNamespace + "ClassOne").Returns(GetType()); //Act var compilation = Sut.Compile(assemblyName); Assembly assembly = null; using (var memoryStream = new MemoryStream()) { compilation.Emit(memoryStream); memoryStream.Flush(); assembly = Assembly.Load(memoryStream.GetBuffer()); } //Assert var type = assembly.GetTypes().FirstOrDefault(t => t.FullName.Equals(BaseNamespace + Roslyn.FurnaceObjectTypes.FurnaceTypeWriter.FurnaceTypeIdentifier + "ClassOne")); Assert.That(type, Is.Not.Null); var instance = Activator.CreateInstance(type); Assert.That(instance, Is.AssignableTo <IFurnaceObjectType <long> >()); }
public void GivenFullName_WhenAddingOneFurnaceType_ThenThereIsOneFurnaceTypeThatHasCorrectBaseTypes() { //Assign const string typeNamespace = "Some"; const string typeName = "Name"; const string fullName = typeNamespace + "." + typeName; //Act Sut.AddFurnaceType(fullName); //Assert Assert.That(Spy.FurnaceTypes.Count(), Is.EqualTo(1)); AssertFurnaceType(Spy.FurnaceTypes.First().SyntaxTree, typeName, typeNamespace); }
public void GivenOneFurnaceType_WhenCompileIsCalled_ThenCompilationHasSyntaxTree() { //Assign const string assemblyName = "TestAssemblyName"; Sut.AddFurnaceType(BaseNamespace + "ClassOne"); TypeFinder.FindType(BaseNamespace + "ClassOne").Returns(GetType()); //Act var compilation = Sut.Compile(assemblyName); //Assert Assert.That(compilation.SyntaxTrees, Contains.Item(Spy.FurnaceTypes.First().SyntaxTree)); }
public void GivenoneFurnaceType_WhenCompileIsCalled_ThenCompilationHasReferences() { //Assign const string assemblyName = "TestAssemblyName"; Sut.AddFurnaceType(BaseNamespace + "ClassOne"); TypeFinder.FindType(BaseNamespace + "ClassOne").Returns(GetType()); //Act var compilation = Sut.Compile(assemblyName); //Assert Assert.That(compilation.References, Has.Some.Matches <MetadataReference>(x => x.Display == typeof(IFurnaceObjectType <long>).Assembly.Location)); Assert.That(compilation.References, Has.Some.Matches <MetadataReference>(x => x.Display == typeof(ClassOne).Assembly.Location)); Assert.That(compilation.References, Has.Some.Matches <MetadataReference>(x => x.Display == typeof(object).Assembly.Location)); }
public void GivenFullName_WhenAddingTwoFurnaceType_ThenThereIsOneFurnaceTypeThatHasCorrectBaseTypes() { //Assign const string typeNamespace = "Some"; const string typeNameOne = "Name"; const string typeNameTwo = "Name"; const string fullNameOne = typeNamespace + "." + typeNameOne; const string fullNameTwo = typeNamespace + "." + typeNameTwo; //Act Sut.AddFurnaceType(fullNameOne); Sut.AddFurnaceType(fullNameTwo); //Assert Assert.That(Spy.FurnaceTypes.Count(), Is.EqualTo(2)); var types = Spy.FurnaceTypes.ToList(); AssertFurnaceType(types[0].SyntaxTree, typeNameOne, typeNamespace); AssertFurnaceType(types[1].SyntaxTree, typeNameTwo, typeNamespace); }
public void GivenoneFurnaceType_WhenCompileIsCalled_ThenCompilationCanEmitWithNoDiagnosticsMessages() { //Assign const string assemblyName = "TestAssemblyName"; Sut.AddFurnaceType(BaseNamespace + "ClassOne"); TypeFinder.FindType(BaseNamespace + "ClassOne").Returns(GetType()); //Act var compilation = Sut.Compile(assemblyName); EmitResult emitResult; using (var memStream = new MemoryStream()) { emitResult = compilation.Emit(memStream); } //Assert Assert.That(emitResult.Diagnostics, Is.Empty); Assert.That(emitResult.Success, Is.True); }
public void GivenoneFurnaceType_WhenCompileIsCalled_ThenCompilationCanEmitAssembly() { //Assign const string assemblyName = "TestAssemblyName"; Sut.AddFurnaceType(BaseNamespace + "ClassOne"); TypeFinder.FindType(BaseNamespace + "ClassOne").Returns(GetType()); //Act var compilation = Sut.Compile(assemblyName); Assembly assembly = null; using (var memoryStream = new MemoryStream()) { compilation.Emit(memoryStream); memoryStream.Flush(); assembly = Assembly.Load(memoryStream.GetBuffer()); } //Assert Assert.That(assembly, Is.Not.Null); }
public void GivenEmptyFullName_WhenCreateFurnaceTypeCalled_NullFullNameExceptionThrown() { //Act var ex = Assert.Throws <FurnaceObjectTypeFactory.FullNameException>(() => Sut.AddFurnaceType(string.Empty)); //Assert Assert.That(ex.InvalidReasons, Contains.Item(FurnaceObjectTypeFactory.FullNameException.EmptyFullName)); }