Пример #1
0
        public void IncrementAndDecrementNestLevelWhenStartingMultipleUnitsOfWork(UnitOfWorkBatchMode unitOfWorkBatchMode)
        {
            // Arrange
            Bootstrapper.Start();

            var unitOfWorkFactory = Bootstrapper.AmbientContainer.GetInstance <IUnitOfWorkFactory>();

            unitOfWorkFactory.UnitOfWorkBatchMode = unitOfWorkBatchMode;

            var unitOfWork = unitOfWorkFactory.CreateUnitOfWork();
            var repository = Bootstrapper.AmbientContainer.GetInstance <Repository <TestModel> >();

            const string Key = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            var testChildA = new TestChildModel("AAA");
            var testChildB = new TestChildModel("BBB");
            var testChildC = new TestChildModel("CCC");

            var testModel = new TestModel(Key);

            testModel.TestChildren.Add(testChildA);
            testModel.TestChildren.Add(testChildB);
            testModel.TestChildren.Add(testChildC);

            using (unitOfWork.Start())
            {
                repository.Create(testModel);

                unitOfWork.Commit();
            }

            // Act & Assert
            using (unitOfWork.Start())
            {
                Assert.That(unitOfWork.NestLevel.Equals(0));

                this.ParentMethod();

                Assert.That(unitOfWork.NestLevel.Equals(0));

                unitOfWork.Commit();
            }
        }
Пример #2
0
        public void PersistNewObjectWithLazyReference()
        {
            // Arrange
            Bootstrapper.Start();
            const string Key = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            var repository        = Bootstrapper.AmbientContainer.GetInstance <Repository <TestModel> >();
            var unitOfWorkFactory = Bootstrapper.AmbientContainer.GetInstance <IUnitOfWorkFactory>();
            var unitOfWork        = unitOfWorkFactory.CreateUnitOfWork();

            var testChild = new TestChildModel("FOO");
            var testModel = new TestModel(Key)
            {
                TestChild = testChild
            };

            // Act
            using (unitOfWork.Start())
            {
                Debug.WriteLine(string.Format("A UnitTest in Local.Data exists: {0}", Local.Data["UnitTest"] == null));

                repository.Create(testModel);

                unitOfWork.Commit();

                Debug.WriteLine(string.Format("B UnitTest in Local.Data exists: {0}", Local.Data["UnitTest"] == null));
            }

            // Assert
            using (unitOfWork.Start())
            {
                Debug.WriteLine(string.Format("C UnitTest in Local.Data exists: {0}", Local.Data["UnitTest"] == null));

                var foundModel = repository.Find.OneMatchingExpression(x => x.Key.Equals(Key));

                var blarg = string.CompareOrdinal(foundModel.TestChild.Key, testChild.Key);

                Assert.That(foundModel.TestChild == testChild);

                Debug.WriteLine(string.Format("D UnitTest in Local.Data exists: {0}", Local.Data["UnitTest"] == null));
            }
        }
Пример #3
0
        public void IncrementAndDecrementNestLevelWhenStartingMultipleUnitsOfWorkAcrossMethodsGivenNestingEnabled()
        {
            // Arrange
            Bootstrapper.Start();

            var unitOfWorkFactory = Bootstrapper.AmbientContainer.GetInstance<IUnitOfWorkFactory>();
            var unitOfWork = unitOfWorkFactory.CreateUnitOfWork();
            var repository = Bootstrapper.AmbientContainer.GetInstance<Repository<TestModel>>();

            const string Key = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            var testChildA = new TestChildModel("AAA");
            var testChildB = new TestChildModel("BBB");
            var testChildC = new TestChildModel("CCC");

            var testModel = new TestModel(Key);

            testModel.TestChildren.Add(testChildA);
            testModel.TestChildren.Add(testChildB);
            testModel.TestChildren.Add(testChildC);

            using (unitOfWork.Start())
            {
                repository.Create(testModel);

                unitOfWork.Commit();
            }

            // Act & Assert
            using (unitOfWork.Start())
            {
                Assert.That(unitOfWork.NestLevel.Equals(0));

                this.ParentMethod();

                Assert.That(unitOfWork.NestLevel.Equals(0));
            }
        }
