public void CompareOutputAgainstGoldenSource([Range(0, 99)] int seed)
        {
            // Arrange
            var gameOutputStringBuilder = new StringBuilder();

            using (var gameOutput = new StringWriter(gameOutputStringBuilder))
            {
                Console.SetOut(gameOutput);
                var dice = new Dice();
                var consoleGameLogger = new ConsoleGameLogger();
                var categorySelector  = new CategorySelector();
                var questionFactory   = new QuestionFactory();
                var game   = new Game(consoleGameLogger, categorySelector, questionFactory);
                var random = new Random(seed);
                var randomAnsweringStrategy = new RandomAnsweringStrategy(random);

                var gameRunner = new GameRunner(dice, randomAnsweringStrategy, random, game);

                // Act
                gameRunner.Start();

                // Assert
                var actualGameOutput   = gameOutputStringBuilder.ToString();
                var expectedGameOutput = File.ReadAllText($@"c:\TestData\GoldenData_{seed}.txt");
                actualGameOutput.Should().BeEquivalentTo(expectedGameOutput);
            }
        }
Exemple #2
0
        private void btnSelect_Click(object sender, EventArgs e)
        {
            DbBrowser db = new DbBrowser();

            using (ItemSelector poetSeletor = new ItemSelector("انتخاب شاعر", db.Poets.ToArray(), null))
            {
                if (poetSeletor.ShowDialog(this) == DialogResult.OK)
                {
                    GanjoorPoet poet = poetSeletor.SelectedItem as GanjoorPoet;
                    PoetId = poet._ID;
                    txtSelectedPoetOrCategory.Text = poet._Name;
                    if (MessageBox.Show(
                            $"آیا تمایل دارید خوانش‌های بخش خاصی از آثار {poet._Name} را دریافت کنید؟",
                            "تأییدیه", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2,
                            MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign) == System.Windows.Forms.DialogResult.No)
                    {
                        db.CloseDb();

                        return;
                    }
                    using (CategorySelector catSelector = new CategorySelector(poet._ID, db))
                    {
                        if (catSelector.ShowDialog(this) == DialogResult.OK)
                        {
                            CatId = catSelector.SelectedCatID;
                            txtSelectedPoetOrCategory.Text = $"{poet._Name} » {db.GetCategory(CatId)._Text}";
                            db.CloseDb();
                        }
                    }
                }
            }
        }
        // GET: Classifier/Edit/5
        public ActionResult Edit(int id)
        {
            using (var db = new ChatLogDataContext())
            {
                // Get the item

                var item = db.ClassifiedMessages.SingleOrDefault(m => m.MessageId == id);

                if (item != null)
                {
                    var log = db.LogMessages.Single(m => m.Id == item.MessageId);

                    return(View("Classify", new ClassifyViewModel()
                    {
                        Categories = db.Categories.ToList(),
                        Selectors = CategorySelector.GetCategorySelectors(db.Categories.ToList()),
                        IsEditMode = true,
                        CategoryId = item.CategoryId.GetValueOrDefault(),
                        MessageId = item.MessageId,
                        SecondCategoryId = item.SecondCategoryId.GetValueOrDefault(),
                        RelatedMessages = db.LogMessages.Where(m => m.SessionFileName == log.SessionFileName).OrderBy(m => m.Id).ToList(),
                        Message = log.Message,
                        Mode = ClassificationMode.Edit,
                        SelectedCategories = item.SelectedCategories == null ? item.CategoryId.Value.ToString("N0") : item.SelectedCategories
                    }));
                }

                return(View("Classify"));
            }
        }
        public void CategorizedTestInUncategorizedFixture()
        {
            CategorySelector selector = new CategorySelector();

            selector.IncludedCategories.Add("grey");
            Assert.True(selector.Includes(new TestFixture(typeof(FixtureWithCategorizedTest))));
        }
