예제 #1
0
		public void AddParentWithChild()
		{
			var book = new Book();
			_books.Add(book);
			Assert.IsNotNull(book);
			Assert.AreNotEqual(book.BookId, 0);
			Assert.AreEqual(book.BookId, 1);
		}
예제 #2
0
		public void ParentWithNullableChild()
		{
			var book = new Book();
			var image = new ImageNullable();

			Assert.That(() => _books.Add(book), Throws.Nothing);
			image.IdBook = book.BookId;
			Assert.That(() => _imagesNullable.Add(image), Throws.Nothing);
		}
예제 #3
0
		public void ParentWithChild()
		{
			var book = new Book();
			_books.Add(book);

			var image = new Image();
			image.IdBook = book.BookId;

			_books.Remove(book);
			Assert.That(() => _images.Add(image), Throws.Exception.TypeOf<ForginKeyConstraintException>());
		}
예제 #4
0
		public static int[] AddBooks(int number, DbAccessLayer mgr)
		{
			var books = new List<Book>();
			for (int i = 0; i < number; i++)
			{
				var book = new Book();
				book.BookName = Guid.NewGuid().ToString();
				books.Add(mgr.InsertWithSelect(book));
			}
			return books.Select(f => f.BookId).ToArray();
		}
		public void ParentWithChild()
		{
			Assert.That(() =>
			{
				using (var transaction = new TransactionScope())
				{
					var book = new Book();
					_books.Add(book);

					var image = new Image();
					image.IdBook = book.BookId;

					_books.Remove(book);
					Assert.That(() => _images.Add(image), Throws.Nothing);
					transaction.Complete();
				}
			}, Throws.Exception.TypeOf<ForginKeyConstraintException>());

		}
예제 #6
0
		public static int[] AddBooksWithImage(int number, int imagesPerBook, DbAccessLayer mgr)
		{
			var books = new List<Book>();
			for (int i = 0; i < number; i++)
			{
				var book = new Book();
				book.BookName = Guid.NewGuid().ToString();
				books.Add(book = mgr.InsertWithSelect(book));

				for (int j = 0; j < imagesPerBook; j++)
				{
					mgr.Insert(new Image()
					{
						Text = Guid.NewGuid().ToString(),
						IdBook = book.BookId
					});
				}
			}
			return books.Select(f => f.BookId).ToArray();
		}
예제 #7
0
		public void RemoveParentWithChild()
		{
			var book = new Book();
			_books.Add(book);

			var image = new Image();
			image.IdBook = book.BookId;
			_images.Add(image);

			Assert.AreNotEqual(book.BookId, 0);
			Assert.AreNotEqual(image.ImageId, 0);

			Assert.AreNotEqual(_books.Count, 0);
			Assert.AreNotEqual(_images.Count, 0);
			Assert.IsTrue(_images.Remove(image));
			Assert.IsTrue(_books.Remove(book));
			Assert.AreEqual(_books.Count, 0);
			Assert.AreEqual(_images.Count, 0);
		}
		public void ParentWithNullableChild()
		{
			Assert.That(() =>
			{
				using (var transaction = new TransactionScope())
				{
					var book = new Book();
					var image = new ImageNullable();

					Assert.That(() => _books.Add(book), Throws.Nothing);
					image.IdBook = book.BookId;
					Assert.That(() => _imagesNullable.Add(image), Throws.Nothing);
					transaction.Complete();
				}
			}, Throws.Nothing);
		}
		public void IdentityInsertAutoSetUninit()
		{
			Assert.That(() =>
			{
				using (var transaction = new TransactionScope())
				{
					using (new IdentityInsertScope(true))
					{
						var image = new Image();
						image.ImageId = 10;
						_images.Add(image);
						var book = new Book();
						_books.Add(book);
						image.IdBook = book.BookId;

						Assert.That(book.BookId, Is.EqualTo(1));
						Assert.That(image.ImageId, Is.EqualTo(10));

						Assert.AreNotEqual(_books.Count, 0);
						Assert.AreNotEqual(_images.Count, 0);
						transaction.Complete();
					}
				}
			}, Throws.Nothing);
		}
		public void AddMultibeItems()
		{
			Assert.That(() =>
			{
				using (var transaction = new TransactionScope())
				{
					var image = new Image();
					_images.Add(image);
					var book = new Book();
					_books.Add(book);
					image.IdBook = book.BookId;

					Assert.AreNotEqual(book.BookId, 0);
					Assert.AreNotEqual(image.ImageId, 0);

					Assert.AreNotEqual(_books.Count, 0);
					Assert.AreNotEqual(_images.Count, 0);
					transaction.Complete();
				}
			}, Throws.Nothing);

		}