Пример #4
0
		public void PersistNewObjectWithLazyReference()
		{
			// Arrange
			Bootstrapper.Start();
			const string Key = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

			var repository = Bootstrapper.AmbientContainer.GetInstance<Repository<TestModel>>();
			var unitOfWorkFactory = Bootstrapper.AmbientContainer.GetInstance<IUnitOfWorkFactory>();
			var unitOfWork = unitOfWorkFactory.CreateUnitOfWork();

			var testChild = new TestChildModel("FOO");
			var testModel = new TestModel(Key) { TestChild = testChild };

			// Act
			using (unitOfWork.Start())
			{
				Debug.WriteLine(string.Format("A UnitTest in Local.Data exists: {0}", Local.Data["UnitTest"] == null));

				repository.Create(testModel);

				unitOfWork.Commit();

				Debug.WriteLine(string.Format("B UnitTest in Local.Data exists: {0}", Local.Data["UnitTest"] == null));
			}

			// Assert
			using (unitOfWork.Start())
			{
				Debug.WriteLine(string.Format("C UnitTest in Local.Data exists: {0}", Local.Data["UnitTest"] == null));

				var foundModel = repository.Find.OneMatchingExpression(x => x.Key.Equals(Key));

				Assert.That(foundModel.TestChild == testChild);

				Debug.WriteLine(string.Format("D UnitTest in Local.Data exists: {0}", Local.Data["UnitTest"] == null));
			}
		}
Пример #5
0
		public void ReturnAllMatchingObjectsGivenFetch()
		{
			// Arrange
			Bootstrapper.Start();
			const string Key = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

			var repository = Bootstrapper.AmbientContainer.GetInstance<Repository<TestModel>>();
			var unitOfWorkFactory = Bootstrapper.AmbientContainer.GetInstance<IUnitOfWorkFactory>();
			var unitOfWork = unitOfWorkFactory.CreateUnitOfWork();

			var testChildA = new TestChildModel("AAA");
			var testChildB = new TestChildModel("BBB");
			var testChildC = new TestChildModel("CCC");
			
			var testModel = new TestModel(Key);

			testModel.TestChildren.Add(testChildA);
			testModel.TestChildren.Add(testChildB);
			testModel.TestChildren.Add(testChildC);

			// Act
			using (unitOfWork.Start())
			{
				repository.Create(testModel);

				unitOfWork.Commit();
			}

			// Assert
			using (unitOfWork.Start())
			{
				var foundModel = repository.Find.All.Fetch(x => x.TestChildren).ToList();

				Assert.That(foundModel.Count.Equals(1));
			}
		}
Пример #6
0
        public void ReturnAllMatchingObjectsGivenFetch()
        {
            // Arrange
            Bootstrapper.Start();
            const string Key = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            var repository        = Bootstrapper.AmbientContainer.GetInstance <Repository <TestModel> >();
            var unitOfWorkFactory = Bootstrapper.AmbientContainer.GetInstance <IUnitOfWorkFactory>();
            var unitOfWork        = unitOfWorkFactory.CreateUnitOfWork();

            var testChildA = new TestChildModel("AAA");
            var testChildB = new TestChildModel("BBB");
            var testChildC = new TestChildModel("CCC");

            var testModel = new TestModel(Key);

            testModel.TestChildren.Add(testChildA);
            testModel.TestChildren.Add(testChildB);
            testModel.TestChildren.Add(testChildC);

            // Act
            using (unitOfWork.Start())
            {
                repository.Create(testModel);

                unitOfWork.Commit();
            }

            // Assert
            using (unitOfWork.Start())
            {
                var foundModel = repository.Find.All.Fetch(x => x.TestChildren).ToList();

                Assert.That(foundModel.Count.Equals(1));
            }
        }