public UsersController(IMapper mapper, IRepository <User> userRepo, ParatextService paratextService)
     : base(mapper)
 {
     _userRepo        = userRepo;
     _paratextService = paratextService;
 }
            public TestEnvironment()
            {
                RealtimeService = new SFMemoryRealtimeService();
                RealtimeService.AddRepository("users", OTType.Json0, new MemoryRepository <User>(new[]
                {
                    new User
                    {
                        Id    = User01,
                        Email = "*****@*****.**",
                        Sites = new Dictionary <string, Site>
                        {
                            { SiteId, new Site {
                                  Projects = { Project01, Project03 }
                              } }
                        }
                    },
                    new User
                    {
                        Id    = User02,
                        Email = "*****@*****.**",
                        Sites = new Dictionary <string, Site>
                        {
                            { SiteId, new Site {
                                  Projects = { Project01, Project02, Project03 }
                              } }
                        }
                    },
                    new User
                    {
                        Id    = User03,
                        Email = "*****@*****.**",
                        Sites = new Dictionary <string, Site> {
                            { SiteId, new Site() }
                        }
                    },
                    new User
                    {
                        Id    = User04,
                        Email = "*****@*****.**",
                        Sites = new Dictionary <string, Site>(),
                        Role  = SystemRole.SystemAdmin
                    }
                }));
                RealtimeService.AddRepository("sf_projects", OTType.Json0, new MemoryRepository <SFProject>(
                                                  new[]
                {
                    new SFProject
                    {
                        Id              = Project01,
                        ParatextId      = "paratext_" + Project01,
                        Name            = "project01",
                        ShortName       = "P01",
                        TranslateConfig = new TranslateConfig
                        {
                            TranslationSuggestionsEnabled = true,
                            Source = new TranslateSource
                            {
                                ParatextId    = "paratextId",
                                Name          = "Source",
                                ShortName     = "SRC",
                                WritingSystem = new WritingSystem
                                {
                                    Tag = "qaa"
                                }
                            }
                        },
                        CheckingConfig = new CheckingConfig
                        {
                            ShareEnabled = false
                        },
                        UserRoles = new Dictionary <string, string>
                        {
                            { User01, SFProjectRole.Administrator },
                            { User02, SFProjectRole.CommunityChecker }
                        },
                        Texts =
                        {
                            new TextInfo
                            {
                                BookNum  = 40,
                                Chapters =
                                {
                                    new Chapter {
                                        Number = 1, LastVerse = 3, IsValid = true, Permissions ={                                                  }
                                    }
                                }
                            },
                            new TextInfo
                            {
                                BookNum  = 41,
                                Chapters =
                                {
                                    new Chapter {
                                        Number = 1, LastVerse = 3, IsValid = true, Permissions ={                                                  }
                                    },
                                    new Chapter {
                                        Number = 2, LastVerse = 3, IsValid = true, Permissions ={                                                  }
                                    }
                                }
                            }
                        }
                    },
                    new SFProject
                    {
                        Id             = Project02,
                        Name           = "project02",
                        ShortName      = "P02",
                        CheckingConfig = new CheckingConfig
                        {
                            ShareEnabled = true,
                            ShareLevel   = CheckingShareLevel.Anyone
                        },
                        UserRoles =
                        {
                            { User02, SFProjectRole.Administrator }
                        },
                    },
                    new SFProject
                    {
                        Id             = Project03,
                        Name           = "project03",
                        ShortName      = "P03",
                        CheckingConfig = new CheckingConfig
                        {
                            ShareEnabled = true,
                            ShareLevel   = CheckingShareLevel.Specific
                        },
                        UserRoles =
                        {
                            { User01, SFProjectRole.Administrator },
                            { User02, SFProjectRole.Translator    }
                        }
                    },
                    new SFProject
                    {
                        Id         = Resource01,
                        ParatextId = "resid_is_16_char",
                        Name       = "resource project",
                        ShortName  = "RES",
                    }
                }));
                RealtimeService.AddRepository("sf_project_user_configs", OTType.Json0,
                                              new MemoryRepository <SFProjectUserConfig>(new[]
                {
                    new SFProjectUserConfig {
                        Id = SFProjectUserConfig.GetDocId(Project01, User01)
                    },
                    new SFProjectUserConfig {
                        Id = SFProjectUserConfig.GetDocId(Project01, User02)
                    },
                    new SFProjectUserConfig {
                        Id = SFProjectUserConfig.GetDocId(Project02, User02)
                    },
                    new SFProjectUserConfig {
                        Id = SFProjectUserConfig.GetDocId(Project03, User01)
                    },
                    new SFProjectUserConfig {
                        Id = SFProjectUserConfig.GetDocId(Project03, User02)
                    }
                }));
                var siteOptions = Substitute.For <IOptions <SiteOptions> >();

                siteOptions.Value.Returns(new SiteOptions
                {
                    Id      = SiteId,
                    Name    = "xForge",
                    Origin  = new Uri("http://localhost"),
                    SiteDir = "xforge"
                });
                var audioService = Substitute.For <IAudioService>();

                EmailService   = Substitute.For <IEmailService>();
                ProjectSecrets = new MemoryRepository <SFProjectSecret>(new[]
                {
                    new SFProjectSecret {
                        Id = Project01
                    },
                    new SFProjectSecret {
                        Id = Project02
                    },
                    new SFProjectSecret
                    {
                        Id        = Project03,
                        ShareKeys = new List <ShareKey>
                        {
                            new ShareKey {
                                Email = "*****@*****.**", Key = "key1111"
                            },
                            new ShareKey {
                                Email = "*****@*****.**", Key = "key1234"
                            },
                            new ShareKey {
                                Email = "*****@*****.**", Key = "key2222"
                            }
                        }
                    },
                });
                EngineService = Substitute.For <IEngineService>();
                SyncService   = Substitute.For <ISyncService>();
                SyncService.SyncAsync(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <bool>())
                .Returns(Task.CompletedTask);
                ParatextService = Substitute.For <IParatextService>();
                IReadOnlyList <ParatextProject> ptProjects = new[]
                {
                    new ParatextProject
                    {
                        ParatextId  = "changedId",
                        Name        = "NewSource",
                        LanguageTag = "qaa"
                    },
                    new ParatextProject
                    {
                        ParatextId = GetProject(Project01).ParatextId
                    },
                    new ParatextProject
                    {
                        ParatextId = "ptProject123"
                    }
                };

                ParatextService.GetProjectsAsync(Arg.Any <UserSecret>()).Returns(Task.FromResult(ptProjects));
                IReadOnlyList <ParatextResource> ptResources = new[]
                {
                    new ParatextResource
                    {
                        ParatextId  = "resource_project",
                        Name        = "ResourceProject",
                        LanguageTag = "qaa"
                    },
                    new ParatextResource
                    {
                        ParatextId = GetProject(Resource01).ParatextId
                    }
                };

                ParatextService.GetResources(Arg.Any <UserSecret>()).Returns(ptResources);
                var userSecrets = new MemoryRepository <UserSecret>(new[]
                {
                    new UserSecret {
                        Id = User01
                    },
                    new UserSecret {
                        Id = User02
                    },
                    new UserSecret {
                        Id = User03
                    }
                });
                var translateMetrics = new MemoryRepository <TranslateMetrics>();

                FileSystemService = Substitute.For <IFileSystemService>();
                var options = Options.Create(new LocalizationOptions {
                    ResourcesPath = "Resources"
                });
                var factory = new ResourceManagerStringLocalizerFactory(options, NullLoggerFactory.Instance);

                Localizer       = new StringLocalizer <SharedResource>(factory);
                SecurityService = Substitute.For <ISecurityService>();
                SecurityService.GenerateKey().Returns("1234abc");
                var transceleratorService = Substitute.For <ITransceleratorService>();

                Service = new SFProjectService(RealtimeService, siteOptions, audioService, EmailService, ProjectSecrets,
                                               SecurityService, FileSystemService, EngineService, SyncService, ParatextService, userSecrets,
                                               translateMetrics, Localizer, transceleratorService);
            }