/// <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)); }
// Private methods private string Solve(string line) { ITestCaseBuilder testCaseBuilder = GetTestCaseBuilder(); string result = Solve(line, testCaseBuilder); return(result); }
private ITestCaseBuilder GetTestCaseBuilder() { if (_testCaseBuilder != null) { return(_testCaseBuilder); } _testCaseBuilder = MakeTestCaseBuilder(); return(_testCaseBuilder); }
/// <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)); } }
/// <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)); } }
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); }
private string Solve(string line, ITestCaseBuilder testCaseBuilder) { ITestCase testCase = testCaseBuilder.ParseInputLine(line); if (testCase != null) { string result = Solve(testCase); return(result); } else { return(null); } }
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); }
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(); }
/// <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)); }
/// <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)); }
public BuilderRegistration(Type sutType, Type ctrType, ITestCaseBuilder builder) : this(sutType, ctrType) { Builder = builder; }
internal void Install(ITestCaseBuilder builder) { testBuilders.Install(builder); }
internal void Install( ITestCaseBuilder builder ) { testBuilders.Install( builder ); }