Beispiel #1
0
        public static IRepositoryBuilder BuildInMemoryRepository(this IRepositoryBuilder repositoryBuilder,
                                                                 InitialData initialData, InMemoryIndex initialIndex)
        {
            if (initialData == null)
            {
                throw new ArgumentNullException(nameof(initialData));
            }
            if (initialIndex == null)
            {
                throw new ArgumentNullException(nameof(initialIndex));
            }

            var dataProvider = new InMemoryDataProvider();

            repositoryBuilder
            .UseLogger(new DebugWriteLoggerAdapter())
            .UseTracer(new SnDebugViewTracer())
            .UseDataProvider(dataProvider)
            .UseInitialData(initialData)
            .UseSharedLockDataProviderExtension(new InMemorySharedLockDataProvider())
            .UseExclusiveLockDataProviderExtension(new InMemoryExclusiveLockDataProvider())
            .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dataProvider))
            .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
            .UseAccessTokenDataProviderExtension(new InMemoryAccessTokenDataProvider())
            .UsePackagingDataProviderExtension(new InMemoryPackageStorageProvider())
            .UseSearchEngine(new InMemorySearchEngine(initialIndex))
            .UseSecurityDataProvider(GetSecurityDataProvider(dataProvider))
            .UseElevatedModificationVisibilityRuleProvider(new ElevatedModificationVisibilityRule())
            .StartWorkflowEngine(false);

            Providers.Instance.PropertyCollector = new EventPropertyCollector();

            return(repositoryBuilder);
        }
        public static IRepositoryBuilder BuildInMemoryRepository(this IRepositoryBuilder repositoryBuilder,
                                                                 InitialData initialData, InMemoryIndex initialIndex)
        {
            if (initialData == null)
            {
                throw new ArgumentNullException(nameof(initialData));
            }
            if (initialIndex == null)
            {
                throw new ArgumentNullException(nameof(initialIndex));
            }

            // Precedence: if a service is registered in the collection, use that
            // instead of creating instances locally.
            var services = (repositoryBuilder as RepositoryBuilder)?.Services;

            if (services?.GetService <DataProvider>() is InMemoryDataProvider dataProvider)
            {
                // If there is an instance in the container, use that. We have to set
                // these instances manually instead of using the extension method so that
                // we do not overwrite the store instance.
                Providers.Instance.DataProvider = dataProvider;
                Providers.Instance.DataStore    = services.GetService <IDataStore>();
            }
            else
            {
                dataProvider = new InMemoryDataProvider();
                repositoryBuilder.UseDataProvider(dataProvider);
            }

            Providers.Instance.ResetBlobProviders();

            var searchEngine = services?.GetService <ISearchEngine>() ?? new InMemorySearchEngine(initialIndex);

            repositoryBuilder
            .UseLogger(new DebugWriteLoggerAdapter())
            .UseTracer(new SnDebugViewTracer())
            .UseInitialData(initialData)
            .UseSharedLockDataProviderExtension(new InMemorySharedLockDataProvider())
            .UseExclusiveLockDataProviderExtension(new InMemoryExclusiveLockDataProvider())
            .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dataProvider))
            .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
            .AddBlobProvider(new InMemoryBlobProvider())
            .UseAccessTokenDataProviderExtension(new InMemoryAccessTokenDataProvider())
            .UsePackagingDataProviderExtension(new InMemoryPackageStorageProvider())
            .UseSearchEngine(searchEngine)
            .UseSecurityDataProvider(GetSecurityDataProvider(dataProvider))
            .UseSecurityMessageProvider(new DefaultMessageProvider(new MessageSenderManager()))
            .UseElevatedModificationVisibilityRuleProvider(new ElevatedModificationVisibilityRule())
            .StartWorkflowEngine(false);

            var statDp = services?.GetService <IStatisticalDataProvider>() as InMemoryStatisticalDataProvider
                         ?? new InMemoryStatisticalDataProvider();

            repositoryBuilder.UseStatisticalDataProvider(statDp);

            Providers.Instance.PropertyCollector = new EventPropertyCollector();

            return(repositoryBuilder);
        }
