コード例 #1
0
		public void AddChildWithoutParent()
		{
			var image = new Image();

			Assert.That(() => _images.Add(image), Throws.Exception.TypeOf<ForginKeyConstraintException>());
			
		}
コード例 #2
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>());
		}
コード例 #3
0
		public void AddChildWithoutParent()
		{
			var image = new Image();
			Assert.That(() =>
			{
				using (var transaction = new TransactionScope())
				{
					Assert.That(() => _images.Add(image), Throws.Nothing);
					transaction.Complete();
				}
			}, Throws.Exception.TypeOf<ForginKeyConstraintException>());

		}
コード例 #4
0
		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>());

		}
コード例 #5
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);
		}
コード例 #6
0
		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);
		}
コード例 #7
0
		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);

		}