Exemple #5
0
 protected void CloseShop()
 {
     MenuHeader.OnInventoryClicked -= OpenInventory;
     CategorySelector.ClearCategory();
     ShopGrid.ClearGrid();
     StoreManager.Clear();
     MessageController.Clean();
 }
        public void DeserializeExcludedCategories()
        {
            CategorySelector selector = new CategorySelector();

            selector.Deserialize(SerializedContent2);
            Assert.Contains("blue", selector.ExcludedCategories.ToArray());
            Assert.Equals(1, selector.ExcludedCategories.Count);
        }
        public void DeserializeIncludedCategories()
        {
            CategorySelector selector = new CategorySelector();

            selector.Deserialize(SerializedContent1);
            Assert.Contains("green", selector.IncludedCategories.ToArray());
            Assert.Equals(1, selector.IncludedCategories.Count);
        }
        public void SerializeExcludedCategories()
        {
            CategorySelector selector = new CategorySelector();

            selector.ExcludedCategories.Add("blue");
            XmlElement serialized = selector.Serialize();

            Assert.Equals(SerializedContent2, serialized.OwnerDocument.InnerXml);
        }
        public void ModifyingExcludedCategoriesFiresEvent()
        {
            CategorySelector selector      = new CategorySelector();
            ModifiedListener eventListener = new ModifiedListener();

            selector.Modified += eventListener.OnModified;
            selector.ExcludedCategories.Add("bla");
            Assert.True(eventListener.ModifiedEventFired, "Modified event wasn't fired.");
        }
        public void FiresChangedEventWhenCategoryAdded()
        {
            CategorySelector selector      = new CategorySelector();
            ModifiedListener eventListener = new ModifiedListener();

            selector.Modified += eventListener.OnModified;
            selector.IncludedCategories.Add("bla");
            Assert.True(eventListener.ModifiedEventFired, "Modified event wasn't fired.");
        }
Exemple #11
0
 private static void SetUpCategorySelector(string optionName, CmdLineHandler clh, IRecipe recipe)
 {
     if (clh.HasOption(optionName))
     {
         var selector = new CategorySelector();
         selector.IncludedCategories.Add(clh.GetOptionValueFor(optionName));
         recipe.RegisterSelector(selector);
     }
 }
        public void ChangingFilterMarksRecipeModified()
        {
            XmlDocumentFactory.Type = typeof(XmlDocumentMock);
            CategorySelector selector = new CategorySelector();
            IRecipe          recipe   = RecipeFactory.NewRecipe(string.Empty);

            recipe.RegisterSelector(selector);
            recipe.Save(@"c:\nirvana.recipe");
            Assert.False(recipe.Modified, "Expected recipe not being modified.");
            selector.IncludedCategories.Add("bla");
            Assert.True(recipe.Modified, "Expected recipe being modified.");
        }
Exemple #13
0
        public void SelectorContainsTestCategory()
        {
            int result = CsUnitApp.Main(new string[] { "/testCategory:green", _recipeOption });

            Assert.Equals(0, result);
            CategorySelector categorySelector = null;

            foreach (ISelector selector in RecipeMock._selectors)
            {
                categorySelector = selector as CategorySelector;
                if (null != categorySelector)
                {
                    break;
                }
            }
            Assert.Contains("green", categorySelector.IncludedCategories.ToArray());
        }
Exemple #14
0
    public override void Enter()
    {
        CloseInventory();

        MenuHeader.OnInventoryClicked += OpenInventory;

        StoreData data = ResourceManager.Instance.Load <StoreData>("Store/Some Random Store");

        StoreManager.Initialize(data);

        string[] categories = StoreManager.GetCategories();

        for (int i = 0; i < categories.Length; i++)
        {
            CategorySelector.AddCategory(i, categories[i], OnSelectCategory);
        }
    }