Beispiel #3
0
        public static RepositoryInstance StartInMemoryRepository(Action <IRepositoryBuilder> buildRepository = null)
        {
            var dataProvider = new InMemoryDataProvider();

            //TODO:~ missing repo start pieces
            // - configuration
            // - user access provider

            var repositoryBuilder = new RepositoryBuilder()
                                    .UseLogger(new DebugWriteLoggerAdapter())
                                    //.UseAccessProvider(new UserAccessProvider())
                                    .UseDataProvider(dataProvider)
                                    .UseInitialData(InitialData.Load(SenseNetServicesData.Instance))
                                    .UseSharedLockDataProviderExtension(new InMemorySharedLockDataProvider())
                                    .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dataProvider))
                                    .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
                                    .UseAccessTokenDataProviderExtension(new InMemoryAccessTokenDataProvider())
                                    .UsePackagingDataProviderExtension(new InMemoryPackageStorageProvider())
                                    .UseSearchEngine(new InMemorySearchEngine(GetInitialIndex()))
                                    .UseSecurityDataProvider(GetSecurityDataProvider(dataProvider))
                                    .UseElevatedModificationVisibilityRuleProvider(new ElevatedModificationVisibilityRule())
                                    .StartWorkflowEngine(false)
                                    as RepositoryBuilder;

            Providers.Instance.PropertyCollector = new EventPropertyCollector();

            buildRepository?.Invoke(repositoryBuilder);

            var repository = Repository.Start(repositoryBuilder);

            return(repository);
        }
        public void RepositoryStart_NodeObservers_EnableOne()
        {
            var dbProvider = new InMemoryDataProvider();

            var repoBuilder = new RepositoryBuilder()
                              .UseAccessProvider(new DesktopAccessProvider())
                              .UseDataProvider(dbProvider)
                              .UseInitialData(GetInitialData())
                              .UseSharedLockDataProviderExtension(new InMemorySharedLockDataProvider())
                              .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dbProvider))
                              .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
                              .AddBlobProvider(new InMemoryBlobProvider())
                              .UseAccessTokenDataProviderExtension(new InMemoryAccessTokenDataProvider())
                              .UseSearchEngine(new InMemorySearchEngine(GetInitialIndex()))
                              .UseSecurityDataProvider(new MemoryDataProvider(DatabaseStorage.CreateEmpty()))
                              .UseSecurityMessageProvider(new DefaultMessageProvider(new MessageSenderManager()))
                              .UseTestingDataProviderExtension(new InMemoryTestingDataProvider())
                              .UseElevatedModificationVisibilityRuleProvider(new ElevatedModificationVisibilityRule())
                              .UseCacheProvider(new EmptyCache())
                              .DisableNodeObservers()
                              .EnableNodeObservers(typeof(TestNodeObserver1))
                              .StartIndexingEngine(false)
                              .StartWorkflowEngine(false)
                              .UseTraceCategories("Test", "Web", "System");


            using (Repository.Start(repoBuilder))
            {
                Assert.AreEqual(1, Providers.Instance.NodeObservers.Length);
                Assert.AreEqual(typeof(TestNodeObserver1), Providers.Instance.NodeObservers[0].GetType());
            }
        }
        public void RepositoryStart_NodeObservers_EnableMore()
        {
            var dbProvider = new InMemoryDataProvider();

            var repoBuilder = new RepositoryBuilder()
                              .UseAccessProvider(new DesktopAccessProvider())
                              .UseDataProvider(dbProvider)
                              .UseInitialData(GetInitialData())
                              .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dbProvider))
                              .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
                              .UseSecurityDataProvider(new MemoryDataProvider(DatabaseStorage.CreateEmpty()))
                              .UseSearchEngine(new InMemorySearchEngine(GetInitialIndex()))
                              .UseElevatedModificationVisibilityRuleProvider(new ElevatedModificationVisibilityRule())
                              .UseCacheProvider(new EmptyCache())
                              .DisableNodeObservers()
                              .EnableNodeObservers(typeof(TestNodeObserver1), typeof(TestNodeObserver2))
                              .StartIndexingEngine(false)
                              .StartWorkflowEngine(false)
                              .UseTraceCategories("Test", "Web", "System");

            using (Repository.Start(repoBuilder))
            {
                Assert.AreEqual(2, Providers.Instance.NodeObservers.Length);
                Assert.IsTrue(Providers.Instance.NodeObservers.Any(no => no.GetType() == typeof(TestNodeObserver1)));
                Assert.IsTrue(Providers.Instance.NodeObservers.Any(no => no.GetType() == typeof(TestNodeObserver2)));
            }
        }
        public void RepositoryStart_NodeObservers_DisableAll()
        {
            var dbProvider = new InMemoryDataProvider();

            var repoBuilder = new RepositoryBuilder()
                              .UseAccessProvider(new DesktopAccessProvider())
                              .UseDataProvider(dbProvider)
                              .UseInitialData(GetInitialData())
                              .UseSharedLockDataProviderExtension(new InMemorySharedLockDataProvider())
                              .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dbProvider))
                              .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
                              .UseAccessTokenDataProviderExtension(new InMemoryAccessTokenDataProvider())
                              .UseSearchEngine(new InMemorySearchEngine(GetInitialIndex()))
                              .UseSecurityDataProvider(new MemoryDataProvider(DatabaseStorage.CreateEmpty()))
                              .UseTestingDataProviderExtension(new InMemoryTestingDataProvider())
                              .UseElevatedModificationVisibilityRuleProvider(new ElevatedModificationVisibilityRule())
                              .UseCacheProvider(new EmptyCache())
                              .DisableNodeObservers()
                              .StartIndexingEngine(false)
                              .StartWorkflowEngine(false)
                              .UseTraceCategories("Test", "Web", "System");

            using (Repository.Start(repoBuilder))
            {
                Assert.IsFalse(Providers.Instance.NodeObservers.Any());
            }
        }
        public void RepositoryStart_NodeObservers_DisableOne()
        {
            var dbProvider = new InMemoryDataProvider();

            var repoBuilder = new RepositoryBuilder()
                              .UseAccessProvider(new DesktopAccessProvider())
                              .UseDataProvider(dbProvider)
                              .UseInitialData(GetInitialData())
                              .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dbProvider))
                              .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
                              .UseSecurityDataProvider(new MemoryDataProvider(DatabaseStorage.CreateEmpty()))
                              .UseSearchEngine(new InMemorySearchEngine(GetInitialIndex()))
                              .UseElevatedModificationVisibilityRuleProvider(new ElevatedModificationVisibilityRule())
                              .UseCacheProvider(new EmptyCache())
                              .DisableNodeObservers(typeof(TestNodeObserver1))
                              .StartIndexingEngine(false)
                              .StartWorkflowEngine(false)
                              .UseTraceCategories("Test", "Web", "System");

            using (Repository.Start(repoBuilder))
            {
                Assert.IsFalse(Providers.Instance.NodeObservers.Any(no => no.GetType() == typeof(TestNodeObserver1)));

                //TODO: currently this does not work, because observers are enabled/disabled globally.
                // Itt will, when we move to a per-thread environment in tests.
                //Assert.IsTrue(Providers.Instance.NodeObservers.Any(no => no.GetType() == typeof(TestNodeObserver2)));
            }
        }
        public void RepositoryStart_DataProviderExtensions_OverrideDefault()
        {
            var dbProvider         = new InMemoryDataProvider();
            var securityDbProvider = new MemoryDataProvider(DatabaseStorage.CreateEmpty());
            var searchEngine       = new InMemorySearchEngine(GetInitialIndex());
            var accessProvider     = new DesktopAccessProvider();
            var emvrProvider       = new ElevatedModificationVisibilityRule();

            // switch this ON here for testing purposes (to check that repo start does not override it)
            SnTrace.Custom.Enabled = true;

            // switch this ON here for testing purposes (to check that repo start does not override it)
            SnTrace.Custom.Enabled = true;

            var repoBuilder = new RepositoryBuilder()
                              .UseAccessProvider(new DesktopAccessProvider())
                              .UseDataProvider(dbProvider)
                              .UseInitialData(GetInitialData())
                              .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dbProvider))
                              .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
                              .UseAccessTokenDataProviderExtension(new TestAccessTokenDataProvider()) // ACTION: set test provider
                              .UseSecurityDataProvider(securityDbProvider)
                              .UseSearchEngine(searchEngine)
                              .UseAccessProvider(accessProvider)
                              .UseElevatedModificationVisibilityRuleProvider(emvrProvider)
                              .StartIndexingEngine(false)
                              .StartWorkflowEngine(false)
                              .UseTraceCategories("Test", "Web", "System");

            using (Repository.Start(repoBuilder))
            {
                Assert.AreEqual(typeof(TestAccessTokenDataProvider), DataStore.GetDataProviderExtension <IAccessTokenDataProviderExtension>().GetType());
            }
        }
