예제 #1
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));
        }
예제 #2
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));
        }