public void ShouldGenerateCommandLineParametersFromTasks()
        {
            var finder      = new Mock <IParameterFinder>();
            var task1       = new Mock <IObsoleteTask>().Object;
            var task2       = new Mock <IObsoleteTask>().Object;
            var typeParsers = new Mock <ITypeParsers>().Object;

            var param1 = new FakeParameter {
                Name = "name1", GeneratedValue = "/name1:value1"
            };
            var param2 = new FakeParameter {
                Name = "name2", GeneratedValue = "/name2:value2"
            };
            var param3 = new FakeParameter {
                Name = "name3", GeneratedValue = @"""/name3:value 3"""
            };

            finder.Setup(f => f.FindParametersInTask(task1)).Returns(new[] { param1, param2 });
            finder.Setup(f => f.FindParametersInTask(task2)).Returns(new[] { param1, param3 });

            var generator = new CommandLineTasksParametersGenerator(finder.Object, typeParsers);

            FakeParameter param2Override = new FakeParameter {
                Name = "name2", GeneratedValue = "/name2:anothervalue2"
            };
            FakeParameter notUsedParameterOverride = new FakeParameter {
                Name = "notused", GeneratedValue = "/notused:notusedvalue"
            };

            var args = generator.GenerateCommandLineParametersForTasks(new[] { param1, param2, param3 }, new [] { param2Override, notUsedParameterOverride });

            Assert.That(args, Is.EqualTo(@"/name1:value1 /name2:anothervalue2 ""/name3:value 3"" /notused:notusedvalue"));
        }
        private static CommonParameter CreateCommonParameter(FakeParameter fakeParameter)
        {
            if (fakeParameter == null)
            {
                return(null);
            }

            var monoCecilParameter = new Mock <MonoCecilParameter>(null);

            monoCecilParameter.Setup(parameter => parameter.Name).Returns(() => fakeParameter.Name);
            monoCecilParameter.Setup(parameter => parameter.ParameterType).Returns(() => CreateMonoCecilTypeReference(fakeParameter.ParameterType));

            var reflectionParameter = new Mock <ReflectionParameter>(null);

            reflectionParameter.Setup(parameter => parameter.Name).Returns(() => fakeParameter.Name);
            reflectionParameter.Setup(parameter => parameter.ParameterType).Returns(() => CreateReflectionType(fakeParameter.ParameterType));

            return(new Mock <CommonParameter>(monoCecilParameter.Object, reflectionParameter.Object).Object);
        }
Example #3
0
        private static ICommonParameter CreateCommonParameter(FakeParameter fakeParameter)
        {
            var monoCecilParameter = CreateMockFor <ParameterDefinition>();
            var typeReference      = CreateTypeReference(fakeParameter.ParameterType);

            monoCecilParameter.Setup(parameter => parameter.Name).Returns(() => fakeParameter.Name);
            monoCecilParameter.Setup(parameter => parameter.ParameterType).Returns(() => typeReference);

            var reflectionParameter = CreateMockFor <ParameterInfo>();

            reflectionParameter.Setup(parameter => parameter.ParameterType).Returns(() => CreateReflectionType(fakeParameter.ParameterType));

            var commonParameter = CreateMockFor <ICommonParameter>();

            commonParameter.Setup(parameter => parameter.Name).Returns(() => fakeParameter.Name);
            commonParameter.Setup(parameter => parameter.FullName).Returns(() => fakeParameter.Name);
            commonParameter.Setup(parameter => parameter.MonoCecil).Returns(() => monoCecilParameter.Object);
            commonParameter.Setup(parameter => parameter.Reflection).Returns(() => reflectionParameter.Object);
            commonParameter.Setup(parameter => parameter.Type).Returns(() => CreateReflectionType(fakeParameter.ParameterType));
            commonParameter.Setup(parameter => parameter.Load(It.IsAny <int>())).Returns(() => commonParameter.Object);

            return(commonParameter.Object);
        }
        public void ShouldGenerateCommandLineParametersFromTasks()
        {
            var finder = new Mock<IParameterFinder>();
            var task1 = new Mock<ITask>().Object;
            var task2 = new Mock<ITask>().Object;
            var typeParsers = new Mock<ITypeParsers>().Object;

            var param1 = new FakeParameter {Name = "name1", GeneratedValue = "/name1:value1"};
            var param2 = new FakeParameter {Name = "name2", GeneratedValue = "/name2:value2"};
            var param3 = new FakeParameter {Name = "name3", GeneratedValue = @"""/name3:value 3"""};

            finder.Setup(f => f.FindParametersInTask(task1)).Returns(new[] {param1, param2});
            finder.Setup(f => f.FindParametersInTask(task2)).Returns(new[] {param1, param3});

            var generator = new CommandLineTasksParametersGenerator(finder.Object, typeParsers);

            FakeParameter param2Override = new FakeParameter {Name = "name2", GeneratedValue = "/name2:anothervalue2"};
            FakeParameter notUsedParameterOverride = new FakeParameter {Name = "notused", GeneratedValue = "/notused:notusedvalue"};

            var args = generator.GenerateCommandLineParametersForTasks(new[] {param1, param2, param3}, new [] {param2Override, notUsedParameterOverride});

            Assert.That(args, Is.EqualTo(@"/name1:value1 /name2:anothervalue2 ""/name3:value 3"" /notused:notusedvalue"));
        }