public void GetEntity()
        {
            Expression <Func <Person, bool> > isabelleExpression = p => p.Id == Names.IsabelleOsborne;

            var recorder = new InMemoryRecordedRepository(Persons);

            //recorder.GetEntity<Person>(params IQueryStrategy[] queryStrategies);
            CallAndAssertGetEntity(() => recorder.GetEntity <Person>(isabelleExpression), recorder, defaultQueryStrategy: typeof(AggregateQueryStrategy));

            //recorder.GetEntity<Person>(ISpecificationQueryStrategy<T> specification);
            CallAndAssertGetEntity(() => recorder.GetEntity <Person>(ExpressionSpecificationStrategy), recorder);

            //recorder.GetEntity<Person>(Expression<Func<T, bool>> predicate, bool throwExceptionIfZeroOrManyFound);
            CallAndAssertGetEntity(() => recorder.GetEntity <Person>(ExpressionSpecificationStrategy, false), recorder, throwSearchException: false);

            //recorder.GetEntity<Person>(Expression<Func<T, bool>> predicate, IQueryStrategy queryStrategy, bool throwExceptionIfZeroOrManyFound);
            CallAndAssertGetEntity(() => recorder.GetEntity <Person>(isabelleExpression, new OrderByQueryStrategy <Person>(), false), recorder, queryStrategy: typeof(OrderByQueryStrategy <Person>), throwSearchException: false);

            //recorder.GetEntity<Person>(Expression<Func<T, bool>> predicate, params IQueryStrategy[] queryStrategies);
            CallAndAssertGetEntity(() => recorder.GetEntity <Person>(isabelleExpression, new OrderByQueryStrategy <Person>(), new OrderByQueryStrategy <Person>()), recorder, queryStrategy: typeof(AggregateQueryStrategy));

            //recorder.GetEntity<Person>(ISpecificationQueryStrategy<T> specification, bool throwExceptionIfZeroOrManyFound);
            CallAndAssertGetEntity(() => recorder.GetEntity <Person>(ExpressionSpecificationStrategy, false), recorder, throwSearchException: false);

            //recorder.GetEntity<Person>(ISpecificationQueryStrategy<T> specification, IQueryStrategy queryStrategy, bool throwExceptionIfZeroOrManyFound);
            CallAndAssertGetEntity(() => recorder.GetEntity <Person>(ExpressionSpecificationStrategy, new OrderByQueryStrategy <Person>(), false), recorder, queryStrategy: typeof(OrderByQueryStrategy <Person>), throwSearchException: false);

            //recorder.GetEntity<Person>(ISpecificationQueryStrategy<T> specification, params IQueryStrategy[] queryStrategies);
            CallAndAssertGetEntity(() => recorder.GetEntity <Person>(ExpressionSpecificationStrategy, new OrderByQueryStrategy <Person>(), new OrderByQueryStrategy <Person>()), recorder, queryStrategy: typeof(AggregateQueryStrategy));

            // public T GetEntity<T>(params IQueryStrategy[] queryStrategies) where T : class
            CallAndAssertGetEntity(() => recorder.GetEntity <Person>(new OrderByQueryStrategy <Person>(), new OrderByQueryStrategy <Person>()), recorder, specificationStrategy: typeof(DefaultSpecificationQueryStrategy <Person>), queryStrategy: typeof(AggregateQueryStrategy), expectException: true);
        }
        public void GetEntities()
        {
            Expression <Func <Parent, bool> > isabelleExpression = p => p.Id == Names.IsabelleOsborne;
            // var additionalQueryData = "DummyData";

            var recorder         = new InMemoryRecordedRepository(Persons);
            var reverseStrategy  = new MaterialiseQueryStrategy();
            var reverseStrategy2 = new MaterialiseQueryStrategy();

            //public IQueryable<T> GetEntities<T>();
            CallAndAssertGetEntities(() => recorder.GetEntities <Person>(), recorder, specificationStrategy: DefaultSpecificationStrategyType, expectedCount: 11);
            CallAndAssertGetEntities(() => recorder.GetEntities <Child>(), recorder, specificationStrategy: typeof(DefaultSpecificationQueryStrategy <Child>), expectedCount: 5);

            //public IQueryable<T> GetEntities<T>(object additionalQueryData);
            //  CallAndAssertGetEntities(() => recorder.GetEntities<Parent>(additionalQueryData), recorder, specificationStrategy: typeof(DefaultSpecificationQueryStrategy<Parent>), additionalQueryData: additionalQueryData);

            //public IQueryable<T> GetEntities<T>(params IQueryStrategy[] queryStrategy);
            CallAndAssertGetEntities(() => recorder.GetEntities <Parent>(reverseStrategy, reverseStrategy2), recorder, specificationStrategy: typeof(DefaultSpecificationQueryStrategy <Parent>), queryStrategy: typeof(AggregateQueryStrategy));

            //public IQueryable<T> GetEntities<T>(Expression<Func<T, bool>> predicate);
            CallAndAssertGetEntities(() => recorder.GetEntities <Parent>(isabelleExpression), recorder, expectedCount: 1);

            //public IQueryable<T> GetEntities<T>(Expression<Func<T, bool>> predicate, params IQueryStrategy[] queryStrategies);
            CallAndAssertGetEntities(() => recorder.GetEntities <Parent>(isabelleExpression, reverseStrategy, reverseStrategy2), recorder, queryStrategy: typeof(AggregateQueryStrategy), expectedCount: 1);

            //public IQueryable<T> GetEntities<T>(ISpecificationQueryStrategy<T> specification);
            CallAndAssertGetEntities(() => recorder.GetEntities <Parent>(ParentExpressionSpecificationStrategy), recorder, expectedCount: 1);

            //public IQueryable<T> GetEntities<T>(ISpecificationQueryStrategy<T> specification, params IQueryStrategy[] queryStrategies);
            CallAndAssertGetEntities(() => recorder.GetEntities <Parent>(ParentExpressionSpecificationStrategy, reverseStrategy, reverseStrategy2), recorder, queryStrategy: typeof(AggregateQueryStrategy), expectedCount: 1);

            //public IQueryable<T> GetEntities<T>(object additionalQueryData, ISpecificationQueryStrategy<T> specification, params IQueryStrategy[] queryStrategies);
            CallAndAssertGetEntities(() => recorder.GetEntities <Parent>(ParentExpressionSpecificationStrategy, reverseStrategy, reverseStrategy2), recorder, queryStrategy: typeof(AggregateQueryStrategy), expectedCount: 1);
        }
        public void GetEntity()
        {
            Expression<Func<Person, bool>> isabelleExpression = p => p.Id == Names.IsabelleOsborne;

            var recorder = new InMemoryRecordedRepository(Persons);

            //recorder.GetEntity<Person>(params IQueryStrategy[] queryStrategies);
            CallAndAssertGetEntity(() => recorder.GetEntity<Person>(isabelleExpression), recorder, defaultQueryStrategy: typeof(AggregateQueryStrategy));

            //recorder.GetEntity<Person>(ISpecificationQueryStrategy<T> specification);
            CallAndAssertGetEntity(() => recorder.GetEntity<Person>(ExpressionSpecificationStrategy), recorder);

            //recorder.GetEntity<Person>(Expression<Func<T, bool>> predicate, bool throwExceptionIfZeroOrManyFound);
            CallAndAssertGetEntity(() => recorder.GetEntity<Person>(ExpressionSpecificationStrategy, false), recorder, throwSearchException: false);

            //recorder.GetEntity<Person>(Expression<Func<T, bool>> predicate, IQueryStrategy queryStrategy, bool throwExceptionIfZeroOrManyFound);
            CallAndAssertGetEntity(() => recorder.GetEntity<Person>(isabelleExpression, new OrderByQueryStrategy<Person>(), false), recorder, queryStrategy: typeof(OrderByQueryStrategy<Person>), throwSearchException: false);

            //recorder.GetEntity<Person>(Expression<Func<T, bool>> predicate, params IQueryStrategy[] queryStrategies);
            CallAndAssertGetEntity(() => recorder.GetEntity<Person>(isabelleExpression, new OrderByQueryStrategy<Person>(), new OrderByQueryStrategy<Person>()), recorder, queryStrategy: typeof(AggregateQueryStrategy));

            //recorder.GetEntity<Person>(ISpecificationQueryStrategy<T> specification, bool throwExceptionIfZeroOrManyFound);
            CallAndAssertGetEntity(() => recorder.GetEntity<Person>(ExpressionSpecificationStrategy, false), recorder, throwSearchException: false);

            //recorder.GetEntity<Person>(ISpecificationQueryStrategy<T> specification, IQueryStrategy queryStrategy, bool throwExceptionIfZeroOrManyFound);
            CallAndAssertGetEntity(() => recorder.GetEntity<Person>(ExpressionSpecificationStrategy, new OrderByQueryStrategy<Person>(), false), recorder, queryStrategy: typeof(OrderByQueryStrategy<Person>), throwSearchException: false);

            //recorder.GetEntity<Person>(ISpecificationQueryStrategy<T> specification, params IQueryStrategy[] queryStrategies);
            CallAndAssertGetEntity(() => recorder.GetEntity<Person>(ExpressionSpecificationStrategy, new OrderByQueryStrategy<Person>(), new OrderByQueryStrategy<Person>()), recorder, queryStrategy: typeof(AggregateQueryStrategy));

            // public T GetEntity<T>(params IQueryStrategy[] queryStrategies) where T : class
            CallAndAssertGetEntity(() => recorder.GetEntity<Person>(new OrderByQueryStrategy<Person>(), new OrderByQueryStrategy<Person>()), recorder, specificationStrategy: typeof(DefaultSpecificationQueryStrategy<Person>), queryStrategy: typeof(AggregateQueryStrategy), expectException: true);
        }
