public void Invoke_WhenLocalPathIsLocal_ShouldUseTheSettedLocalPath() { // Arrange var requestDelegate = fixture.Create <RequestDelegate>(); var httpClientMock = fixture.Freeze <Mock <IProxyHttpClient> >(); var options = CreateProxyOptions(); options.PrefixType = PathPrefixType.Local; var request = new HttpRequestMock { PathBase = "/mylocalprefix" }; optionsMock.Setup(x => x.Value).Returns(options); httpClientFactoryMock.Setup(x => x.Create(HttpClientType.HttpClient)) .Returns(httpClientMock.Object); var subject = new ProxyServerMiddleware(httpClientFactoryMock.Object, requestDelegate, optionsMock.Object); // Action subject.Invoke(new HttpContextMock(request)).Wait(); // Assets httpClientMock.Verify(x => x.SendAsync(It.Is <HttpRequestMessage>(p => p.RequestUri.LocalPath == "/mylocalprefix"), HttpCompletionOption.ResponseHeadersRead)); }
public void Can_use_fileStream() { byte[] fileBytes = uploadedTextFile.ReadFully(); string fileText = Encoding.ASCII.GetString(fileBytes); "File content size {0}".Print(fileBytes.Length); "File content is {0}".Print(fileText); var mockRequest = new HttpRequestMock(); var mockResponse = new HttpResponseMock(); mockRequest.Headers.Add("Range", "bytes=6-8"); var httpResult = new HttpResult(uploadedTextFile, "audio/mpeg"); bool reponseWasAutoHandled = mockResponse.WriteToResponse(mockRequest, httpResult); Assert.That(reponseWasAutoHandled, Is.True); string writtenString = mockResponse.GetOutputStreamAsString(); Assert.That(writtenString, Is.EqualTo(fileText.Substring(6, 3))); Assert.That(mockResponse.Headers["Content-Range"], Is.EqualTo("bytes 6-8/33")); Assert.That(mockResponse.Headers["Content-Length"], Is.EqualTo(writtenString.Length.ToString())); Assert.That(mockResponse.Headers["Accept-Ranges"], Is.EqualTo("bytes")); Assert.That(mockResponse.StatusCode, Is.EqualTo(206)); }
public void Invoke_WhenQueryStringIsSetted_ShouldUseTheSettedQuery() { // Arrange var requestDelegate = fixture.Create <RequestDelegate>(); var httpClientMock = fixture.Freeze <Mock <IProxyHttpClient> >(); var options = CreateProxyOptions(); var request = new HttpRequestMock { QueryString = new QueryString("?myQueryString") }; optionsMock.Setup(x => x.Value).Returns(options); httpClientFactoryMock.Setup(x => x.Create(HttpClientType.HttpClient)) .Returns(httpClientMock.Object); var subject = new ProxyServerMiddleware(httpClientFactoryMock.Object, requestDelegate, optionsMock.Object); // Action subject.Invoke(new HttpContextMock(request)).Wait(); // Assets httpClientMock.Verify(x => x.SendAsync(It.Is <HttpRequestMessage>(p => p.RequestUri.Query == "?myQueryString"), HttpCompletionOption.ResponseHeadersRead)); }
public WhenANewAccountIsCreated() { _request = HttpRequestMock.MockRequest(); _request.Headers.Add("password", "beans"); AccountController.Post(_request, TestHelper.NameMock, TestHelper.EmailAddressMock); }
public void Can_seek_from_middle_to_middle() { var mockRequest = new HttpRequestMock(); mockRequest.Headers.Add("Range", "bytes=3-5"); var mockResponse = new HttpResponseMock(); string customText = "1234567890"; byte[] customTextBytes = customText.ToUtf8Bytes(); var ms = new MemoryStream(); ms.Write(customTextBytes, 0, customTextBytes.Length); var httpResult = new HttpResult(ms, "audio/mpeg"); bool reponseWasAutoHandled = mockResponse.WriteToResponse(mockRequest, httpResult); Assert.That(reponseWasAutoHandled, Is.True); string writtenString = mockResponse.GetOutputStreamAsString(); Assert.That(writtenString, Is.EqualTo("456")); Assert.That(mockResponse.Headers["Content-Range"], Is.EqualTo("bytes 3-5/10")); Assert.That(mockResponse.Headers["Content-Length"], Is.EqualTo(writtenString.Length.ToString())); Assert.That(mockResponse.Headers["Accept-Ranges"], Is.EqualTo("bytes")); Assert.That(mockResponse.StatusCode, Is.EqualTo(206)); }
public void Can_respond_to_non_range_requests_with_200_OK_response() { var mockRequest = new HttpRequestMock(); var mockResponse = new HttpResponseMock(); string customText = "1234567890"; byte[] customTextBytes = customText.ToUtf8Bytes(); var ms = new MemoryStream(); ms.Write(customTextBytes, 0, customTextBytes.Length); var httpResult = new HttpResult(ms, "audio/mpeg"); bool reponseWasAutoHandled = mockResponse.WriteToResponse(mockRequest, httpResult); Assert.That(reponseWasAutoHandled, Is.True); string writtenString = mockResponse.GetOutputStreamAsString(); Assert.That(writtenString, Is.EqualTo(customText)); Assert.That(mockResponse.Headers["Content-Range"], Is.Null); Assert.That(mockResponse.Headers["Accept-Ranges"], Is.EqualTo("bytes")); Assert.That(mockResponse.StatusCode, Is.EqualTo(200)); }
public void SetupController() { //arrange var testRoom1 = new Room(1, "testRoom1", new DateTime(2000, 12, 12)); var testRoom2 = new Room(2, "testRoom2", new DateTime(2001, 12, 12)); var testAccount = new Account(1, "ashley", "*****@*****.**", AccountType.Full); _authenticationManager = new MockTimeWarpAuthenticationManager(); var token = _authenticationManager.AddUser(new AccountPassword(testAccount, "")); _request = HttpRequestMock.MockRequest(); _request.Headers.Add("login-token", token); _roomRepository = new MockRoomRepository(); _roomRepository.Add(testRoom1); _roomRepository.Add(testRoom2); _accountRepository = new MockAccountsRepository(); _accountRepository.Add(testAccount); _nowProvider = new FakeNowProvider(); var roomsController = new RoomInfoController(_roomRepository, _accountRepository, _authenticationManager, _nowProvider); _globalRoomInfoController = new GlobalRoomInfoController(_roomRepository); _roomInfoController = roomsController; }
public void Can_seek_from_beginning_to_further_than_end() { // Not sure if this would ever occur in real streaming scenarios, but it does occur // when some crawlers use range headers to specify a max size to return. // e.g. Facebook crawler always sends range header of 'bytes=0-524287'. var mockRequest = new HttpRequestMock(); var mockResponse = new HttpResponseMock(); mockRequest.Headers[HttpHeaders.Range] = "bytes=0-524287"; string customText = "1234567890"; byte[] customTextBytes = customText.ToUtf8Bytes(); var ms = new MemoryStream(); ms.Write(customTextBytes, 0, customTextBytes.Length); var httpResult = new HttpResult(ms, "audio/mpeg"); bool reponseWasAutoHandled = mockResponse.WriteToResponse(mockRequest, httpResult); Assert.That(reponseWasAutoHandled, Is.True); string writtenString = mockResponse.GetOutputStreamAsString(); Assert.That(writtenString, Is.EqualTo(customText)); Assert.That(mockResponse.Headers["Content-Range"], Is.EqualTo("bytes 0-9/10")); Assert.That(mockResponse.Headers["Content-Length"], Is.EqualTo(writtenString.Length.ToString())); Assert.That(mockResponse.Headers["Accept-Ranges"], Is.EqualTo("bytes")); Assert.That(mockResponse.StatusCode, Is.EqualTo(206)); }
public void TestIsMatchWithContentPattern(bool isMatchResult) { var contnetPatternMock = NewMock <IHttpRequestContentPattern>(); const string method = "post"; const string path = "/"; var contentBytes = new byte[0]; const string contentType = "application/json"; contnetPatternMock.Setup(x => x.IsMatch(contentBytes, contentType)).Returns(isMatchResult); var httpRequestMock = new HttpRequestMock { Method = MethodPattern.Standart(method), Path = PathPattern.Smart(path), Content = contnetPatternMock.Object, Query = QueryPattern.Any(), Headers = HeadersPattern.Any() }; var httpRequestPattern = new HttpRequestPattern(httpRequestMock); var httpRequestInfo = new HttpRequest { Method = method, Path = path, ContentBytes = contentBytes, ContentType = contentType }; httpRequestPattern.IsMatch(httpRequestInfo).ShouldBeEquivalentTo(isMatchResult); }
public void SetRequestPath(string path) { var pathString = new PathString(path); HttpRequestMock .Setup(m => m.Path) .Returns(pathString); }
public void TestDefaultRoute() { // Arrange // Mock the HTTP request also HttpRequestMock mockRequest = new HttpRequestMock(); Uri mockUrl = new Uri("http://www.cosmomonger.com/"); mockRequest.Expect(r => r.Url) .Returns(mockUrl); mockRequest.Expect(r => r.HttpMethod) .Returns("GET"); mockRequest.Expect(r => r.AppRelativeCurrentExecutionFilePath) .Returns("~/"); HttpContextMock mockHttpContext = new HttpContextMock(); mockHttpContext.Expect(c => c.Request) .Returns(mockRequest.Object); // Act RouteCollection routeCollection = new RouteCollection(); MvcApplication.RegisterRoutes(routeCollection); RouteData routeData = routeCollection.GetRouteData(mockHttpContext.Object); // Assert Assert.AreEqual("Home", routeData.Values["controller"], "Default controller is HomeController"); Assert.AreEqual("Index", routeData.Values["action"], "Default action is Index"); Assert.AreEqual(String.Empty, routeData.Values["id"], "Default Id is empty string"); /* * // This code can almost render a view * HttpRequestMock mockRequest = new HttpRequestMock(); * Uri mockUrl = new Uri("http://www.cosmomonger.com/"); * mockRequest.Expect(r => r.Url) * .Returns(mockUrl); * mockRequest.Expect(r => r.HttpMethod) * .Returns("GET"); * mockRequest.Expect(r => r.AppRelativeCurrentExecutionFilePath) * .Returns("~/"); * * HttpContextMock mockHttpContext = new HttpContextMock(); * mockHttpContext.Expect(c => c.Request) * .Returns(mockRequest.Object); * * RouteCollection routeCollection = new RouteCollection(); * MvcApplication.RegisterRoutes(routeCollection); * RouteData routeData = routeCollection.GetRouteData(mockHttpContext.Object); * * ControllerContext controllerContext = new ControllerContext(mockHttpContext.Object, routeData, controller); * StringWriter writer = new StringWriter(); * result.ExecuteResult(controllerContext); * ViewContext viewContext = new ViewContext(controllerContext, result.View, result.ViewData, result.TempData); * result.View.Render(viewContext, writer); * Assert.Fail(writer.ToString()); */ }
/// <summary> /// Initializes a new instance of the <see cref="HttpRequestBuilder"/> class. /// </summary> public HttpRequestBuilder(HttpContext httpContext) { CommonValidator.CheckForNullReference(httpContext, nameof(HttpContext)); this.request = new HttpRequestMock(httpContext) { Scheme = HttpScheme.Http, Path = "/" }; }
public void SetContentType_HttpRequestTestStruct_TextHtml() { var request = new HttpRequestMock(); request.SetContentType(TestStruct); var act = request.ContentType; var exp = TestStruct.ToString(); Assert.AreEqual(exp, act); }
public void SetUp() { authenticationConfig = AuthenticationConfig.Builder.RedirectUri("test://example.com").Build(); keycloakConfig = new KeycloakConfig(kcConfig); credentialManagerMock = new CredentialManagerMock(); IHttpResponse httpResponse = (HttpResponseMock)HttpResponseMock.newResponse().withStatusCode(200); var requestToBeExecuted = new HttpRequestToBeExecutedMock(Task.FromResult(httpResponse), null); IHttpRequest httpRequestMock = (HttpRequestMock)HttpRequestMock.newRequest().withGetResult(requestToBeExecuted); httpModuleMock = (HttpServiceModuleMock)HttpServiceModuleMock.newMock().withNewRequest(httpRequestMock); authenticatorToTest = new OIDCAuthenticator(authenticationConfig, keycloakConfig, credentialManagerMock, httpModuleMock, logger); }
internal HttpRequestMockBuilder() { httpRequestMock = new HttpRequestMock { Method = MethodPattern.Any(), Path = PathPattern.Any(), Query = QueryPattern.Any(), Content = ContentPattern.Any(), Headers = HeadersPattern.Any() }; httpResponseMockBuilder = new HttpResponseMockBuilder(200); }
public void GetContentType_HttpRequest_TextHtml() { var request = new HttpRequestMock() { ContentType = "text/html" }; var act = request.GetContentType(); var exp = TextHtml; Assert.AreEqual(exp, act); }
private T StringToPoco <T>(string str) { var testAppHost = new TestAppHost(new Container(), GetType().Assembly); NameValueCollection queryString = HttpUtility.ParseQueryString(str); var restPath = new RestPath(typeof(T), "/query", "GET, POST"); var restHandler = new RestHandler() { RestPath = restPath }; var httpReq = new HttpRequestMock("query", "GET", "application/json", "query", queryString, new MemoryStream(), new NameValueCollection()); var request = (T)restHandler.CreateRequest(httpReq, "query"); return(request); }
public void SendVerificationCodeSuccessful() { // Arrange string testUserName = "******"; Mock <User> mockUserModel = new Mock <User>(); Mock <CosmoMongerMembershipUser> mockUser = new Mock <CosmoMongerMembershipUser>(mockUserModel.Object); mockUser.Expect(m => m.SendVerificationCode(It.IsRegex("http://www.cosmomonger.com/Account/VerifyEmail?username=TestUser&verificationCode=.*"))) .AtMostOnce().Verifiable(); Mock <MembershipProvider> mockMembership = new Mock <MembershipProvider>(); mockMembership.Expect <MembershipUser>(m => m.GetUser(testUserName, false)) .Returns(mockUser.Object).AtMostOnce().Verifiable(); // Mock the HTTP request also HttpRequestMock mockRequest = new HttpRequestMock(); Uri mockUrl = new Uri("http://www.cosmomonger.com/Account/SendVerificationCode?username=TestUser"); mockRequest.Expect(r => r.Url) .Returns(mockUrl); mockRequest.Expect(r => r.HttpMethod) .Returns("GET"); mockRequest.Expect(r => r.AppRelativeCurrentExecutionFilePath) .Returns("~/Account/"); HttpContextMock mockHttpContext = new HttpContextMock(); mockHttpContext.Expect(c => c.Request) .Returns(mockRequest.Object); RouteCollection routeCollection = new RouteCollection(); MvcApplication.RegisterRoutes(routeCollection); RouteData route = routeCollection.GetRouteData(mockHttpContext.Object); AccountController controller = new AccountController(mockMembership.Object); controller.ControllerContext = new ControllerContext(mockHttpContext.Object, route, new Mock <ControllerBase>().Object); controller.Url = new UrlHelper(new RequestContext(mockHttpContext.Object, route)); // Act ViewResult result = (ViewResult)controller.SendVerificationCode(testUserName); // Assert Assert.That(result.ViewName, Is.EqualTo("SentVerificationCode"), "Should have returned the SentVerificationCode view"); }
public void Can_deserialize_TestRequest_QueryStringSerializer_output() { // Setup var testAppHost = new TestAppHost(new Container(), typeof(TestService).Assembly); var restPath = new RestPath(typeof(TestRequest), "/service", "GET"); var restHandler = new RestHandler { RestPath = restPath }; var requestString = "ListOfA={ListOfB:[{Property:prop1},{Property:prop2}]}"; NameValueCollection queryString = HttpUtility.ParseQueryString(requestString); var httpReq = new HttpRequestMock("service", "GET", "application/json", "service", queryString, new MemoryStream(), new NameValueCollection()); var request2 = (TestRequest)restHandler.CreateRequest(httpReq, "service"); Assert.That(request2.ListOfA.Count, Is.EqualTo(1)); Assert.That(request2.ListOfA.First().ListOfB.Count, Is.EqualTo(2)); }
public void Can_deserialize_TestRequest_QueryStringSerializer_output() { // Setup var testAppHost = new TestAppHost(new Container(), typeof(TestService).Assembly); var restPath = new RestPath(typeof(TestRequest), "/service", "GET"); var restHandler = new RestHandler { RestPath = restPath }; var requestString = "ListOfA={ListOfB:[{Property:prop1},{Property:prop2}]}"; NameValueCollection queryString = HttpUtility.ParseQueryString(requestString); var httpReq = new HttpRequestMock("service", "GET", "application/json", "service", queryString, new MemoryStream(), new NameValueCollection()); var request2 = (TestRequest)restHandler.CreateRequest(httpReq, "service"); Assert.That(request2.ListOfA.Count, Is.EqualTo(1)); Assert.That(request2.ListOfA.First().ListOfB.Count, Is.EqualTo(2)); }
public void TestIsMatch(string method, string expectedMethod, bool expected) { const string pathPattern = "/"; var httpRequestMock = new HttpRequestMock { Method = MethodPattern.Standart(method), Path = PathPattern.Smart(pathPattern), Query = QueryPattern.Any(), Headers = HeadersPattern.Any(), Content = ContentPattern.Any() }; var httpRequestPattern = new HttpRequestPattern(httpRequestMock); var httpRequestInfo = new HttpRequest { Method = expectedMethod, Path = pathPattern }; httpRequestPattern.IsMatch(httpRequestInfo).ShouldBeEquivalentTo(expected); }
protected UserControllerTestBase() { FakeNowProvider = new FakeNowProvider { Now = new DateTime(2000, 12, 12, 12, 12, 0) }; var usersCache = new MockUserStateRepository(); var calc = FakeTimeCalculatorFactory.GetTimeWarpStateCalculator(); var account = new Account(AccountId, TestHelper.NameMock, TestHelper.EmailAddressMock, AccountType.Full); var accountRepository = new MockAccountsRepository(); var authenticationManager = new MockTimeWarpAuthenticationManager(); var token = authenticationManager.AddUser(new AccountPassword(account, "bean")); accountRepository.Add(account); var timeWarpUser = new UserStateManager(calc, usersCache); Request = HttpRequestMock.MockRequest(); Request.Headers.Add("login-token", token); Controller = new UserStateController(timeWarpUser, FakeNowProvider, accountRepository, authenticationManager); }
public void IndexTest() { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); //Create a cookie object var cookie = new HttpCookie(Constants.CookieName) { Value = "12", Expires = DateTime.MaxValue }; //Create a cookie ccollection var cookieCollection = new HttpCookieCollection { cookie }; //Add Cookie HttpRequestMock.SetupGet(x => x.Cookies).Returns(cookieCollection); //Get the controller var objController = GetController(); //Get the result view var result = objController.Index() as ViewResult; stopWatch.Stop(); // Get the elapsed time as a TimeSpan value. TimeSpan ts = stopWatch.Elapsed; // Format and display the TimeSpan value. string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Assert.IsNotNull(result.Model); }
public void GetPhysicalPath_Honours_WebHostPhysicalPath() { using (var appHost = new BasicAppHost { ConfigFilter = c => { c.WebHostPhysicalPath = "c:/Windows/Temp"; } }.Init()) { var mock = new HttpRequestMock(); string originalPath = appHost.Config.WebHostPhysicalPath; string path = mock.GetPhysicalPath(); var normalizePaths = (Func<string, string>)(p => p == null ? null : p.Replace('\\', '/')); Assert.That(normalizePaths(path), Is.EqualTo(normalizePaths("{0}/{1}".Fmt(originalPath, mock.PathInfo)))); } }
public void Can_use_fileStream() { byte[] fileBytes = uploadedTextFile.ReadFully(); string fileText = Encoding.ASCII.GetString(fileBytes); "File content size {0}".Print(fileBytes.Length); "File content is {0}".Print(fileText); var mockRequest = new HttpRequestMock(); var mockResponse = new HttpResponseMock(); mockRequest.Headers.Add("Range", "bytes=6-8"); var httpResult = new HttpResult(uploadedTextFile, "audio/mpeg"); bool reponseWasAutoHandled = mockResponse.WriteToResponse(mockRequest, httpResult); Assert.That(reponseWasAutoHandled, Is.True); string writtenString = mockResponse.GetOutputStreamAsString(); Assert.That(writtenString, Is.EqualTo(fileText.Substring(6, 3))); Assert.That(mockResponse.Headers["Content-Range"], Is.EqualTo("bytes 6-8/33")); Assert.That(mockResponse.Headers["Content-Length"], Is.EqualTo(writtenString.Length.ToString())); Assert.That(mockResponse.Headers["Accept-Ranges"], Is.EqualTo("bytes")); Assert.That(mockResponse.StatusCode, Is.EqualTo(206)); }
public void Can_seek_from_middle_to_middle() { var mockRequest = new HttpRequestMock(); mockRequest.Headers.Add("Range", "bytes=3-5"); var mockResponse = new HttpResponseMock(); string customText = "1234567890"; byte[] customTextBytes = customText.ToUtf8Bytes(); var ms = new MemoryStream(); ms.Write(customTextBytes, 0, customTextBytes.Length); var httpResult = new HttpResult(ms, "audio/mpeg"); bool reponseWasAutoHandled = mockResponse.WriteToResponse(mockRequest, httpResult); Assert.That(reponseWasAutoHandled, Is.True); string writtenString = mockResponse.GetOutputStreamAsString(); Assert.That(writtenString, Is.EqualTo("456")); Assert.That(mockResponse.Headers["Content-Range"], Is.EqualTo("bytes 3-5/10")); Assert.That(mockResponse.Headers["Content-Length"], Is.EqualTo(writtenString.Length.ToString())); Assert.That(mockResponse.Headers["Accept-Ranges"], Is.EqualTo("bytes")); Assert.That(mockResponse.StatusCode, Is.EqualTo(206)); }
public void Can_seek_from_beginning_to_further_than_end() { // Not sure if this would ever occur in real streaming scenarios, but it does occur // when some crawlers use range headers to specify a max size to return. // e.g. Facebook crawler always sends range header of 'bytes=0-524287'. var mockRequest = new HttpRequestMock(); var mockResponse = new HttpResponseMock(); mockRequest.Headers[HttpHeaders.Range] = "bytes=0-524287"; string customText = "1234567890"; byte[] customTextBytes = customText.ToUtf8Bytes(); var ms = new MemoryStream(); ms.Write(customTextBytes, 0, customTextBytes.Length); var httpResult = new HttpResult(ms, "audio/mpeg"); bool reponseWasAutoHandled = mockResponse.WriteToResponse(mockRequest, httpResult); Assert.That(reponseWasAutoHandled, Is.True); string writtenString = mockResponse.GetOutputStreamAsString(); Assert.That(writtenString, Is.EqualTo(customText)); Assert.That(mockResponse.Headers["Content-Range"], Is.EqualTo("bytes 0-9/10")); Assert.That(mockResponse.Headers["Content-Length"], Is.EqualTo(writtenString.Length.ToString())); Assert.That(mockResponse.Headers["Accept-Ranges"], Is.EqualTo("bytes")); Assert.That(mockResponse.StatusCode, Is.EqualTo(206)); }
public void Can_respond_to_non_range_requests_with_200_OK_response() { var mockRequest = new HttpRequestMock(); var mockResponse = new HttpResponseMock(); string customText = "1234567890"; byte[] customTextBytes = customText.ToUtf8Bytes(); var ms = new MemoryStream(); ms.Write(customTextBytes, 0, customTextBytes.Length); var httpResult = new HttpResult(ms, "audio/mpeg"); bool reponseWasAutoHandled = mockResponse.WriteToResponse(mockRequest, httpResult); Assert.That(reponseWasAutoHandled, Is.True); string writtenString = mockResponse.GetOutputStreamAsString(); Assert.That(writtenString, Is.EqualTo(customText)); Assert.That(mockResponse.Headers["Content-Range"], Is.Null); Assert.That(mockResponse.Headers["Accept-Ranges"], Is.EqualTo("bytes")); Assert.That(mockResponse.StatusCode, Is.EqualTo(200)); }
public void SetRequestMethod(string method) => HttpRequestMock .Setup(m => m.Method) .Returns(method);
public WhenAQuickLogonAccountIsCreated() { _request = HttpRequestMock.MockRequest(); _result = AccountController.Post(_request, "quickLoginTest"); }
public HttpRequestPattern(HttpRequestMock requestMock) { this.requestMock = requestMock; }
private static HttpRequestMock GetHttpRequestMock(XmlDbUpdateRecordedAction action) { var httpRequest = new HttpRequestMock(); var options = QPConnectionScope.Current.IdentityInsertOptions; var entityTypeCode = action.BackendAction.EntityType.Code; if (entityTypeCode == EntityTypeCode.VirtualContent) { entityTypeCode = EntityTypeCode.Content; } var actionTypeCode = action.BackendAction.ActionType.Code; httpRequest.SetForm(action.Form); httpRequest.Form.Add(HttpContextFormConstants.Ids, string.Join(",", action.Ids)); if (actionTypeCode == ActionTypeCode.AddNew && options.Contains(entityTypeCode)) { httpRequest.Form.Add(HttpContextFormConstants.DataForceId, action.Ids.First()); } switch (action.Code) { case ActionCode.AddNewContent: if (options.Contains(EntityTypeCode.Field)) { AddListItem(httpRequest.Form, HttpContextFormConstants.DataForceFieldIds, action.ChildIds); } if (options.Contains(EntityTypeCode.ContentLink)) { AddListItem(httpRequest.Form, HttpContextFormConstants.DataForceLinkIds, action.ChildLinkIds); } break; case ActionCode.CreateLikeContent: if (options.Contains(EntityTypeCode.Content)) { httpRequest.Form.Add(HttpContextFormConstants.ForceId, action.ResultId.ToString()); } if (options.Contains(EntityTypeCode.Field)) { httpRequest.Form.Add(HttpContextFormConstants.ForceFieldIds, action.ChildIds); } if (options.Contains(EntityTypeCode.ContentLink)) { httpRequest.Form.Add(HttpContextFormConstants.ForceLinkIds, action.ChildLinkIds); } break; case ActionCode.CreateLikeField: if (options.Contains(EntityTypeCode.Field)) { httpRequest.Form.Add(HttpContextFormConstants.ForceId, action.ResultId.ToString()); } if (options.Contains(EntityTypeCode.Field)) { httpRequest.Form.Add(HttpContextFormConstants.ForceVirtualFieldIds, action.VirtualFieldIds); } if (options.Contains(EntityTypeCode.Field)) { httpRequest.Form.Add(HttpContextFormConstants.ForceChildFieldIds, action.ChildIds); } if (options.Contains(EntityTypeCode.ContentLink)) { httpRequest.Form.Add(HttpContextFormConstants.ForceLinkId, action.ChildId.ToString()); } if (options.Contains(EntityTypeCode.ContentLink)) { httpRequest.Form.Add(HttpContextFormConstants.ForceChildLinkIds, action.ChildLinkIds); } break; case ActionCode.AddNewVirtualContents: case ActionCode.VirtualContentProperties: case ActionCode.VirtualFieldProperties: if (options.Contains(EntityTypeCode.Field)) { AddListItem(httpRequest.Form, HttpContextFormConstants.DataForceVirtualFieldIds, action.VirtualFieldIds); } break; case ActionCode.AddNewField: case ActionCode.FieldProperties: if (options.Contains(EntityTypeCode.ContentLink)) { httpRequest.Form.Add(HttpContextFormConstants.DataContentLinkForceLinkId, action.ChildId.ToString()); AddListItem(httpRequest.Form, HttpContextFormConstants.DataForceChildLinkIds, action.ChildIds); } if (options.Contains(EntityTypeCode.Field)) { AddListItem(httpRequest.Form, HttpContextFormConstants.DataForceVirtualFieldIds, action.VirtualFieldIds); httpRequest.Form.Add(HttpContextFormConstants.DataForceBackwardId, action.BackwardId.ToString()); AddListItem(httpRequest.Form, HttpContextFormConstants.DataForceChildFieldIds, action.ChildIds); } break; case ActionCode.AddNewCustomAction: httpRequest.Form.Add(HttpContextFormConstants.DataForceActionCode, action.CustomActionCode); if (options.Contains(EntityTypeCode.BackendAction)) { httpRequest.Form.Add(HttpContextFormConstants.DataForceActionId, action.ChildId.ToString()); } break; case ActionCode.AddNewVisualEditorPlugin: case ActionCode.VisualEditorPluginProperties: if (options.Contains(EntityTypeCode.VisualEditorCommand)) { AddListItem(httpRequest.Form, HttpContextFormConstants.DataForceCommandIds, action.ChildIds); } break; case ActionCode.AddNewWorkflow: case ActionCode.WorkflowProperties: if (options.Contains(EntityTypeCode.WorkflowRule)) { AddListItem(httpRequest.Form, HttpContextFormConstants.DataForceRulesIds, action.ChildIds); } break; } httpRequest.SetPath(action.BackendAction.ControllerActionUrl.Replace("~", string.Empty)); return(httpRequest); }
public void VerifyAll() { ConnectionInfoMock.VerifyAll(); HttpRequestMock.VerifyAll(); HttpResponseMock.VerifyAll(); }
public void SetQueryString(string queryString) => HttpRequestMock .Setup(m => m.QueryString) .Returns(new QueryString(queryString));
public void GetPhysicalPath_Honours_WebHostPhysicalPath() { string root = "c:/MyWebRoot"; HttpRequestMock mock = new HttpRequestMock(); // Note: due to the static nature of EndpointHostConfig.Instance, running this // test twice withing NUnit fails the test. You'll need to reload betwen each // run. Assert.AreNotEqual( EndpointHostConfig.Instance.WebHostPhysicalPath, root ); string originalPath = EndpointHostConfig.Instance.WebHostPhysicalPath; string path = mock.GetPhysicalPath(); Assert.AreEqual( string.Format( "{0}/{1}", originalPath, mock.PathInfo ), path ); EndpointHostConfig.Instance.WebHostPhysicalPath = root; path = mock.GetPhysicalPath(); Assert.AreEqual( string.Format( "{0}/{1}", root, mock.PathInfo ), path ); }
public void GetPhysicalPath_Honours_WebHostPhysicalPath() { using (new BasicAppHost().Init()) { string root = "c:/MyWebRoot"; var mock = new HttpRequestMock(); string originalPath = HostContext.Config.WebHostPhysicalPath; string path = mock.GetPhysicalPath(); Assert.AreEqual(string.Format("{0}/{1}", originalPath, mock.PathInfo), path); HostContext.Config.WebHostPhysicalPath = root; path = mock.GetPhysicalPath(); Assert.AreEqual(string.Format("{0}/{1}", root, mock.PathInfo), path); } }
public void SetHttps(bool isHttps) => HttpRequestMock .Setup(m => m.IsHttps) .Returns(isHttps);
public void SetHost(string host) => HttpRequestMock .Setup(m => m.Host) .Returns(new HostString(host));