Exemple #1
0
        public async Task GetGlossaryEntry()
        {
            var contextId = Guid.NewGuid().ToString();

            await using (var context = InMemoryContentDbContext(contextId))
            {
                await context.AddAsync(
                    new GlossaryEntry
                {
                    Title = "Exclusion",
                    Slug  = "exclusion",
                    Body  = "Exclusion body",
                }
                    );

                await context.SaveChangesAsync();
            }

            await using (var context = InMemoryContentDbContext(contextId))
            {
                var glossaryService = new GlossaryService(context);

                var result = await glossaryService.GetGlossaryEntry("exclusion");

                var viewModel = result.AssertRight();

                Assert.Equal("Exclusion", viewModel.Title);
                Assert.Equal("exclusion", viewModel.Slug);
                Assert.Equal("Exclusion body", viewModel.Body);
            }
        }
        public GlossaryController(GlossaryService glossaryService)
        {
            this._glossaryService = glossaryService;
            var connectionString = Settings.GetStringDB();

            ur = new UserRepository(connectionString);
        }
Exemple #3
0
        public async Task GetAllGlossaryEntries()
        {
            var contextId = Guid.NewGuid().ToString();

            await using (var context = InMemoryContentDbContext(contextId))
            {
                await context.AddRangeAsync(
                    new GlossaryEntry
                {
                    Title = "Exclusion",
                    Slug  = "exclusion",
                    Body  = "Exclusion body",
                },
                    new GlossaryEntry
                {
                    Title = "Absence",
                    Slug  = "absence",
                    Body  = "Absence body",
                },
                    new GlossaryEntry
                {
                    Title = "expedient",     // lowercase first letter
                    Slug  = "expedient-slug",
                    Body  = "Expedient body"
                });

                await context.SaveChangesAsync();
            }

            await using (var context = InMemoryContentDbContext(contextId))
            {
                var glossaryService = new GlossaryService(context);

                var result = await glossaryService.GetAllGlossaryEntries();

                Assert.Equal(26, result.Count);

                Assert.Equal("A", result[0].Heading);
                Assert.Single(result[0].Entries);
                Assert.Equal("Absence", result[0].Entries[0].Title);
                Assert.Equal("absence", result[0].Entries[0].Slug);
                Assert.Equal("Absence body", result[0].Entries[0].Body);

                Assert.Equal("B", result[1].Heading);
                Assert.Empty(result[1].Entries);

                Assert.Equal("E", result[4].Heading);
                Assert.Equal(2, result[4].Entries.Count);
                Assert.Equal("Exclusion", result[4].Entries[0].Title);
                Assert.Equal("exclusion", result[4].Entries[0].Slug);
                Assert.Equal("Exclusion body", result[4].Entries[0].Body);
                Assert.Equal("expedient", result[4].Entries[1].Title);
                Assert.Equal("expedient-slug", result[4].Entries[1].Slug);
                Assert.Equal("Expedient body", result[4].Entries[1].Body);

                Assert.Equal("Z", result[25].Heading);
                Assert.Empty(result[25].Entries);
            }
        }
        public IGlossaryService Build()
        {
            var glossaryService = new GlossaryService(DatabaseConnection, SqlBuilder);

            ResetFields();

            return(glossaryService);
        }
Exemple #5
0
        public async Task GetGlossaryEntry_NotFound()
        {
            await using var context = InMemoryContentDbContext();
            var glossaryService = new GlossaryService(context);

            var result = await glossaryService.GetGlossaryEntry("absence");

            result.AssertNotFound();
        }
Exemple #6
0
        public int AddGlossary(GlossaryForm form)
        {
            using (var uow = UnitOfWorkFactory.Create <NovelContext>())
            {
                var service = new GlossaryService(uow);
                var results = service.SaveChanges(form);

                return(results);
            }
        }
Exemple #7
0
        public PagedList <GlossaryGrid> Search(SearchModel <GlossaryCriteria> searchModel)
        {
            using (var uow = UnitOfWorkFactory.Create <NovelContext>())
            {
                var service = new GlossaryService(uow);
                var results = service.Search(searchModel);

                return(results);
            }
        }
Exemple #8
0
        public async Task GetAllGlossaryEntries_NoEntries()
        {
            await using var context = InMemoryContentDbContext();
            var glossaryService = new GlossaryService(context);

            var result = await glossaryService.GetAllGlossaryEntries();

            Assert.Equal(26, result.Count);

            result.ForEach(category => Assert.Empty(category.Entries));
        }
