2015-10-07 11:50:44 +02:00
|
|
|
|
//
|
|
|
|
|
|
// BlogUnitTest.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;
|
2015-10-13 22:53:39 +02:00
|
|
|
|
using System.Web.Configuration;
|
|
|
|
|
|
using System.Configuration;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Web.Http;
|
2015-10-07 11:50:44 +02:00
|
|
|
|
|
2015-10-13 22:53:39 +02:00
|
|
|
|
namespace Yavsc
|
2015-10-07 11:50:44 +02:00
|
|
|
|
{
|
2015-10-13 22:53:39 +02:00
|
|
|
|
|
2015-10-07 11:50:44 +02:00
|
|
|
|
[TestFixture ()]
|
2015-10-13 22:53:39 +02:00
|
|
|
|
public class AccountUnitTestCase
|
2015-10-07 11:50:44 +02:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public string UserName { get; set; }
|
|
|
|
|
|
public string Email { get; set; }
|
|
|
|
|
|
public string Password { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
AccountController accountController;
|
2015-10-13 22:53:39 +02:00
|
|
|
|
|
|
|
|
|
|
public AccountController AccountController {
|
|
|
|
|
|
get {
|
|
|
|
|
|
return accountController;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
string defaultMembershipProvider = null;
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public virtual void Init()
|
2015-10-07 11:50:44 +02:00
|
|
|
|
{
|
2015-10-13 22:53:39 +02:00
|
|
|
|
webSource = new XSPWebSource (configurationManager.Address, configurationManager.Port, !root);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var server = new ApplicationServer (webSource, configurationManager.Root) {
|
|
|
|
|
|
Verbose = configurationManager.Verbose,
|
|
|
|
|
|
SingleApplication = !root
|
|
|
|
|
|
};
|
|
|
|
|
|
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);
|
2015-10-07 11:50:44 +02:00
|
|
|
|
accountController = new AccountController ();
|
2015-10-13 22:53:39 +02:00
|
|
|
|
string da = (string) configuration.AppSettings.Settings ["DefaultAvatar"].Value;
|
|
|
|
|
|
MembershipSection s = configuration.GetSection ("system.web/membership") as MembershipSection;
|
|
|
|
|
|
defaultMembershipProvider = s.DefaultProvider;
|
2015-10-07 11:50:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test ()]
|
2015-10-13 22:53:39 +02:00
|
|
|
|
public virtual void Register ()
|
2015-10-07 11:50:44 +02:00
|
|
|
|
{
|
|
|
|
|
|
ViewResult actionResult = accountController.Register (
|
|
|
|
|
|
new Yavsc.Model.RolesAndMembers.RegisterViewModel () {
|
|
|
|
|
|
UserName = UserName, Email = Email,
|
|
|
|
|
|
Password = "tpwd", ConfirmPassword = Password,
|
|
|
|
|
|
IsApprouved = true
|
|
|
|
|
|
},
|
|
|
|
|
|
"/testreturnurl") as ViewResult;
|
2015-10-13 22:53:39 +02:00
|
|
|
|
Assert.AreSame ("",actionResult.ViewName);
|
2015-10-07 11:50:44 +02:00
|
|
|
|
MembershipUser u = Membership.GetUser (UserName, false);
|
|
|
|
|
|
Assert.NotNull (u);
|
|
|
|
|
|
Assert.False (u.IsApproved);
|
|
|
|
|
|
// TODO : check mail for test,
|
|
|
|
|
|
// get the validation key from its body,
|
|
|
|
|
|
// and use the accountController.Validate(username,key)
|
|
|
|
|
|
u.IsApproved = true;
|
|
|
|
|
|
Membership.UpdateUser (u);
|
|
|
|
|
|
Assert.True (u.IsApproved);
|
|
|
|
|
|
}
|
2015-10-13 22:53:39 +02:00
|
|
|
|
|
2015-10-07 11:50:44 +02:00
|
|
|
|
[TestFixtureTearDown()]
|
2015-10-13 22:53:39 +02:00
|
|
|
|
public virtual void Unregister()
|
2015-10-07 11:50:44 +02:00
|
|
|
|
{
|
|
|
|
|
|
ViewResult actionResult =
|
|
|
|
|
|
accountController.Unregister (UserName, true) as ViewResult;
|
|
|
|
|
|
Assert.AreEqual (actionResult.ViewName, "Index");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|