public static void Test_TestityClassBuilder_TestAddedField() { //arrange TestityClassBuilder scriptBuilder = new TestityClassBuilder(typeof(EngineScriptComponent).Name + "Script"); Mock<IMemberImplementationProvider> implementationProvider = BuildMemberImplementationMock("testField", typeof(EngineScriptComponent), MemberImplementationModifier.Private, new Type[] { typeof(ExposeDataMemeberAttribute) }); //act scriptBuilder.AddClassField(implementationProvider.Object); //assert Assert.IsTrue(scriptBuilder.Compile().Contains("private " + typeof(EngineScriptComponent).FullName + " testField")); Assert.IsTrue(scriptBuilder.Compile().Contains("[" + typeof(ExposeDataMemeberAttribute).FullName+ "]")); }
public static void Test_TestityClassBuilder_TestAddedField() { //arrange TestityClassBuilder scriptBuilder = new TestityClassBuilder(typeof(EngineScriptComponent).Name + "Script"); Mock <IMemberImplementationProvider> implementationProvider = BuildMemberImplementationMock("testField", typeof(EngineScriptComponent), MemberImplementationModifier.Private, new Type[] { typeof(ExposeDataMemeberAttribute) }); //act scriptBuilder.AddClassField(implementationProvider.Object); //assert Assert.IsTrue(scriptBuilder.Compile().Contains("private " + typeof(EngineScriptComponent).FullName + " testField")); Assert.IsTrue(scriptBuilder.Compile().Contains("[" + typeof(ExposeDataMemeberAttribute).FullName + "]")); }
public static void Test_TestityClassBuilder_Test_Adding_Base_Class() { //arrange TestityClassBuilder scriptBuilder = new TestityClassBuilder(typeof(EngineScriptComponent).Name + "Script"); //act scriptBuilder.AddBaseClass<EngineScriptComponent>(new DefaultTypeSyntaxBuilder()); //assert Assert.IsTrue(scriptBuilder.Compile().Contains(" : " + typeof(EngineScriptComponent).FullName)); Assert.Throws<InvalidOperationException>(() => scriptBuilder.AddBaseClass<EngineScriptComponent>(new DefaultTypeSyntaxBuilder())); Assert.DoesNotThrow(() => scriptBuilder.AddBaseClass<ICloneable>(new DefaultTypeSyntaxBuilder())); Assert.IsTrue(scriptBuilder.Compile().Contains(", " + typeof(ICloneable).FullName)); }
public static void Test_TestityClassBuilder_Test_Adding_Base_Class() { //arrange TestityClassBuilder scriptBuilder = new TestityClassBuilder(typeof(EngineScriptComponent).Name + "Script"); //act scriptBuilder.AddBaseClass <EngineScriptComponent>(new DefaultTypeSyntaxBuilder()); //assert Assert.IsTrue(scriptBuilder.Compile().Contains(" : " + typeof(EngineScriptComponent).FullName)); Assert.Throws <InvalidOperationException>(() => scriptBuilder.AddBaseClass <EngineScriptComponent>(new DefaultTypeSyntaxBuilder())); Assert.DoesNotThrow(() => scriptBuilder.AddBaseClass <ICloneable>(new DefaultTypeSyntaxBuilder())); Assert.IsTrue(scriptBuilder.Compile().Contains(", " + typeof(ICloneable).FullName)); }
public static void Test_Generate_Class_With_Serialized_Fields() { //arrange //generate mappers List <ITypeRelationalMapper> mappers = new List <ITypeRelationalMapper>(); mappers.Add(new StringTypeRelationalMapper()); mappers.Add(new EngineTypeRelationalMapper()); mappers.Add(new PrimitiveTypeRelationalMapper(new UnityPrimitiveTypeExclusion())); mappers.Add(new DefaultTypeRelationalMapper()); Mock <ITypeExclusion> exclusionMock = new Mock <ITypeExclusion>(MockBehavior.Strict); //setup always false exclusion exclusionMock.Setup(x => x.isExcluded(It.IsAny <Type>())).Returns(false); TestityClassBuilder builder = new TestityClassBuilder(typeof(TestSerializedClass).Name + "Script"); UnityBuildProcessTypeRelationalMapper chainMapper = new UnityBuildProcessTypeRelationalMapper(mappers); AddSerializedMemberStep buildStep = new AddSerializedMemberStep(chainMapper, new SerializedMemberParser(), exclusionMock.Object); buildStep.Process(builder, typeof(TestSerializedClass)); string classCompiled = builder.Compile(); //Assert.NotNull(null, classCompiled); //Assert.("dfdhh", null, classCompiled); }
public static void Test_Generate_Class_With_Serialized_Fields() { //arrange //generate mappers List<ITypeRelationalMapper> mappers = new List<ITypeRelationalMapper>(); mappers.Add(new StringTypeRelationalMapper()); mappers.Add(new EngineTypeRelationalMapper()); mappers.Add(new PrimitiveTypeRelationalMapper(new UnityPrimitiveTypeExclusion())); mappers.Add(new DefaultTypeRelationalMapper()); Mock<ITypeExclusion> exclusionMock = new Mock<ITypeExclusion>(MockBehavior.Strict); //setup always false exclusion exclusionMock.Setup(x => x.isExcluded(It.IsAny<Type>())).Returns(false); TestityClassBuilder builder = new TestityClassBuilder(typeof(TestSerializedClass).Name + "Script"); UnityBuildProcessTypeRelationalMapper chainMapper = new UnityBuildProcessTypeRelationalMapper(mappers); AddSerializedMemberStep buildStep = new AddSerializedMemberStep(chainMapper, new SerializedMemberParser(), exclusionMock.Object); buildStep.Process(builder, typeof(TestSerializedClass)); string classCompiled = builder.Compile(); //Assert.NotNull(null, classCompiled); //Assert.("dfdhh", null, classCompiled); }
public static void Test_TestityClassBuilder_Test_Adding_Method() { //arrange TestityClassBuilder scriptBuilder = new TestityClassBuilder(typeof(EngineScriptComponent).Name + "Script"); Mock<IMemberImplementationProvider> implementationProvider = BuildMemberImplementationMock("TestMethod", typeof(string), MemberImplementationModifier.Public, Enumerable.Empty<Type>()); //act scriptBuilder.AddMemberMethod(implementationProvider.Object, BuildBodyProviderMockEmpty().Object, BuildParameterProviderMock(typeof(string), typeof(int)).Object); //assert Assert.IsTrue(scriptBuilder.Compile().Contains("TestMethod(System.String String1")); }
public static void Test_TestityClassBuilder_Test_Adding_Method() { //arrange TestityClassBuilder scriptBuilder = new TestityClassBuilder(typeof(EngineScriptComponent).Name + "Script"); Mock <IMemberImplementationProvider> implementationProvider = BuildMemberImplementationMock("TestMethod", typeof(string), MemberImplementationModifier.Public, Enumerable.Empty <Type>()); //act scriptBuilder.AddMemberMethod(implementationProvider.Object, BuildBodyProviderMockEmpty().Object, BuildParameterProviderMock(typeof(string), typeof(int)).Object); //assert Assert.IsTrue(scriptBuilder.Compile().Contains("TestMethod(System.String String1")); }