public override void Execute(IntegerFactorization entity)
        {
            Logger.SetExecutionId(entity.Id);
            var job = new IntegerFactorizationJob(Logger, _integerFactorizationDataService);

            entity        = _integerFactorizationDataService.Get(entity.Id);
            entity.Status = Status.InProgress;
            _integerFactorizationDataService.Update(entity);
            _integerFactorizationDataService.SaveChanges();

            var result = job.Run(entity.Number);

            if (result.IsSuccess)
            {
                entity.FactorP = result.Factors.P;
                entity.FactorQ = result.Factors.Q;
                entity.Status  = result.HadWarnings ? Status.FinishedWithWarnings : Status.Finished;
            }
            else
            {
                if (entity.Status != Status.Canceled && !entity.Messages.Last().Message.Contains("canceled"))
                {
                    entity.Status = Status.FinishedWithErrors;
                }
            }

            if (entity.FinishTime == null)
            {
                entity.FinishTime = DateTime.Now;
            }

            //_integerFactorizationDataService.Update(entity);
            _integerFactorizationDataService.SaveChanges();
        }
예제 #2
0
        public void RunTest_2()
        {
            var dataService = new Mock <IDataService <IntegerFactorization> >();
            var logger      = new Mock <IExecutionLogger>();
            var job         = new IntegerFactorizationJob(logger.Object, dataService.Object);

            var result = job.Run(8);

            Assert.AreEqual(2, result.Factors.P);
            Assert.AreEqual(4, result.Factors.Q);
            Assert.AreEqual(false, result.HadWarnings);
            Assert.AreEqual(true, result.IsSuccess);
        }
예제 #3
0
        public void RunTest_1()
        {
            var dataService = new Mock <IDataService <IntegerFactorization> >();
            var logger      = new Mock <IExecutionLogger>();
            var job         = new IntegerFactorizationJob(logger.Object, dataService.Object);

            for (var i = 0; i < 10; ++i)
            {
                try
                {
                    var result = job.Run(15);
                    Assert.AreEqual(15, result.Factors.P * result.Factors.Q);
                }
                catch (InvalidOperationException)
                {
                }
            }
        }