コード例 #1
0
        internal PrototypeInMemoryContext WithTestData()
        {
            var fibonacciNumberSeriesValues = new Int64[] { 0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 };

            using (var numberRepository = new NumberRepository(this))
            {
                for (var i = 0; i <= 100; i++)
                {
                    var number = new Number()
                    {
                        Identifier = Guid.NewGuid(),
                        Value      = i
                    };

                    numberRepository.Add(number);
                }

                SaveChanges();

                using (var numberSeriesRepository = new NumberSeriesRepository(this))
                {
                    numberSeriesRepository.Add(NumberSeries.Named.Fibonacci);
                    SaveChanges();

                    using (var numberSeriesNumberRepository = new NumberSeriesNumberRepository(this))
                    {
                        var fibonacciNumbers = numberRepository.FindWhere(entity => fibonacciNumberSeriesValues.Contains(entity.Value));

                        foreach (var fibonacciNumber in fibonacciNumbers)
                        {
                            var fibonacciNumberSeriesNumber = new NumberSeriesNumber()
                            {
                                Identifier             = Guid.NewGuid(),
                                NumberIdentifier       = fibonacciNumber.Identifier,
                                NumberSeriesIdentifier = NumberSeries.Named.Fibonacci.Identifier
                            };

                            numberSeriesNumberRepository.Add(fibonacciNumberSeriesNumber);
                        }

                        SaveChanges();
                    }
                }
            }

            return(this);
        }
コード例 #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);
                        }
                    }
                }
            }
        }