예제 #1
0
        public void TypesFailedToCompileDoNotExistAsProducts()
        {
            //-- arrange

            var backend          = new TestBackend();
            var libraryUnderTest = new TypeLibrary <TestArtifact>(backend);

            var key1  = new TypeKey(this.GetType(), typeof(ITestContractA));
            var type1 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key1));

            var key2  = new TypeKey(this.GetType(), typeof(ITestContractB));
            var type2 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key2));

            var key3  = new TypeKey(this.GetType(), typeof(ITestContractC));
            var type3 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key3));

            var key4  = new TypeKey(this.GetType(), typeof(ITestContractD));
            var type4 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key4));

            libraryUnderTest.DeclareTypeMember(key1, type1);
            libraryUnderTest.DeclareTypeMember(key2, type2);
            libraryUnderTest.DeclareTypeMember(key3, type3);
            libraryUnderTest.DeclareTypeMember(key4, type4);

            backend.ExpectCompileWithErrors(
                new[] { type1, type2, type3, type4 },
                success: new[] { true, false, true, false });

            //-- act

            Assert.Throws <CompilationErrorsException>(() => {
                libraryUnderTest.CompileDeclaredTypeMembers();
            });

            //-- Assert

            Assert.Throws <KeyNotFoundException>(() => {
                libraryUnderTest.GetProduct(ref key2);
            });

            Assert.Throws <KeyNotFoundException>(() => {
                libraryUnderTest.GetProduct(ref key4);
            });
        }
예제 #2
0
        public void SucceededProductsExistAfterFailedCompilation()
        {
            //-- arrange

            var backend          = new TestBackend();
            var libraryUnderTest = new TypeLibrary <TestArtifact>(backend);

            var key1  = new TypeKey(this.GetType(), typeof(ITestContractA));
            var type1 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key1));

            var key2  = new TypeKey(this.GetType(), typeof(ITestContractB));
            var type2 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key2));

            var key3  = new TypeKey(this.GetType(), typeof(ITestContractC));
            var type3 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key3));

            var key4  = new TypeKey(this.GetType(), typeof(ITestContractD));
            var type4 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key4));

            libraryUnderTest.DeclareTypeMember(key1, type1);
            libraryUnderTest.DeclareTypeMember(key2, type2);
            libraryUnderTest.DeclareTypeMember(key3, type3);
            libraryUnderTest.DeclareTypeMember(key4, type4);

            backend.ExpectCompileWithErrors(
                new[] { type1, type2, type3, type4 },
                success: new[] { true, false, true, false });

            //-- act

            Assert.Throws <CompilationErrorsException>(() => {
                libraryUnderTest.CompileDeclaredTypeMembers();
            });

            var product1 = libraryUnderTest.GetProduct(ref key1);
            var product3 = libraryUnderTest.GetProduct(ref key3);

            //-- Assert

            product1.Artifact.SourceType.Should().BeSameAs(type1);
            product3.Artifact.SourceType.Should().BeSameAs(type3);
        }
예제 #3
0
        public void CompilationErrorsExceptionThrownWhenSomeTypesFailToCompile()
        {
            //-- arrange

            var backend          = new TestBackend();
            var libraryUnderTest = new TypeLibrary <TestArtifact>(backend);

            var key1  = new TypeKey(this.GetType(), typeof(ITestContractA));
            var type1 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key1));

            var key2  = new TypeKey(this.GetType(), typeof(ITestContractB));
            var type2 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key2));

            var key3  = new TypeKey(this.GetType(), typeof(ITestContractC));
            var type3 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key3));

            var key4  = new TypeKey(this.GetType(), typeof(ITestContractD));
            var type4 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key4));

            libraryUnderTest.DeclareTypeMember(key1, type1);
            libraryUnderTest.DeclareTypeMember(key2, type2);
            libraryUnderTest.DeclareTypeMember(key3, type3);
            libraryUnderTest.DeclareTypeMember(key4, type4);

            backend.ExpectCompileWithErrors(
                new[] { type1, type2, type3, type4 },
                success: new[] { true, false, true, false });

            //-- act

            var exception = Assert.Throws <CompilationErrorsException>(() => {
                libraryUnderTest.CompileDeclaredTypeMembers();
            });

            //-- Assert

            exception.TypesFailedToCompile.Should().NotBeNull();
            exception.TypesFailedToCompile.Count.Should().Be(2);
            exception.TypesFailedToCompile[0].Type.Should().BeSameAs(type2);
            exception.TypesFailedToCompile[1].Type.Should().BeSameAs(type4);
        }