private IMatchSyntax GetEventExpectation(Action <T> action, out string eventName) { object[] arguments; using (var recorder = new InvocationRecorder()) { action(mock); eventName = recorder.Invocation.Method.Name; arguments = recorder.Invocation.Arguments; } var symbol = eventName.StartsWith(Constants.ADD) ? " += " : " -= "; var methodMatcher = new MethodNameMatcher(eventName, MockObject.MockedTypes.PrimaryType); var descriptionOverride = new DescriptionOverride(eventName.Replace(Constants.ADD, string.Empty).Replace(Constants.REMOVE, string.Empty) + symbol, methodMatcher); EnsureMatchingMethodExistsOnMock(methodMatcher, "an event named " + eventName); BuildableExpectation.MethodMatcher = descriptionOverride; if (arguments.Length == 1 && arguments[0] != null && !((MulticastDelegate)arguments[0]).Method.Name.Contains(">")) { WithArguments(new DelegateMatcher((MulticastDelegate)arguments[0])); } else { WithArguments(Is.Anything); } return(this); }
protected override void Execute(CodeActivityContext context) { string configurationFile = ConfigurationFile.Get(context); string manifestFile = ModelManifestFile.Get(context); string version = VersionOverride.Get(context); string description = DescriptionOverride.Get(context); var serverConfig = Helper.GetServerConfig(configurationFile); CodeCrib.AX.Manage.ModelStore store = null; if (serverConfig.AOSVersionOrigin.Substring(0, 3) == "6.0") { store = new Manage.ModelStore(serverConfig.DatabaseServer, string.Format("{0}", serverConfig.Database)); } else { store = new Manage.ModelStore(serverConfig.DatabaseServer, string.Format("{0}_model", serverConfig.Database)); } if (!string.IsNullOrEmpty(version) || !string.IsNullOrEmpty(description)) { store.CreateModel(manifestFile, version, description); } else { store.CreateModel(manifestFile); } if (SetNoInstallMode.Get(context)) { store.SetNoInstallMode(); } }
public void OverridesDescriptionOfOtherMatcherWithThatPassedToConstructor() { Matcher m1 = new DescriptionOverride("m1", new AlwaysMatcher(true, "always true")); Matcher m2 = new DescriptionOverride("m2", new AlwaysMatcher(false, "always false")); AssertDescription.IsEqual(m1, "m1"); AssertDescription.IsEqual(m2, "m2"); }
public void DelegatesMatchingToAnotherMatcher() { Matcher m1 = new DescriptionOverride("irrelevant", new AlwaysMatcher(true, "always true")); Matcher m2 = new DescriptionOverride("irrelevant", new AlwaysMatcher(false, "always false")); Assert.IsTrue(m1.Matches(new object()), "m1"); Assert.IsFalse(m2.Matches(new object()), "m2"); }
/// <summary> /// Sets the property. /// </summary> /// <param name="propertyName">Name of the property.</param> /// <returns></returns> protected internal IValueSyntaxBuilder SetProperty(string propertyName) { Matcher methodMatcher = new DescriptionOverride(propertyName + " = ", new MethodNameMatcher(Constants.SET + propertyName, MockObject.MockedTypes.PrimaryType)); EnsureMatchingMethodExistsOnMock(methodMatcher, "a setter for property " + propertyName); BuildableExpectation.MethodMatcher = methodMatcher; return(new PropertyValueBuilder(this)); }
/// <summary> /// Gets the property. /// </summary> /// <param name="propertyName">Name of the property.</param> /// <returns></returns> protected void GetProperty(string propertyName) { Matcher methodMatcher = new DescriptionOverride(propertyName, new MethodNameMatcher(Constants.GET + propertyName, MockObject.MockedTypes.PrimaryType)); EnsureMatchingMethodExistsOnMock(methodMatcher, "a getter for property " + propertyName); BuildableExpectation.MethodMatcher = methodMatcher; BuildableExpectation.ArgumentsMatcher = new DescriptionOverride(String.Empty, new ArgumentsMatcher()); }
protected IValueSyntaxBuilder SetIndexer(params object[] expectedArguments) { Matcher methodMatcher = new DescriptionOverride(String.Empty, new MethodNameMatcher(Constants.SET_ITEM, MockObject.MockedTypes.PrimaryType)); EnsureMatchingMethodExistsOnMock(methodMatcher, "an indexed setter"); BuildableExpectation.DescribeAsIndexer(); BuildableExpectation.MethodMatcher = methodMatcher; return(new IndexSetterBuilder(BuildableExpectation, this).WithParameters(expectedArguments)); }
/// <summary> /// Sets up the Get Indexer expectations /// </summary> /// <param name="expectedArguments"></param> /// <remarks>No need to pass the method name because it is always 'get_Item'.</remarks> private void GetIndexer(object[] expectedArguments) { Matcher methodMatcher = new DescriptionOverride(string.Empty, new MethodNameMatcher(Constants.GET_ITEM, MockObject.MockedTypes.PrimaryType)); EnsureMatchingMethodExistsOnMock(methodMatcher, "an indexed getter"); BuildableExpectation.DescribeAsIndexer(); BuildableExpectation.MethodMatcher = methodMatcher; BuildableExpectation.ArgumentsMatcher = new IndexGetterArgumentsMatcher(ArgumentMatchers(expectedArguments)); //*DevNote: Use the section below when Get[] is refactored //name = ((MethodCallExpression) expression.Body).Method.Name.Replace(GET, string.Empty); //IMatchSyntax matchSyntax = GetProperty(name); ////check for args //if (expectedArguments.Length > 0) //{ // //properties have args when used like GetProperty(m=>m.prop[1]) // base.With(expectedArguments); //} }