private void PopulateRepositoryManager(EntityIdAllocatorFactory idAllocator) { var repositoryManager = new RepositoryManager(); repositoryManager.AddRepository <User>(new UserRepository()); repositoryManager.AddRepository <Conversation>(new ConversationRepository()); repositoryManager.AddRepository <Participation>(new ParticipationRepository()); ServiceRegistry.RegisterService <RepositoryManager>(repositoryManager); int userId2 = idAllocator.AllocateEntityId <User>(); int userId3 = idAllocator.AllocateEntityId <User>(); var usersToAddToConversation = new List <int> { DefaultUser.Id, userId2, userId3 }; var userRepository = (UserRepository)repositoryManager.GetRepository <User>(); var participationRepository = (ParticipationRepository)repositoryManager.GetRepository <Participation>(); foreach (int userId in usersToAddToConversation) { var user = new User("user" + userId, userId, new ConnectionStatus(userId, ConnectionStatus.Status.Connected)); userRepository.AddEntity(user); } SetUpMultiUserConversation(usersToAddToConversation, repositoryManager, idAllocator); DefaultConversationIdDefaultUserIsIn = participationRepository.GetConversationIdByUserIds(usersToAddToConversation); }
private static IServiceRegistry CreateLoadedServiceRegistry() { IServiceRegistry serviceRegistry = new ServiceRegistry(); var repositoryManager = new RepositoryManager(); repositoryManager.AddRepository <User>(new UserRepository()); repositoryManager.AddRepository <Conversation>(new ConversationRepository()); repositoryManager.AddRepository <Participation>(new ParticipationRepository()); serviceRegistry.RegisterService <RepositoryManager>(repositoryManager); serviceRegistry.RegisterService <IClientService>(new ClientService(serviceRegistry)); return(serviceRegistry); }
private static IServiceRegistry RegisterServices() { IServiceRegistry serviceRegistry = new ServiceRegistry(); var repositoryManager = new RepositoryManager(); repositoryManager.AddRepository <User>(new UserRepository()); repositoryManager.AddRepository <Conversation>(new ConversationRepository()); repositoryManager.AddRepository <Participation>(new ParticipationRepository()); serviceRegistry.RegisterService <RepositoryManager>(repositoryManager); serviceRegistry.RegisterService <IClientManager>(new ClientManager()); serviceRegistry.RegisterService <EntityIdAllocatorFactory>(new EntityIdAllocatorFactory()); return(serviceRegistry); }
public void ReturnsCorrectRepository() { IEntityRepository userRepository = new UserRepository(); IEntityRepository conversationRepository = new ConversationRepository(); IEntityRepository participationRepository = new ParticipationRepository(); var repositoryManager = new RepositoryManager(); repositoryManager.AddRepository <User>(userRepository); repositoryManager.AddRepository <Conversation>(conversationRepository); repositoryManager.AddRepository <Participation>(participationRepository); IReadOnlyEntityRepository <Conversation> retrievedConversationRepository = repositoryManager.GetRepository <Conversation>(); Assert.AreEqual(conversationRepository, retrievedConversationRepository); }
public void CanAddRepository() { IEntityRepository userRepository = new UserRepository(); var repositoryManager = new RepositoryManager(); repositoryManager.AddRepository <User>(userRepository); Assert.AreEqual(userRepository, repositoryManager.GetRepository <User>()); }
public void TestAddRepository() { var foo = new Mock <IRepository>().Object; var bar = new Mock <IRepository>().Object; manager.AddRepository(bar); manager.AddRepository(foo, true); CollectionAssert.AreEqual(new[] { foo, bar }, manager.GetRepositories()); }
/// <inheritdoc /> public override IPackage Load(ConfigBucketBase config, Type expectedClass) { if (!typeof(IPackageRoot).IsAssignableFrom(expectedClass)) { throw new ArgumentException($"The type must implement \"{nameof(IPackageRoot)}\"."); } if (string.IsNullOrEmpty(config.Name)) { throw new RuntimeException("The \"name\" property not allowed to be empty."); } if (string.IsNullOrEmpty(config.Version)) { throw new RuntimeException("The \"version\" property not allowed to be empty."); } IPackage realPackage, package; realPackage = package = base.Load(config, expectedClass); if (realPackage is PackageAlias packageAlias) { realPackage = packageAlias.GetAliasOf(); } if (!(realPackage is PackageRoot packageRoot)) { throw new UnexpectedException($"The package type does not meet expectations and should be: {nameof(PackageRoot)}"); } if (config.MinimumStability != null) { packageRoot.SetMinimunStability(config.MinimumStability); } packageRoot.SetPlatforms(config.Platforms); var aliases = new List <ConfigAlias>(); var stabilityFlags = new Dictionary <string, Stabilities>(); var references = new Dictionary <string, string>(); var required = new HashSet <string>(); void ExtractRequire(Link[] links) { var requires = new Dictionary <string, string>(); foreach (var link in links) { required.Add(link.GetTarget().ToLower()); requires[link.GetTarget()] = link.GetConstraint().GetPrettyString(); } ExtractAliases(requires, aliases); ExtractStabilityFlags(requires, packageRoot.GetMinimumStability(), stabilityFlags); ExtractReferences(requires, references); } ExtractRequire(realPackage.GetRequires()); ExtractRequire(realPackage.GetRequiresDev()); if (required.Contains(config.Name.ToLower())) { throw new RuntimeException($"Root package \"{config.Name}\" cannot require itself in its bucket.json{Environment.NewLine}Did you accidentally name your root package after an external package?"); } packageRoot.SetAliases(aliases.ToArray()); packageRoot.SetStabilityFlags(stabilityFlags); packageRoot.SetReferences(references); packageRoot.SetPreferStable(config.PreferStable); var repositories = RepositoryFactory.CreateDefaultRepository(io, this.config, manager); foreach (var repository in repositories) { manager.AddRepository(repository); } packageRoot.SetRepositories(this.config.GetRepositories()); return(package); }