Exemple #9
0
        public PagedList <Glossary> Search(SearchModel <GlossaryCriteria> searchModel)
        {
            using (var uow = UnitOfWorkFactory.Create <NovelContext>())
            {
                var service = new GlossaryService(uow);

                var c       = searchModel.Criteria;
                var results = service.View <Glossary>().Where(w => w.IsDeleted == false)
                              .Join(service.View <Connector>().Where(w => w.ConnectorType == R.ConnectorType.NOVEL_GLOSSARY && w.SourceID == c.IDToInt),
                                    g => g.ID, cn => cn.TargetID, (g, cn) => g);

                return(results.ToPagedList(searchModel.PagedListConfig));
            }
        }
Exemple #10
0
        public GlossaryDetail Get(GlossaryCriteria criteria)
        {
            using (var uow = UnitOfWorkFactory.Create <NovelContext>())
            {
                var service = new GlossaryService(uow);
                var detail  = service.Get(criteria);

                detail.Summarize = service.View <Summarize>().Where(w => w.SourceTable == R.SourceTable.GLOSSARY && w.SourceID == detail.ID).SingleOrDefault() ?? new Summarize();

                detail.UserAction = new UserActionFacade().Get(new ViewForm {
                    UserID = criteria.ByUserID, SourceID = detail.ID, SourceTable = R.SourceTable.GLOSSARY
                });

                return(detail);
            }
        }
Exemple #11
0
        public void GlossaryServiceShouldAddNewItemAndSearch()
        {
            using (var context = new GlossaryDbContext(Options))
            {
                var service = new GlossaryService(context);
                var t       = Task.Run(async() => await service.Create(Fake1)).Result;
            }

            GlossaryItem Inserted;

            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new GlossaryDbContext(Options))
            {
                var service = new GlossaryService(context);
                Inserted = Task.Run(async() => await service.Get(Fake1.Id)).Result;
                Assert.AreEqual(Fake1.Id, Inserted.Id);
            }
        }
Exemple #12
0
        public void GlosssaryServicesShouldUpdateAndDeleteanItem()
        {
            using (var context = new GlossaryDbContext(Options))
            {
                var service = new GlossaryService(context);
                var t       = Task.Run(async() => await service.Create(Fake1)).Result;
            }

            GlossaryItem Updated;

            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new GlossaryDbContext(Options))
            {
                var service = new GlossaryService(context);
                var i       = Task.Run(async() => await service.Update(new GlossaryItem {
                    Id = Fake1.Id, Term = "Updated", Definition = "Updated"
                })).Result;
                Updated = Task.Run(async() => await service.Get(Fake1.Id)).Result;
                Assert.AreEqual(Updated.Id, Fake1.Id);
                Assert.AreEqual(Updated.Term, "Updated");
                Assert.AreEqual(Updated.Definition, "Updated");
            }
        }
Exemple #13
0
        public void GlosssaryServicesShouldReturnTheListOfItems()
        {
            var options = new DbContextOptionsBuilder <GlossaryDbContext>()
                          .UseInMemoryDatabase(databaseName: "List_database")
                          .Options;

            using (var context = new GlossaryDbContext(options))
            {
                var service1 = new GlossaryService(context);
                var t1       = Task.Run(async() => await service1.Create(Fake1)).Result;
                var t2       = Task.Run(async() => await service1.Create(Fake2)).Result;
                var t3       = Task.Run(async() => await service1.Create(Fake3)).Result;
            }

            var items = new List <GlossaryItem>();

            // Use a separate instance of the context to verify correct data was saved to database
            using (var context1 = new GlossaryDbContext(options))
            {
                var service2 = new GlossaryService(context1);
                items = Task.Run(async() => await service2.Get("")).Result;
                Assert.AreEqual(items.Count, 3);
            }
        }
Exemple #14
0
        public int AddNovel(NovelForm form)
        {
            using (var uow = UnitOfWorkFactory.Create <NovelContext>())
            {
                var service = new NovelService(uow);
                var id      = service.SaveChanges(form);

                if (form.Glossaries != null && form.InlineEditProperty == form.PropertyName(m => m.Glossaries))
                {
                    foreach (var glossary in form.Glossaries)
                    {
                        var glossaryService = new GlossaryService(uow);
                        var glossaryForm    = new GlossaryForm();
                        new PropertyMapper <Glossary, GlossaryForm>(glossary, glossaryForm).Map();
                        glossaryForm.SourceID    = id;
                        glossaryForm.SourceTable = R.SourceTable.NOVEL;
                        glossaryForm.ByUserID    = form.ByUserID;

                        var glossaryID = glossaryService.SaveChanges(glossaryForm);
                    }
                }
                return(id);
            }
        }
