Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Developing Next Generation Smart Clients using .NET 2.0 working with Existing .NET 1.1 SOA-based XML Web Services

, 16 Aug 2005
Comprehensive guide to development of .NET 2.0 Smart Clients working with existing Service Oriented Architecture based XML web services, fully utilizing the Enterprise Library
smartclientsoa_src.zip
SmartClient
Client
SMI.App
Controls
Forms
Modules
Properties
app.manifest
Settings.settings
Resources
240.png
Bottom.png
BuilderDialog_delete.bmp
DarkBlue.bmp
download-xp.gif
Earth.png
fldropen.png
iSync.gif
Leonardo_da_Vinci_My_Computer.png
LightBlue.bmp
LoginBox.jpg
LoginButton.jpg
LoginButton1.jpg
LoginButton2.jpg
Logo1.png
LogoPic.jpg
Middle.png
Refresh.bmp
refresh.ico
refresh1.ico
RightArrow.bmp
SuccessComplete.bmp
Task.bmp
Tasks.png
Top.png
TurnOffButton.bmp
wi0062-32.ico
wi0063-32.ico
wi0064-16.ico
wi0064-32.ico
SmartInstitute.App.csproj.user
wi0064-32.ico
SMI.Automation
Commands
Course
Framework
Security
Students
UI
Controls
Documents
MiscDocuments
StudentDocuments
Factories
Forms
Helpers
Misc
Properties
Settings.settings
Resources
BuilderDialog_delete.bmp
LogoSmall.bmp
Misho.jpg
My Pic 7.jpg
table.ico
SmartInstitute.Automation.csproj.user
Web References
SmartInstituteServices.AccountService
Account.datasource
AccountService.disco
AccountService.wsdl
Reference.map
SmartInstituteServices.CourseService
Course.datasource
CourseService.disco
CourseService.wsdl
Reference.map
SmartInstituteServices.SecurityService
Reference.map
SecurityService.disco
SecurityService.wsdl
SmartInstituteServices.StudentService
Reference.map
Student.datasource
StudentService.disco
StudentService.wsdl
SMI.ObjectModel.Enhanced
Base
Models
Properties
Settings.settings
Settings
SmartInstitute.ObjectModel.csproj.user
UMS.ObjectModel.Enhanced.csproj.user
SMI.Objects
SmartInstitute.csproj.user
CodeSmith
Tier
BusinessLogicLayer
Entity.cst
EntityBase.cst
EntityCollection.cst
EntityCollectionBase.cst
Enum.cst
IEntity.cst
DataAccessLayer
App.config.cst
CommonSql.cst
Configuration.cst
DBConcurrencyException.cst
DBException.cst
Factories
EntityRepositoryFactory.cst
IEntityRepository.cst
SqlClient
CVS
Entries
Entries.Extra
Entries.Extra.Old
Entries.Old
Repository
Root
TortoiseCVS.Status
SqlEntityRepository.cst
SqlEntityRepositoryBase.cst
TransactionManager.cst
UnitTests
EntityRepositoryTest.cst
WebServiceClient
WsEntityRepository.cst
WsEntityRepositoryBase.cst
Main.cst
nant.cst
References
GotDotNet.ApplicationBlocks.Data.dll
Microsoft.ApplicationBlocks.Data.dll
nunit.framework.dll
StoredProcedures.cst
vsnet2003.project.cst
vsnet2003.solution.cst
vsnet2005.project.cst
vsnet2005.solution.cst
WebService
Web.config.cst
WebService.cst
Database
SmartInstitute.bak
Library
Microsoft.Practices.EnterpriseLibrary.Caching.dll
Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Configuration.dll
Microsoft.Practices.EnterpriseLibrary.Data.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll
Microsoft.Practices.EnterpriseLibrary.Logging.dll
Microsoft.Practices.EnterpriseLibrary.Security.ActiveDirectory.dll
Microsoft.Practices.EnterpriseLibrary.Security.Cache.CachingStore.dll
Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll
Microsoft.Practices.EnterpriseLibrary.Security.Database.Authentication.dll
Microsoft.Practices.EnterpriseLibrary.Security.Database.dll
Microsoft.Practices.EnterpriseLibrary.Security.dll
nunit.core.dll
nunit.framework.dll
Server
BLL
SmartInstitute.csproj.user
DAL
Factories
SmartInstitute.DataAccessLayer.csproj.user
SqlClient
Utilities
GotDotNet.ApplicationBlocks.Data.dll
Microsoft.ApplicationBlocks.Data.dll
nunit.framework.dll
UnitTests
SmartInstitute.build
SmartInstitute.Facade
FacadeTest
SmartInstitute.Facade.csproj.user
SmartInstitute.Test
App.ico
SmartInstitute.Test.csproj.user
SmartInstituteServices
Global.asax
log
SmartInstituteServices.csproj.webinfo
SQL
Setup
SecurityDatabase
SecurityDatabaseConsole
App.ico
SecurityDatabaseConsole.exe.manifest
SR.strings
Tests
Tools.SecurityDatabaseConsole.csproj.user
using System;
using System.Security.Cryptography;
using NUnit.Framework;
using Microsoft.Practices.EnterpriseLibrary.Security;
namespace SmartInstitute.Facade.FacadeTest
{
	/// <summary>
	/// Test the entire Facade simulating a real use of the entire system
	/// 
	/// Here's the test plan:
	/// 1. Create new student
	/// 2. Try changing soem property and save
	/// 3. Try deep load
	/// 4. Get all courses and register the courses to the student
	/// 5. Calculate assessment
	/// 6. Ensure accounts record created properly
	/// 7. Drop course, delete some course
	/// 8. Recalculate assessment
	/// 9. Ensure accounts record updated properly
	/// 10. Add some payment record in accounts
	/// 11. Cleanup accounts
	/// </summary>
    [TestFixture]
	public class TestFacade
	{
		public TestFacade()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		private Facade _Facade;

