Click here to Skip to main content
15,867,488 members
Articles / Web Development / ASP.NET

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

Rate me:
Please Sign up or sign in to vote.
4.96/5 (134 votes)
16 Aug 200540 min read 1.2M   3.9K   462  
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
// =====================================================================================
// Copyright © 2005 by . All rights are reserved.
// 
// If you like this code then feel free to go ahead and use it.
// The only thing I ask is that you don't remove or alter my copyright notice.
//
// Your use of this software is entirely at your own risk. I make no claims or
// warrantees about the reliability or fitness of this code for any particular purpose.
// If you make changes or additions to this code please mark your code as being yours.
// 
// website , email OmarALZabir@gmail.com, msn oazabir@hotmail.com
// =====================================================================================



using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using NUnit.Framework;
using SmartInstitute.DataAccessLayer.Factories;

namespace SmartInstitute.DataAccessLayer.UnitTests
{
    /// <summary>
    /// Provides tests for the and CourseTakenByStudent objects (entity, collection and repository).
    /// </summary>
    [TestFixture]
    public class CourseTakenByStudentRepositoryTest
    {
    	// the CourseTakenByStudent instance used to test the repository.
		private CourseTakenByStudent mock;
		
		// the CourseTakenByStudentCollection instance used to test the repository.
		CourseTakenByStudentCollection mockCollection;
		
		/// <summary>
		/// Creates a new <see cref="CourseTakenByStudentRepositoryTest"/> instance.
		/// </summary>	
		public CourseTakenByStudentRepositoryTest()
		{			
			this.mock = (CourseTakenByStudent)CreateMockInstance();	
		}
        
        /// <summary>
		/// This method is used to construct the test environment prior to running the tests.
		/// </summary>
        [TestFixtureSetUp]
        public void Init()
        {
			System.Console.WriteLine(new String('-', 75));
			//System.Console.WriteLine("-- Testing the CourseTakenByStudent Entity with the " + Configuration.Settings.ClientType + " --");
			System.Console.WriteLine(new String('-', 75));
        }
    
    	/// <summary>
		/// This method is used to restore the environment after the tests are completed.
		/// </summary>
        [TestFixtureTearDown]
        public void Dispose()
        {       	
			System.Console.WriteLine();
			System.Console.WriteLine();
        }
    
    
		/// <summary>
		/// Inserts a mock CourseTakenByStudent entity into the database.
		/// </summary>
		[Test]
		public void Step_1_Insert()
		{			
			Assert.IsTrue(CourseTakenByStudentRepository.Current.Insert(this.mock), "Insert failed");
			System.Console.WriteLine("CourseTakenByStudentRepository.Current.Insert(this.mock):");			
			System.Console.WriteLine(this.mock);
		}
		
		
		/// <summary>
		/// Selects all CourseTakenByStudent objects of the database.
		/// </summary>
		[Test]
		public void Step_2_SelectAll()
		{
			mockCollection = CourseTakenByStudentRepository.Current.GetAll();
			Assert.IsTrue(mockCollection.Count > 0, "No records returned.");
			System.Console.WriteLine("CourseTakenByStudentRepository.Current.GetAll():");			
			System.Console.WriteLine(mockCollection);
			
			if (mockCollection.Count > 0)
			{
				CourseTakenByStudentRepository.Current.DeepLoad(mockCollection[0]);
			}
		}
		
		/// <summary>
		/// Deep load all CourseTakenByStudent children.
		/// </summary>
		[Test]
		public void Step_3_DeepLoad()
		{
			if (mockCollection.Count > 0)
			{
				mockCollection.Shuffle();			
				CourseTakenByStudentRepository.Current.DeepLoad(mockCollection[0]);
				System.Console.WriteLine("CourseTakenByStudent instance correctly deep loaded at 1 level.");
				
				mockCollection.Shuffle();
				CourseTakenByStudentRepository.Current.DeepLoad(mockCollection[0], true);
				System.Console.WriteLine("CourseTakenByStudent instance correctly deep loaded at N level.");
			}
			
			
		}
		
		/// <summary>
		/// Updates a mock CourseTakenByStudent entity into the database.
		/// </summary>
		[Test]
		public void Step_4_Update()
		{
			this.mock = UpdateMockInstance(this.mock);
			Assert.IsTrue(CourseTakenByStudentRepository.Current.Update(this.mock), "Update failed.");			
		
			// TODO : select sur l'id
			// TODO : verif si l'object recup? est egal
			
			System.Console.WriteLine("CourseTakenByStudentRepository.Current.Update(this.mock):");			
			System.Console.WriteLine(this.mock);
		}
		
		
		/// <summary>
		/// Delete the mock CourseTakenByStudent entity into the database.
		/// </summary>
		[Test]
		public void Step_5_Delete()
		{
			Assert.IsTrue(CourseTakenByStudentRepository.Current.Delete(this.mock), "Delete failed.");
			System.Console.WriteLine("CourseTakenByStudentRepository.Current.Delete(this.mock):");			
			System.Console.WriteLine(this.mock);
		}
		
		#region Serialization tests
		