Beispiel #9
0
        public void DataAvailableInProviderIsLoadAutomatically()
        {
            var getRepositoryThatWillBeReused = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id));

            var builder = XmlRepository.GetPropertyMappingBuilderFor <Person>();

            builder.Map(p => p.Id).ToAttribute();

            builder.ApplyMappingsGlobal();

            var prefilledInMemoryProvider = new InMemoryDataProvider(
                @"<root>
  <Person>
    <Id>c186fb12-dd38-4784-8b48-aad96a6510c4</Id>
    <LastName>Bucher</LastName>
    <FirstName>Peter</FirstName>
    <Geek>
      <Id>8f8b747e-3f16-4938-a384-980fc8aa8dd7</Id>
      <SuperId>test</SuperId>
      <Alias>Jackal</Alias>
    </Geek>
    <Friends></Friends>
    <Birthday>17.10.1983 00:00:00</Birthday>
  </Person>
</root>");

            using (var repository = XmlRepository.Get(RepositoryFor <Person>
                                                      .WithIdentity(p => p.Id)
                                                      .WithDataProvider(prefilledInMemoryProvider)))
            {
                var test = repository.LoadAll();

                Assert.That(repository.LoadAll(), Is.Not.Null);
            }
        }
Beispiel #10
0
        private static RepositoryBuilder CreateRepositoryBuilder(InitialData initialData = null)
        {
            var dataProvider = new InMemoryDataProvider();

            Providers.Instance.DataProvider = dataProvider;

            var builder = new RepositoryBuilder()
                          .UseTracer(new SnFileSystemTracer())
                          .UseLogger(new SnFileSystemEventLogger())
                          .UseAccessProvider(new DesktopAccessProvider())
                          .UseDataProvider(dataProvider)
                          .UseSharedLockDataProviderExtension(new InMemorySharedLockDataProvider())
                          .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dataProvider))
                          .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
                          .UseInitialData(initialData ?? InitialData.Load(new SenseNetServicesInitialData()))
                          .UseAccessTokenDataProviderExtension(new InMemoryAccessTokenDataProvider())
                          .UseSearchEngine(new InMemorySearchEngine(GetInitialIndex()))
                          .UseSecurityDataProvider(GetSecurityDataProvider(dataProvider))
                          //.UseTestingDataProviderExtension(new InMemoryTestingDataProvider())
                          .UseElevatedModificationVisibilityRuleProvider(new ElevatedModificationVisibilityRule())
                          .StartWorkflowEngine(false)
                          .DisableNodeObservers()
                          .EnableNodeObservers(TypeResolver.GetType("SenseNet.ContentRepository.SettingsCache"))
                          //.EnableNodeObservers(typeof(SettingsCache))
                          .UseTraceCategories("System", "Test", "Event", "Custom") as RepositoryBuilder;

            return(builder);
        }