		private Student student = new Student( 0, "First", "Middle", "Last", "Present1", "Present2", 
			"Permanent1", "Permanent2", Guid.NewGuid().ToString(), 
			1, 3.78f, 10, DateTime.Now, DateTime.Now,
			DateTime.Now );
			
		/// <summary>
		/// This method is used to construct the test environment prior to running the tests.
		/// </summary>
		[TestFixtureSetUp]
		public void Init()
		{
			_Facade = new Facade();
		}
    
		/// <summary>
		/// This method is used to restore the environment after the tests are completed.
		/// </summary>
		[TestFixtureTearDown]
		public void Dispose()
		{       	
			
		}

		[Test]
		public void Step_01_NewStudent()
		{
			_Facade.AddNewStudent( student );

			Assert.IsTrue( student.ID > 0, "Student not properly inserted" );
		}

		[Test]
		public void Step_02_SaveStudent()
		{
			student.StudentID = student.StudentID + "E";

			Assert.IsTrue( _Facade.SaveStudent( student ) );

			Assert.IsTrue( student.StudentID.EndsWith("E"), "Save did not work properly" );
		}

		[Test]
		public void Step_03_DeepLoad()
		{
			student = _Facade.GetStudentDetail( student.ID );

			Assert.IsNotNull( student, "Get Student Detail not working" );
			Assert.IsNotNull( student.AssessmentCollection, "No assessment found" );
			Assert.IsNotNull( student.AccountCollection, "No account found" );
		}

		[Test]
		public void Step_04_AddCourses()
		{
			// Assign all the courses to the student
			CourseCollection courses = _Facade.GetAllCoursesAndSections();

			Assert.IsTrue( courses.Count >= 2, "At least 2 courses needed for test" );

			CourseTakenByStudentCollection coursesTaken = new CourseTakenByStudentCollection();
			
			// Add the first section of all course to registration
			foreach( Course course in courses )
			{
				Assert.IsTrue( course.CourseSectionCollection.Count >= 1, "At least one section must be present for each course" );

				CourseSection section = course.CourseSectionCollection[0];

				CourseTakenByStudent courseTaken = new CourseTakenByStudent( 0, student.ID,
					course.ID, section.ID, 1, false, DateTime.Now );

				coursesTaken.Add( courseTaken );				
			}

			// Register the selected sections
			Assert.AreEqual( _Facade.RegisterCourses( student.ID, coursesTaken ), coursesTaken.Count );

			// Ensure all courses are properly registered
			student.CourseTakenByStudentCollection = _Facade.GetRegisteredCourses( student.ID );
			
			Assert.AreEqual( coursesTaken.Count, student.CourseTakenByStudentCollection.Count );
		}

		[Test]
		public void Step_05_CalculateAssessment()
		{
			Assessment assessment = _Facade.CalculateAssessment( student.ID );
			Assert.IsNotNull( assessment, "Assessment not properly calculated" );
			Assert.IsTrue( assessment.ID == 0, "Assessment should not be inserted upon calculation" );
			
			Assert.IsTrue( _Facade.SaveAssessment( student.ID, assessment ), "Assessment not inserted properly" );
			Assert.IsTrue( assessment.ID > 0, "Assessment not properly inserted in database" );

			Assessment ass = _Facade.GetAssessment( student.ID );
			Assert.IsNotNull( ass, "Assessment get failed" );
		}

		[Test]
		public void Step_06_ModifyRegistration()
		{
			// Drop all course
			foreach( CourseTakenByStudent2 courseTaken in student.CourseTakenByStudentCollection )
			{
				courseTaken.Dropped = true;
			}

			Assert.IsTrue( _Facade.SaveRegistration( student.ID, student.CourseTakenByStudentCollection ),
				"Registration save failed" );

			Assessment ass = _Facade.GetAssessment( student.ID );
			Assert.IsNotNull( ass, "Assessment was not saved properly" );

			Assert.AreEqual( ass.TuitionFee, 0, "Tuition fee is supposed to be zero for all dropped course" );

			// undrop all course
			foreach( CourseTakenByStudent2 courseTaken in student.CourseTakenByStudentCollection )
			{
				courseTaken.Dropped = false;
			}

			Assert.IsTrue( _Facade.SaveRegistration( student.ID, student.CourseTakenByStudentCollection ),
				"Registration save failed" );

			Assessment assAfter = _Facade.GetAssessment( student.ID );
			Assert.IsNotNull( assAfter, "Assessment was not saved properly" );

			Assert.IsTrue( assAfter.TuitionFee > 0, "Tuition fee is supposed to be greater than 0" );

		}

