예제 #1
0
 /// <summary>
 /// Register a new builder for corresponding types. If a builder was already existing for this association, it's replaced by the new one
 /// </summary>
 /// <param name="sutType">Type of System Under Test</param>
 /// <param name="ctrType">Type of Constraint</param>
 /// <param name="builder">Instance of builder deicated for these types of System Under Test and Constraint</param>
 internal void Register(Type sutType, Type ctrType, ITestCaseBuilder builder)
 {
     if (IsHandling(sutType, ctrType))
         registrations.FirstOrDefault(reg => reg.SystemUnderTestType.Equals(sutType) && reg.ConstraintType.Equals(ctrType)).Builder = builder;
     else
         registrations.Add(new BuilderRegistration(sutType, ctrType, builder));
 }
예제 #2
0
        // Private methods

        private string Solve(string line)
        {
            ITestCaseBuilder testCaseBuilder = GetTestCaseBuilder();
            string           result          = Solve(line, testCaseBuilder);

            return(result);
        }
예제 #3
0
        private ITestCaseBuilder GetTestCaseBuilder()
        {
            if (_testCaseBuilder != null)
            {
                return(_testCaseBuilder);
            }

            _testCaseBuilder = MakeTestCaseBuilder();
            return(_testCaseBuilder);
        }
예제 #4
0
 /// <summary>
 /// Register a new builder for corresponding types. If a builder was already existing for this association, it's replaced by the new one
 /// </summary>
 /// <param name="sutType">Type of System Under Test</param>
 /// <param name="ctrType">Type of Constraint</param>
 /// <param name="builder">Instance of builder deicated for these types of System Under Test and Constraint</param>
 internal void Register(Type sutType, Type ctrType, ITestCaseBuilder builder)
 {
     if (IsHandling(sutType, ctrType))
     {
         registrations.FirstOrDefault(reg => reg.SystemUnderTestType.Equals(sutType) && reg.ConstraintType.Equals(ctrType)).Builder = builder;
     }
     else
     {
         registrations.Add(new BuilderRegistration(sutType, ctrType, builder));
     }
 }
예제 #5
0
 /// <summary>
 /// Register a new builder for corresponding types. If a builder was already existing for this association, it's replaced by the new one
 /// </summary>
 /// <param name="sutType">Type of System Under Test</param>
 /// <param name="ctrType">Type of Constraint</param>
 /// <param name="builder">Instance of builder deicated for these types of System Under Test and Constraint</param>
 internal void Register(Type sutType, Type ctrType, ITestCaseBuilder builder)
 {
     if (IsHandling(sutType, ctrType))
     {
         registrations.FirstOrDefault(reg => IsRegistered(reg, sutType, ctrType)).Builder = builder;
     }
     else
     {
         registrations.Add(new BuilderRegistration(sutType, ctrType, builder));
     }
 }
예제 #6
0
        public void Install(object extension)
        {
            ITestCaseBuilder builder = extension as ITestCaseBuilder;

            if (builder == null)
            {
                throw new ArgumentException(
                          extension.GetType().FullName + " is not an ITestCaseBuilder", "exception");
            }

            builders.Insert(0, builder);
        }
예제 #7
0
        private string Solve(string line, ITestCaseBuilder testCaseBuilder)
        {
            ITestCase testCase = testCaseBuilder.ParseInputLine(line);

            if (testCase != null)
            {
                string result = Solve(testCase);
                return(result);
            }
            else
            {
                return(null);
            }
        }
예제 #8
0
        public void CanAddTestCaseBuilder()
        {
            ITestCaseBuilder mockBuilder = Substitute.For <ITestCaseBuilder>();

            mockBuilder.CanBuildFrom(null).Returns(true);

            IExtensionPoint ep = host.GetExtensionPoint("TestCaseBuilders");

            ep.Install(mockBuilder);
            ITestCaseBuilder builders = (ITestCaseBuilder)ep;

            builders.BuildFrom(null);

            mockBuilder.Received().BuildFrom(null);
        }
