PageRenderTime 184ms CodeModel.GetById 179ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

/src/Otis.Tests/CollectionMappingTest.cs

http://otis-lib.googlecode.com/
C# | 62 lines | 50 code | 8 blank | 4 comment | 0 complexity | f5d1d88601a066f5bdb9eeba901e2d4e MD5 | raw file
 1/*
 2 * Created by: Zdeslav Vojkovic
 3 * Created: Friday, October 26, 2007
 4 */
 5
 6using System;
 7using System.Collections.Generic;
 8using NUnit.Framework;
 9using Otis.Tests.Entity;
10
11namespace Otis.Tests
12{
13	[TestFixture]
14	public class CollectionMappingTest
15	{
16		private IAssembler<AttributedUserDTO, User> m_assembler;
17		private List<User> m_source;
18
19		[SetUp]
20		public void SetUp()
21		{
22			Configuration cfg = new Configuration();
23			cfg.AddType(typeof(AttributedUserDTO));
24			m_assembler = cfg.GetAssembler<AttributedUserDTO, User>();
25			m_source = new List<User>(3);
26			m_source.Add(new User());
27			m_source[0].FirstName = "Zdeslav";
28			m_source[0].LastName = "Vojkovic";
29			m_source[0].Age = 33;
30			m_source[0].Id = 1;
31			m_source[0].UserName = "zdeslavv";
32
33			m_source.Add(Helpers.CreateComplexUser());
34			m_source.Add(m_source[1].Boss);
35		}
36
37		[TearDown]
38		public void TearDown() {}
39
40		[Test]
41		public void Enumerable_Can_Convert_To_Array()
42		{
43			AttributedUserDTO[] dtos = m_assembler.ToArray(m_source);
44			Assert.AreEqual(m_source[0].FirstName + " " + m_source[0].LastName, dtos[0].FullName);
45			Assert.AreEqual(m_source[1].FirstName + " " + m_source[1].LastName, dtos[1].FullName);
46			Assert.AreEqual(m_source[2].FirstName + " " + m_source[2].LastName, dtos[2].FullName);
47		}
48
49		[Test]
50		public void Enumerable_Can_Convert_To_Collection()
51		{
52			ICollection<AttributedUserDTO> dtos = m_assembler.ToList(m_source);
53			int i = 0;
54			foreach (AttributedUserDTO dto in dtos)
55			{
56				Assert.AreEqual(m_source[i].FirstName + " " + m_source[i].LastName, dto.FullName);
57				i++;
58			}
59		}
60	}
61}
62