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

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

            var testModel01 = new TestModel("ABCDEF");
            var testModel02 = new TestModel("HIJKLM");
            var testModel03 = new TestModel("ABCXYZ");

            // Act
            using (unitOfWork.Start())
            {
                repository.Create(testModel01);
                repository.Create(testModel02);
                repository.Create(testModel03);

                unitOfWork.Commit();
            }

            // Assert
            using (unitOfWork.Start())
            {
                var foundModel = repository.Find.AllMatchingSpecification(TestModelSpecifications.TestPropertyStartsWithABCAndEndsWithXYZ()).ToList();

                Assert.That(foundModel.Count.Equals(1));
            }
        }
Пример #2
0
        public void ReturnsEmptyEnumerationGivenNoMatchingObjects()
        {
            // Arrange
            Bootstrapper.Start();

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

            var testModel01 = new TestModel("BLARG");
            var testModel02 = new TestModel("BENNY");
            var testModel03 = new TestModel("BOOFY");

            // Act
            using (unitOfWork.Start())
            {
                repository.Create(testModel01);
                repository.Create(testModel02);
                repository.Create(testModel03);

                unitOfWork.Commit();
            }

            // Assert
            using (unitOfWork.Start())
            {
                var foundModel = repository.Find.AllMatchingSpecification(TestModelSpecifications.TestPropertyStartsWithABC());

                Assert.That(!foundModel.Any());
            }
        }