== CoDBIS == '''Имплементација на апликацијата CoDBIS во ASP.Net''' Во продолжение се дадени изворните кодови на страниците за регистрација, логирање, внесување лични информации, внесување активности и преглед на биографијата. '''За регистрација на корисници''' {{{ #!c# Register.aspx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using Microsoft.AspNet.Membership.OpenAuth; namespace CoDBIS.Account { public partial class Register : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { RegisterUser.ContinueDestinationPageUrl = Request.QueryString["ReturnUrl"]; } protected void RegisterUser_CreatedUser(object sender, EventArgs e) { FormsAuthentication.SetAuthCookie(RegisterUser.UserName, createPersistentCookie: false); string continueUrl = RegisterUser.ContinueDestinationPageUrl; if (!OpenAuth.IsLocalUrl(continueUrl)) { continueUrl = "AddInfo.aspx"; } Response.Redirect(continueUrl); } } } Register.aspx <%@ Page Title="Register" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="CoDBIS.Account.Register" %>

Регистрирај се.

Искористете ја формата подолу за да креирате нова корисничка сметка.

Лозинката мора да има повеќе од <%: Membership.MinRequiredPasswordLength %> карактери.

Registration Form
  1. Корисничко име
  2. Електронска адреса
  3. Лозинка
  4. Потврди ја лозинката
}}} '''За логирање на корисници''' {{{ #!c# Login.aspx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Microsoft.AspNet.Membership.OpenAuth; using System.Web.Security; namespace CoDBIS.Account { public partial class Login : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { RegisterHyperLink.NavigateUrl = "Register.aspx"; var returnUrl = HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]); if (!String.IsNullOrEmpty(returnUrl)) { RegisterHyperLink.NavigateUrl += "?ReturnUrl=" + returnUrl; } } } } Login.aspx <%@ Page Title="Login" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="CoDBIS.Account.Login" %> <%@ Register Src="~/Account/OpenAuthProviders.ascx" TagPrefix="uc" TagName="OpenAuthProviders" %>

Најавете се.

Искористете ги вашето корисничко име и лозинката за да се најавите на апликацијата.

Log in Form
  1. Корисничко име
  2. Лозинка
  3. Запомни ме?

Ако немате корисничка сметка Регистрирајте се .

}}} '''Додавање лични податоци за корисникот''' {{{ #!c# Addinfo.aspx.cs using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace CoDBIS.Account { public partial class AddInfo : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string korisnik = User.Identity.Name; lblUserName.Text = korisnik; } protected void btnAdd_Click(object sender, EventArgs e) { string connString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; SqlConnection conn = new SqlConnection(connString); conn.Open(); string updateCommand = "UPDATE [Users] SET [PlaceOfBirth]=@PlaceOfBirth, [Gender]=@Gender, [DateOfBirth]=@DateOfBirth, [Position]=@Position, [FirstNameLastName]=@FirstNameLastName, [Employer]=@Employer, [EducationLevel]=@EducationLevel, [EducationInstitution]=@EducationInstitution WHERE ([UserName]=@UserName)"; SqlCommand cmd = new SqlCommand(updateCommand, conn); cmd.Parameters.AddWithValue("@PlaceOfBirth", txtMesto.Text); cmd.Parameters.AddWithValue("@Gender", rblPol.SelectedValue.ToString()); cmd.Parameters.AddWithValue("@DateOfBirth", Convert.ToDateTime( txtDatum.Text)); cmd.Parameters.AddWithValue("@Position", txtPozicija.Text); cmd.Parameters.AddWithValue("@FirstNameLastName", txtImePrezime.Text); cmd.Parameters.AddWithValue("@Employer", txtVrabotenVo.Text); cmd.Parameters.AddWithValue("@EducationLevel", txtObrazovanie.Text); cmd.Parameters.AddWithValue("@EducationInstitution", txtInstitucija.Text); cmd.Parameters.AddWithValue("@UserName", lblUserName.Text); cmd.ExecuteNonQuery(); conn.Close(); lblMessage.Text = "Вашите податоци се успешно зачувани."; txtImePrezime.Text = ""; txtMesto.Text = ""; txtDatum.Text = ""; txtObrazovanie.Text = ""; txtInstitucija.Text = ""; txtVrabotenVo.Text = ""; txtPozicija.Text = ""; } protected void BirthCalendar_SelectionChanged(object sender, EventArgs e) { txtDatum.Text = BirthCalendar.SelectedDate.ToString("dd/MM/yyyy"); } } } Addinfo.aspx <%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="AddInfo.aspx.cs" Inherits="CoDBIS.Account.AddInfo" %>

Дополнете ги следниве податоци за да ги комплетирате/ажурирате Вашите кориснички податоци или кликнете на копчето Продолжи ако сакате подоцна да ги внесете овие податоци:


   
Машки Женски
   
   
     
   
   
   
   
 
 
 


}}} '''Внес на нова активност за логираниот корисник и додавање на корисник кон веќе постоечка активност''' {{{ #!c# Inserting.aspx.cs using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; namespace CoDBIS.Account { public partial class Inserting : System.Web.UI.Page { string identity; protected void Page_Load(object sender, EventArgs e) { string korisnik = User.Identity.Name; lblUsername.Text = korisnik; string userId = Membership.GetUser().ProviderUserKey.ToString(); lblUserID.Text = userId; } protected void btnInsert_Click(object sender, EventArgs e) { string connString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; SqlConnection conn = new SqlConnection(connString); conn.Open(); string insertCommand1 = "insert into [Activities] (Name, Category, Place, Date) values (@Name, @Category, @Place, @Date)"; insertCommand1 += "; SELECT SCOPE_IDENTITY() ; "; SqlCommand cmd1 = new SqlCommand(insertCommand1, conn); cmd1.Parameters.AddWithValue("@Name", txtName.Text); cmd1.Parameters.AddWithValue("@Category", txtCategory.Text); cmd1.Parameters.AddWithValue("@Place", txtPlace.Text); cmd1.Parameters.AddWithValue("@Date", Convert.ToDateTime(txtDate.Text)); identity = cmd1.ExecuteScalar().ToString(); lblActivityID.Text = identity; string insertCommand2 = "insert into [UsersOnActivities] (NameOfRole, UserID, ActivityID) values (@NameOfRole, @UserID, @ActivityID)"; SqlCommand cmd2 = new SqlCommand(insertCommand2, conn); cmd2.Parameters.AddWithValue("@NameOfRole", txtRole.Text); cmd2.Parameters.AddWithValue("@UserID", lblUserID.Text); cmd2.Parameters.AddWithValue("@ActivityID", lblActivityID.Text); cmd2.ExecuteNonQuery(); conn.Close(); lblMessage.Text = "Активноста е успешно внесена во Вашата биографија."; txtName.Text = ""; txtCategory.Text = ""; txtPlace.Text = ""; txtDate.Text = ""; txtRole.Text = ""; } protected void btnShow_Click(object sender, EventArgs e) { gvMe.Visible = true; } protected void btnAddMe_Click(object sender, EventArgs e) { foreach (GridViewRow row in gvMe.Rows) { if (((CheckBox)row.FindControl("CheckBox1")).Checked) { int ActivityID = Convert.ToInt32(gvMe.DataKeys[row.RowIndex].Value); lblExistingActivity.Text = ActivityID.ToString(); string connString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; SqlConnection conn = new SqlConnection(connString); conn.Open(); string insertCommand3 = "insert into [UsersOnActivities] (NameOfRole, UserID, ActivityID) values (@NameOfRole, @UserID, @ActivityID)"; SqlCommand cmd3 = new SqlCommand(insertCommand3, conn); cmd3.Parameters.AddWithValue("@NameOfRole", txtRoleOnExisting.Text); cmd3.Parameters.AddWithValue("@UserID", lblUserID.Text); cmd3.Parameters.AddWithValue("@ActivityID", lblExistingActivity.Text); cmd3.ExecuteNonQuery(); conn.Close(); lblMessage.Text = "Успешно сте додадени на активноста."; } } } } } Inserting.aspx <%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Inserting.aspx.cs" Inherits="CoDBIS.Account.Inserting" %>

Додадете нова активност на која сте учествувале:

 
 
 
 
 
   

Пребарајте веќе постоечки активности и приклучете се:


Внеси име на активноста:



}}} '''Преглед на биографија за корисникот''' {{{ #!c# MyBiography.aspx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Microsoft.AspNet.Membership.OpenAuth; using System.Web.Security; using System.Data.SqlClient; using System.Configuration; using System.Data; namespace CoDBIS.Account { public partial class MyBiography : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string korisnik = User.Identity.Name; lblUsername.Text = korisnik; if (!User.Identity.IsAuthenticated) { Response.Redirect("Login.aspx"); } } } } MyBiography.aspx <%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="MyBiography.aspx.cs" Inherits="CoDBIS.Account.MyBiography" %>

Лични податоци:

ИмеПрезиме:
ДатумНаРаѓање:
МестоНаРаѓање:
Пол:
КонтактЕмеил:
ИмеНаОбразовнаИнституција:
НивоНаОбразование:
ОстанатоОбразование:
ВработенВо:
РаботнаПозиција:
 
ИмеПрезиме:
ДатумНаРаѓање:
МестоНаРаѓање:
Пол:
КонтактЕмеил:
ИмеНаОбразовнаИнституција:
НивоНаОбразование:
ОстанатоОбразование:
ВработенВо:
РаботнаПозиција:
 
ИмеПрезиме:
ДатумНаРаѓање:
МестоНаРаѓање:
Пол:
КонтактЕмеил:
ИмеНаОбразовнаИнституција:
НивоНаОбразование:
ОстанатоОбразование:
ВработенВо:
РаботнаПозиција:

 

Листа на активности:

ИмеНаАктивноста:
ТипКатегоријаНаАктивноста:
МестоНаОдржувањеОбјава:
Датум:
Улога:

ИмеНаАктивноста:
ТипКатегоријаНаАктивноста:
МестоНаОдржувањеОбјава:
Датум:
Улога:


Листата со активности е празна. ИмеНаАктивноста:
ТипКатегоријаНаАктивноста:
МестоНаОдржувањеОбјава:
Датум:
Улога:


ИмеНаАктивноста:
ТипКатегоријаНаАктивноста:
МестоНаОдржувањеОбјава:
Датум:
Улога:

ИмеНаАктивноста:
ТипКатегоријаНаАктивноста:
МестоНаОдржувањеОбјава:
Датум:
Улога:

}}} '''Прототип на апликацијата направена со Naked Objects во ASP.Net''' '''User.cs''' {{{ #!c# using NakedObjects; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CoDBIS_NakedObjects { public class User { public override string ToString() { return Name; } [Hidden] public virtual int Id { get; set; } [StringLength (50)] public virtual string Name { get; set; } public virtual string Gender { get; set; } public virtual string PlaceOfBirth { get; set; } [Mask("d")] public virtual DateTime DateOfBirth { get; set; } public virtual string Email { get; set; } public virtual string Employer { get; set; } public virtual string Position { get; set; } public IDomainObjectContainer Container { set; protected get; } #region AddActivity (collection) private ICollection _AddActivity = new List(); public virtual ICollection AddActivity { get { return _AddActivity; } set { _AddActivity = value; } } public void AddToAddActivity(AddUserOnActivity value) { if (!(_AddActivity.Contains(value))) { _AddActivity.Add(value); } } public void RemoveFromAddActivity(AddUserOnActivity value) { if (_AddActivity.Contains(value)) { _AddActivity.Remove(value); } } public IList Choices0RemoveFromAddActivity() { return _AddActivity.ToList(); } #endregion public AddUserOnActivity CreateNewUserOnActivity() //CreateNewOrder od tip Order { var order = Container.NewTransientInstance(); order.User = this; return order; } public AddUserOnActivity CreateNewAddUserOnActivity() { AddUserOnActivity obj = Container.NewTransientInstance(); obj.User = this; return obj; } } } }}} '''Activity.cs''' {{{ #!c# using NakedObjects; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CoDBIS_NakedObjects { public class Activity { public override string ToString() { return Name; } [Hidden] public virtual int Id { get; set; } [StringLength (50), Title] public virtual string Name { get; set; } public virtual string Place { get; set; } // [Title, Mask("d")] public virtual DateTime Date { get; set; } public virtual string Category { get; set; } } } }}} '''Activityhistory.cs''' {{{ #!c# using NakedObjects; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CoDBIS_NakedObjects { public class ActivityHistory { public override string ToString() { return Role.ToString() + " на " + Activity; } [Hidden] public virtual int Id { get; set; } [Hidden] public virtual AddUserOnActivity AddUserOnActivity { get; set; } public virtual Activity Activity { get; set; } [DefaultValue("")] public virtual string Role { get; set; } } } }}} '''Adduseronactivity.cs''' {{{ #!c# using NakedObjects; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CoDBIS_NakedObjects { public class AddUserOnActivity { public override string ToString() { return User.ToString(); } [Hidden] public virtual int Id { get; set; } [Disabled] public virtual User User { get; set; } #region History (collection) private ICollection _History = new List(); public virtual ICollection History { get { return _History; } set { _History = value; } } public void AddToHistory(ActivityHistory value) { if (!(_History.Contains(value))) { _History.Add(value); } } public void RemoveFromHistory(ActivityHistory value) { if (_History.Contains(value)) { _History.Remove(value); } } public IList Choices0RemoveFromHistory() { return _History.ToList(); } #endregion public IDomainObjectContainer Container { set; protected get; } public ActivityHistory AddToHistory() { var history = Container.NewTransientInstance(); history.AddUserOnActivity = this; return history; } public ActivityHistory CreateNewActivityHistory() { ActivityHistory obj = Container.NewTransientInstance(); obj.AddUserOnActivity = this; return obj; } } } }}} '''Mydbcontext.cs''' {{{ #!c# using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CoDBIS_NakedObjects { public class MyDbContext : DbContext { public MyDbContext(String name) : base(name) { } public MyDbContext() { } public DbSet Users { get; set; } } } }}} '''Userrepository.cs''' {{{ #!c# using NakedObjects; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CoDBIS_NakedObjects { [DisplayName("Users")] public class UserRepository { public IDomainObjectContainer Container { set; protected get; } public IQueryable AllUsers() { return Container.Instances(); } public User CreateNewUser() { User obj = Container.NewTransientInstance(); //set up any parameters //Container.Persist(ref obj); return obj; } #region Find public User Find(string searchString) { var query = from obj in Container.Instances() where obj.Name.ToUpper().Contains(searchString.ToUpper()) select obj; return query.FirstOrDefault(); //(If inheriting from AbsractFactoryAndRepository can use:) return SingleObjectWarnIfNoMatch(query); } #endregion } } }}} '''Activityrepository.cs''' {{{ #!c# using NakedObjects; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CoDBIS_NakedObjects { [DisplayName("Activities")] public class ActivityRepository { public IDomainObjectContainer Container { set; protected get; } public IQueryable AllActivitys() { return Container.Instances(); } public Activity CreateNewActivity() { Activity obj = Container.NewTransientInstance(); //set up any parameters //Container.Persist(ref obj); return obj; } #region Find public Activity Find(string name ) { var query = from obj in Container.Instances() where obj.Name.ToUpper().Contains(name.ToUpper()) select obj; return query.FirstOrDefault(); //(If inheriting from AbsractFactoryAndRepository can use:) return SingleObjectWarnIfNoMatch(query); } #endregion } } }}} '''Runweb.cs''' {{{ #!c# using CoDBIS_NakedObjects; using NakedObjects.Boot; using NakedObjects.Core.Context; using NakedObjects.Core.NakedObjectsSystem; using NakedObjects.EntityObjectStore; using NakedObjects.Services; using NakedObjects.Web.Mvc; using NakedObjects.Web.Mvc.Helpers; using System.Data.Entity; using System.Data.Entity.Infrastructure; namespace CoDBIS_MVC.App_Start { public class RunWeb : RunMvc { protected override NakedObjectsContext Context { get { return HttpContextContext.CreateInstance(); } } protected override IServicesInstaller MenuServices { get { return new ServicesInstaller( new UserRepository(), new ActivityRepository()); } } protected override IServicesInstaller ContributedActions { get { return new ServicesInstaller(); } } protected override IServicesInstaller SystemServices { get { return new ServicesInstaller(new SimpleEncryptDecrypt()); } } // example functions that gets types for AssociateTypes below //private static Type[] AdventureWorksTypes() { // var allTypes = AppDomain.CurrentDomain.GetAssemblies().Single(a => a.GetName().Name == "AdventureWorksModel").GetTypes(); // return allTypes.Where(t => t.BaseType == typeof(AWDomainObject) && !t.IsAbstract).ToArray(); //} // //private static Type[] CodeFirstTypes() { // return new[] {typeof(Class1), typeof(Class2)}; //} protected override IObjectPersistorInstaller Persistor { get { Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0"); //For in-memory database Database.SetInitializer(new DropCreateDatabaseIfModelChanges()); //Optional behaviour for CodeFirst var installer = new EntityPersistorInstaller(); //installer.UsingEdmxContext("Model").AssociateTypes(AdventureWorksTypes); // for Model/Database First installer.AddCodeFirstDbContextConstructor(() => new MyDbContext()); //For Code First return installer; } } public static void Run() { new RunWeb().Start(); } } } }}} '''Тестирање на апликацијата со Selenium IDE''' Тестовите се експортирани како C#/NUnit/Web Driver. '''Register.cs''' {{{ using System; using System.Text; using System.Text.RegularExpressions; using System.Threading; using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using OpenQA.Selenium.Support.UI; namespace SeleniumTests { [TestFixture] public class Register { private IWebDriver driver; private StringBuilder verificationErrors; private string baseURL; private bool acceptNextAlert = true; [SetUp] public void SetupTest() { driver = new FirefoxDriver(); baseURL = "http://localhost:1400/"; verificationErrors = new StringBuilder(); } [TearDown] public void TeardownTest() { try { driver.Quit(); } catch (Exception) { // Ignore errors if unable to close the browser } Assert.AreEqual("", verificationErrors.ToString()); } [Test] public void TheRegisterTest() { driver.Navigate().GoToUrl(baseURL + "/Default.aspx"); driver.FindElement(By.Id("ctl10_registerLink")).Click(); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_UserName")).Clear(); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_UserName")).SendKeys("novstudent3"); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_Email")).Clear(); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_Email")).SendKeys("novstudent1@mail.com"); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_Password")).Clear(); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_Password")).SendKeys("novstudent"); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_ConfirmPassword")).Clear(); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_ConfirmPassword")).SendKeys("novstudent"); driver.FindElement(By.Name("ctl00$MainContent$RegisterUser$CreateUserStepContainer$ctl09")).Click(); driver.FindElement(By.Id("MainContent_txtImePrezime")).Clear(); driver.FindElement(By.Id("MainContent_txtImePrezime")).SendKeys("Student Nov"); driver.FindElement(By.Id("MainContent_txtMesto")).Clear(); driver.FindElement(By.Id("MainContent_txtMesto")).SendKeys("New York"); driver.FindElement(By.Id("MainContent_txtDatum")).Clear(); driver.FindElement(By.Id("MainContent_txtDatum")).SendKeys("01-08-1990"); driver.FindElement(By.Id("MainContent_txtObrazovanie")).Clear(); driver.FindElement(By.Id("MainContent_txtObrazovanie")).SendKeys("BS"); driver.FindElement(By.Id("MainContent_txtInstitucija")).Clear(); driver.FindElement(By.Id("MainContent_txtInstitucija")).SendKeys("Proba"); driver.FindElement(By.Id("MainContent_txtVrabotenVo")).Clear(); driver.FindElement(By.Id("MainContent_txtVrabotenVo")).SendKeys("Proba"); driver.FindElement(By.Id("MainContent_txtPozicija")).Clear(); driver.FindElement(By.Id("MainContent_txtPozicija")).SendKeys("Proba"); driver.FindElement(By.Id("MainContent_btnAdd")).Click(); driver.FindElement(By.Id("MainContent_Button2")).Click(); driver.FindElement(By.Id("MainContent_Button1")).Click(); driver.FindElement(By.Id("MainContent_txtActivity")).Clear(); driver.FindElement(By.Id("MainContent_txtActivity")).SendKeys("rrr"); driver.FindElement(By.Id("MainContent_btnShow")).Click(); driver.FindElement(By.Id("MainContent_txtRoleOnExisting")).Clear(); driver.FindElement(By.Id("MainContent_txtRoleOnExisting")).SendKeys("uuu"); driver.FindElement(By.Id("MainContent_gvMe_CheckBox1_0")).Click(); driver.FindElement(By.Id("MainContent_btnAddMe")).Click(); driver.FindElement(By.LinkText("Мојата Биографија")).Click(); } private bool IsElementPresent(By by) { try { driver.FindElement(by); return true; } catch (NoSuchElementException) { return false; } } private bool IsAlertPresent() { try { driver.SwitchTo().Alert(); return true; } catch (NoAlertPresentException) { return false; } } private string CloseAlertAndGetItsText() { try { IAlert alert = driver.SwitchTo().Alert(); string alertText = alert.Text; if (acceptNextAlert) { alert.Accept(); } else { alert.Dismiss(); } return alertText; } finally { acceptNextAlert = true; } } } } }}} '''LoginFieldValidation.cs''' {{{ using System; using System.Text; using System.Text.RegularExpressions; using System.Threading; using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using OpenQA.Selenium.Support.UI; namespace SeleniumTests { [TestFixture] public class LoginFieldValidation { private IWebDriver driver; private StringBuilder verificationErrors; private string baseURL; private bool acceptNextAlert = true; [SetUp] public void SetupTest() { driver = new FirefoxDriver(); baseURL = "http://localhost:1400/"; verificationErrors = new StringBuilder(); } [TearDown] public void TeardownTest() { try { driver.Quit(); } catch (Exception) { // Ignore errors if unable to close the browser } Assert.AreEqual("", verificationErrors.ToString()); } [Test] public void TheLoginFieldValidationTest() { driver.Navigate().GoToUrl(baseURL + "/"); driver.FindElement(By.Id("ctl10_loginLink")).Click(); driver.FindElement(By.Id("MainContent_ctl00_btnLogin")).Click(); driver.FindElement(By.Id("MainContent_ctl00_UserName")).Clear(); driver.FindElement(By.Id("MainContent_ctl00_UserName")).SendKeys("student123"); driver.FindElement(By.Id("MainContent_ctl00_Password")).Clear(); driver.FindElement(By.Id("MainContent_ctl00_Password")).SendKeys("aaa"); driver.FindElement(By.Id("MainContent_ctl00_btnLogin")).Click(); driver.FindElement(By.Id("MainContent_ctl00_UserName")).Clear(); driver.FindElement(By.Id("MainContent_ctl00_UserName")).SendKeys("student12"); driver.FindElement(By.Id("MainContent_ctl00_Password")).Clear(); driver.FindElement(By.Id("MainContent_ctl00_Password")).SendKeys("student1233"); driver.FindElement(By.Id("MainContent_ctl00_btnLogin")).Click(); driver.FindElement(By.Id("MainContent_ctl00_UserName")).Clear(); driver.FindElement(By.Id("MainContent_ctl00_UserName")).SendKeys("student123"); driver.FindElement(By.Id("MainContent_ctl00_Password")).Clear(); driver.FindElement(By.Id("MainContent_ctl00_Password")).SendKeys("student123"); driver.FindElement(By.Id("MainContent_ctl00_btnLogin")).Click(); } private bool IsElementPresent(By by) { try { driver.FindElement(by); return true; } catch (NoSuchElementException) { return false; } } private bool IsAlertPresent() { try { driver.SwitchTo().Alert(); return true; } catch (NoAlertPresentException) { return false; } } private string CloseAlertAndGetItsText() { try { IAlert alert = driver.SwitchTo().Alert(); string alertText = alert.Text; if (acceptNextAlert) { alert.Accept(); } else { alert.Dismiss(); } return alertText; } finally { acceptNextAlert = true; } } } } }}} '''Registerfieldvalidation.cs''' {{{ using System; using System.Text; using System.Text.RegularExpressions; using System.Threading; using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using OpenQA.Selenium.Support.UI; namespace SeleniumTests { [TestFixture] public class RegisterFieldValidation { private IWebDriver driver; private StringBuilder verificationErrors; private string baseURL; private bool acceptNextAlert = true; [SetUp] public void SetupTest() { driver = new FirefoxDriver(); baseURL = "http://localhost:1400/"; verificationErrors = new StringBuilder(); } [TearDown] public void TeardownTest() { try { driver.Quit(); } catch (Exception) { // Ignore errors if unable to close the browser } Assert.AreEqual("", verificationErrors.ToString()); } [Test] public void TheRegisterFieldValidationTest() { driver.Navigate().GoToUrl(baseURL + "/"); driver.FindElement(By.Id("ctl10_registerLink")).Click(); driver.FindElement(By.Name("ctl00$MainContent$RegisterUser$CreateUserStepContainer$ctl09")).Click(); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_UserName")).Clear(); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_UserName")).SendKeys("abc"); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_Email")).Clear(); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_Email")).SendKeys("abc@mail.com"); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_Password")).Clear(); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_Password")).SendKeys("abcabc1"); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_ConfirmPassword")).Clear(); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_ConfirmPassword")).SendKeys("abcabc1"); driver.FindElement(By.Name("ctl00$MainContent$RegisterUser$CreateUserStepContainer$ctl09")).Click(); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_UserName")).Clear(); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_UserName")).SendKeys("abcde"); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_Password")).Clear(); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_Password")).SendKeys("abcdefg1"); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_ConfirmPassword")).Clear(); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_ConfirmPassword")).SendKeys("abvv"); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_ConfirmPassword")).Clear(); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_ConfirmPassword")).SendKeys("abcdefg1"); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_UserName")).Clear(); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_UserName")).SendKeys("abcdefg"); driver.FindElement(By.Name("ctl00$MainContent$RegisterUser$CreateUserStepContainer$ctl09")).Click(); driver.FindElement(By.LinkText("Мојата Биографија")).Click(); } private bool IsElementPresent(By by) { try { driver.FindElement(by); return true; } catch (NoSuchElementException) { return false; } } private bool IsAlertPresent() { try { driver.SwitchTo().Alert(); return true; } catch (NoAlertPresentException) { return false; } } private string CloseAlertAndGetItsText() { try { IAlert alert = driver.SwitchTo().Alert(); string alertText = alert.Text; if (acceptNextAlert) { alert.Accept(); } else { alert.Dismiss(); } return alertText; } finally { acceptNextAlert = true; } } } } }}} '''Search.cs''' {{{ using System; using System.Text; using System.Text.RegularExpressions; using System.Threading; using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using OpenQA.Selenium.Support.UI; namespace SeleniumTests { [TestFixture] public class Search { private IWebDriver driver; private StringBuilder verificationErrors; private string baseURL; private bool acceptNextAlert = true; [SetUp] public void SetupTest() { driver = new FirefoxDriver(); baseURL = "http://localhost:1400/"; verificationErrors = new StringBuilder(); } [TearDown] public void TeardownTest() { try { driver.Quit(); } catch (Exception) { // Ignore errors if unable to close the browser } Assert.AreEqual("", verificationErrors.ToString()); } [Test] public void TheSearchTest() { driver.Navigate().GoToUrl(baseURL + "/Default.aspx"); driver.FindElement(By.LinkText("Контакт")).Click(); driver.FindElement(By.Id("txtSearch")).Clear(); driver.FindElement(By.Id("txtSearch")).SendKeys("IS"); driver.FindElement(By.Id("btnSearch")).Click(); driver.FindElement(By.LinkText("Почетна")).Click(); driver.FindElement(By.Id("txtSearch")).Clear(); driver.FindElement(By.Id("txtSearch")).SendKeys("IS"); driver.FindElement(By.Id("btnSearch")).Click(); } private bool IsElementPresent(By by) { try { driver.FindElement(by); return true; } catch (NoSuchElementException) { return false; } } private bool IsAlertPresent() { try { driver.SwitchTo().Alert(); return true; } catch (NoAlertPresentException) { return false; } } private string CloseAlertAndGetItsText() { try { IAlert alert = driver.SwitchTo().Alert(); string alertText = alert.Text; if (acceptNextAlert) { alert.Accept(); } else { alert.Dismiss(); } return alertText; } finally { acceptNextAlert = true; } } } } }}} '''Changepassword.cs''' {{{ using System; using System.Text; using System.Text.RegularExpressions; using System.Threading; using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using OpenQA.Selenium.Support.UI; namespace SeleniumTests { [TestFixture] public class ChangePassword { private IWebDriver driver; private StringBuilder verificationErrors; private string baseURL; private bool acceptNextAlert = true; [SetUp] public void SetupTest() { driver = new FirefoxDriver(); baseURL = "http://localhost:1400/"; verificationErrors = new StringBuilder(); } [TearDown] public void TeardownTest() { try { driver.Quit(); } catch (Exception) { // Ignore errors if unable to close the browser } Assert.AreEqual("", verificationErrors.ToString()); } [Test] public void TheChangePasswordTest() { driver.Navigate().GoToUrl(baseURL + "/Default.aspx"); driver.FindElement(By.Id("ctl10_loginLink")).Click(); driver.FindElement(By.Id("MainContent_ctl00_UserName")).Clear(); driver.FindElement(By.Id("MainContent_ctl00_UserName")).SendKeys("student123"); driver.FindElement(By.Id("MainContent_ctl00_Password")).Clear(); driver.FindElement(By.Id("MainContent_ctl00_Password")).SendKeys("student123"); driver.FindElement(By.Id("MainContent_ctl00_btnLogin")).Click(); driver.FindElement(By.Id("ctl10_hpLink")).Click(); driver.FindElement(By.Id("MainContent_ctl07_ChangePasswordContainerID_CurrentPassword")).Clear(); driver.FindElement(By.Id("MainContent_ctl07_ChangePasswordContainerID_CurrentPassword")).SendKeys("student123"); driver.FindElement(By.Id("MainContent_ctl07_ChangePasswordContainerID_NewPassword")).Clear(); driver.FindElement(By.Id("MainContent_ctl07_ChangePasswordContainerID_NewPassword")).SendKeys("student1234"); driver.FindElement(By.Id("MainContent_ctl07_ChangePasswordContainerID_ConfirmNewPassword")).Clear(); driver.FindElement(By.Id("MainContent_ctl07_ChangePasswordContainerID_ConfirmNewPassword")).SendKeys("student1234"); driver.FindElement(By.Name("ctl00$MainContent$ctl07$ChangePasswordContainerID$ctl04")).Click(); driver.FindElement(By.LinkText("Одјави се")).Click(); driver.FindElement(By.Id("ctl10_loginLink")).Click(); driver.FindElement(By.Id("MainContent_ctl00_UserName")).Clear(); driver.FindElement(By.Id("MainContent_ctl00_UserName")).SendKeys("student123"); driver.FindElement(By.Id("MainContent_ctl00_Password")).Clear(); driver.FindElement(By.Id("MainContent_ctl00_Password")).SendKeys("student1234"); driver.FindElement(By.Id("MainContent_ctl00_btnLogin")).Click(); driver.FindElement(By.LinkText("Одјави се")).Click(); } private bool IsElementPresent(By by) { try { driver.FindElement(by); return true; } catch (NoSuchElementException) { return false; } } private bool IsAlertPresent() { try { driver.SwitchTo().Alert(); return true; } catch (NoAlertPresentException) { return false; } } private string CloseAlertAndGetItsText() { try { IAlert alert = driver.SwitchTo().Alert(); string alertText = alert.Text; if (acceptNextAlert) { alert.Accept(); } else { alert.Dismiss(); } return alertText; } finally { acceptNextAlert = true; } } } } }}} '''Addinfo.cs''' {{{ using System; using System.Text; using System.Text.RegularExpressions; using System.Threading; using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using OpenQA.Selenium.Support.UI; namespace SeleniumTests { [TestFixture] public class AddInfoLater { private IWebDriver driver; private StringBuilder verificationErrors; private string baseURL; private bool acceptNextAlert = true; [SetUp] public void SetupTest() { driver = new FirefoxDriver(); baseURL = "http://localhost:1400/"; verificationErrors = new StringBuilder(); } [TearDown] public void TeardownTest() { try { driver.Quit(); } catch (Exception) { // Ignore errors if unable to close the browser } Assert.AreEqual("", verificationErrors.ToString()); } [Test] public void TheAddInfoLaterTest() { driver.Navigate().GoToUrl(baseURL + "/"); driver.FindElement(By.Id("ctl10_registerLink")).Click(); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_UserName")).Clear(); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_UserName")).SendKeys("mojasmetka1"); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_Email")).Clear(); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_Email")).SendKeys("adresa@mail.com"); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_Password")).Clear(); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_Password")).SendKeys("mojasmetka1"); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_ConfirmPassword")).Clear(); driver.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_ConfirmPassword")).SendKeys("mojasmetka1"); driver.FindElement(By.Name("ctl00$MainContent$RegisterUser$CreateUserStepContainer$ctl09")).Click(); driver.FindElement(By.Id("MainContent_Button2")).Click(); driver.FindElement(By.LinkText("Мојата Биографија")).Click(); driver.FindElement(By.CssSelector("span.username")).Click(); driver.FindElement(By.Id("MainContent_txtImePrezime")).Clear(); driver.FindElement(By.Id("MainContent_txtImePrezime")).SendKeys("moja"); driver.FindElement(By.Id("MainContent_rblPol_1")).Click(); driver.FindElement(By.Id("MainContent_txtMesto")).Clear(); driver.FindElement(By.Id("MainContent_txtMesto")).SendKeys("ww"); driver.FindElement(By.Id("MainContent_txtDatum")).Clear(); driver.FindElement(By.Id("MainContent_txtDatum")).SendKeys("16.06.1989"); driver.FindElement(By.Id("MainContent_txtObrazovanie")).Clear(); driver.FindElement(By.Id("MainContent_txtObrazovanie")).SendKeys("ww"); driver.FindElement(By.Id("MainContent_txtInstitucija")).Clear(); driver.FindElement(By.Id("MainContent_txtInstitucija")).SendKeys("ww"); driver.FindElement(By.Id("MainContent_txtVrabotenVo")).Clear(); driver.FindElement(By.Id("MainContent_txtVrabotenVo")).SendKeys("ww"); driver.FindElement(By.Id("MainContent_txtPozicija")).Clear(); driver.FindElement(By.Id("MainContent_txtPozicija")).SendKeys("ww"); driver.FindElement(By.Id("MainContent_btnAdd")).Click(); driver.FindElement(By.LinkText("Мојата Биографија")).Click(); } private bool IsElementPresent(By by) { try { driver.FindElement(by); return true; } catch (NoSuchElementException) { return false; } } private bool IsAlertPresent() { try { driver.SwitchTo().Alert(); return true; } catch (NoAlertPresentException) { return false; } } private string CloseAlertAndGetItsText() { try { IAlert alert = driver.SwitchTo().Alert(); string alertText = alert.Text; if (acceptNextAlert) { alert.Accept(); } else { alert.Dismiss(); } return alertText; } finally { acceptNextAlert = true; } } } } }}} '''Addnewactivity.cs''' {{{ using System; using System.Text; using System.Text.RegularExpressions; using System.Threading; using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using OpenQA.Selenium.Support.UI; namespace SeleniumTests { [TestFixture] public class AddNewActivity { private IWebDriver driver; private StringBuilder verificationErrors; private string baseURL; private bool acceptNextAlert = true; [SetUp] public void SetupTest() { driver = new FirefoxDriver(); baseURL = "http://localhost:1400/"; verificationErrors = new StringBuilder(); } [TearDown] public void TeardownTest() { try { driver.Quit(); } catch (Exception) { // Ignore errors if unable to close the browser } Assert.AreEqual("", verificationErrors.ToString()); } [Test] public void TheAddNewActivityTest() { driver.Navigate().GoToUrl(baseURL + "/Default.aspx"); driver.FindElement(By.Id("ctl10_loginLink")).Click(); driver.FindElement(By.Id("MainContent_ctl00_UserName")).Clear(); driver.FindElement(By.Id("MainContent_ctl00_UserName")).SendKeys("student123"); driver.FindElement(By.Id("MainContent_ctl00_Password")).Clear(); driver.FindElement(By.Id("MainContent_ctl00_Password")).SendKeys("student1234"); driver.FindElement(By.Id("MainContent_ctl00_RememberMe")).Click(); driver.FindElement(By.Id("MainContent_ctl00_btnLogin")).Click(); driver.FindElement(By.Id("MainContent_Button1")).Click(); driver.FindElement(By.Id("MainContent_txtName")).Clear(); driver.FindElement(By.Id("MainContent_txtName")).SendKeys("nestonovo"); driver.FindElement(By.Id("MainContent_txtCategory")).Clear(); driver.FindElement(By.Id("MainContent_txtCategory")).SendKeys("/"); driver.FindElement(By.Id("MainContent_txtPlace")).Clear(); driver.FindElement(By.Id("MainContent_txtPlace")).SendKeys("Proba"); driver.FindElement(By.Id("MainContent_txtDate")).Clear(); driver.FindElement(By.Id("MainContent_txtDate")).SendKeys("11.11.2013"); driver.FindElement(By.Id("MainContent_txtRole")).Clear(); driver.FindElement(By.Id("MainContent_txtRole")).SendKeys("/"); driver.FindElement(By.Id("MainContent_btnInsert")).Click(); driver.FindElement(By.LinkText("Мојата Биографија")).Click(); driver.FindElement(By.LinkText("Одјави се")).Click(); } private bool IsElementPresent(By by) { try { driver.FindElement(by); return true; } catch (NoSuchElementException) { return false; } } private bool IsAlertPresent() { try { driver.SwitchTo().Alert(); return true; } catch (NoAlertPresentException) { return false; } } private string CloseAlertAndGetItsText() { try { IAlert alert = driver.SwitchTo().Alert(); string alertText = alert.Text; if (acceptNextAlert) { alert.Accept(); } else { alert.Dismiss(); } return alertText; } finally { acceptNextAlert = true; } } } } }}} '''Addusertoexistingactivity.cs''' {{{ using System; using System.Text; using System.Text.RegularExpressions; using System.Threading; using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using OpenQA.Selenium.Support.UI; namespace SeleniumTests { [TestFixture] public class AddUserToExistingActivity { private IWebDriver driver; private StringBuilder verificationErrors; private string baseURL; private bool acceptNextAlert = true; [SetUp] public void SetupTest() { driver = new FirefoxDriver(); baseURL = "http://localhost:1400/"; verificationErrors = new StringBuilder(); } [TearDown] public void TeardownTest() { try { driver.Quit(); } catch (Exception) { // Ignore errors if unable to close the browser } Assert.AreEqual("", verificationErrors.ToString()); } [Test] public void TheAddUserToExistingActivityTest() { driver.Navigate().GoToUrl(baseURL + "/"); driver.FindElement(By.Id("ctl10_loginLink")).Click(); driver.FindElement(By.Id("MainContent_ctl00_UserName")).Clear(); driver.FindElement(By.Id("MainContent_ctl00_UserName")).SendKeys("student123"); driver.FindElement(By.Id("MainContent_ctl00_Password")).Clear(); driver.FindElement(By.Id("MainContent_ctl00_Password")).SendKeys("student123"); driver.FindElement(By.Id("MainContent_ctl00_RememberMe")).Click(); driver.FindElement(By.Id("MainContent_ctl00_btnLogin")).Click(); driver.FindElement(By.Id("MainContent_Button1")).Click(); driver.FindElement(By.Id("MainContent_txtActivity")).Clear(); driver.FindElement(By.Id("MainContent_txtActivity")).SendKeys("nnnn"); driver.FindElement(By.Id("MainContent_btnShow")).Click(); driver.FindElement(By.Id("MainContent_txtRoleOnExisting")).Clear(); driver.FindElement(By.Id("MainContent_txtRoleOnExisting")).SendKeys("mmm"); driver.FindElement(By.Id("MainContent_gvMe_CheckBox1_0")).Click(); driver.FindElement(By.Id("MainContent_btnAddMe")).Click(); driver.FindElement(By.LinkText("Мојата Биографија")).Click(); driver.FindElement(By.LinkText("2")).Click(); } private bool IsElementPresent(By by) { try { driver.FindElement(by); return true; } catch (NoSuchElementException) { return false; } } private bool IsAlertPresent() { try { driver.SwitchTo().Alert(); return true; } catch (NoAlertPresentException) { return false; } } private string CloseAlertAndGetItsText() { try { IAlert alert = driver.SwitchTo().Alert(); string alertText = alert.Text; if (acceptNextAlert) { alert.Accept(); } else { alert.Dismiss(); } return alertText; } finally { acceptNextAlert = true; } } } } }}} '''Кориснички случај: Внесување нова активност и приклучување кон веќе постоечка''' ''' Use Case: ''' Внесување на активност и приклучување кон активност [[BR]] ''' Цел: ''' Корисникот креира нова активност, се приклучува кон веќе постоечка, т.е се додава себеси и/или додава некој друг учесник.[[BR]] ''' Категорија: ''' Примарна [[BR]] ''' Предуслов: ''' Да се има одржано некаква активност (креирано некој труд, проект, семинар и сл.) [[BR]] ''' Пост услов при успех: ''' Успешно внесен учесник на активност. [[BR]] ''' Пост услов при неуспех: ''' Неуспешно внесен учесник на активност и обид за повторено внесување. [[BR]] ''' Актер: ''' Главен уредник и регистрирани корисници. [[BR]] ''' Triggering Event: ''' Корисникот да сака да внесе некаква активност или да се приклучи кон веќе постоечка или да додаде некој друг учесник.[[BR]] ''' Опис: ''' 1. Корисник креира нова активност, ја става улогата што ја имал во активноста и со клик на копче активноста се додава во неговата биографија. [[BR]] 2. Ако претпоставиме дека ја има активноста во системот, може при впишување на името, да се нуди листа со активности кои ги содржат клучните зборови (од кои некоја е таа што се бара) и корисникот се приклучува во листата на учесници во таа активност. [[BR]] 3. Ако при внес на нова активност, истата ја има во системот, а корисникот поради некоја причина не избере да се приклучи кон неа и продолжи да ја креира како нова, пред последната потврда за внес се проверуваат внесените параметри. Ако се поклопуваат повеќето, ќе врати порака дека има слична активност, па корисникот ќе може да избере дали да се приклучи. Ако се поклопуваат сите параметри главниот уредник може да го одбие креирањето на новата активност, за да се избегне повторување. (пр. активност нека биде напишана книга, со истите автори, истиот наслов, ист издавач, ама различно издание и година на издавање, што е всушност нова активност.)[[BR]] ''' Екстензии: ''' [[BR]] Еден корисник може да има повеќе улоги во одредена активност. [[BR]] Кога корисник сака да додаде други учесници кои учествувале на активноста заедно со него, ако корисникот кој треба да се додаде го има во системот, при самото впишување на неговото име се нуди како избор и се додава, по што се чека тој учесник да потврди дека сака да се додаде на одредената активност. Ако го нема во системот се третира само како атрибут име и презиме.[[BR]] Корисник може да се додава на активност (себеси или друг учесник), само ако ја има активноста, т.е. задолжително е прво да се креира активност, (корисникот може да го има или нема на системот) и тогаш се врши приклучување на учесници кон активности.