예제 #9
0
        public void CanAddTestCaseBuilder()
        {
            DynamicMock mock = new DynamicMock(typeof(ITestCaseBuilder));

            mock.ExpectAndReturn("CanBuildFrom", true, null);
            mock.Expect("BuildFrom");

            IExtensionPoint ep = host.GetExtensionPoint("TestCaseBuilders");

            ep.Install(mock.MockInstance);
            ITestCaseBuilder builders = (ITestCaseBuilder)ep;

            builders.BuildFrom(null);

            mock.Verify();
        }
예제 #10
0
        /// <summary>
        /// Create a new instance of a test case
        /// </summary>
        /// <param name="sutXml"></param>
        /// <param name="ctrXml"></param>
        /// <returns></returns>
        public TestCase Instantiate(AbstractSystemUnderTestXml sutXml, AbstractConstraintXml ctrXml)
        {
            if (sutXml == null)
            {
                throw new ArgumentNullException("sutXml");
            }
            if (ctrXml == null)
            {
                throw new ArgumentNullException("ctrXml");
            }

            ITestCaseBuilder builder = null;

            //Look for registration ...
            var registration = registrations.FirstOrDefault(reg => sutXml.GetType() == reg.SystemUnderTestType && ctrXml.GetType() == reg.ConstraintType);

            if (registration == null)
            {
                throw new ArgumentException(string.Format("'{0}' is not an expected type for a constraint for a system under test '{1}'.", ctrXml.GetType().Name, sutXml.GetType().Name));
            }

            //Apply the chooser if needed
            if (registration.Builder == null)
            {
                registration.Chooser.Choose(sutXml, ctrXml);
            }

            //Get Builder and initiate it
            builder = registration.Builder;
            builder.Setup(sutXml, ctrXml);

            //Build
            builder.Build();
            var ctr = builder.GetConstraint();
            var sut = builder.GetSystemUnderTest();

            //Apply negation if needed
            if (ctrXml.Not)
            {
                ctr = new NotConstraint(ctr);
            }

            return(new TestCase(sut, ctr));
        }
예제 #11
0
        /// <summary>
        /// Create a new instance of a test case
        /// </summary>
        /// <param name="sutXml"></param>
        /// <param name="ctrXml"></param>
        /// <returns></returns>
        public TestCase Instantiate(AbstractSystemUnderTestXml sutXml, AbstractConstraintXml ctrXml)
        {
            sutXml = sutXml ?? throw new ArgumentNullException("sutXml");
            ctrXml = ctrXml ?? throw new ArgumentNullException("ctrXml");

            ITestCaseBuilder builder = null;

            //Look for registration ...
            var registration = registrations.FirstOrDefault(reg => IsRegistered(reg, sutXml.GetType(), ctrXml.GetType()));

            if (registration == null)
            {
                throw new ArgumentException(string.Format("'{0}' is not an expected type for a constraint with a system-under-test '{1}'.", ctrXml.GetType().Name, sutXml.GetType().Name));
            }

            //Apply the chooser if needed
            if (registration.Builder == null)
            {
                registration.Chooser.Choose(sutXml, ctrXml);
            }

            //Get Builder and initiate it
            builder = registration.Builder;
            builder.Setup(sutXml, ctrXml, configuration, variables, serviceLocator);

            //Build
            builder.Build();
            NUnitCtr.Constraint ctr = builder.GetConstraint();
            var sut = builder.GetSystemUnderTest();

            //Apply negation if needed
            if (ctrXml.Not)
            {
                ctr = new NUnitCtr.NotConstraint(ctr);
            }

            return(new TestCase(sut, ctr));
        }
예제 #12
0
 public BuilderRegistration(Type sutType, Type ctrType, ITestCaseBuilder builder)
     : this(sutType, ctrType)
 {
     Builder = builder;
 }
예제 #13
0
 public BuilderRegistration(Type sutType, Type ctrType, ITestCaseBuilder builder)
     : this(sutType, ctrType)
 {
     Builder = builder;
 }
예제 #14
0
 internal void Install(ITestCaseBuilder builder)
 {
     testBuilders.Install(builder);
 }
예제 #15
0
 internal void Install( ITestCaseBuilder builder )
 {
     testBuilders.Install( builder );
 }