Beispiel #11
0
 protected static ISecurityDataProvider GetSecurityDataProvider(InMemoryDataProvider repo)
 {
     return(new MemoryDataProvider(new DatabaseStorage
     {
         Aces = new List <StoredAce>
         {
             new StoredAce {
                 EntityId = 2, IdentityId = 1, LocalOnly = false, AllowBits = 0x0EF, DenyBits = 0x000
             }
         },
         Entities = repo.LoadEntityTreeAsync(CancellationToken.None).GetAwaiter().GetResult()
                    .ToDictionary(x => x.Id, x => new StoredSecurityEntity
         {
             Id = x.Id,
             OwnerId = x.OwnerId,
             ParentId = x.ParentId,
             IsInherited = true,
             HasExplicitEntry = x.Id == 2
         }),
         Memberships = new List <Membership>
         {
             new Membership
             {
                 GroupId = Identifiers.AdministratorsGroupId,
                 MemberId = Identifiers.AdministratorUserId,
                 IsUser = true
             }
         },
         Messages = new List <Tuple <int, DateTime, byte[]> >()
     }));
 }
 private void SeedData()
 {
     if (!_dbContext.Publishers.Any())
     {
         _dbContext.Publishers.AddRange(InMemoryDataProvider.GetInMemoryDataPublishers());
         _dbContext.SaveChanges();
     }
 }
 private void SeedData()
 {
     if (!_dbContext.NewsArticles.Any())
     {
         _dbContext.AddRange(InMemoryDataProvider.GetInMemoryDataNewsArticles());
         _dbContext.SaveChanges();
     }
 }
        public void WhenConstructedWithInitialNullOrEmptyDataContent_DefaultRootElementIsReturned()
        {
            var provider = new InMemoryDataProvider(null);

            Assert.That(provider.Load <Person>(), Is.EqualTo(XmlRepository.RootElementXml));

            provider = new InMemoryDataProvider(string.Empty);

            Assert.That(provider.Load <Person>(), Is.EqualTo(XmlRepository.RootElementXml));
        }
Beispiel #15
0
        public void ShouldThrowOnMissingStartNode()
        {
            InMemoryDataProvider dataProvider = new InMemoryDataProvider(new List <INode> {
                new Node("nEnd")
            }, new List <IEdge>());
            Func <Task> func = async() => await dataProvider.ShortestPaths("nStart", "nEnd");

            func
            .Should()
            .Throw <ArgumentNullException>();
        }
Beispiel #16
0
        public void UT_AccessToken_GetOrAdd_MaxTimeOut()
        {
            var dataProvider = new InMemoryDataProvider();

            dataProvider.SetExtension(typeof(IAccessTokenDataProviderExtension), new InMemoryAccessTokenDataProvider());
            Providers.Instance.DataProvider = dataProvider;

            // ACTION
            var token = AccessTokenVault.GetOrAddToken(1, TimeSpan.MaxValue);

            // ASSERT
            Assert.AreEqual(DateTime.MaxValue, token.ExpirationDate);
        }
