public ConfiguredCall SetResultForLastCall(IReturn valueToReturn, MatchArgs matchArgs) { var spec = _getCallSpec.FromPendingSpecification(matchArgs); CheckResultIsCompatibleWithCall(valueToReturn, spec); _configuredResults.SetResult(spec, valueToReturn); return new ConfiguredCall(action => _callActions.Add(spec, action)); }
private static void CheckResultIsCompatibleWithCall(IReturn valueToReturn, ICallSpecification spec) { var requiredReturnType = spec.ReturnType(); if (!valueToReturn.CanBeAssignedTo(requiredReturnType)) { throw new CouldNotSetReturnDueToTypeMismatchException(valueToReturn.TypeOrNull(), spec.GetMethodInfo()); } }
public override void Context() { _value = new object(); _substitutionContext = mock<ISubstitutionContext>(); _substitutionContext .stub(x => x.LastCallShouldReturn(It.IsAny<IReturn>(), It.IsAny<MatchArgs>())) .IgnoreArguments() .WhenCalled(x => _returnValueSet = (IReturn) x.Arguments[0]); temporarilyChange(() => SubstitutionContext.Current).to(_substitutionContext); }
public void SetResultForLastCall(IReturn valueToReturn, MatchArgs matchArgs) { if (_pendingSpecification.HasPendingCallSpec()) { SetResultForCall(_pendingSpecification.UseCallSpec(), valueToReturn, matchArgs); } else { var lastCall = _callStack.Pop(); SetResultForCall(lastCall, valueToReturn, matchArgs); } }
public override void Context() { _sub = mock<IFoo>(); _substitutionContext = mock<ISubstitutionContext>(); _callRouter = mock<ICallRouter>(); _substitutionContext.stub(x => x.GetCallRouterFor(_sub)) .IgnoreArguments() .Return(_callRouter); _callRouter.stub(x => x.SetReturnForType(It.IsAny<Type>(), It.IsAny<IReturn>())) .IgnoreArguments() .WhenCalled(x => _returnValueSet = (IReturn)x.Arguments[1]); temporarilyChange(() => SubstitutionContext.Current).to(_substitutionContext); }
public ConfiguredCall LastCallShouldReturn(IReturn value, MatchArgs matchArgs) { if (_lastCallRouter.Value == null) throw new CouldNotSetReturnDueToNoLastCallException(); if (_argumentSpecifications.Value.Any()) { //Clear invalid arg specs so they will not affect other tests _argumentSpecifications.Value.Clear(); throw new UnexpectedArgumentMatcherException(); } var configuredCall = _lastCallRouter.Value.LastCallShouldReturn(value, matchArgs); ClearLastCallRouter(); return configuredCall; }
public TResponse Delete <TResponse>(IReturn <TResponse> request) { return(DeleteAsync(request).GetSyncResponse()); }
public void SetReturnForType(Type type, IReturn returnValue) { TypeUseForSetReturnForType = type; ReturnValueUsedForSetReturnForType = returnValue; }
public ResultForTypeSpec(Type type, IReturn resultToReturn) { _type = type; _resultToReturn = resultToReturn; }
public ResultForCallSpec(ICallSpecification callSpecification, IReturn resultToReturn) { _callSpecification = callSpecification; _resultToReturn = resultToReturn; }
public void LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs) { }
void SetResultForCall(ICallSpecification callSpecification, IReturn valueToReturn, MatchArgs matchArgs) { var callSpecForReturnValue = GetCallSpecForArgMatchStrategy(callSpecification, matchArgs); _configuredResults.SetResult(callSpecForReturnValue, valueToReturn); }
public void SetResultForCall(ICall call, IReturn valueToReturn, MatchArgs matchArgs) { var callSpecification = _callSpecificationFactory.CreateFrom(call, matchArgs); _configuredResults.SetResult(callSpecification, valueToReturn); }
public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs) { return(new ConfiguredCall(x => { })); }
public TResponse Get <TResponse>(IReturn <TResponse> request) { return(GetAsync(request).GetSyncResponse()); }
public Task <TResponse> PutAsync <TResponse>(IReturn <TResponse> requestDto) { return(SendAsync <TResponse>(HttpMethods.Put, ResolveTypedUrl(HttpMethods.Put, requestDto), requestDto)); }
public Task <TResponse> DeleteAsync <TResponse>(IReturn <TResponse> requestDto) { return(SendAsync <TResponse>(HttpMethods.Delete, ResolveTypedUrl(HttpMethods.Delete, requestDto), null)); }
public TResponse CustomMethod <TResponse>(string httpVerb, IReturn <TResponse> request) { return(SendAsync <TResponse>(httpVerb, ResolveTypedUrl(httpVerb, request), request).GetSyncResponse()); }
public TResponse Patch <TResponse>(IReturn <TResponse> request) { return(SendAsync <TResponse>(HttpMethods.Patch, ResolveTypedUrl(HttpMethods.Patch, request), request).GetSyncResponse()); }
/// <summary> /// Alias for ToUrl /// </summary> /// <returns></returns> public static string ToRelativeUri(this IReturn request, string httpMethod, string formatFallbackToPredefinedRoute = null) { return(request.ToUrl(httpMethod, formatFallbackToPredefinedRoute)); }
public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs) { return(ConfigureCall.SetResultForLastCall(returnValue, matchArgs)); }
public static string ToUrl(this IReturn request, string httpMethod, string formatFallbackToPredefinedRoute = null) { httpMethod = httpMethod.ToUpper(); var requestType = request.GetType(); var requestRoutes = routesCache.GetOrAdd(requestType, GetRoutesForType); if (requestRoutes.Count == 0) { if (formatFallbackToPredefinedRoute == null) { throw new InvalidOperationException("There are no rest routes mapped for '{0}' type. ".Fmt(requestType) + "(Note: The automatic route selection only works with [Route] attributes on the request DTO and" + "not with routes registered in the IAppHost!)"); } var predefinedRoute = "/{0}/syncreply/{1}".Fmt(formatFallbackToPredefinedRoute, requestType.Name); if (httpMethod == "GET" || httpMethod == "DELETE" || httpMethod == "OPTIONS" || httpMethod == "HEAD") { var queryProperties = RestRoute.GetQueryProperties(request.GetType()); predefinedRoute += "?" + RestRoute.GetQueryString(request, queryProperties); } return(predefinedRoute); } var routesApplied = requestRoutes.Select(route => route.Apply(request, httpMethod)).ToList(); var matchingRoutes = routesApplied.Where(x => x.Matches).ToList(); if (matchingRoutes.Count == 0) { var errors = string.Join(String.Empty, routesApplied.Select(x => "\r\n\t{0}:\t{1}".Fmt(x.Route.Path, x.FailReason)).ToArray()); var errMsg = "None of the given rest routes matches '{0}' request:{1}" .Fmt(requestType.Name, errors); throw new InvalidOperationException(errMsg); } RouteResolutionResult matchingRoute; if (matchingRoutes.Count > 1) { matchingRoute = FindMostSpecificRoute(matchingRoutes); if (matchingRoute == null) { var errors = String.Join(String.Empty, matchingRoutes.Select(x => "\r\n\t" + x.Route.Path).ToArray()); var errMsg = "Ambiguous matching routes found for '{0}' request:{1}".Fmt(requestType.Name, errors); throw new InvalidOperationException(errMsg); } } else { matchingRoute = matchingRoutes[0]; } var url = matchingRoute.Uri; if (httpMethod == HttpMethods.Get || httpMethod == HttpMethods.Delete || httpMethod == HttpMethods.Head) { var queryParams = matchingRoute.Route.FormatQueryParameters(request); if (!String.IsNullOrEmpty(queryParams)) { url += "?" + queryParams; } } return(url); }
public void SetResultForLastCall(IReturn valueToReturn, MatchArgs matchArgs) { var lastCall = _callStack.Pop(); SetResultForCall(lastCall, valueToReturn, matchArgs); }
public ReturnController(IReturnServices IssueService, IStudentServices studentService, IBookService bookservices, IReturn Issuemodel, IStaffServices staffSevices) { _entity = new Return(); _IReturnServices = IssueService; _IStudentServices = studentService; _IBookService = bookservices; _IReturn = Issuemodel; _IStaffServices = staffSevices; }
public IEnumerable <TResponse> GetLazy <TResponse>(IReturn <QueryResponse <TResponse> > queryDto) { throw new NotImplementedException(); }
public TResponse Delete <TResponse>(IReturn <TResponse> request) { throw new NotImplementedException(); }
public ConfiguredCall LastCallShouldReturn(IReturn value, MatchArgs matchArgs) { if (_lastCallRouter.Value == null) throw new CouldNotSetReturnDueToNoLastCallException(); var configuredCall = _lastCallRouter.Value.LastCallShouldReturn(value, matchArgs); ClearLastCallRouter(); return configuredCall; }
public TResponse Patch <TResponse>(IReturn <TResponse> requestDto) { throw new NotImplementedException(); }
public void SetResult(ICallSpecification callSpecification, IReturn result) { _results.Add(new ResultForCallSpec(callSpecification, result)); }
public Task <TResponse> SendAsync <TResponse>(IReturn <TResponse> requestDto) { return(SendAsync <TResponse>((object)requestDto)); }
public void SetResult(Type type, IReturn resultToReturn) { _results.Enqueue(new ResultForTypeSpec(type, resultToReturn)); }
public Task <TResponse> PutAsync <TResponse>(IReturn <TResponse> requestDto) { throw new NotImplementedException(); }
public void LastCallShouldReturn(IReturn value, MatchArgs matchArgs) { if (_lastCallRouter == null) throw new SubstituteException(); _lastCallRouter.LastCallShouldReturn(value, matchArgs); }
public Task <TResponse> CustomMethodAsync <TResponse>(string httpVerb, IReturn <TResponse> requestDto) { throw new NotImplementedException(); }
public void SetResultForCall(ICall call, IReturn valueToReturn, MatchArgs matchArgs) { var spec = _getCallSpec.FromCall(call, matchArgs); CheckResultIsCompatibleWithCall(valueToReturn, spec); _configuredResults.SetResult(spec, valueToReturn); }
public void SetReturnForType(Type type, IReturn returnValue) { _substituteState.ResultsForType.SetResult(type, returnValue); }
public void LastCallShouldReturn(IReturn value, MatchArgs matchArgs) { if (_lastCallRouter.Value == null) throw new CouldNotSetReturnException(); _lastCallRouter.Value.LastCallShouldReturn(value, matchArgs); _lastCallRouter.Value = null; }
public void LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs) { _resultSetter.SetResultForLastCall(returnValue, matchArgs); }
public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs) { return new ConfiguredCall(x => { }); }
public ConfiguredCall LastCallShouldReturn(IReturn value, MatchArgs matchArgs) { return innerContext.LastCallShouldReturn(value, matchArgs); }
public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs) { return ConfigureCall.SetResultForLastCall(returnValue, matchArgs); }
public override void Context() { base.Context(); _returnValue = mock <IReturn>(); }