Пример #1
0
        public void FunctionalLifeSpanTest_ShouldProduceDesiredResults()
        {
            // Arrange.
            var package              = new SimulatedAutofacDependencyPackage();
            var databaseName         = EnhancedReadabilityGuid.New().ToString();
            var configurationBuilder = new ConfigurationBuilder();
            var configuration        = configurationBuilder.Build();
            var scope                       = (IDependencyScope)null;
            var commandMediator             = (ICommandMediator)null;
            var command                     = new GetFibonacciNumberValuesCommand();
            var fibonacciNumberSeriesValues = new Int64[] { 0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 };

            using (var engine = package.CreateEngine(configuration))
            {
                // Arrange.
                scope           = engine.Container.CreateScope();
                commandMediator = scope.Resolve <ICommandMediator>();

                using (var context = new PrototypeInMemoryContext(configuration, databaseName).WithTestData())
                {
                    using (var repositoryFactory = new PrototypeRepositoryFactory(configuration, context))
                    {
                        using (var commandHandler = new GetFibonacciNumberValuesCommandHandler(commandMediator, repositoryFactory))
                        {
                            // Act.
                            var result = commandHandler.Process(command);

                            // Assert.
                            result.Should().BeEquivalentTo(fibonacciNumberSeriesValues);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Processes the specified command.
        /// </summary>
        /// <param name="command">
        /// The command to process.
        /// </param>
        /// <param name="repositories">
        /// An object that provides access to data access repositories.
        /// </param>
        /// <param name="transaction">
        /// A transaction that is used to process the command.
        /// </param>
        /// <param name="controlToken">
        /// A token that ensures thread safety for the operation.
        /// </param>
        /// <returns>
        /// The result that is emitted when processing the command.
        /// </returns>
        protected sealed override IEnumerable <Int64> Process(GetFibonacciNumberValuesCommand command, IFactoryProducedInstanceGroup repositories, IDataAccessTransaction transaction, ConcurrencyControlToken controlToken)
        {
            var numberSeriesNumberRepository = repositories.Get <NumberSeriesNumberRepository>();

            return(numberSeriesNumberRepository.FindWhere(entity => entity.NumberSeries.Identifier == NumberSeries.Named.Fibonacci.Identifier).Select(entity => entity.Number.Value).ToList());
        }