Beispiel #17
0
        public void UT_AccessToken_Create_MaxTimeOut()
        {
            var dataProvider = new InMemoryDataProvider();

            dataProvider.SetExtension(typeof(IAccessTokenDataProviderExtension), new InMemoryAccessTokenDataProvider());
            Providers.Instance.DataProvider = dataProvider;

            // ACTION
            var token = AccessTokenVault.CreateTokenAsync(1, TimeSpan.MaxValue, CancellationToken.None).Result;

            // ASSERT
            Assert.AreEqual(DateTime.MaxValue, token.ExpirationDate);
        }
        public void RepositoryStart_NamedProviders()
        {
            var dbProvider         = new InMemoryDataProvider();
            var securityDbProvider = new MemoryDataProvider(DatabaseStorage.CreateEmpty());
            var searchEngine       = new InMemorySearchEngine(GetInitialIndex());
            var accessProvider     = new DesktopAccessProvider();
            var emvrProvider       = new ElevatedModificationVisibilityRule();

            // switch this ON here for testing purposes (to check that repo start does not override it)
            SnTrace.Custom.Enabled = true;

            var repoBuilder = new RepositoryBuilder()
                              .UseAccessProvider(new DesktopAccessProvider())
                              .UseDataProvider(dbProvider)
                              .UseInitialData(GetInitialData())
                              .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dbProvider))
                              .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
                              .AddBlobProvider(new InMemoryBlobProvider())
                              .UseSecurityDataProvider(securityDbProvider)
                              .UseSecurityMessageProvider(new DefaultMessageProvider(new MessageSenderManager()))
                              .UseSearchEngine(searchEngine)
                              .UseAccessProvider(accessProvider)
                              .UseElevatedModificationVisibilityRuleProvider(emvrProvider)
                              .StartIndexingEngine(false)
                              .StartWorkflowEngine(false)
                              .UseTraceCategories("Test", "Web", "System");

            using (Repository.Start(repoBuilder))
            {
                Assert.AreSame(dbProvider, Providers.Instance.DataStore.DataProvider);
                Assert.AreEqual(searchEngine, SearchManager.SearchEngine);
                Assert.AreEqual(accessProvider, AccessProvider.Current);
                Assert.AreEqual(emvrProvider, Providers.Instance.ElevatedModificationVisibilityRuleProvider);

                // Currently this does not work, because the property below re-creates the security
                // db provider from the prototype, so it cannot be ref equal with the original.
                // Assert.AreEqual(securityDbProvider, SecurityHandler.SecurityContext.DataProvider);
                Assert.AreEqual(securityDbProvider, Providers.Instance.SecurityDataProvider);

                // Check a few trace categories that were switched ON above.
                Assert.IsTrue(SnTrace.Custom.Enabled);
                Assert.IsTrue(SnTrace.Test.Enabled);
                Assert.IsTrue(SnTrace.Web.Enabled);
                Assert.IsTrue(SnTrace.System.Enabled);
                Assert.IsFalse(SnTrace.TaskManagement.Enabled);
                Assert.IsFalse(SnTrace.Workflow.Enabled);
            }
        }
Beispiel #19
0
        public async Task ShouldHandleMissingNodes()
        {
            var nStart = new Node("nStart", incomingEdgeIds: new List <string> {
                "e2"
            }, outgoingEdgeIds: new List <string> {
                "e1"
            });
            var n1 = new Node("n1", incomingEdgeIds: new List <string> {
                "e6"
            }, outgoingEdgeIds: new List <string> {
                "e2", "e4", "e7"
            });
            var n2 = new Node("n2", incomingEdgeIds: new List <string> {
                "e1", "e3", "e7"
            }, outgoingEdgeIds: new List <string> {
                "e6"
            });
            var n3 = new Node("n3", incomingEdgeIds: new List <string> {
                "e4"
            }, outgoingEdgeIds: new List <string> {
                "e3", "e5"
            });
            var nEnd = new Node("nEnd", incomingEdgeIds: new List <string> {
                "e5"
            }, outgoingEdgeIds: new List <string> {
            });
            var e1 = new Edge("e1", "nStart", "n2");
            var e2 = new Edge("e2", "n1", "nStart");
            var e3 = new Edge("e3", "n3", "n2");
            var e4 = new Edge("e4", "n1", "n3");
            var e5 = new Edge("e5", "n3", "nEnd");
            var e6 = new Edge("e6", "n2", "n1");
            var e7 = new Edge("e7", "n1", "n2");

            var inMemoryProvider = new InMemoryDataProvider(
                new INode[] { nStart, n2, n3, nEnd },
                new IEdge[] { e1, e2, e3, e4, e5, e6, e7 });

            var result = await inMemoryProvider.ShortestPaths("nStart", "nEnd");

            result
            .Should()
            .BeEquivalentTo(new IPath[]
            {
                new Path(new IGraphObject[] { nStart, e1, n2, e3, n3, e5, nEnd })
            }, options => options.WithStrictOrderingFor(x => x.NodesAndEdges));
        }
