big refactoring, and more

New routes, new juice flow, the tags on posts
This commit is contained in:
Paul Schneider
2015-10-17 14:45:57 +02:00
parent d04a68db01
commit 1805cb3e17
46 changed files with 1458 additions and 634 deletions

52
TestAPI/AllTests.cs Normal file
View File

@ -0,0 +1,52 @@
//
// AllTests.cs
//
// Author:
// Paul Schneider <paul@pschneider.fr>
//
// Copyright (c) 2015 GNU GPL
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using NUnit.Framework;
using System;
using Yavsc.Model.Blogs;
using Yavsc.Controllers;
using System.Web.Mvc;
using System.Web.Security;
using System.Web.Configuration;
using System.Configuration;
using System.IO;
using System.Web.Http;
using Mono.WebServer;
using System.Net;
using System.Collections;
namespace Yavsc
{
public class AllTests
{
[Suite]
public static IEnumerable Suite
{
get
{
ArrayList suite = new ArrayList ();
suite.Add(new BlogUnitTestCase());
return suite;
}
}
}
}

View File

@ -25,7 +25,7 @@ using Yavsc.Model.Blogs;
namespace Yavsc
{
[TestFixture ()]
public class BlogUnitTestCase: AccountUnitTestCase
public class BlogUnitTestCase: ServerTestCase
{
[TestFixtureSetUp]

11
TestAPI/ChangeLog Normal file
View File

@ -0,0 +1,11 @@
2015-10-17 Paul Schneider <paul@pschneider.fr>
* AllTests.cs:
* HelloWorld.cs:
* DebugServer.cs:
* TestAPI.csproj:
* TestAutomate.cs:
* ServerTestCase.cs:
* BlogUnitTestCase.cs:
* test-domain-TestAPI.config:

51
TestAPI/DebugServer.cs Normal file
View File

@ -0,0 +1,51 @@
//
// DebugServer.cs
//
// Author:
// Paul Schneider <paul@pschneider.fr>
//
// Copyright (c) 2015 GNU GPL
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using NUnit.Framework;
using System.Net;
using Mono.WebServer.XSP;
namespace Mono.WebServer.Test
{
public class DebugServer : IDisposable
{
#region IDisposable implementation
public void Dispose ()
{
// would have a sense when managing the Xsp server instance:
// server.Stop();
}
#endregion
string physicalPath = @"/home/paul/workspace/totem/web/";
public int Run ()
{
return Server.Main (new [] { "--applications", "/:"+physicalPath, "--port", "8080", "--nonstop" });
}
}
}

73
TestAPI/HelloWorld.cs Normal file
View File

@ -0,0 +1,73 @@
//
// HelloWorld.cs
//
//
// HelloWorld.cs
//
// Author:
// Leonardo Taglialegne <leonardo.taglialegne@gmail.com>
//
// Copyright (c) 2013 Leonardo Taglialegne.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using NUnit.Framework;
using System.Net;
using Mono.WebServer.XSP;
namespace Mono.WebServer.Test
{
[TestFixture]
public class HelloWorld
{
[Test]
public void TestCase ()
{
using (var server = new DebugServer()) {
Assert.AreEqual (0, server.Run ());
var wc = new WebClient ();
try {
string downloaded = wc.DownloadString ("http://localhost:8080/");
//Assert.AreEqual (Environment.CurrentDirectory, downloaded);
// ResponseHeaders {
// Date: Thu, 15 Oct 2015 16:12:00 GMT
// Server: Mono.WebServer.XSP/3.8.0.0 Linux
// X-AspNetMvc-Version: 3.0
// X-AspNet-Version: 4.0.30319
// Content-Length: 2180
// Cache-Control: private
// Content-Type: text/html
// Set-Cookie: ASP.NET_SessionId=ED208D636A4312B9745E396D; path=/
// Keep-Alive: timeout=15, max=100
// Connection: Keep-Alive } System.Net.WebHeaderCollection
Assert.Greater(wc.ResponseHeaders["Set-Cookie"].Length, 10);
} catch (WebException e) {
Assert.Fail (e.Message);
}
}
}
}
}

View File

@ -28,12 +28,17 @@ using System.Web.Configuration;
using System.Configuration;
using System.IO;
using System.Web.Http;
using Mono.WebServer;
using System.Net;
using System.Web.Hosting;
using Mono.Web.Util;
using Mono.WebServer.Options;
namespace Yavsc
{
[TestFixture ()]
public class AccountUnitTestCase
public class ServerTestCase
{
public string UserName { get; set; }
@ -47,33 +52,70 @@ namespace Yavsc
return accountController;
}
}
string defaultMembershipProvider = null;
[Test]
public virtual void Init()
{
webSource = new XSPWebSource (configurationManager.Address, configurationManager.Port, !root);
var server = new ApplicationServer (webSource, configurationManager.Root) {
Verbose = configurationManager.Verbose,
SingleApplication = !root
};
ApplicationServer WebAppServer;
string defaultMembershipProvider = null;
[Test]
public virtual void Start()
{
// get the web config
string physicalPath = @"/home/paul/workspace/totem/web/";
string physicalPathToConfig = physicalPath + "/Web.config";
ExeConfigurationFileMap exemap = new ExeConfigurationFileMap ();
exemap.ExeConfigFilename = physicalPathToConfig ;
Configuration config = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration (exemap, ConfigurationUserLevel.None);
string basedir = AppDomain.CurrentDomain.BaseDirectory;
string curdir = Directory.GetCurrentDirectory ();
string dummyVirtualPath = "/";
string physicalPath = @"/home/paul/workspace/totem/web/";
WebConfigurationFileMap map = new WebConfigurationFileMap ();
map.VirtualDirectories.Add(dummyVirtualPath, new VirtualDirectoryMapping(physicalPath, true));
Configuration configuration = WebConfigurationManager.OpenMappedWebConfiguration(map, dummyVirtualPath);
accountController = new AccountController ();
string da = (string) configuration.AppSettings.Settings ["DefaultAvatar"].Value;
MembershipSection s = configuration.GetSection ("system.web/membership") as MembershipSection;
defaultMembershipProvider = s.DefaultProvider;
int Port=8080;
XSPWebSource websource=new XSPWebSource(IPAddress.Any,Port);
WebAppServer=new ApplicationServer(websource,physicalPath);
var broker = new XSPRequestBroker ();
var host = new XSPApplicationHost ();
host.RequestBroker = broker;
host.Server = WebAppServer;
broker.InitializeLifetimeService ();
host.InitializeLifetimeService ();
// ApplicationHost h = new XSPApplicationHost();
//"[[hostname:]port:]VPath:realpath"
string cmdLine=Port+":/:"+physicalPath;
WebAppServer.AddApplicationsFromCommandLine (cmdLine);
WebAppServer.Broker = broker;
WebAppServer.AppHost = host;
// WebAppServer.AddApplicationsFromConfigFile (physicalPath+"/Web.config");
// WebConfigurationFileMap map = new WebConfigurationFileMap ();
// map.VirtualDirectories.Add (dummyVirtualPath, new VirtualDirectoryMapping (physicalPath, true));
// TODO why not? Configuration configuration = WebConfigurationManager.OpenMappedWebConfiguration (map, dummyVirtualPath);
// string da = (string)config.AppSettings.Settings ["DefaultAvatar"].Value;
// MembershipSection s = config.GetSection ("system.web/membership") as MembershipSection;
// defaultMembershipProvider = s.DefaultProvider;
// ??? WebConfigurationManager.ConfigPath
Configuration cfg = WebConfigurationManager.OpenWebConfiguration (dummyVirtualPath);
// WebConfigurationManager.AppSettings.Clear ();
// WebConfigurationManager.ConnectionStrings.Clear ();
// var mbrssect = WebConfigurationManager.GetWebApplicationSection ("system.web/membership") as MembershipSection;
//
// mbrssect.Providers.Clear ();
var syswebcfg = WebConfigurationManager.GetWebApplicationSection ("system.web") as ConfigurationSection;
WebAppServer.Start (true,2000);
// System.Threading.Thread.Sleep(30000);
}
[Test ()]
public virtual void Register ()
{
accountController = new AccountController ();
ViewResult actionResult = accountController.Register (
new Yavsc.Model.RolesAndMembers.RegisterViewModel () {
UserName = UserName, Email = Email,
@ -93,7 +135,11 @@ namespace Yavsc
Assert.True (u.IsApproved);
}
[TestFixtureTearDown()]
[Test()]
public virtual void Stop() {
WebAppServer.Stop();
}
public virtual void Unregister()
{
ViewResult actionResult =

View File

@ -58,11 +58,37 @@
<Reference Include="System.Web.Mvc" />
<Reference Include="System.Web.ApplicationServices" />
<Reference Include="System.Web" />
<Reference Include="System.Configuration" />
<Reference Include="System.Web.Routing" />
<Reference Include="System.Web.Http" />
<Reference Include="System.Web.Abstractions" />
<Reference Include="System.Security" />
<Reference Include="System.Net" />
<Reference Include="Mono.WebServer2">
<HintPath>..\..\..\..\..\usr\lib\mono\4.5\Mono.WebServer2.dll</HintPath>
</Reference>
<Reference Include="xsp4">
<HintPath>..\..\..\..\..\usr\lib\mono\4.5\xsp4.exe</HintPath>
</Reference>
<Reference Include="nunit.util, Version=2.6.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
<Package>nunit</Package>
</Reference>
<Reference Include="nunit.mocks, Version=2.6.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
<Package>nunit</Package>
</Reference>
<Reference Include="nunit-console-runner, Version=2.6.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
<Package>nunit</Package>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestAutomate.cs" />
<Compile Include="BlogUnitTest.cs" />
<Compile Include="BlogUnitTestCase.cs" />
<Compile Include="TestByteA.cs" />
<Compile Include="AllTests.cs" />
<Compile Include="HelloWorld.cs" />
<Compile Include="ServerTestCase.cs" />
<Compile Include="DebugServer.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
@ -74,8 +100,28 @@
<Project>{77044C92-D2F1-45BD-80DD-AA25B311B027}</Project>
<Name>Web</Name>
</ProjectReference>
<ProjectReference Include="..\NpgsqlBlogProvider\NpgsqlBlogProvider.csproj">
<Project>{C6E9E91B-97D3-48D9-8AA7-05356929E162}</Project>
<Name>NpgsqlBlogProvider</Name>
</ProjectReference>
<ProjectReference Include="..\NpgsqlContentProvider\NpgsqlContentProvider.csproj">
<Project>{821FF72D-9F4B-4A2C-B95C-7B965291F119}</Project>
<Name>NpgsqlContentProvider</Name>
</ProjectReference>
<ProjectReference Include="..\NpgsqlMRPProviders\NpgsqlMRPProviders.csproj">
<Project>{BBA7175D-7F92-4278-96FC-84C495A2B5A6}</Project>
<Name>NpgsqlMRPProviders</Name>
</ProjectReference>
<ProjectReference Include="..\SalesCatalog\SalesCatalog.csproj">
<Project>{90BF2234-7252-4CD5-B2A4-17501B19279B}</Project>
<Name>SalesCatalog</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="test-domain-TestAPI.config">
<Gettext-ScanForTranslations>False</Gettext-ScanForTranslations>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
</Project>

View File

@ -55,7 +55,9 @@ namespace TestAPI
[Test]
public void DoTheTest()
{
// Establish
context.Invoke ();
// Because
of.Invoke ();
should_be_in_state_0.Invoke ();
should_not_be_in_state_1.Invoke ();