|
/****************************************************************************************************
Copyright (C) 2010 RapidWebDev Organization (http://rapidwebdev.org)
Author: Tim, Legal Name: Long Yi, Email: tim.yi@RapidWebDev.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BaoJianSoft.Common;
using BaoJianSoft.Common.Data;
using BaoJianSoft.Platform;
using BaoJianSoft.Platform.Initialization;
using BaoJianSoft.Platform.Linq;
using NBehave.Narrator.Framework;
using NBehave.Spec.NUnit;
using NUnit.Framework;
namespace BaoJianSoft.Tests.BehaveTest.Stories
{
[TestFixture, Theme]
public class MemberLoginStory : SetupFixture
{
private Story _story;
private UserObject _Uobject;
//private UserObject _Uobject2;
private IMembershipApi _membershipApi;
private string _oldpassword;
private string _newpassword;
//private string _passwordAnswer;
private IList<Guid> createdObjectIds;
private BehaveMemberShipUtils _utils;
private LoginResults _ret;
[SetUp]
public void Setup()
{
Console.WriteLine("=================Setup===================");
createdObjectIds = new List<Guid>();
base.GlobalSetup();
_utils = new BehaveMemberShipUtils();
_membershipApi = SpringContext.Current.GetObject<IMembershipApi>();
Console.WriteLine("============Ending Setup===================");
}
[TearDown]
public void CleanUp()
{
Console.WriteLine("============Clean Up====================");
using (MembershipDataContext ctx = DataContextFactory.Create<MembershipDataContext>())
{
foreach (Guid createdObjectId in createdObjectIds)
{
ctx.Memberships.Delete(m => m.UserId == createdObjectId);
ctx.Users.Delete(u => u.UserId == createdObjectId);
ctx.SubmitChanges();
}
}
createdObjectIds.Clear();
Console.WriteLine("========Ending Clean Up====================");
}
[Story, Test]
public void MemberLoginWithCorrectUserNameAndPwd()
{
_story = new Story("Login with UserName and Password");
_story.AsA("User")
.IWant("to be able to login ")
.SoThat("I can use features");
_story.WithScenario("login with a correct username and password")
.Given("Create a new with old password", () =>
{
_Uobject = _utils.CreateUserObject("Eunge Liu",true);
_oldpassword = "123Hello";
_newpassword = "Hello123456";
_membershipApi.Save(_Uobject, _oldpassword, "123Hello");
createdObjectIds.Add(_Uobject.UserId);
})
.When("I login", () =>
{
_ret = _membershipApi.Login(_Uobject.UserName, _oldpassword);
})
.Then("The User can get Successful Logon",
() =>
{
_ret.ShouldEqual(LoginResults.Successful);
});
this.CleanUp();
}
[Story, Test]
public void MemberLoginWithCorrectUserNameAndWrongPwd()
{
_story = new Story("Login with UserName and Password");
_story.AsA("User")
.IWant("to be able to login ")
.SoThat("I can use features");
_story.WithScenario("login with a correct username and wrong password")
.Given("Create a new with password", () =>
{
_Uobject = _utils.CreateUserObject("Eunge Liu",true);
_oldpassword = "123Hello";
_newpassword = "Hello123456";
_membershipApi.Save(_Uobject, _oldpassword, "123Hello");
createdObjectIds.Add(_Uobject.UserId);
})
.When("I login", () =>
{
_ret = _membershipApi.Login(_Uobject.UserName, _newpassword);
})
.Then("The User can get InvalidCredential Logon",
() =>
{
_ret.ShouldEqual(LoginResults.InvalidCredential);
});
this.CleanUp();
}
[Story, Test]
public void MemberLoginWithWrongUserNameAndPwd()
{
}
[Story, Test]
public void MemberLoginWithCorrectUserNameAndPwdAndUserFalseApproved()
{
_story = new Story("Login with UserName and Password");
_story.AsA("User")
.IWant("to be able to login ")
.SoThat("I can use features");
_story.WithScenario("login with a correct username and wrong password")
.Given("Create a new with password", () =>
{
_Uobject = _utils.CreateUserObject("Eunge Liu", false);
_oldpassword = "123Hello";
_newpassword = "Hello123456";
_membershipApi.Save(_Uobject, _oldpassword, "123Hello");
createdObjectIds.Add(_Uobject.UserId);
})
.When("I login", () =>
{
_ret = _membershipApi.Login(_Uobject.UserName, _newpassword);
})
.Then("The User can get InvalidCredential Logon",
() =>
{
_ret.ShouldEqual(LoginResults.InvalidCredential);
});
this.CleanUp();
}
[Story, Test]
public void MemberLoginWithCorrectUserNameAndPwdAndDisableOrganzation()
{ }
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I've worked as a software architect and developer based on Microsoft .NET framework and web technology since 2002, having rich experience on SaaS, multiple-tier web system and website development. I've devoted into open source project development since 2003, and have created 3 main projects including DataQuicker (ORM), ExcelQuicker (Excel Report Generator), and RapidWebDev (Enterprise-level CMS)
I worked in BenQ (8 mo), Bleum (4 mo), Newegg (1 mo), Microsoft (3 yr) and Autodesk (5 yr) before 2012. Now I own a startup company in Shanghai China to deliver the exceptional results to global internet users by leveraging the power of Internet and the local excellence.