		/// <summary>
		/// Serialize the mock CourseTakenByStudent entity into a temporary file.
		/// </summary>
		[Test]
		public void Step_6_SerializeEntity()
		{
			string fileName = "temp_CourseTakenByStudent.xml";
		
			XmlSerializer mySerializer = new XmlSerializer(typeof(CourseTakenByStudent)); 
			StreamWriter myWriter = new StreamWriter(fileName); 
			mySerializer.Serialize(myWriter, this.mock); 
			myWriter.Close();
			System.Console.WriteLine("this.mock correctly serialized to a temporary file.");			
		}
		
		/// <summary>
		/// Deserialize the mock CourseTakenByStudent entity from a temporary file.
		/// </summary>
		[Test]
		public void Step_7_DeserializeEntity()
		{
			string fileName = "temp_CourseTakenByStudent.xml";
		
			XmlSerializer mySerializer = new XmlSerializer(typeof(CourseTakenByStudent)); 
			FileStream myFileStream = new FileStream(fileName,  FileMode.Open); 
			this.mock = (CourseTakenByStudent) mySerializer.Deserialize(myFileStream);
			myFileStream.Close();
			File.Delete(fileName);
			
			System.Console.WriteLine("this.mock correctly deserialized from a temporary file.");
		}
		
		/// <summary>
		/// Serialize a CourseTakenByStudent collection into a temporary file.
		/// </summary>
		[Test]
		public void Step_8_SerializeCollection()
		{
			string fileName = "temp_CourseTakenByStudentCollection.xml";
		
			CourseTakenByStudentCollection mockCollection = new CourseTakenByStudentCollection();
			mockCollection.Add(this.mock);
		
			XmlSerializer mySerializer = new XmlSerializer(typeof(CourseTakenByStudentCollection)); 
			StreamWriter myWriter = new StreamWriter(fileName); 
			mySerializer.Serialize(myWriter, mockCollection); 
			myWriter.Close();
			
			System.Console.WriteLine("CourseTakenByStudentCollection correctly serialized to a temporary file.");					
		}
		
		
		/// <summary>
		/// Deserialize a CourseTakenByStudent collection from a temporary file.
		/// </summary>
		[Test]
		public void Step_9_DeserializeCollection()
		{
			string fileName = "temp_CourseTakenByStudentCollection.xml";
		
			XmlSerializer mySerializer = new XmlSerializer(typeof(CourseTakenByStudentCollection)); 
			FileStream myFileStream = new FileStream(fileName,  FileMode.Open); 
			CourseTakenByStudentCollection mockCollection = (CourseTakenByStudentCollection) mySerializer.Deserialize(myFileStream);
			myFileStream.Close();
			File.Delete(fileName);
			System.Console.WriteLine("CourseTakenByStudentCollection correctly deserialized from a temporary file.");	
		}
		#endregion
						
		#region Mock Instance
		///<summary>
		///  Returns a Typed CourseTakenByStudent Entity with mock values.
		///</summary>
		public CourseTakenByStudent CreateMockInstance()
		{		
			CourseTakenByStudent mock = new CourseTakenByStudent();
						
			mock.Status = (int)12; /*new Guid("20E43088-4618-4F4A-B8AD-FC31B50D94CD")*/
			mock.NonCredit = false; /*new Guid("20E43088-4618-4F4A-B8AD-FC31B50D94CD")*/
			mock.ChangeStamp = new DateTime(2005, 7, 25, 14, 34, 54, 468); /*new Guid("20E43088-4618-4F4A-B8AD-FC31B50D94CD")*/
			CourseCollection _collection0 = CourseRepository.Current.GetAll();
			_collection0.Shuffle();
			if (_collection0.Count > 0)
			{
				mock.CourseID = _collection0[0].ID;
			}
			CourseSectionCollection _collection1 = CourseSectionRepository.Current.GetAll();
			_collection1.Shuffle();
			if (_collection1.Count > 0)
			{
				mock.SectionID = _collection1[0].ID;
			}
			StudentCollection _collection2 = StudentRepository.Current.GetAll();
			_collection2.Shuffle();
			if (_collection2.Count > 0)
			{
				mock.StudentID = _collection2[0].ID;
			}
		   return (CourseTakenByStudent)mock;
		}
		
		
		///<summary>
		///  Update the Typed CourseTakenByStudent Entity with modified mock values.
		///</summary>
		public CourseTakenByStudent UpdateMockInstance(CourseTakenByStudent mock)
		{
			mock.Status = (int)13;
			mock.NonCredit = true;
			mock.ChangeStamp = new DateTime(2005, 7, 25, 14, 34, 54, 468);
			CourseCollection _collection0 = CourseRepository.Current.GetAll();
			_collection0.Shuffle();
			if (_collection0.Count > 0)
			{
				mock.CourseID = _collection0[0].ID;
			}
			CourseSectionCollection _collection1 = CourseSectionRepository.Current.GetAll();
			_collection1.Shuffle();
			if (_collection1.Count > 0)
			{
				mock.SectionID = _collection1[0].ID;
			}
			StudentCollection _collection2 = StudentRepository.Current.GetAll();
			_collection2.Shuffle();
			if (_collection2.Count > 0)
			{
				mock.StudentID = _collection2[0].ID;
			}
		   return (CourseTakenByStudent)mock;
		}
		
		#endregion
    }
}

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


Written By
Architect BT, UK (ex British Telecom)
United Kingdom United Kingdom

Comments and Discussions