//[DeploymentItem("XmlFiles\\cancertopics.xml")] //[DeploymentItem("XmlFiles\\PageTemplateConfiguration.xml")] public void InitializePageAssemblyInfo_Test() { PageAssemblyContext_Accessor target = new PageAssemblyContext_Accessor(); // TODO: Initialize to an appropriate value string xmlFilePath = TestContext.TestDeploymentDir + "\\PublishedContent\\PageInstructions\\cancertopics.xml"; IPageAssemblyInstruction pageAssemblyInfo = null; using (HttpSimulator httpSimulator = GetStandardSimulatedRequest()) { using (XmlReader xmlReader = XmlReader.Create(xmlFilePath)) { xmlReader.MoveToContent(); string pageAssemblyInfoTypeName = xmlReader.LocalName; //XmlSerializer serializer = _serializers[pageAssemblyInfoTypeName]; XmlSerializer serializer = new XmlSerializer(typeof(SinglePageAssemblyInstruction)); // Deserialize the XML into an object. pageAssemblyInfo = (IPageAssemblyInstruction)serializer.Deserialize(xmlReader); } IPageAssemblyInstruction info = pageAssemblyInfo; DisplayVersions dispayVersion = DisplayVersions.Web; //Load the page template info for the current request PageTemplateInfo pageTemplateInfo = new PageTemplateInfo(); pageTemplateInfo.PageTemplatePath = "FOO.ASPX"; target.InitializePageAssemblyInfo(info, dispayVersion, pageTemplateInfo, "url"); Assert.Inconclusive("A method that does not return a value cannot be verified."); } }
public void RichTextEditor_CreateDefaultProvider() { using (var httpRequest = new HttpSimulator().SimulateRequest()) { //arrange var context = new Mock <ISubtextContext>(); var httpContext = new Mock <HttpContextBase>(); httpContext.Setup(c => c.Request.ApplicationPath).Returns("path"); context.Setup(c => c.UrlHelper).Returns( new BlogUrlHelper(new RequestContext(httpContext.Object, new RouteData()), null)); context.Setup(c => c.Blog).Returns(new Blog { Host = "host" }); var page = new SubtextPage { SubtextContext = context.Object }; var editor = new RichTextEditor { Page = page }; //act editor.InitControls(new EventArgs()); //post var provider = editor.Provider; Assert.IsTrue(provider is FtbBlogEntryEditorProvider, "FtbBlogEntryEditorProvider is created by default."); } }
public void RichTextEditor_CreatePlainText_IfPreferenceSet() { using (var httpRequest = new HttpSimulator().SimulateRequest()) { //arrange var context = new Mock <ISubtextContext>(); var httpContext = new Mock <HttpContextBase>(); httpContext.Setup(c => c.Request.ApplicationPath).Returns("path"); context.Setup(c => c.UrlHelper).Returns( new BlogUrlHelper(new RequestContext(httpContext.Object, new RouteData()), null)); context.Setup(c => c.Blog).Returns(new Blog { Host = "host" }); var page = new SubtextPage { SubtextContext = context.Object }; var editor = new RichTextEditor { Page = page }; //set use plain text in user preferences Preferences.UsePlainHtmlEditor = true; //act editor.InitControls(new EventArgs()); //post var provider = editor.Provider; Assert.IsTrue(provider is PlainTextBlogEntryEditorProvider, "PlainTextBlogEntryEditorProvider is created if it is selected in user preferences."); } }
public void GetSnippetsNotAssociatedWithSlots_Test() { using (HttpSimulator httpSimulator = GetStandardSimulatedRequest()) { string path = "/cancertopics"; SectionDetail target = new SectionDetail(); // TODO: Initialize to an appropriate value List <SnippetInfo> expected = null; // TODO: Initialize to an appropriate value expected = new List <SnippetInfo>() { new SnippetInfo { ContentID = "", Data = "", SlotName = "FooterSlot", SnippetTemplatePath = "" }, new SnippetInfo { ContentID = "", Data = "", SlotName = "LeftNavSlot", SnippetTemplatePath = "" } }; List <SnippetInfo> actual; List <string> snippets = new List <string>() { "BannerSlot" }; IEnumerable <string> templateSlotExclusionList = snippets; SectionDetail sectionDetail = SectionDetailFactory.GetSectionDetail(path); actual = sectionDetail.GetSnippetsNotAssociatedWithSlots(templateSlotExclusionList); Assert.AreEqual(expected.ToArray()[0].SlotName, actual.ToArray()[0].SlotName); Assert.AreEqual(expected.ToArray()[1].SlotName, actual.ToArray()[1].SlotName); } }
public void AddCycleTestSad() { using (HttpSimulator simulator = new HttpSimulator()) { simulator.SimulateRequest(); JIC.Base.TestStat t = JIC.Repositories.DBInteractions.Utitlities.Transe(JIC.Crime.Repositories.DBInteractions.DBFactory.Get(), () => { var serv = new JIC.Services.Services.CourtConfigurationService(Base.CaseType.Crime); serv.AddCycle(new List <DateTime> { DateTime.Now.AddDays(1), DateTime.Now.AddDays(3), DateTime.Now.AddDays(3), DateTime.Now.AddDays(4) }, Base.Cycle.FirstCycle, 1); return(Base.TestStat.Pass); }); switch (t) { case Base.TestStat.Fail: Assert.AreEqual(1, 1); break; case Base.TestStat.Pass: Assert.Fail(); break; default: break; } } }
public void CanParseRequestUrl(string url, string appPath, string physicalPath, string expectedHost, int expectedPort, string expectedAppPath, string expectedPage, string expectedAppDomainAppPath) { HttpSimulator simulator = new HttpSimulator(appPath, physicalPath); Assert.AreEqual(expectedAppPath, simulator.ApplicationPath); Assert.AreEqual(expectedAppDomainAppPath, simulator.PhysicalApplicationPath); }
protected override void Establish_context() { CommandFactory = MockRepository.GenerateStub <ICommandFactory>(); _sut = new RegistrationHandler(CommandFactory, null); Request = CreateRequest(); }
public void CanGetQueryString() { HttpSimulator simulator = new HttpSimulator(); simulator.SimulateRequest(new Uri("http://localhost/Test.aspx?param1=value1¶m2=value2¶m3=value3")); for (int i = 1; i <= 3; i++) { Assert.AreEqual("value" + i, HttpContext.Current.Request.QueryString["param" + i], "Could not find query string field 'param{0}'", i); } simulator.SimulateRequest(new Uri("http://localhost/Test.aspx?param1=new-value1¶m2=new-value2¶m3=new-value3¶m4=new-value4")); for (int i = 1; i <= 4; i++) { Assert.AreEqual("new-value" + i, HttpContext.Current.Request.QueryString["param" + i], "Could not find query string field 'param{0}'", i); } simulator.SimulateRequest(new Uri("http://localhost/Test.aspx?")); Assert.AreEqual(string.Empty, HttpContext.Current.Request.QueryString.ToString()); Assert.AreEqual(0, HttpContext.Current.Request.QueryString.Count); simulator.SimulateRequest(new Uri("http://localhost/Test.aspx")); Assert.AreEqual(string.Empty, HttpContext.Current.Request.QueryString.ToString()); Assert.AreEqual(0, HttpContext.Current.Request.QueryString.Count); simulator.SimulateRequest(new Uri("http://localhost/Test.aspx?param-name")); Assert.AreEqual("param-name", HttpContext.Current.Request.QueryString.ToString()); Assert.AreEqual(1, HttpContext.Current.Request.QueryString.Count); Assert.IsNull(HttpContext.Current.Request.QueryString["param-name"]); }
public void CanSimulateFormPost() { using (var simulator = new HttpSimulator()) { var form = new NameValueCollection(); form.Add("Test1", "Value1"); form.Add("Test2", "Value2"); simulator.SimulateRequest(new Uri("http://localhost/Test.aspx"), form); Assert.AreEqual("Value1", simulator.Context.Request.Form["Test1"]); Assert.AreEqual("Value2", simulator.Context.Request.Form["Test2"]); Assert.AreEqual(new Uri("http://localhost/Test.aspx"), simulator.Context.Request.Url); } using (var simulator = new HttpSimulator()) { simulator.SetFormVariable("Test1", "Value1") .SetFormVariable("Test2", "Value2") .SimulateRequest(new Uri("http://localhost/Test.aspx")); Assert.AreEqual("Value1", simulator.Context.Request.Form["Test1"]); Assert.AreEqual("Value2", simulator.Context.Request.Form["Test2"]); Assert.AreEqual(new Uri("http://localhost/Test.aspx"), simulator.Context.Request.Url); } }
protected MvcControllerTestBase(TestSetup <TSession> setup) { if (setup == null) { throw new ArgumentException("Please initialise the test class by creating a constructor and passing the setup argument to base()", "setup"); } _setup = setup; _controller = new Lazy <TController>(() => { var container = setup.Container; var requestScope = container.BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag, setup.AdditionalConfig); _httpRequest = new HttpSimulator().SimulateRequest(); var controller = requestScope.Resolve <TController>(); SetupRequestMocking(requestScope, controller); _session = requestScope.Resolve <TSession>(); if (setup.SessionSetup != null) { setup.SessionSetup(_session); } return(controller); }, LazyThreadSafetyMode.ExecutionAndPublication); }
public void Setup() { _autoSubstitute = AutoSubstituteContainer.Create(); _context = _autoSubstitute.Resolve <ControllerContext>(); _lookup = _autoSubstitute.Resolve <ICurtinUserService>(); DependencyResolver.SetResolver(new AutofacDependencyResolver(_autoSubstitute.Container)); _httpSimulator = new HttpSimulator().SimulateRequest(); }
public void CanGetLocalPathCorrectly(string url, string appPath, string expectedLocalPath) { HttpSimulator simulator = new HttpSimulator(appPath, @"c:\inetpub\wwwroot\AppPath\"); simulator.SimulateRequest(new Uri(url)); Assert.AreEqual(expectedLocalPath, HttpContext.Current.Request.Path); Assert.AreEqual(expectedLocalPath, HttpContext.Current.Request.Url.LocalPath); }
public void Setup() { _autoSubstitute = AutoSubstituteContainer.Create(); _context = _autoSubstitute.Resolve <ControllerContext>(); DependencyResolver.SetResolver(new AutofacDependencyResolver(_autoSubstitute.Container)); _httpSimulator = new HttpSimulator().SimulateRequest(); _form = _context.HttpContext.Request.Form; }
protected override void Establish_context() { _sut = new ValidationErrorResult(new List <INotification> { new ValidationError("foo"), new ValidationError("bar") }); _request = new HttpSimulator().SimulateRequest(); }
public void Simulator_Assigns_CurrentContext() { using (HttpSimulator simulator = new HttpSimulator()) { simulator.SimulateRequest(); Assert.IsNotNull(HttpContext.Current); } }
public void CanGetSetSession() { using (var simulator = new HttpSimulator("/", @"c:\inetpub\").SimulateRequest()) { simulator.Context.Session["Test"] = "Success"; Assert.AreEqual("Success", simulator.Context.Session["Test"]); } }
public void Notice_contains_Request() { AirbrakeNotice notice = null; const string url = "http://example.com/?Query.Key1=Query.Value1&Query.Key2=Query.Value2"; const string referer = "http://github.com/"; string physicalApplicationPath = Environment.CurrentDirectory + Path.DirectorySeparatorChar; var httpSimulator = new HttpSimulator("/", physicalApplicationPath) .SetFormVariable("Form.Key1", "Form.Value1") .SetFormVariable("Form.Key2", "Form.Value2") .SetHeader("Header.Key1", "Header.Value1") .SetHeader("Header.Key2", "Header.Value2") .SetReferer(new Uri(referer)) .SimulateRequest(new Uri(url)); using (httpSimulator) { try { Thrower.Throw(new Exception("Halp!")); } catch (Exception exception) { AirbrakeError error = this.builder.ErrorFromException(exception); notice = this.builder.Notice(error); } } Console.WriteLine(CleanXmlSerializer.ToXml(notice)); Assert.That(notice, Is.Not.Null); Assert.That(notice.Error, Is.Not.Null); #if !NET35 // We have defined a NET35 constant in the Visual Studio 2008 project so the below code isn't executed, // since it requires HttpSimulator which in turn requires .NET 4.0, which in turn requires Visual Studio 2010. Assert.That(notice.Request, Is.Not.Null); Assert.That(notice.Request.Url, Is.EqualTo(url)); Assert.That(notice.Request.Component, Is.EqualTo(typeof(Thrower).FullName)); Assert.That(notice.Request.Action, Is.EqualTo("Throw")); Assert.That(notice.Request.CgiData, Contains.Item(new AirbrakeVar("Content-Type", "application/x-www-form-urlencoded"))); Assert.That(notice.Request.CgiData, Contains.Item(new AirbrakeVar("Header.Key1", "Header.Value1"))); Assert.That(notice.Request.CgiData, Contains.Item(new AirbrakeVar("Header.Key2", "Header.Value2"))); Assert.That(notice.Request.CgiData, Contains.Item(new AirbrakeVar("Referer", referer))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("APPL_PHYSICAL_PATH", physicalApplicationPath))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("QUERY_STRING", "Query.Key1=Query.Value1&Query.Key2=Query.Value2"))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("Form.Key1", "Form.Value1"))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("Form.Key2", "Form.Value2"))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("Query.Key1", "Query.Value1"))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("Query.Key2", "Query.Value2"))); #endif }
public void GetFileInstructionTest() { using (HttpSimulator httpSimulator = GetStandardSimulatedRequest()) { IFileInstruction actual = FileInstructionFactory.GetFileInstruction("/cancertopics/test.pdf"); GenericFileInstruction expected = GetTestFileInstuction(); Assert.AreEqual(expected, actual); } }
public void CanGetResponse() { HttpSimulator simulator = new HttpSimulator(); simulator.SimulateRequest(); HttpContext.Current.Response.Write("Hello World!"); HttpContext.Current.Response.Flush(); Assert.AreEqual("Hello World!", simulator.ResponseText); }
public void CanDispose() { using (HttpSimulator simulator = new HttpSimulator()) { simulator.SimulateRequest(); Assert.IsNotNull(HttpContext.Current); } Assert.IsNull(HttpContext.Current); }
public void PageTemplateConfigurationPathTest() { using (HttpSimulator httpSimulator = GetStandardSimulatedRequest()) { string actual; actual = PageTemplateResolver_Accessor.PageTemplateConfigurationPath; Assert.Inconclusive("Verify the correctness of this test method."); } }
public void SetUp() { HttpSimulator = new HttpSimulator().SimulateRequest(); Logger = DependencyResolver.Current.GetService <ILog>(); DaoFactory = DependencyResolver.Current.GetService <IDaoFactory>(); Session = DependencyResolver.Current.GetService <ISession>(); ManagerFactory = DependencyResolver.Current.GetService <IManagerFactory>(); }
public void GetPageAssemblyInfo_SinglePageAssemblyInstruction_XMLFileNotExixts_Test() { using (HttpSimulator httpSimulator = GetStandardSimulatedRequest()) { IPageAssemblyInstruction actual = PageAssemblyInstructionFactory.GetPageAssemblyInfo("/cancertopics2"); SinglePageAssemblyInstruction expected = GetCancerTopicsSinglePageAssemblyInstuction(); Assert.AreNotEqual(expected, actual); } }
public void Setup() { var autoSubstitute = AutoSubstituteContainer.Create(); _context = autoSubstitute.Resolve <ControllerContext>(); _filterProvider = new FilterProvider(); DependencyResolver.SetResolver(new AutofacDependencyResolver(autoSubstitute.Container)); _httpSimulator = new HttpSimulator().SimulateRequest(); }
public void CanGetSetCookies() { using (var simulator = new HttpSimulator()) { simulator.SimulateRequest(new Uri("http://localhost/Test.aspx"), HttpVerb.POST); simulator.Context.Response.Cookies.Add(new HttpCookie("a", "b")); Assert.AreEqual("b", HttpContext.Current.Response.Cookies["a"].Value); } }
public void GetField_HTML_Title_Field_Test() { using (HttpSimulator httpSimulator = GetStandardSimulatedRequest()) { string HTML_Title = "Cancer Topics Home Page--About This Booklet"; IPageAssemblyInstruction actual = PageAssemblyInstructionFactory.GetPageAssemblyInfo("/multicancertopics"); Assert.AreEqual(HTML_Title, actual.GetField("HTML_Title")); } }
public void CanSimulateUserAgent() { using (var simulator = new HttpSimulator()) { var headers = new NameValueCollection(); headers.Add("User-Agent", "Agent1"); simulator.SimulateRequest(new Uri("http://localhost/Test.aspx"), HttpVerb.POST, headers); Assert.AreEqual("Agent1", simulator.Context.Request.UserAgent); } }
public void InitializeContext() { using (HttpSimulator simulator = new HttpSimulator()) { simulator.SimulateRequest(new Uri("http://localhost/")); HttpContext.Current.Application.Add(GlobalConstants.UrlSaltKeyName, HttpContextSalt); this.httpContext = HttpContext.Current; } }
public void GetField_HTML_MetaDescription_Test() { using (HttpSimulator httpSimulator = GetStandardSimulatedRequest()) { string MetaDescription = "sdfds --About This Booklet"; IPageAssemblyInstruction actual = PageAssemblyInstructionFactory.GetPageAssemblyInfo("/multicancertopics"); Assert.AreEqual(MetaDescription, actual.GetField("HTML_MetaDescription")); } }
public void GetField_HTML_MetaKeywords_Test() { using (HttpSimulator httpSimulator = GetStandardSimulatedRequest()) { string MetaKeywords = "cancer,information,About This Booklet"; IPageAssemblyInstruction actual = PageAssemblyInstructionFactory.GetPageAssemblyInfo("/multicancertopics"); Assert.AreEqual(MetaKeywords, actual.GetField("HTML_MetaKeywords")); } }
public void CanSimulateRemoteRequests() { using (var simulator = new HttpSimulator()) { simulator.SetIsLocalRequest(false) .SimulateRequest(new Uri("http://something.com/Test.aspx"), HttpVerb.GET); Assert.IsFalse(HttpContext.Current.Request.IsLocal); } }
public void UsePlainHtmlEditor_IsFalse_ByDefault() { using (var httpRequest = new HttpSimulator("http://localhost").SimulateRequest()) { //arrange / act var option = Preferences.UsePlainHtmlEditor; //post Assert.IsFalse(option); } }
public void ProvideEditor_Default_Is_FtbEditor() { using (var httpRequest = new HttpSimulator("http://localhost").SimulateRequest()) { //arrange BlogEntryEditorProvider provider; //act ProviderConfigurationHelper.LoadProviderCollection<BlogEntryEditorProvider>("BlogEntryEditor", out provider); //post (in test app.config the FtbBlogEntryEditorProvider is selected by default) Assert.IsTrue(provider is FtbBlogEntryEditorProvider, "FtbBlogEntryEditorProvider is created by default."); } }
public void UsePlainHtmlEditor_SetValue() { using (var http = new HttpSimulator("http://localhost").SimulateRequest()) { //arrange Preferences.UsePlainHtmlEditor = true; //act var option = Preferences.UsePlainHtmlEditor; //post Assert.IsTrue(option); } }
////[Test] public void TestHttpHandlerWritesCorrectResponse() { using (var simulator = new HttpSimulator("/", @"c:\inetpub\")) { simulator.SetFormVariable("username", "phil") .SetReferer(new Uri("http://example.com/1/")) .SimulateRequest(new Uri("http://localhost/MyHandler.ashx?id=1234")); var handler = new TestHttpHandler(); handler.ProcessRequest(HttpContext.Current); HttpContext.Current.Response.Flush(); const string expected = @"c:\inetpub\MyHandler.ashx:phil:1234:http://example.com/1/"; Assert.AreEqual(expected, simulator.ResponseText, "The Expected Response is all wrong."); } //HttpContext.Current is set to null again. }
public void RichTextEditor_CreateDefaultProvider() { using (var httpRequest = new HttpSimulator().SimulateRequest()) { //arrange var context = new Mock<ISubtextContext>(); var httpContext = new Mock<HttpContextBase>(); httpContext.Setup(c => c.Request.ApplicationPath).Returns("path"); context.Setup(c => c.UrlHelper).Returns( new BlogUrlHelper(new RequestContext(httpContext.Object, new RouteData()), null)); context.Setup(c => c.Blog).Returns(new Blog { Host = "host" }); var page = new SubtextPage { SubtextContext = context.Object }; var editor = new RichTextEditor { Page = page }; //act editor.InitControls(new EventArgs()); //post var provider = editor.Provider; Assert.IsTrue(provider is FtbBlogEntryEditorProvider, "FtbBlogEntryEditorProvider is created by default."); } }
public void RichTextEditor_CreatePlainText_IfPreferenceSet() { using (var httpRequest = new HttpSimulator().SimulateRequest()) { //arrange var context = new Mock<ISubtextContext>(); var httpContext = new Mock<HttpContextBase>(); httpContext.Setup(c => c.Request.ApplicationPath).Returns("path"); context.Setup(c => c.UrlHelper).Returns( new BlogUrlHelper(new RequestContext(httpContext.Object, new RouteData()), null)); context.Setup(c => c.Blog).Returns(new Blog { Host = "host" }); var page = new SubtextPage { SubtextContext = context.Object }; var editor = new RichTextEditor { Page = page }; //set use plain text in user preferences Preferences.UsePlainHtmlEditor = true; //act editor.InitControls(new EventArgs()); //post var provider = editor.Provider; Assert.IsTrue(provider is PlainTextBlogEntryEditorProvider, "PlainTextBlogEntryEditorProvider is created if it is selected in user preferences."); } }
/*//[RowTest] ////[Row("http://*****:*****@"c:\InetPub\wwwRoot\")] ////[Row("http://*****:*****@"c:\InetPub\wwwRoot\")] ////[Row("http://*****:*****@"c:\InetPub\wwwRoot\", "localhost", 60653, "/", "/Test.aspx", @"c:\InetPub\wwwRoot\")] ////[Row("http://*****:*****@"c:\InetPub\wwwRoot\", "localhost", 60653, "/", "/Test/Test.aspx", @"c:\InetPub\wwwRoot\")] ////[Row("http://*****:*****@"c:\InetPub\wwwRoot\AppPath\", "localhost", 60653, "/AppPath", "/AppPath/Test.aspx", @"c:\InetPub\wwwRoot\AppPath\")] ////[Row("http://*****:*****@"c:\InetPub\wwwRoot\AppPath\", "localhost", 60653, "/AppPath", "/AppPath/Test.aspx", @"c:\InetPub\wwwRoot\AppPath\")]*/ public void CanParseRequestUrl(string url, string appPath, string physicalPath, string expectedHost, int expectedPort, string expectedAppPath, string expectedPage, string expectedAppDomainAppPath) { var simulator = new HttpSimulator(appPath, physicalPath); Assert.AreEqual(expectedAppPath, simulator.ApplicationPath); Assert.AreEqual(expectedAppDomainAppPath, simulator.PhysicalApplicationPath); }
/*//[RowTest] ////[Row("http://localhost/Test/Default.aspx", "/Test", "/Test")] ////[Row("http://localhost/Test/Default.aspx", "/Test/", "/Test")] ////[Row("http://localhost/Test/Default.aspx", "//Test//", "/Test")] ////[Row("http://localhost/Test/Subtest/Default.aspx", "/Test", "/Test")] ////[Row("http://localhost/Test/Subtest/Default.aspx", "/Test/", "/Test")] ////[Row("http://localhost/Test/Subtest/Default.aspx", "//Test//", "/Test")] ////[Row("http://localhost/Test/Default.aspx", "", "/")] ////[Row("http://localhost/Test/Default.aspx", "/", "/")] ////[Row("http://localhost/Test/Default.aspx", null, "/")]*/ public void CanSetApplicationPathCorrectly(string url, string appPath, string expectedAppPath) { var simulator = new HttpSimulator(appPath, @"c:\inetpub\wwwroot\site1\test"); Assert.AreEqual(expectedAppPath, simulator.ApplicationPath); simulator.SimulateRequest(new Uri(url)); Assert.AreEqual(expectedAppPath, HttpContext.Current.Request.ApplicationPath); Assert.AreEqual(expectedAppPath, HttpRuntime.AppDomainAppVirtualPath); Assert.AreEqual(expectedAppPath, HostingEnvironment.ApplicationVirtualPath); }
/*//[RowTest] ////[Row("http://localhost/Test/default.aspx", "/Test", @"c:\projects\test", @"c:\projects\test\", @"c:\projects\test\default.aspx")] ////[Row("http://localhost/Test/Subtest/default.aspx", "/Test", @"c:\projects\test", @"c:\projects\test\", @"c:\projects\test\Subtest\default.aspx")] ////[Row("http://localhost/test/default.aspx", "/", @"c:\inetpub\wwwroot\", @"c:\inetpub\wwwroot\", @"c:\inetpub\wwwroot\test\default.aspx")] ////[Row("http://localhost/test/default.aspx", "/", @"c:\inetpub\wwwroot", @"c:\inetpub\wwwroot\", @"c:\inetpub\wwwroot\test\default.aspx")]*/ public void CanSetAppPhysicalPathCorrectly(string url, string appPath, string appPhysicalPath, string expectedPhysicalAppPath, string expectedPhysicalPath) { var simulator = new HttpSimulator(appPath, appPhysicalPath); Assert.AreEqual(expectedPhysicalAppPath, simulator.PhysicalApplicationPath); simulator.SimulateRequest(new Uri(url), HttpVerb.GET); Assert.AreEqual(expectedPhysicalPath, simulator.PhysicalPath); Assert.AreEqual(expectedPhysicalAppPath, HttpRuntime.AppDomainAppPath); Assert.AreEqual(expectedPhysicalAppPath, HostingEnvironment.ApplicationPhysicalPath); Assert.AreEqual(expectedPhysicalPath, HttpContext.Current.Request.PhysicalPath); }
////[Test] public void CanGetQueryString() { var simulator = new HttpSimulator(); simulator.SimulateRequest(new Uri("http://localhost/Test.aspx?param1=value1¶m2=value2¶m3=value3")); for (var i = 1; i <= 3; i++) Assert.AreEqual("value" + i, HttpContext.Current.Request.QueryString["param" + i], "Could not find query string field 'param{0}'", i); simulator.SimulateRequest(new Uri("http://localhost/Test.aspx?param1=new-value1¶m2=new-value2¶m3=new-value3¶m4=new-value4")); for (var i = 1; i <= 4; i++) Assert.AreEqual("new-value" + i, HttpContext.Current.Request.QueryString["param" + i], "Could not find query string field 'param{0}'", i); simulator.SimulateRequest(new Uri("http://localhost/Test.aspx?")); Assert.AreEqual(string.Empty, HttpContext.Current.Request.QueryString.ToString()); Assert.AreEqual(0, HttpContext.Current.Request.QueryString.Count); simulator.SimulateRequest(new Uri("http://localhost/Test.aspx")); Assert.AreEqual(string.Empty, HttpContext.Current.Request.QueryString.ToString()); Assert.AreEqual(0, HttpContext.Current.Request.QueryString.Count); simulator.SimulateRequest(new Uri("http://localhost/Test.aspx?param-name")); Assert.AreEqual("param-name", HttpContext.Current.Request.QueryString.ToString()); Assert.AreEqual(1, HttpContext.Current.Request.QueryString.Count); Assert.IsNull(HttpContext.Current.Request.QueryString["param-name"]); }
////[Test] public void CanDispose() { using (var simulator = new HttpSimulator()) { simulator.SimulateRequest(); Assert.IsNotNull(HttpContext.Current); } Assert.IsNull(HttpContext.Current); }
//[RowTest] ////[Row("/", "/", @"c:\inetpub\wwwroot\")] ////[Row("/Test/Test.aspx", "/", @"c:\inetpub\wwwroot\Test\Test.aspx")] ////[Row("/Test/Blah/Test.aspx", "/", @"c:\inetpub\wwwroot\Test\Blah\Test.aspx")] ////[Row("/Test", "/Test", @"c:\inetpub\wwwroot")] ////[Row("/Test/", "/Test", @"c:\inetpub\wwwroot\")] public void CanMapPath(string virtualPath, string appPath, string expectedMapPath) { var url = new Uri("http://localhost/Test/Test.aspx"); var simulator = new HttpSimulator(appPath, @"c:\inetpub\wwwroot\"); simulator.SimulateRequest(url); //Create a virtual path object. var vpath = ReflectionHelper.Instantiate("System.Web.VirtualPath, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", new[] { typeof(string) }, virtualPath); Assert.IsNotNull(vpath); var environment = HttpSimulatorTester.CallGetEnvironment(); var vpathString = ReflectionHelper.InvokeProperty<string>(vpath, "VirtualPathString"); var appVirtPath = ReflectionHelper.GetPrivateInstanceFieldValue<object>("_appVirtualPath", environment); Assert.IsNotNull(appVirtPath); Console.WriteLine("VPATH: " + vpath); Console.WriteLine("App-VPATH: " + appVirtPath); Console.WriteLine("vpath.VirtualPathString == '{0}'", vpathString); var mapping = ReflectionHelper.InvokeNonPublicMethod<string>(typeof(HostingEnvironment), "GetVirtualPathToFileMapping", vpath); Console.WriteLine("GetVirtualPathToFileMapping: --->{0}<---", (mapping ?? "{NULL}")); var o = ReflectionHelper.GetPrivateInstanceFieldValue<object>("_configMapPath", environment); Console.WriteLine("_configMapPath: {0}", o ?? "{null}"); var mappedPath = ReflectionHelper.InvokeNonPublicMethod<string>(environment, "MapPathActual", vpath, false); Console.WriteLine("MAPPED: " + mappedPath); Assert.AreEqual(expectedMapPath, HttpContext.Current.Request.MapPath(virtualPath)); }
//[RowTest] //////[Row("http://*****:*****@"c:\InetPub\wwwRoot\")] //////[Row("http://*****:*****@"c:\InetPub\wwwRoot\", "localhost", 60653, "/", "/Test.aspx", @"c:\InetPub\wwwRoot\")] //////[Row("http://*****:*****@"c:\InetPub\wwwRoot\", "localhost", 60653, "/", "/Test/Test.aspx", @"c:\InetPub\wwwRoot\")] //////[Row("http://*****:*****@"c:\InetPub\wwwRoot\AppPath\", "localhost", 60653, "/AppPath", "/AppPath/Test.aspx", @"c:\InetPub\wwwRoot\AppPath\")] //////[Row("http://*****:*****@"c:\InetPub\wwwRoot\AppPath\", "localhost", 60653, "/AppPath", "/AppPath/Test.aspx", @"c:\InetPub\wwwRoot\AppPath\")] public void CanSimulateRequest(string url, string appPath, string physicalPath, string expectedHost, int expectedPort, string expectedAppPath, string expectedLocalPath, string expectedPhysicalPath) { var simulator = new HttpSimulator(appPath, physicalPath); simulator.SimulateRequest(new Uri(url)); Assert.AreEqual(expectedHost, HttpContext.Current.Request.Url.Host); Assert.AreEqual(expectedPort, HttpContext.Current.Request.Url.Port); Assert.AreEqual(expectedAppPath, HttpContext.Current.Request.ApplicationPath); Assert.AreEqual(expectedPhysicalPath, HttpContext.Current.Request.PhysicalApplicationPath); Assert.AreEqual(expectedLocalPath, HttpContext.Current.Request.Url.LocalPath); }
//[RowTest] ////[Row("http://localhost/AppPath/default.aspx", "/AppPath", "/AppPath/default.aspx")] ////[Row("http://localhost/AppPath/default.aspx", "/", "/AppPath/default.aspx")] public void CanGetLocalPathCorrectly(string url, string appPath, string expectedLocalPath) { var simulator = new HttpSimulator(appPath, @"c:\inetpub\wwwroot\AppPath\"); simulator.SimulateRequest(new Uri(url)); Assert.AreEqual(expectedLocalPath, HttpContext.Current.Request.Path); Assert.AreEqual(expectedLocalPath, HttpContext.Current.Request.Url.LocalPath); }
// //[Test] public void CanSimulateFormPost() { using (var simulator = new HttpSimulator()) { var form = new NameValueCollection {{"Test1", "Value1"}, {"Test2", "Value2"}}; simulator.SimulateRequest(new Uri("http://localhost/Test.aspx"), form); Assert.AreEqual("Value1", HttpContext.Current.Request.Form["Test1"]); Assert.AreEqual("Value2", HttpContext.Current.Request.Form["Test2"]); } using (var simulator = new HttpSimulator()) { simulator.SetFormVariable("Test1", "Value1") .SetFormVariable("Test2", "Value2") .SimulateRequest(new Uri("http://localhost/Test.aspx")); Assert.AreEqual("Value1", HttpContext.Current.Request.Form["Test1"]); Assert.AreEqual("Value2", HttpContext.Current.Request.Form["Test2"]); } }
// //[Test] public void CanGetReferer() { var simulator = new HttpSimulator(); simulator.SetReferer(new Uri("http://example.com/Blah.aspx")).SimulateRequest(); Assert.AreEqual(new Uri("http://example.com/Blah.aspx"), HttpContext.Current.Request.UrlReferrer); simulator = new HttpSimulator(); simulator.SimulateRequest().SetReferer(new Uri("http://x.example.com/Blah.aspx")); Assert.AreEqual(new Uri("http://x.example.com/Blah.aspx"), HttpContext.Current.Request.UrlReferrer); }
// //[Test] public void CanGetResponse() { var simulator = new HttpSimulator(); simulator.SimulateRequest(); HttpContext.Current.Response.Write("Hello World!"); HttpContext.Current.Response.Flush(); Assert.AreEqual("Hello World!", simulator.ResponseText); }