コード例 #1
0
        public void Add_SavesToDatabase()
        {
            var options = new DbContextOptionsBuilder <GameInfoContext>()
                          .UseInMemoryDatabase(databaseName: "AddQuest_ToDb")
                          .Options;

            using (var context = new GameInfoContext(options))
            {
                var questToAdd = new AddQuestInputModel()
                {
                    Title = "QuestTitle", QuestText = "QuestText", CompletionCondition = "None"
                };

                questToAdd.QuestGiver = null;

                var service = new QuestsService(context, null);
                service.Add(questToAdd);

                var expectedQuest = new Quest()
                {
                    Title = questToAdd.Title, QuestText = questToAdd.QuestText, CompletionCondition = questToAdd.CompletionCondition
                };

                Assert.NotEmpty(context.Quests);
                Assert.Equal(expectedQuest.Title, context.Quests.First().Title);
                Assert.Equal(expectedQuest.QuestText, context.Quests.First().QuestText);
                Assert.Equal(expectedQuest.CompletionCondition, context.Quests.First().CompletionCondition);
            }
        }
コード例 #2
0
        public void All_WithData_ReturnsSameData()
        {
            var options = new DbContextOptionsBuilder <GameInfoContext>()
                          .UseInMemoryDatabase(databaseName: "Db_WithQuests")
                          .Options;

            using (var context = new GameInfoContext(options))
            {
                var service = new QuestsService(context, null);

                var quests = new List <Quest>
                {
                    new Quest()
                    {
                        Title = "1", QuestText = "1", CompletionCondition = "1"
                    },
                    new Quest()
                    {
                        Title = "2", QuestText = "2", CompletionCondition = "2"
                    },
                    new Quest()
                    {
                        Title = "3", QuestText = "3", CompletionCondition = "3"
                    }
                };

                context.Quests.AddRange(quests);
                context.SaveChanges();

                Assert.Equal(3, service.All().Count);
            }
        }
コード例 #3
0
        public QuestsViewModel()
        {
            var qs = new QuestsService();

            Quests = qs.GetQuestBySubSubClass(QuestClass, SubQuestClass, SubSubQuestClass);
            Title  = SubSubQuestClass;
        }
コード例 #4
0
        public SubQuestClassesViewModel()
        {
            var qs = new QuestsService();

            SubQuestClasses = qs.GetSubQuestClassNames(QuestClass);
            Title           = QuestClass;
        }
コード例 #5
0
        public void ByName_WithQuest_ReturnsQuest()
        {
            var options = new DbContextOptionsBuilder <GameInfoContext>()
                          .UseInMemoryDatabase(databaseName: "DbFor_ByName_WithQuest")
                          .Options;

            using (var context = new GameInfoContext(options))
            {
                var service = new QuestsService(context, null);

                var questTitle = "QuestTitle";

                var quest = new Quest()
                {
                    Title               = questTitle,
                    QuestText           = "TextForQuest",
                    CompletionCondition = "None"
                };

                context.Quests.Add(quest);
                context.SaveChanges();

                var questFromDb = service.ByName(questTitle);

                Assert.Equal(quest.Title, questFromDb.Title);
                Assert.Equal(quest.QuestText, questFromDb.QuestText);
                Assert.Equal(quest.CompletionCondition, questFromDb.CompletionCondition);
            }
        }
コード例 #6
0
        private void SetQuests()
        {
            var qs = new QuestsService();

            QuestTotal    = qs.GetTotal();
            QuestComplete = qs.GetNumberOfComplete();
        }
コード例 #7
0
        private void CheckBox_CheckedChanged(object sender, CheckedChangedEventArgs e)
        {
            var qs           = new QuestsService();
            var questChecked = (CheckBox)sender;

            qs.UpdateQuestCheck(questChecked.IsChecked, Quest);
        }
コード例 #8
0
        public QuestsViewModel(string questClass)
        {
            QuestClass = questClass;
            var qs = new QuestsService();

            Quests = qs.GetQuestByClass(QuestClass);
            Title  = SubSubQuestClass;
        }