Exemple #15
0
        public int AddGroup(GroupForm form)
        {
            using (var uow = UnitOfWorkFactory.Create <NovelContext>())
            {
                var service = new GroupService(uow);
                var id      = service.SaveChanges(form);

                var connectorService = new ConnectorService(uow);

                if (form.Feeds != null || form.InlineEditProperty == form.PropertyName(m => m.Feeds))
                {
                    var feedService = new FeedService(uow);
                    foreach (var feed in form.Feeds)
                    {
                        feed.UrlHash         = feed.Url.GetIntHash();
                        feed.Status          = feed.Status == 0 ? R.FeedStatus.ACTIVE : feed.Status;
                        feed.LastSuccessDate = DateTime.Now.AddYears(-10);
                        var feedForm = new GenericForm <Feed>
                        {
                            ByUserID  = form.ByUserID,
                            DataModel = feed
                        };
                        var feedID = feedService.SaveChanges(feedForm);

                        // add to connector only if it a new feed
                        if (feed.ID == 0)
                        {
                            // connect series to feed
                            var connectorForm = new ConnectorForm()
                            {
                                ByUserID      = form.ByUserID,
                                ConnectorType = R.ConnectorType.GROUP_FEED,
                                SourceID      = id,
                                TargetID      = feedID
                            };
                            connectorService.SaveChanges(connectorForm);
                        }
                    }
                }

                if (form.Glossaries != null && form.InlineEditProperty == form.PropertyName(m => m.Glossaries))
                {
                    foreach (var glossary in form.Glossaries)
                    {
                        var glossaryService = new GlossaryService(uow);
                        var glossaryForm    = new GlossaryForm();
                        new PropertyMapper <Glossary, GlossaryForm>(glossary, glossaryForm).Map();
                        glossaryForm.ByUserID = form.ByUserID;

                        var glossaryID = glossaryService.SaveChanges(glossaryForm);

                        // connect group to glossary
                        var connectorForm = new ConnectorForm()
                        {
                            ByUserID      = form.ByUserID,
                            ConnectorType = R.ConnectorType.GROUP_GLOSSARY,
                            SourceID      = id,
                            TargetID      = glossaryID
                        };
                        connectorService.SaveChanges(connectorForm);
                    }
                }
                return(id);
            }
        }
Exemple #16
0
        public async Task RunAsync()
        {
            isDev = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WAZEBOT_ISDEV"));

            var token = Environment.GetEnvironmentVariable("DISCORD_API_TOKEN");

            if (token == null)
            {
                throw new ArgumentNullException(nameof(token), "No Discord API token env var found");
            }

            VerifyEnvironmentVariables();

            var clientConfig = new DiscordSocketConfig
            {
                LogLevel            = isDev ? LogSeverity.Info : LogSeverity.Warning,
                AlwaysDownloadUsers = true
            };

            client      = new DiscordSocketClient(clientConfig);
            client.Log += Log;

            var commandsConfig = new CommandServiceConfig
            {
                CaseSensitiveCommands = false
            };

            commands   = new CommandService(commandsConfig);
            httpClient = new HttpClient();
            httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("WazeBotDiscord/1.0");

            var autoreplyService = new AutoreplyService();
            await autoreplyService.InitAutoreplyServiceAsync();

            var keywordService = new KeywordService();
            await keywordService.InitKeywordServiceAsync();

            var glossaryService = new GlossaryService(httpClient);
            await glossaryService.InitAsync();

            var lookupService = new LookupService(httpClient);
            await lookupService.InitAsync();

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton(commands);
            serviceCollection.AddSingleton(autoreplyService);
            serviceCollection.AddSingleton(keywordService);
            serviceCollection.AddSingleton(lookupService);
            serviceCollection.AddSingleton(glossaryService);
            serviceCollection.AddSingleton(httpClient);

            client.Ready += async() => await client.SetGameAsync("with junction boxes");

            var twitterService = new TwitterService(client);

            serviceCollection.AddSingleton(twitterService);

            client.Connected += async() => await twitterService.InitTwitterServiceAsync();

            client.Disconnected += (ex) =>
            {
                twitterService.StopAllStreams();
                return(Task.CompletedTask);
            };

            services = serviceCollection.BuildServiceProvider();

            client.MessageReceived += async(SocketMessage msg) =>
                                      await AutoreplyHandler.HandleAutoreplyAsync(msg, autoreplyService);

            client.MessageReceived += async(SocketMessage msg) =>
                                      await KeywordHandler.HandleKeywordAsync(msg, keywordService, client);

            client.UserJoined += async(SocketGuildUser user) => await UserJoinedRoleSyncEvent.SyncRoles(user, client);

            await InstallCommands();

            await client.LoginAsync(TokenType.Bot, token);

            await client.StartAsync();

            await Task.Delay(-1);
        }
Exemple #17
0
 public GlossaryModule(GlossaryService glossarySvc)
 {
     _glossarySvc = glossarySvc;
 }
Exemple #18
0
 private readonly GlossaryService _glossaryService; //< Instance of GlossaryService to performs CRUD operations
 public GlossaryController(GlossaryService _glossaryService)
 {
     this._glossaryService = _glossaryService;
 }