Beispiel #20
0
        protected RepositoryBuilder CreateRepositoryBuilderForTest()
        {
            var dataProvider         = new InMemoryDataProvider();
            var securityDataProvider = GetSecurityDataProvider(dataProvider);

            return(new RepositoryBuilder()
                   .UseAccessProvider(new DesktopAccessProvider())
                   .UseDataProvider(dataProvider)
                   .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dataProvider))
                   .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
                   .UseSearchEngine(new InMemorySearchEngine())
                   .UseSecurityDataProvider(securityDataProvider)
                   .UseElevatedModificationVisibilityRuleProvider(new ElevatedModificationVisibilityRule())
                   .StartWorkflowEngine(false)
                   .DisableNodeObservers()
                   .EnableNodeObservers(typeof(SettingsCache))
                   .UseTraceCategories("Test", "Event", "Custom") as RepositoryBuilder);
        }
        public void RepositoryStart_AuditEventWriter_Database()
        {
            var originalWriter = SnLog.AuditEventWriter;
            var auditWriter    = new DatabaseAuditEventWriter();

            var dbProvider         = new InMemoryDataProvider();
            var securityDbProvider = new MemoryDataProvider(DatabaseStorage.CreateEmpty());
            var searchEngine       = new InMemorySearchEngine(GetInitialIndex());
            var accessProvider     = new DesktopAccessProvider();
            var emvrProvider       = new ElevatedModificationVisibilityRule();

            try
            {
                // Clear the slot to ensure a real test.
                Providers.Instance.AuditEventWriter = null;

                var repoBuilder = new RepositoryBuilder()
                                  .UseAccessProvider(new DesktopAccessProvider())
                                  .UseDataProvider(dbProvider)
                                  .UseAuditEventWriter(auditWriter) // <-- The important line
                                  .UseInitialData(GetInitialData())
                                  .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dbProvider))
                                  .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
                                  .AddBlobProvider(new InMemoryBlobProvider())
                                  .UseSecurityDataProvider(securityDbProvider)
                                  .UseSecurityMessageProvider(new DefaultMessageProvider(new MessageSenderManager()))
                                  .UseSearchEngine(searchEngine)
                                  .UseAccessProvider(accessProvider)
                                  .UseElevatedModificationVisibilityRuleProvider(emvrProvider)
                                  .StartIndexingEngine(false)
                                  .StartWorkflowEngine(false)
                                  .UseTraceCategories("Test", "Web", "System");

                using (Repository.Start(repoBuilder))
                {
                    Assert.AreSame(auditWriter, Providers.Instance.AuditEventWriter);
                    Assert.AreSame(auditWriter, SnLog.AuditEventWriter);
                }
            }
            finally
            {
                SnLog.AuditEventWriter = originalWriter;
            }
        }
        public void RepositoryStart_NullPopulator()
        {
            var dbProvider2 = new InMemoryDataProvider();

            Providers.Instance.DataProvider = dbProvider2;
            var securityDbProvider = new MemoryDataProvider(DatabaseStorage.CreateEmpty());
            var searchEngine       = new InMemorySearchEngine(GetInitialIndex());
            var accessProvider     = new DesktopAccessProvider();
            var emvrProvider       = new ElevatedModificationVisibilityRule();

            var repoBuilder = new RepositoryBuilder()
                              .UseAccessProvider(new DesktopAccessProvider())
                              .UseDataProvider(dbProvider2)
                              .UseInitialData(GetInitialData())
                              .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dbProvider2))
                              .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
                              .AddBlobProvider(new InMemoryBlobProvider())
                              .UseSecurityDataProvider(securityDbProvider)
                              .UseSecurityMessageProvider(new DefaultMessageProvider(new MessageSenderManager()))
                              .UseSearchEngine(searchEngine)
                              .UseAccessProvider(accessProvider)
                              .UseElevatedModificationVisibilityRuleProvider(emvrProvider)
                              .StartIndexingEngine(false)
                              .StartWorkflowEngine(false)
                              .UseTraceCategories("Test", "Web", "System");

            var originalIsOuterSearchEngineEnabled = Indexing.IsOuterSearchEngineEnabled;

            Indexing.IsOuterSearchEngineEnabled = false;
            try
            {
                using (Repository.Start(repoBuilder))
                {
                    Assert.IsFalse(SearchManager.IsOuterEngineEnabled);
                    Assert.AreEqual(typeof(InternalSearchEngine), SearchManager.SearchEngine.GetType());
                    var populator = SearchManager.GetIndexPopulator();
                    Assert.AreEqual(typeof(NullPopulator), populator.GetType());
                }
            }
            finally
            {
                Indexing.IsOuterSearchEngineEnabled = originalIsOuterSearchEngineEnabled;
            }
        }
