/// <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> protected override void Process(AddFibonacciNumberCommand command, IFactoryProducedInstanceGroup repositories, IDataAccessTransaction transaction, ConcurrencyControlToken controlToken) { var fibonacciNumberSeries = NumberSeries.Named.Fibonacci; var numberRepository = repositories.Get <NumberRepository>(); var number = numberRepository.FindByValue(command.NumberValue); if (number is null) { number = new Number() { Identifier = Guid.NewGuid(), Value = command.NumberValue }; numberRepository.Add(number); } var numberSeriesNumberRespository = repositories.Get <NumberSeriesNumberRepository>(); var numberSeriesNumber = numberSeriesNumberRespository.FindWhere(entity => entity.Number.Value == number.Value && entity.NumberSeriesIdentifier == fibonacciNumberSeries.Identifier).SingleOrDefault(); if (numberSeriesNumber is null) { numberSeriesNumber = new NumberSeriesNumber() { Identifier = Guid.NewGuid(), Number = number, NumberIdentifier = number.Identifier, NumberSeriesIdentifier = fibonacciNumberSeries.Identifier }; numberSeriesNumberRespository.Add(numberSeriesNumber); } }
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); }