Пример #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);
                        }
                    }
                }
            }
        }
Пример #2
0
        public void FunctionalLifeSpanTest_ShouldProduceDesiredResults()
        {
            // Arrange.
            var databaseName                = EnhancedReadabilityGuid.New().ToString();
            var configuration               = new ConfigurationBuilder().Build();
            var fibonacciNumberSeriesName   = "Fibonacci";
            var fibonacciNumberSeriesValues = new Int64[] { 0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 };

            using (var context = new PrototypeInMemoryContext(configuration, databaseName).WithTestData())
            {
                using (var numberSeriesRepository = new NumberSeriesRepository(context))
                {
                    // Act.
                    var fibonacciNumberSeries = numberSeriesRepository.FindByName(fibonacciNumberSeriesName);

                    // Assert.
                    fibonacciNumberSeries.Should().NotBeNull();
                    fibonacciNumberSeries.Name.Should().Be(fibonacciNumberSeriesName);

                    using (var numberSeriesNumberRepository = new NumberSeriesNumberRepository(context))
                    {
                        // Act.
                        var fibonacciNumberSeriesNumbers = numberSeriesNumberRepository.FindWhere(entity => entity.NumberSeriesIdentifier == fibonacciNumberSeries.Identifier);
                        var fibonacciNumberIdentifiers   = fibonacciNumberSeriesNumbers.Select(entity => entity.NumberIdentifier);

                        // Assert.
                        fibonacciNumberSeriesNumbers.Should().NotBeNull();
                        fibonacciNumberSeriesNumbers.Count().Should().Be(fibonacciNumberSeriesValues.Length);

                        using (var numberRepository = new NumberRepository(context))
                        {
                            // Act.
                            var fibonacciNumbers = numberRepository.FindWhere(entity => fibonacciNumberIdentifiers.Contains(entity.Identifier)).OrderBy(entity => entity.Value);

                            // Assert.
                            fibonacciNumbers.Select(entity => entity.Value).Should().BeEquivalentTo(fibonacciNumberSeriesValues);
                        }
                    }
                }
            }
        }