00001
00002 using System;
00003 using NUnit.Framework;
00004
00005 namespace Foodolini.Database.Test
00006 {
00010 [TestFixture]
00011 public class PictureTest : DatabaseTest
00012 {
00019 [TestFixtureSetUp]
00020 public void LoadStressTestVector(){
00021 Random prgn = new Random((int)(DateTime.Now.Ticks % int.MaxValue));
00022 prgn.NextBytes(stressTestVector);
00023 }
00024
00028 private static readonly byte[] smallTestVector = {45, 78, 92, 0, 1,2, 34};
00029
00033 private static readonly byte[] stressTestVector = new byte[5 * 1024 * 1024];
00034
00038 [Test]
00039 public void CreateTable(){
00040 this.repository.CreateTable<Picture>();
00041 }
00042
00051 [Test]
00052 public void Save(){
00053
00054 Picture p = new Picture();
00055 p.Image = smallTestVector;
00056
00057 this.repository.Add<Picture>(p);
00058 }
00059
00063 [Test]
00064 public void SaveLoad(){
00065
00066 Picture picture = new Picture();
00067 picture.Image = smallTestVector;
00068
00069
00070 this.repository.Add<Picture>(picture);
00071
00072
00073 Picture pic = null;
00074 foreach(var p in this.repository.All<Picture>()){
00075 if(pic != null)
00076 Assert.Fail("Database contained more that one item, after running Save()");
00077 pic = p;
00078 }
00079
00080
00081 Assert.AreEqual(smallTestVector.Length, pic.Image.Length, "Byte array lenght mismatch");
00082
00083
00084 for(int i = 0; i < smallTestVector.Length; i++)
00085 Assert.AreEqual(smallTestVector[i], pic.Image[i], "Byte array mismatch");
00086 }
00087
00094 [Test]
00095 public void StressTest(){
00096
00097 Picture picture = new Picture();
00098
00099 picture.Image = stressTestVector;
00100
00101
00102 this.repository.Add<Picture>(picture);
00103
00104
00105 Picture pic = null;
00106 foreach(var p in this.repository.All<Picture>()){
00107
00108 if(pic != null)
00109 Assert.Fail("Database contained more that one item, after running Save()");
00110 pic = p;
00111 }
00112
00113
00114 Assert.AreEqual(stressTestVector.Length, pic.Image.Length, "Byte array lenght mismatch");
00115
00116
00117 for(int i = 0; i < stressTestVector.Length; i++)
00118 Assert.AreEqual(stressTestVector[i], pic.Image[i], "Byte array mismatch");
00119 }
00120
00121
00122 }
00123 }