Beispiel #23
0
        protected static RepositoryBuilder CreateRepositoryBuilder()
        {
            var dataProvider = new InMemoryDataProvider();

            return(new RepositoryBuilder()
                   .UseAccessProvider(new DesktopAccessProvider())
                   .UseDataProvider(dataProvider)
                   .UseInitialData(GetInitialData())
                   .UseSharedLockDataProviderExtension(new InMemorySharedLockDataProvider())
                   .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dataProvider))
                   .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
                   .UseAccessTokenDataProviderExtension(new InMemoryAccessTokenDataProvider())
                   .UseSearchEngine(new InMemorySearchEngine(GetInitialIndex()))
                   .UseSecurityDataProvider(GetSecurityDataProvider(dataProvider))
                   .UseElevatedModificationVisibilityRuleProvider(new ElevatedModificationVisibilityRule())
                   .StartWorkflowEngine(false)
                   //.DisableNodeObservers()
                   //.EnableNodeObservers(typeof(SettingsCache))
                   .UseTraceCategories("Test", "Event", "Custom") as RepositoryBuilder);
        }
Beispiel #24
0
        public async Task ShouldHandleNoConenction()
        {
            var n1 = new Node("nStart", new List <string> {
                "e1"
            });
            var n2             = new Node("nEnd");
            var e1             = new Edge("e1", "nStart", "nStart");
            var expectedResult = new IPath[0];

            InMemoryDataProvider dataProvider = new InMemoryDataProvider(new List <INode> {
                n1, n2
            }, new List <IEdge> {
                e1
            });
            var result = await dataProvider.ShortestPaths("nStart", "nEnd");

            result
            .Should()
            .BeEquivalentTo(expectedResult, options => options.WithStrictOrderingFor(x => x.NodesAndEdges));
        }
Beispiel #25
0
        public async Task ShouldFindPaths(IEnumerable <INode> nodes, IEnumerable <IEdge> edges, IEnumerable <IPath> expectedResult)
        {
            _output.WriteLine($"Excepted ({expectedResult.Count()}):");
            foreach (var path in expectedResult)
            {
                _output.WriteLine(path.DebugOutput());
            }

            InMemoryDataProvider dataProvider = new InMemoryDataProvider(nodes, edges);
            var result = await dataProvider.ShortestPaths("nStart", "nEnd");

            _output.WriteLine($"Result ({result.Count()}): ");
            foreach (var path in result)
            {
                _output.WriteLine(path.DebugOutput());
            }

            result
            .Should()
            .BeEquivalentTo(expectedResult, options => options.WithStrictOrderingFor(x => x.NodesAndEdges));
        }
        public void Indexing_Centralized_InMemory_ExecuteUnprocessed()
        {
            var dataProvider = new InMemoryDataProvider();
            var searchEngine = new SearchEngineForActivityQueueSelectorTests(false);
            var nodeId       = 0;
            var versionId    = 0;
            var path         = string.Empty;

            ActivityQueueSelectorTest(searchEngine, dataProvider, s =>
            {
                // create a valid version
                var nodeName = "Indexing_Centralized_InMemory_ExecuteUnprocessed";
                var node     = new SystemFolder(Repository.Root)
                {
                    Name = nodeName
                };
                using (new SystemAccount())
                    node.Save();
                nodeId    = node.Id;
                versionId = node.VersionId;
                path      = node.Path;
            });

            DataProvider.Current.DeleteAllIndexingActivities();
            RegisterActivity(IndexingActivityType.AddDocument, IndexingActivityRunningState.Waiting, nodeId, versionId, path);
            RegisterActivity(IndexingActivityType.UpdateDocument, IndexingActivityRunningState.Waiting, nodeId, versionId, path);
            RegisterActivity(IndexingActivityType.UpdateDocument, IndexingActivityRunningState.Waiting, nodeId, versionId, path);

            SnTrace.Test.Write("Indexing_Centralized_InMemory_ExecuteUnprocessed ACTION");

            searchEngine = new SearchEngineForActivityQueueSelectorTests(true);
            ActivityQueueSelectorTest(searchEngine, dataProvider, s =>
            {
                var log = searchEngine.GetIndexingLog();
                Assert.AreEqual(
                    "CENTRALIZED. deletions: 0, updates: 0, addition: 1\r\n" +
                    "CENTRALIZED. deletions: 0, updates: 1, addition: 0\r\n" +
                    "CENTRALIZED. deletions: 0, updates: 1, addition: 0\r\n", log);
            });
        }