コード例 #9
0
        private void CheckBox_CheckedChanged(object sender, CheckedChangedEventArgs e)
        {
            var   qs           = new QuestsService();
            var   questChecked = (CheckBox)sender;
            Quest quest        = questChecked.BindingContext as Quest;

            qs.UpdateQuestCheck(questChecked.IsChecked, quest);
        }
コード例 #10
0
        public SubSubQuestClassesViewModel(string questClass, string subQuestClass)
        {
            QuestClass    = questClass;
            SubQuestClass = subQuestClass;
            var qs = new QuestsService();

            SubSubQuestClasses = qs.GetSubSubQuestClassNames(QuestClass, SubQuestClass);
            Title = QuestClass;
        }
コード例 #11
0
        public QuestPage(Quest quest)
        {
            Quest = quest;
            InitializeComponent();
            var qs = new QuestsService();

            QuestLocation       = qs.GetLocationByQuest(Quest);
            this.BindingContext = new QuestViewModel(Quest);
        }
コード例 #12
0
        public void All_WithNoData_ReturnsNoData()
        {
            var options = new DbContextOptionsBuilder <GameInfoContext>()
                          .UseInMemoryDatabase(databaseName: "NoQuests_Db")
                          .Options;

            using (var context = new GameInfoContext(options))
            {
                var service = new QuestsService(context, null);
                Assert.Equal(0, service.All().Count);
            }
        }
コード例 #13
0
        public void ById_WithNoQuests_ReturnsNull()
        {
            var options = new DbContextOptionsBuilder <GameInfoContext>()
                          .UseInMemoryDatabase(databaseName: "NoQuests_DbFor_ById")
                          .Options;

            using (var context = new GameInfoContext(options))
            {
                var service = new QuestsService(context, null);
                Assert.Null(service.ById(1));
            }
        }
コード例 #14
0
        public void Delete_NoData_ReturnsNull()
        {
            var options = new DbContextOptionsBuilder <GameInfoContext>()
                          .UseInMemoryDatabase(databaseName: "NoQuests_Db_ForDelete")
                          .Options;

            using (var context = new GameInfoContext(options))
            {
                var service = new QuestsService(context, null);
                Assert.False(service.Delete(2));
            }
        }
コード例 #15
0
        public void OnMore(object sender, EventArgs e)
        {
            var item          = (ListView)sender;
            var subQuestClass = item.SelectedItem.ToString();
            var qs            = new QuestsService();

            if (qs.GetSubSubQuestClassNames(QuestClass, subQuestClass).Count > 1)
            {
                Navigation.PushAsync(new SubSubQuestClassesPage(QuestClass, subQuestClass));
            }
            else
            {
                Navigation.PushAsync(new QuestsPage(QuestClass, subQuestClass));
            }
        }
コード例 #16
0
        public QuestViewModel(Quest quest)
        {
            Quest = quest;
            Title = Quest.QuestName;
            var qs = new QuestsService();

            if (Quest.Location != "")
            {
                QuestLocation = qs.GetLocationByQuest(Quest);
                if (QuestLocation == null)
                {
                    return;
                }
                HasLocationLink = true;
            }
        }
コード例 #17
0
        public void Delete_WithData_DeletesQuest()
        {
            var options = new DbContextOptionsBuilder <GameInfoContext>()
                          .UseInMemoryDatabase(databaseName: "Db_WithQuest_ForDelete")
                          .Options;

            using (var context = new GameInfoContext(options))
            {
                context.Quests.Add(new Quest()
                {
                    Title = "ToDelete", QuestText = "None", CompletionCondition = "None"
                });
                context.SaveChanges();
            }

            using (var context = new GameInfoContext(options))
            {
                var service = new QuestsService(context, null);
                var result  = service.Delete(1);

                Assert.True(result);
                Assert.Equal(0, context.Quests.Count());
            }
        }
コード例 #18
0
        public QuestClassesViewModel()
        {
            var qs = new QuestsService();

            QuestClasses = qs.GetQuestClassNames();
        }
コード例 #19
0
 public QuestsController(QuestsService service)
 {
     _service = service;
 }
コード例 #20
0
 public QuestsController(QuestsService qs)
 {
     _qs = qs;
 }
コード例 #21
0
 public KnightsController(KnightsService ks, QuestsService qs)
 {
     _ks = ks;
     _qs = qs;
 }