Beispiel #1
0
 public CurrencyService(
     IDatabaseScope database,
     IGenericRepository <Entities.Currency> currencyRepository
     ) : base(database, currencyRepository)
 {
     _currencyReposiotry = currencyRepository;
 }
Beispiel #2
0
        public void MigrationCanAddPostMigration()
        {
            IMigrationBuilder builder = Mock.Of <IMigrationBuilder>();

            Mock.Get(builder)
            .Setup(x => x.Build(It.IsAny <Type>(), It.IsAny <IMigrationContext>()))
            .Returns <Type, IMigrationContext>((t, c) =>
            {
                switch (t.Name)
                {
                case nameof(NoopMigration):
                    return(new NoopMigration(c));

                case nameof(TestMigration):
                    return(new TestMigration(c));

                case nameof(TestPostMigration):
                    return(new TestPostMigration(c));

                default:
                    throw new NotSupportedException();
                }
            });

            var            database = new TestDatabase();
            IDatabaseScope scope    = Mock.Of <IDatabaseScope>(x => x.Notifications == Mock.Of <IScopedNotificationPublisher>());

            Mock.Get(scope)
            .Setup(x => x.Database)
            .Returns(database);

            var sqlContext = new SqlContext(
                new SqlServerSyntaxProvider(Options.Create(new GlobalSettings())),
                DatabaseType.SQLCe,
                Mock.Of <IPocoDataFactory>());
            var scopeProvider = new MigrationTests.TestScopeProvider(scope)
            {
                SqlContext = sqlContext
            };

            MigrationPlan plan = new MigrationPlan("Test")
                                 .From(string.Empty).To <TestMigration>("done");

            TestMigration.MigrateCount     = 0;
            TestPostMigration.MigrateCount = 0;

            new MigrationContext(plan, database, s_loggerFactory.CreateLogger <MigrationContext>());

            var upgrader = new Upgrader(plan);
            IMigrationPlanExecutor executor = GetMigrationPlanExecutor(scopeProvider, scopeProvider, builder);

            upgrader.Execute(
                executor,
                scopeProvider,
                Mock.Of <IKeyValueService>());

            Assert.AreEqual(1, TestMigration.MigrateCount);
            Assert.AreEqual(1, TestPostMigration.MigrateCount);
        }
        public ITransactionScope TransactionScope()
        {
            if (_scope == null || _scope.IsDisposed)
            {
                _scope = _factory.Create(true);
            }

            return(_scope);
        }
        public IConnectionScope Scope()
        {
            if (_scope == null || _scope.IsDisposed)
            {
                _scope = _factory.Create(false);
            }

            return(_scope);
        }
Beispiel #5
0
 public CountryService(IDatabaseScope database,
                       CurrentUserInfo currentUser,
                       IGenericRepository <Entities.Country> countriesRepository,
                       IGenericRepository <Entities.UserCountry> userCountryRepository)
     : base(database, countriesRepository)
 {
     _currentUser           = currentUser;
     _countriesRepository   = countriesRepository;
     _userCountryRepository = userCountryRepository;
 }
Beispiel #6
0
 public AuthenticationService(IDatabaseScope database,
                              IGenericRepository <Entities.User> userRepository,
                              CryptographyService cryptographyService,
                              EmailService emailService,
                              ITokenProvider tokenProvider)
 {
     _database            = database;
     _userRepository      = userRepository;
     _cryptographyService = cryptographyService;
     _emailService        = emailService;
     _tokenProvider       = tokenProvider;
 }
Beispiel #7
0
 public UserService(
     IDatabaseScope database,
     IGenericRepository <Entities.User> userRepository,
     IGenericRepository <Entities.Role> roleRepository,
     IGenericRepository <Entities.Country> countryRepository,
     IGenericRepository <Entities.Currency> currencyRepository)
 {
     _database           = database;
     _userRepository     = userRepository;
     _roleRepository     = roleRepository;
     _countryRepository  = countryRepository;
     _currencyRepository = currencyRepository;
 }
Beispiel #8
0
        public SeedService(IDatabaseScope database,
                           IGenericRepository <Currency> currencyRepository,
                           IGenericRepository <Role> roleRepository,
                           IGenericRepository <User> userRepository,
                           IGenericRepository <EmailTemplate> emailTemplateRepository,
                           //IGenericRepository<Settings> settingsRepository,
                           CryptographyService cryptographyService)
        {
            _database                = database;
            _currencyRepository      = currencyRepository;
            _roleRepository          = roleRepository;
            _userRepository          = userRepository;
            _cryptographyService     = cryptographyService;
            _emailTemplateRepository = emailTemplateRepository;
            //_settingsRepository = settingsRepository;

            allRoles = new Dictionary <string, Role>();
        }