Пример #4
0
        public void WhenCourseCreateIsCalledThenIExpectItToDoSomething()
        {
            // Arrange
            var repository = new InMemoryRecordedRepository();

            // Act
            var request  = CreateValidRequest();
            var response = CourseHandlers.Handle(repository, request);

            // Assert
            response.HasValidationIssues.ShouldEqual(false);

            var events = repository.CommandRepository.CommandEvents;
            var course = (Course)events.AddedEvents.First().Entity;

            course.CourseID.ShouldEqual(request.CommandModel.CourseID);
            course.Credits.ShouldEqual(request.CommandModel.Credits);
            course.DepartmentID.ShouldEqual(request.CommandModel.DepartmentID);
            course.Title.ShouldEqual(request.CommandModel.Title);

            events.SavedEvents.Count.ShouldEqual(1);
            events.ModifiedEvents.Count.ShouldEqual(0);
            events.DeletedEvents.Count.ShouldEqual(0);
            events.AddedEvents.Count.ShouldEqual(1);
        }
        public void GetEntities()
        {
            Expression<Func<Parent, bool>> isabelleExpression = p => p.Id == Names.IsabelleOsborne;
            // var additionalQueryData = "DummyData";

            var recorder = new InMemoryRecordedRepository(Persons);
            var reverseStrategy = new MaterialiseQueryStrategy();
            var reverseStrategy2 = new MaterialiseQueryStrategy();

            //public IQueryable<T> GetEntities<T>();
            CallAndAssertGetEntities(() => recorder.GetEntities<Person>(), recorder, specificationStrategy: DefaultSpecificationStrategyType, expectedCount: 11);
            CallAndAssertGetEntities(() => recorder.GetEntities<Child>(), recorder, specificationStrategy: typeof(DefaultSpecificationQueryStrategy<Child>), expectedCount: 5);

            //public IQueryable<T> GetEntities<T>(object additionalQueryData);
            //  CallAndAssertGetEntities(() => recorder.GetEntities<Parent>(additionalQueryData), recorder, specificationStrategy: typeof(DefaultSpecificationQueryStrategy<Parent>), additionalQueryData: additionalQueryData);

            //public IQueryable<T> GetEntities<T>(params IQueryStrategy[] queryStrategy);
            CallAndAssertGetEntities(() => recorder.GetEntities<Parent>(reverseStrategy, reverseStrategy2), recorder, specificationStrategy: typeof(DefaultSpecificationQueryStrategy<Parent>), queryStrategy: typeof(AggregateQueryStrategy));

            //public IQueryable<T> GetEntities<T>(Expression<Func<T, bool>> predicate);
            CallAndAssertGetEntities(() => recorder.GetEntities<Parent>(isabelleExpression), recorder, expectedCount: 1);

            //public IQueryable<T> GetEntities<T>(Expression<Func<T, bool>> predicate, params IQueryStrategy[] queryStrategies);
            CallAndAssertGetEntities(() => recorder.GetEntities<Parent>(isabelleExpression, reverseStrategy, reverseStrategy2), recorder, queryStrategy: typeof(AggregateQueryStrategy), expectedCount: 1);

            //public IQueryable<T> GetEntities<T>(ISpecificationQueryStrategy<T> specification);
            CallAndAssertGetEntities(() => recorder.GetEntities<Parent>(ParentExpressionSpecificationStrategy), recorder, expectedCount: 1);

            //public IQueryable<T> GetEntities<T>(ISpecificationQueryStrategy<T> specification, params IQueryStrategy[] queryStrategies);
            CallAndAssertGetEntities(() => recorder.GetEntities<Parent>(ParentExpressionSpecificationStrategy, reverseStrategy, reverseStrategy2), recorder, queryStrategy: typeof(AggregateQueryStrategy), expectedCount: 1);

            //public IQueryable<T> GetEntities<T>(object additionalQueryData, ISpecificationQueryStrategy<T> specification, params IQueryStrategy[] queryStrategies);
            CallAndAssertGetEntities(() => recorder.GetEntities<Parent>(ParentExpressionSpecificationStrategy, reverseStrategy, reverseStrategy2), recorder, queryStrategy: typeof(AggregateQueryStrategy), expectedCount: 1);

        }
        public void WhenUpdateCourseIsCalledThenIExpectItToDoSomething()
        {
            // Arrange
            var repository = new InMemoryRecordedRepository();
            var factory = new UpdateCourseHandlerFactory();
            factory._SetRepository(repository);

            // Act
            var request = CreateValidRequest();
            var response = factory.Object.Handle(request);

            // Assert
            response.HasValidationIssues.ShouldEqual(false);

            // Check modified entity
            var events = repository.CommandRepository.CommandEvents;
            var course = (Course)events.ModifiedEvents.First().Entity;
            course.CourseID.ShouldEqual(request.CommandModel.CourseID);
            course.Credits.ShouldEqual(request.CommandModel.Credits);
            course.DepartmentID.ShouldEqual(request.CommandModel.DepartmentID);
            course.Title.ShouldEqual(request.CommandModel.Title);

            events.SavedEvents.Count.ShouldEqual(1);
            events.ModifiedEvents.Count.ShouldEqual(1);
            events.DeletedEvents.Count.ShouldEqual(0);
            events.AddedEvents.Count.ShouldEqual(0);
        }
        public void CheckValidationRules()
        {
            Func<CountryCreate.Request, ValidationMessageCollection> CallSut = request =>
            {
                var inMemoryRepository = new InMemoryRecordedRepository();
                var reponse = CountryHandlers.Handle(inMemoryRepository, request);
                return reponse.ValidationDetails;
            };

            var invalidRequest = CreateValidRequest(p => p.CommandModel.Name = "China", p => p.CommandModel.Population = 9);
            Assert2.CheckContextualValidation("Population", "Really? I think we all know China has a bigger population than that.", () => CallSut(invalidRequest));
        }
        public void WhenCourseUpdateCreditsIsCalledThenIExpectItToDoSomething()
        {
            var efTestExtensions = new EfRepositoryTestExtension();
            EntityFrameworkRepositoryExtensions.SetDefaultImplementation(efTestExtensions);

            // Arrange
            var repository = new InMemoryRecordedRepository();

            // Act
            var request = CreateValidRequest();
            var response = CourseHandlers.Handle(repository, request);

            // Assert
            response.HasValidationIssues.ShouldEqual(false);

            efTestExtensions.ExecuteStoredProcudureCallCount.ShouldEqual(1);
        }
        public void WhenCourseUpdateCreditsIsCalledThenIExpectItToDoSomething()
        {
            var efTestExtensions = new EfRepositoryTestExtension();

            EntityFrameworkRepositoryExtensions.SetDefaultImplementation(efTestExtensions);

            // Arrange
            var repository = new InMemoryRecordedRepository();

            // Act
            var request  = CreateValidRequest();
            var response = CourseHandlers.Handle(repository, request);

            // Assert
            response.HasValidationIssues.ShouldEqual(false);

            efTestExtensions.ExecuteStoredProcudureCallCount.ShouldEqual(1);
        }
        private IEnumerable <Person> CallAndAssertGetEntities(
            Func <IQueryable <Person> > getEntities,
            InMemoryRecordedRepository recorder,
            Type specificationStrategy = null,
            Type queryStrategy         = null,
            object additionalQueryData = null,
            int expectedCount          = 6)
        {
            var persons = default(IEnumerable <Person>);

            persons = getEntities.Invoke().ToList();
            persons.Count().ShouldEqual(expectedCount);

            var qEvent = (SimpleRepositoryQueryEvent)recorder.QueryRepository.QueryEvents.Single();

            //            qEvent.QueryStrategy.GetType().ShouldEqual(queryStrategy ?? typeof(DefaultQueryStrategy));
            qEvent.AdditionalQueryData.ShouldEqual(additionalQueryData);

            recorder.QueryRepository.QueryEvents.Clear();
            return(persons);
        }
        public void WhenCourseDeleteIsCalledThenIExpectItToDoSomething()
        {
            // Arrange
            var repository = new InMemoryRecordedRepository();

            // Act
            var request = CreateValidRequest();
            var response = CourseHandlers.Handle(repository, request);

            // Assert
            response.HasValidationIssues.ShouldEqual(false);

            var events = repository.CommandRepository.CommandEvents;
            var course = (Course)events.DeletedEvents.First().Entity;
            course.CourseID.ShouldEqual(request.CommandModel.CourseId);

            events.SavedEvents.Count.ShouldEqual(1);
            events.ModifiedEvents.Count.ShouldEqual(0);
            events.DeletedEvents.Count.ShouldEqual(1);
            events.AddedEvents.Count.ShouldEqual(0);
        }
        private Person CallAndAssertGetEntity(
            Func <Person> getEntity,
            InMemoryRecordedRepository recorder,
            Type specificationStrategy = null,
            Type queryStrategy         = null,
            bool throwSearchException  = true,
            object additionalQueryData = null,
            bool expectException       = false,
            Type defaultQueryStrategy  = null)
        {
            if (defaultQueryStrategy == null)
            {
                defaultQueryStrategy = typeof(DefaultQueryStrategy);
            }

            var person = default(Person);

            try
            {
                person = getEntity.Invoke();
                person.Id.ShouldEqual(Persons.Cast <Person>().Single(p => p.Id == Names.IsabelleOsborne).Id);
                expectException.ShouldEqual(false);
            }
            catch (EntitySearchRepositoryException)
            {
                expectException.ShouldEqual(true);
            }

            var qEvent = (SimpleRepositoryQueryEvent)recorder.QueryRepository.QueryEvents.Single();

            qEvent.ThrowExceptionIfZeroOrManyFound.ShouldEqual(throwSearchException);
            //            qEvent.QueryStrategy.GetType().ShouldEqual(queryStrategy ?? defaultQueryStrategy);
            qEvent.AdditionalQueryData.ShouldEqual(additionalQueryData);

            recorder.QueryRepository.QueryEvents.Clear();
            return(person);
        }
        public void CheckEntitySearchRepositoryExceptionThrown()
        {
            var recorder = new InMemoryRecordedRepository(Persons);

            CallAndAssertGetEntity(() => recorder.GetEntity <Person>(p => p.FirstName == "NotFound"), recorder, expectException: true, defaultQueryStrategy: typeof(AggregateQueryStrategy));
        }
 public void CheckEntitySearchRepositoryExceptionThrown()
 {
     var recorder = new InMemoryRecordedRepository(Persons);
     CallAndAssertGetEntity(() => recorder.GetEntity<Person>(p => p.FirstName == "NotFound"), recorder, expectException: true, defaultQueryStrategy: typeof(AggregateQueryStrategy));
 }
        private IEnumerable<Person> CallAndAssertGetEntities(
            Func<IQueryable<Person>> getEntities,
            InMemoryRecordedRepository recorder,
            Type specificationStrategy = null,
            Type queryStrategy = null,
            object additionalQueryData = null,
            int expectedCount = 6)
        {
            var persons = default(IEnumerable<Person>);

            persons = getEntities.Invoke().ToList();
            persons.Count().ShouldEqual(expectedCount);

            var qEvent = (SimpleRepositoryQueryEvent)recorder.QueryRepository.QueryEvents.Single();
            //            qEvent.QueryStrategy.GetType().ShouldEqual(queryStrategy ?? typeof(DefaultQueryStrategy));
            qEvent.AdditionalQueryData.ShouldEqual(additionalQueryData);

            recorder.QueryRepository.QueryEvents.Clear();
            return persons;
        }
        private Person CallAndAssertGetEntity(
            Func<Person> getEntity,
            InMemoryRecordedRepository recorder,
            Type specificationStrategy = null,
            Type queryStrategy = null,
            bool throwSearchException = true,
            object additionalQueryData = null,
            bool expectException = false,
            Type defaultQueryStrategy = null)
        {
            if (defaultQueryStrategy == null)
                defaultQueryStrategy = typeof(DefaultQueryStrategy);

            var person = default(Person);
            try
            {
                person = getEntity.Invoke();
                person.Id.ShouldEqual(Persons.Cast<Person>().Single(p => p.Id == Names.IsabelleOsborne).Id);
                expectException.ShouldEqual(false);
            }
            catch (EntitySearchRepositoryException)
            {
                expectException.ShouldEqual(true);
            }

            var qEvent = (SimpleRepositoryQueryEvent)recorder.QueryRepository.QueryEvents.Single();
            qEvent.ThrowExceptionIfZeroOrManyFound.ShouldEqual(throwSearchException);
            //            qEvent.QueryStrategy.GetType().ShouldEqual(queryStrategy ?? defaultQueryStrategy);
            qEvent.AdditionalQueryData.ShouldEqual(additionalQueryData);

            recorder.QueryRepository.QueryEvents.Clear();
            return person;
        }