Beispiel #27
0
 protected static ISecurityDataProvider GetSecurityDataProvider(InMemoryDataProvider repo)
 {
     return(new MemoryDataProvider(new DatabaseStorage
     {
         Aces = new List <StoredAce>
         {
             new StoredAce {
                 EntityId = 2, IdentityId = 1, LocalOnly = false, AllowBits = 0x0EF, DenyBits = 0x000
             }
         },
         Entities = repo.GetSecurityEntities().ToDictionary(e => e.Id, e => e),
         Memberships = new List <Membership>
         {
             new Membership
             {
                 GroupId = Identifiers.AdministratorsGroupId,
                 MemberId = Identifiers.AdministratorUserId,
                 IsUser = true
             }
         },
         Messages = new List <Tuple <int, DateTime, byte[]> >()
     }));
 }
Beispiel #28
0
        public static IRepositoryBuilder BuildInMemoryRepository(this IRepositoryBuilder repositoryBuilder)
        {
            var dataProvider = new InMemoryDataProvider();

            repositoryBuilder
            .UseLogger(new DebugWriteLoggerAdapter())
            .UseTracer(new SnDebugViewTracer())
            .UseDataProvider(dataProvider)
            .UseInitialData(InitialData.Load(SenseNetServicesData.Instance))
            .UseSharedLockDataProviderExtension(new InMemorySharedLockDataProvider())
            .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dataProvider))
            .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
            .UseAccessTokenDataProviderExtension(new InMemoryAccessTokenDataProvider())
            .UsePackagingDataProviderExtension(new InMemoryPackageStorageProvider())
            .UseSearchEngine(new InMemorySearchEngine(GetInitialIndex()))
            .UseSecurityDataProvider(GetSecurityDataProvider(dataProvider))
            .UseElevatedModificationVisibilityRuleProvider(new ElevatedModificationVisibilityRule())
            .StartWorkflowEngine(false);

            Providers.Instance.PropertyCollector = new EventPropertyCollector();

            return(repositoryBuilder);
        }
        /* ============================================================================================== */

        protected void ActivityQueueSelectorTest(ISearchEngine searchEngine, InMemoryDataProvider dataProvider, Action <string> callback, [CallerMemberName] string memberName = "")
        {
            if (dataProvider == null)
            {
                dataProvider = new InMemoryDataProvider();
            }
            var securityDataProvider = GetSecurityDataProvider(dataProvider);

            Configuration.Indexing.IsOuterSearchEngineEnabled = true;
            CommonComponents.TransactionFactory = dataProvider;
            DistributedApplication.Cache.Reset();

            var indxManConsole = new StringWriter();
            var repoBuilder    = new RepositoryBuilder()
                                 .UseDataProvider(dataProvider)
                                 .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dataProvider))
                                 .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
                                 .UseAccessProvider(new DesktopAccessProvider())
                                 .UsePermissionFilterFactory(new EverythingAllowedPermissionFilterFactory())
                                 .UseSearchEngine(searchEngine)
                                 .UseSecurityDataProvider(securityDataProvider)
                                 .UseCacheProvider(new EmptyCache())
                                 .UseTraceCategories("ContentOperation", "Event", "Repository", "IndexQueue", "Index", "Query")
                                 .DisableNodeObservers()
                                 .EnableNodeObservers(typeof(SettingsCache))
                                 .StartWorkflowEngine(false);

            repoBuilder.Console = indxManConsole;

            using (Repository.Start(repoBuilder))
            {
                using (Tests.Tools.Swindle(typeof(SearchManager), "_searchEngineSupport", new SearchEngineSupport()))
                {
                    callback(indxManConsole.ToString());
                }
            }
        }
Beispiel #30
0
        public async Task ShouldHandleMissingEdges()
        {
            var nStart = new Node("nStart", new List <string> {
                "e2"
            }, new List <string> {
                "e1"
            });
            var nEnd = new Node("nEnd", new List <string> {
                "e1"
            }, new List <string> {
                "e2"
            });
            var e1 = new Edge("e1", "nStart", "nEnd");
            var e2 = new Edge("e2", "nEnd", "nStart");
            var inMemoryProvider = new InMemoryDataProvider(new INode[] { nStart, nEnd }, new IEdge[] { e1 });
            var result           = await inMemoryProvider.ShortestPaths("nStart", "nEnd");

            result
            .Should()
            .BeEquivalentTo(new IPath[]
            {
                new Path(new IGraphObject[] { nStart, e1, nEnd })
            }, options => options.WithStrictOrderingFor(x => x.NodesAndEdges));
        }