Beispiel #9
0
        public ContentNodeKit GetMediaSource(IDatabaseScope scope, int id)
        {
            var sql = SqlMediaSourcesSelect()
                      .Append(SqlObjectTypeNotTrashed(SqlContext, Constants.ObjectTypes.Media))
                      .Append(SqlWhereNodeId(SqlContext, id))
                      .Append(SqlOrderByLevelIdSortOrder(scope.SqlContext));

            var dto = scope.Database.Fetch <ContentSourceDto>(sql).FirstOrDefault();

            if (dto == null)
            {
                return(ContentNodeKit.Empty);
            }

            var serializer = _contentCacheDataSerializerFactory.Create(ContentCacheDataSerializerEntityType.Media);

            return(CreateMediaNodeKit(dto, serializer));
        }
Beispiel #10
0
        public static MeasurementResult Measure(IDatabaseScope scope, int totalCycles)
        {
            var firstSession = scope.OpenSession();

            firstSession.Dispose();

            long totalTicks = 0;

            for (int i = 0; i < totalCycles; i++)
            {
                var watch = Stopwatch.StartNew();

                scope.OpenSession();
                scope.Dispose();

                watch.Stop();

                totalTicks += watch.Elapsed.Ticks;
            }

            var result = new MeasurementResult(totalTicks, totalCycles);

            return(result);
        }
 public PersistedGrantStore(IDatabaseScope database, IGenericRepository <Grant> entityRepository)
 {
     _database         = database;
     _entityRepository = entityRepository;
 }
 public UserStore(IDatabaseScope database, IGenericRepository <User> entityRepository)
 {
     _database         = database;
     _entityRepository = entityRepository;
 }
Beispiel #13
0
        public void CanExecute()
        {
            NullLoggerFactory loggerFactory = NullLoggerFactory.Instance;

            var            database = new TestDatabase();
            IDatabaseScope scope    = Mock.Of <IDatabaseScope>(x => x.Notifications == Mock.Of <IScopedNotificationPublisher>());

            Mock.Get(scope)
            .Setup(x => x.Database)
            .Returns(database);

            var sqlContext    = new SqlContext(new SqlServerSyntaxProvider(Options.Create(new GlobalSettings())), DatabaseType.SQLCe, Mock.Of <IPocoDataFactory>());
            var scopeProvider = new MigrationTests.TestScopeProvider(scope)
            {
                SqlContext = sqlContext
            };

            IMigrationBuilder migrationBuilder = Mock.Of <IMigrationBuilder>();

            Mock.Get(migrationBuilder)
            .Setup(x => x.Build(It.IsAny <Type>(), It.IsAny <IMigrationContext>()))
            .Returns <Type, IMigrationContext>((t, c) =>
            {
                switch (t.Name)
                {
                case "DeleteRedirectUrlTable":
                    return(new DeleteRedirectUrlTable(c));

                case "NoopMigration":
                    return(new NoopMigration(c));

                default:
                    throw new NotSupportedException();
                }
            });

            var executor = new MigrationPlanExecutor(scopeProvider, scopeProvider, loggerFactory, migrationBuilder);

            MigrationPlan plan = new MigrationPlan("default")
                                 .From(string.Empty)
                                 .To <DeleteRedirectUrlTable>("{4A9A1A8F-0DA1-4BCF-AD06-C19D79152E35}")
                                 .To <NoopMigration>("VERSION.33");

            IKeyValueService kvs = Mock.Of <IKeyValueService>();

            Mock.Get(kvs).Setup(x => x.GetValue(It.IsAny <string>()))
            .Returns <string>(k => k == "Umbraco.Tests.MigrationPlan" ? string.Empty : null);

            string state;

            using (IScope s = scopeProvider.CreateScope())
            {
                // read current state
                var sourceState = kvs.GetValue("Umbraco.Tests.MigrationPlan") ?? string.Empty;

                // execute plan
                state = executor.Execute(plan, sourceState);

                // save new state
                kvs.SetValue("Umbraco.Tests.MigrationPlan", sourceState, state);

                s.Complete();
            }

            Assert.AreEqual("VERSION.33", state);
            Assert.AreEqual(1, database.Operations.Count);
            Assert.AreEqual("DROP TABLE [umbracoRedirectUrl]", database.Operations[0].Sql);
        }
Beispiel #14
0
 public UserService(IGenericRepository <Entities.User> genericRepository, IDatabaseScope databaseScope, IMapper mapper)
 {
     _genericRepository = genericRepository;
     _databaseScope     = databaseScope;
     _mapper            = mapper;
 }
Beispiel #15
0
 protected EntityService(IDatabaseScope database, IGenericRepository <TEntity> entityRepository)
 {
     _database         = database;
     _entityRepository = entityRepository;
 }
        private static void Measure(IDatabaseScope scope)
        {
            var result = DatabaseScopeMeasurement.Measure(scope, totalCycles);

            WriteResults(scope.GetType().Name, result);
        }
Beispiel #17
0
 public TestScopeProvider(IDatabaseScope scope) => _scope = scope;
Beispiel #18
0
 public TestService(
     IDatabaseScope database,
     IGenericRepository <Entities.TestEntity> repository
     ) : base(database, repository)
 {
 }