Exemple #15
0
        public static void Main(string[] args)
        {
            var rand = args.Length > 0 && int.TryParse(args[0], out var seed)
                ? new Random(seed)
                : new Random();

            var dice = new Dice();
            var consoleGameLogger = new ConsoleGameLogger();
            var categorySelector  = new CategorySelector();
            var questionFactory   = new QuestionFactory();

            var game = new Game(consoleGameLogger, categorySelector, questionFactory);
            var randomAnsweringStrategy = new ConsoleAnsweringStrategy();

            var gameRunner = new GameRunner(dice, randomAnsweringStrategy, rand, game);

            gameRunner.Start();
        }
        private ClassifyViewModel GetNextUnclassifiedItem(ClassificationMode mode, ChatLogDataContext db, int currentId)
        {
            var firstitem = db.LogMessages.OrderBy(m => m.Id).FirstOrDefault(m => m.Status == (short)mode);

            try
            {
                if (firstitem != null)
                {
                    var newitem = db.LogMessages.OrderBy(m => m.Id).FirstOrDefault(m => m.Status == (short)mode && m.Id > currentId);

                    if (newitem != null)
                    {
                        firstitem = newitem;
                    }
                }

                if (firstitem == null)
                {
                    firstitem = new LogMessage()
                    {
                        Id = 0, Message = string.Empty
                    };
                }

                // Get related messages
                var related = db.LogMessages.Where(m => m.SessionFileName == firstitem.SessionFileName).OrderBy(m => m.Id).ToList();

                return(new ClassifyViewModel()
                {
                    MessageId = firstitem.Id,
                    Mode = mode,
                    Message = firstitem.Message,
                    Categories = db.Categories.ToList(),
                    RelatedMessages = related,
                    Selectors = CategorySelector.GetCategorySelectors(db.Categories.ToList()),
                    SelectedCategories = string.Empty
                });
            }
            finally
            {
                firstitem = null;
            }
        }
        public void GenerateTestData([Range(0, 99)] int testRunId)
        {
            if (!Directory.Exists(TestDataPath))
            {
                Directory.CreateDirectory(TestDataPath);
            }

            var filePath = Path.Combine(TestDataPath, $@"GoldenData_{testRunId}.txt");

            if (!File.Exists(filePath))
            {
                using (var gameOutput = File.CreateText(filePath))
                {
                    Console.SetOut(gameOutput);

                    var dice = new Dice();
                    var consoleGameLogger = new ConsoleGameLogger();
                    var categorySelector  = new CategorySelector();
                    var questionFactory   = new QuestionFactory();
                    var game   = new Game(consoleGameLogger, categorySelector, questionFactory);
                    var random = new Random(testRunId);
                    var randomAnsweringStrategy = new RandomAnsweringStrategy(random);

                    var gameRunner = new GameRunner(dice, randomAnsweringStrategy, random, game);
                    gameRunner.Start();

                    gameOutput.Flush();
                }

                Assert.Pass("Master data file created successfully.");
            }
            else
            {
                Assert.Pass("Master data already exists.");
            }
        }
 public void DeserializeExcludedCategories() {
    CategorySelector selector = new CategorySelector();
    selector.Deserialize(SerializedContent2);
    Assert.Contains("blue", selector.ExcludedCategories.ToArray());
    Assert.Equals(1, selector.ExcludedCategories.Count);
 }
 public void SerializeExcludedCategories() {
    CategorySelector selector = new CategorySelector();
    selector.ExcludedCategories.Add("blue");
    XmlElement serialized = selector.Serialize();
    Assert.Equals(SerializedContent2, serialized.OwnerDocument.InnerXml);
 }
 public void DeserializeIncludedCategories() {
    CategorySelector selector = new CategorySelector();
    selector.Deserialize(SerializedContent1);
    Assert.Contains("green", selector.IncludedCategories.ToArray());
    Assert.Equals(1, selector.IncludedCategories.Count);
 }
 public void ModifyingExcludedCategoriesFiresEvent() {
    CategorySelector selector = new CategorySelector();
    ModifiedListener eventListener = new ModifiedListener();
    selector.Modified += eventListener.OnModified;
    selector.ExcludedCategories.Add("bla");
    Assert.True(eventListener.ModifiedEventFired, "Modified event wasn't fired.");
 }
 public void CategorizedTestInUncategorizedFixture() {
    CategorySelector selector = new CategorySelector();
    selector.IncludedCategories.Add("grey");
    Assert.True(selector.Includes(new TestFixture(typeof(FixtureWithCategorizedTest))));
 }
 public void ChangingFilterMarksRecipeModified() {
    XmlDocumentFactory.Type = typeof(XmlDocumentMock);
    CategorySelector selector = new CategorySelector();
    IRecipe recipe = RecipeFactory.NewRecipe(string.Empty);
    recipe.RegisterSelector(selector);
    recipe.Save(@"c:\nirvana.recipe");
    Assert.False(recipe.Modified, "Expected recipe not being modified.");
    selector.IncludedCategories.Add("bla");
    Assert.True(recipe.Modified, "Expected recipe being modified.");
 }
 public void FiresChangedEventWhenCategoryAdded() {
    CategorySelector selector = new CategorySelector();
    ModifiedListener eventListener = new ModifiedListener();
    selector.Modified += eventListener.OnModified;
    selector.IncludedCategories.Add("bla");
    Assert.True(eventListener.ModifiedEventFired, "Modified event wasn't fired.");
 }