		[Test]
		public void Step_07_EnsureAccounts()
		{
			AccountCollection accounts = _Facade.GetAccountsOfStudent( student.ID );
			Assert.AreEqual( accounts.Count, 1, "There should be an account record after assessment" );

			Assert.AreEqual( accounts[0].Type, (int)AccountTypeEnum.Assessment, "Invalid type of account head" );

			Account payment1 = new Account( 0, student.ID, "First Payment", DateTime.Now, 
				0, 1000, 0, DateTime.Now, (int)AccountTypeEnum.Other, string.Empty, string.Empty, string.Empty );

			Assert.IsTrue( _Facade.AddNewAccount( payment1 ), "New Account was not inserted" );

			Account payment2 = new Account( 0, student.ID, "Second Payment", DateTime.Now, 
				0, 1000, 0, DateTime.Now, (int)AccountTypeEnum.Other, string.Empty, string.Empty, string.Empty );

			Assert.IsTrue( _Facade.AddNewAccount( payment2 ), "New Account was not inserted" );
		}

		[Test]
		public void Step_08_AddSyncTest()
		{
			// Refresh full object graph
			student = _Facade.GetStudentDetail( student.ID );

			int oldCount = student.AccountCollection.Count;

			Account payment1 = new Account( 0, student.ID, "First Payment", DateTime.Now, 
				0, 1000, 0, DateTime.Now, (int)AccountTypeEnum.Other, string.Empty, string.Empty, string.Empty );
			student.AccountCollection.Add( payment1 );

			// Perform sync
			Assert.IsTrue( _Facade.SyncStudent( student ), "Synchronization failed" );

			// Refresh full object graph
			student = _Facade.GetStudentDetail( student.ID );

			// Test
			Assert.AreEqual( 1, student.AssessmentCollection.Count, "Assessment was calculated" );
			Assert.AreEqual( oldCount+1, student.AccountCollection.Count, "Account was not deleted" );
		}

		[Test]
		public void Step_08_DeleteSyncTest()
		{
			// Refresh full object graph
			student = _Facade.GetStudentDetail( student.ID );

			foreach( Assessment ass in student.AssessmentCollection )
				ass.MarkToDelete();
			foreach( Account acc in student.AccountCollection )
				acc.MarkToDelete();
			foreach( CourseTakenByStudent ctbs in student.CourseTakenByStudentCollection )
				ctbs.MarkToDelete();

			// Perform sync
			Assert.IsTrue( _Facade.SyncStudent( student ), "Synchronization failed" );

			// Refresh full object graph
			student = _Facade.GetStudentDetail( student.ID );

			// Test
			Assert.AreEqual( 1, student.AssessmentCollection.Count, "Assessment was not deleted" );
			Assert.AreEqual( 1, student.AccountCollection.Count, "Account was not deleted" );
			Assert.AreEqual( 0, student.CourseTakenByStudentCollection.Count, "CourseTakenByStudent was not deleted" );


		}

		[Test]
		public void Step_80_LoginTest()
		{	
			// Login attempt using credential
			string token = _Facade.Login( "Administrator", HashStringMD5( "admin" ) );
			//IToken token = _Facade.Login( "Administrator", "admin" );
			Assert.IsNotNull( token, "Login failed for admnistrator using credential" );

			// Invalid attempt
			Assert.IsNull( _Facade.Login( Guid.NewGuid().ToString(), HashStringMD5( "admin" ) ), 
			"Security Bridge! Authentication not working" );

			// Login attempt using security token
			bool result = _Facade.Login( token );
			Assert.IsTrue( result, "Login failed using security token" );

			// Logout the user
			_Facade.Logout( token );
			Assert.IsFalse( _Facade.Login( token ), "Logout not working, token still accepted" );

			// Test authorization
			Assert.IsTrue( _Facade.IsInRole("Administrator", "Administrators"), "Role based security not working" );
			Assert.IsTrue( _Facade.IsAuthorized("Administrator", Constants.Authorization.CAN_LOGIN), "Rule Provider not working" );

			Assert.IsFalse( _Facade.IsInRole("Administrator", "Anonymous"), "Role based security not working" );
			try
			{
				Assert.IsFalse( _Facade.IsAuthorized("Administrator", "gaga"), "Rule Provider not working" );
			}
			catch
			{
			}
		}

		[Test]
		public void Step_99_Cleanup()
		{
			_Facade.DeleteStudent( student.ID );
		}

		private string HashStringMD5( string textToHash )
		{
			MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider();
			byte[] byteValue = System.Text.Encoding.UTF8.GetBytes(textToHash);
			byte[] byteHash = MD5.ComputeHash(byteValue);
			MD5.Clear();

			return Convert.ToBase64String(byteHash);

		}

	}
}

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author


| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 17 Aug 2005
Article Copyright 2005 by Omar Al Zabir
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid