Exemplo n.º 1
0
        public void RecipeFactoryProducingNonDefault()
        {
            RecipeFactory.Type = typeof(MySpecialRecipe);
            var recipe = RecipeFactory.NewRecipe(string.Empty);

            Assert.Equals(typeof(MySpecialRecipe), recipe.GetType());
        }
Exemplo n.º 2
0
        public void DefaultCreatesRecipeInstance()
        {
            RecipeFactory.Type = RecipeFactory.Default;
            var recipe = RecipeFactory.NewRecipe(string.Empty);

            Assert.Equals(typeof(Recipe), recipe.GetType());
        }
Exemplo n.º 3
0
        public void RecipeFileName()
        {
            RecipeFactory.Type = typeof(MySpecialRecipe);
            var recipe = RecipeFactory.NewRecipe("foo.recipe");

            Assert.Equals("foo.recipe", recipe.PathName);
        }
Exemplo n.º 4
0
        public void FindAssemblyByNameInEmptyRecipe()
        {
            var r  = RecipeFactory.NewRecipe(string.Empty);
            var ta = r[_csUnitTestExePath];

            Assert.Null(ta);
        }
Exemplo n.º 5
0
        //-------------------------------------------------------------------------------------------
        public GameSession()
        {
            int dexterity = RandomNumberGenerator.SimpleNumberBetween(3, 40);

            CurrentPlayer = new Player
                            (
                "Player",
                "Paladin",
                15,
                10,
                10,
                20,
                dexterity
                            );

            if (!CurrentPlayer.Weapons.Any())
            {
                CurrentPlayer.AddWeaponToWeapons(WeaponFactory.CreateWeapon(1001));
            }
            CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(6001));
            CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(4000), 4);
            CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(4001), 4);
            CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(4002), 4);
            CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(4003), 4);
            CurrentPlayer.LearnRecipe(RecipeFactory.RecipeByID(1));
            CurrentPlayer.LearnRecipe(RecipeFactory.RecipeByID(2));

            CurrentWorld    = WorldFactory.CreateWorld(CurrentPlayer.Name);
            CurrentLocation = CurrentWorld.LocationAt(0, 0);
        }
Exemplo n.º 6
0
        public GameSession()
        {
            #region Initialize Player

            CurrentPlayer = new Player("Scott", "Fighter", 0, 10, 10, 1000000);

            if (!CurrentPlayer.Weapons.Any())
            {
                CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(1001));
            }

            CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(2001));
            CurrentPlayer.LearnRecipe(RecipeFactory.RecipeByID(1));
            CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(3001));
            CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(3002));
            CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(3003));

            #endregion Initialize Player

            #region Initialize World

            CurrentWorld    = WorldFactory.CreateWorld();
            CurrentLocation = CurrentWorld.LocationAt(0, 0);

            #endregion Initialize World
        }
Exemplo n.º 7
0
        public void CriterionAppliedWithMultipleAssemblies()
        {
            var recipe = RecipeFactory.NewRecipe("twoassemblies.deleteme.recipe");

            recipe.AddAssembly(_testDll);
            var testDll = Path.Combine(Util.SolutionCodeBase,
                                       "csUnit.CompatibilityTests\\NUnit-2.4.7\\bin\\Debug\\NUnit-2.4.7.dll");

            recipe.AddAssembly(testDll);
            var listener = new SimpleRecipeListener(recipe);

            recipe.RunTests(new TestRun(new AllTestsCriterion()));
            recipe.Join();
            Assert.Equals(7, listener.TestCount);
            Assert.Equals(5, listener.PassedCount);

            listener = new SimpleRecipeListener(recipe);
            var setCriterion = new MultipleTestsCriterion();

            setCriterion.Add("TestDll", "TestDll.ClassWithTests", "AFailingTest");
            setCriterion.Add("TestDll", "TestDll.ClassWithTests", "ATestWithError");
            recipe.RunTests(new TestRun(setCriterion));

            recipe.Join();
            Assert.Equals(2, listener.TestCount);
        }
Exemplo n.º 8
0
        public void EmptyRecipeTestRunDoesntFail()
        {
            var recipe = RecipeFactory.NewRecipe(string.Empty);

            recipe.RunTests(new TestRun(new AllTestsCriterion()));
            Assert.False(recipe.TestsRunning);
        }
Exemplo n.º 9
0
        public void SelectingNoneIncludesAll()
        {
            RecipeFactory.Type = typeof(ASpecialRecipe);
            var recipe = RecipeFactory.NewRecipe(string.Empty);

            _fc.ResetAllCategories();

            var testRun = new TestRun(new AllTestsCriterion());

            recipe.RunTests(testRun);

            ISelector registeredFilter = null;

            foreach (var filter in recipe.Selectors)
            {
                if (filter.Equals(_fc.Filter))
                {
                    registeredFilter = filter;
                    break;
                }
            }
// ReSharper disable PossibleNullReferenceException
            Assert.True(registeredFilter.Includes(new ASpecialTestMethod("Blue")));
// ReSharper restore PossibleNullReferenceException
            Assert.True(registeredFilter.Includes(new ASpecialTestMethod("Red")));
            Assert.True(registeredFilter.Includes(new ASpecialTestMethod("Green")));
        }
Exemplo n.º 10
0
        private static void PopulatePlayerRecipes(JsonDocument document, Player player)
        {
            var fileVersion = FileVersion(document);

            switch (fileVersion)
            {
            case "0.1.000":
                foreach (var recipeToken in
                         document.RootElement
                         .GetProperty(nameof(GameSession.CurrentPlayer))
                         .GetProperty(nameof(Player.Recipes))
                         .EnumerateArray())
                {
                    var recipeId = recipeToken.GetProperty(nameof(Recipe.ID)).GetInt32();

                    var recipe = RecipeFactory.RecipeByID(recipeId);

                    player.Recipes.Add(recipe);
                }

                break;

            default:
                throw new InvalidDataException($"File version '{fileVersion}' not recognized");
            }
        }
Exemplo n.º 11
0
        public GameSession()
        {
            CurrentPlayer = new Player("Chad", "Magic User?", 0, 20, 20, 10, 10, 101);

            if (!CurrentPlayer.Weapons.Any())
            {
                CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(1001));
                CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(1005));
            }

            if (!CurrentPlayer.MagicList.Any())
            {
                CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(7001));
                CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(7002));
            }

            CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(8001));

            // Legendary Sword
            CurrentPlayer.LearnRecipe(RecipeFactory.RecipeByID(1));
            CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(3000));
            CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(3001));
            CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(3002));

            // Prison Key
            CurrentPlayer.LearnRecipe(RecipeFactory.RecipeByID(2));
            CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(3003));
            CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(3004));
            CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(3005));

            CurrentWorld = WorldFactory.CreateWorld();

            CurrentLocation = CurrentWorld.LocationAt(-3, 1);
        }
Exemplo n.º 12
0
        public void StoresRelativePaths()
        {
// ReSharper disable AssignNullToNotNullAttribute
// ReSharper disable PossibleNullReferenceException
            XmlDocumentFactory.Type = typeof(XmlDocumentMock);
            LoaderFactory.Type      = typeof(LoaderMock);
            var codeBase = GetType().Assembly.CodeBase;

            var url = new Uri(codeBase);
            var assemblyPathName = url.AbsolutePath;

            var fi   = new FileInfo(assemblyPathName);
            var path = fi.DirectoryName;

            var src = RecipeFactory.NewRecipe(Path.Combine(path, "StoresRelativePaths.recipe"));

            src.Clear();
            src.AddAssembly(assemblyPathName);
            src.Save();

            var doc = XmlDocumentFactory.CreateInstance();

            doc.Load(Path.Combine(path, "StoresRelativePaths.recipe"));
            var elem = doc["recipe"]["assembly"];

            Assert.Equals("csUnit.Core.Tests.DLL", elem.Attributes["path"].Value);
// ReSharper restore AssignNullToNotNullAttribute
// ReSharper restore PossibleNullReferenceException
        }
Exemplo n.º 13
0
        public GameSession()
        {
            #region Create player

            var dex = RandomNumberGenerator.NumberBetween(3, 18);
            CurrentPlayer = new Player("Scott", "Fighter", 0, dex, 10, 10, 1000);

            #endregion

            if (CurrentPlayer.Inventory.Weapons.Any() == false)
            {
                CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(1001));
            }

            CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(2001));
            CurrentPlayer.LearnRecipe(RecipeFactory.RecipeByID(1));
            CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(3001));
            CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(3002));
            CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(3003));
            CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(4001));
            CurrentPlayer.AddItemToInventory(ItemFactory.CreateGameItem(4002));

            CurrentWorld = WorldFactory.CreateWorld();

            CurrentLocation = CurrentWorld.LocationAt(0, -1);
        }
Exemplo n.º 14
0
 public void TearDown()
 {
     XmlDocumentFactory.Type = XmlDocumentFactory.Default;
     XmlDocumentMock.Reset();
     RecipeFactory.Type = RecipeFactory.Default;
     RecipeFactory.NewRecipe(string.Empty);
 }
Exemplo n.º 15
0
        public void ApplyBitterToRecipe()
        {
            RecipeFactory     myFactory           = new RecipeFactory();
            IRecipe           myRecipe            = myFactory.GetRecipe(RecipeTypes.Beer);
            IngredientFactory myIngredientFactory = new IngredientFactory();
            var ingredient = myIngredientFactory.GetIngredient(IngredientType.Fermentable);

            ingredient.Amount = 10;
            (ingredient as IFermentable).DiastaticPower = 1.04;
            myRecipe.Ingredients.Add(ingredient);
            //adding bitters is just a test for my sanity in querying interfaces and dealing with Covariance
            //note it will be repeated on the IBU calculation as the fermentable power impacts bitterness
            ingredient        = myIngredientFactory.GetIngredient(IngredientType.BitterSeason);
            ingredient.Amount = 1.5;
            (ingredient as IBitter).BitteringFactor       = 15;
            (ingredient as IBitter).BitterCalculationTime = 60;
            myRecipe.Ingredients.Add(ingredient);
            myRecipe.BatchVolume            = 6.5;
            myRecipe.TotalEfficiencyPercent = 70;
            var ibus = myRecipe.GetEstimatedBitterness();

            Assert.AreEqual(myRecipe.Bitters.Count, 1);
            //May need to check formula.  BeerSmith usually is a little higher.  BeerSmith has been known to tweak their forumulas though.
            Assert.AreEqual(63.81, Math.Round(ibus, 2));
        }
Exemplo n.º 16
0
        public void FilterControlRegistersFilter()
        {
            RecipeFactory.Type = typeof(ASpecialRecipe);
            var recipe = RecipeFactory.NewRecipe(string.Empty);

            Assert.NotNull(_fc);
            Assert.Equals(recipe.Selectors.Count, 1);
        }
Exemplo n.º 17
0
        public void AddAssembly()
        {
            LoaderFactory.Type = typeof(LoaderMock);
            var r = RecipeFactory.NewRecipe(string.Empty);

            r.AddAssembly(_csUnitTestExePath);
            Assert.Equals(1, r.AssemblyCount);
        }
Exemplo n.º 18
0
        public void FilterControlRegistersFilter()
        {
            RecipeFactory.Type = typeof(ASpecialRecipe);
            _fc = new CategoryControl();
            IRecipe recipe = RecipeFactory.NewRecipe("");

            Assert.Greater(recipe.Selectors.Count, 0);
        }
Exemplo n.º 19
0
 protected override void Execute(object sender, EventArgs args)
 {
     if (CommandTarget.AskSaveModifiedRecipe() == false)
     {
         return;
     }
     RecipeFactory.NewRecipe(string.Empty);
 }
Exemplo n.º 20
0
        public void FiresClosingLoadedEventsWithNewInstance()
        {
            var eventHandler = new MyEventHandler2();

            RecipeFactory.Loaded  += eventHandler.OnRecipeLoaded;
            RecipeFactory.Closing += eventHandler.OnRecipeClosing;
            RecipeFactory.NewRecipe(string.Empty);
            Assert.Equals("OnRecipeClosingOnRecipeLoaded", eventHandler.Events);
        }
Exemplo n.º 21
0
        public GameSession()
        {
            CurrentLocation = CurrentWorld.LocationAt(0, 0);

            CurrentPlayer = new Player("Test", "Fighter", 10, gold: 1000);
            CurrentPlayer.AddToInventory(ItemFactory.NewItem(1001));
            CurrentPlayer.AddToInventory(ItemFactory.NewItem(2001));
            CurrentPlayer.LearnRecipe(RecipeFactory.GetRecipe(1));
        }
Exemplo n.º 22
0
        public void FindAssemblyByName()
        {
            LoaderFactory.Type = typeof(LoaderMock);
            var r = RecipeFactory.NewRecipe(string.Empty);

            r.AddAssembly(_csUnitTestExePath);
            var ta = r[_csUnitTestExePath];

            Assert.Equals(ta.Name.CodeBase, _csUnitTestExePath);
        }
Exemplo n.º 23
0
        public void FindAssemblyByNameWithUnknownName()
        {
            LoaderFactory.Type = typeof(LoaderMock);
            IRecipe r = RecipeFactory.NewRecipe(string.Empty);

            r.AddAssembly(_csUnitTestExePath);
            var ta = r["fluffy duck"];

            Assert.Null(ta);
        }
Exemplo n.º 24
0
    private void Awake()
    {
        object[] objects = Resources.LoadAll("Recipes");
        recipes = new Recipe[objects.Length];
        for (int i = 0; i < objects.Length; i++)
        {
            recipes[i] = (Recipe)objects[i];
        }

        instance = this;
    }
Exemplo n.º 25
0
        public void RecipeCurrentIsUsefulForInvalidRecipePathName()
        {
            var eventHandler = new MyEventHandler2();

            RecipeFactory.Loaded     += eventHandler.OnRecipeLoaded;
            RecipeFactory.LoadFailed += eventHandler.OnRecipeLoadFailed;
            Assert.NotNull(RecipeFactory.Current);
            RecipeFactory.Load("invalid.recipe");
            Assert.NotNull(RecipeFactory.Current);
            Assert.Equals("OnRecipeLoadFailed", eventHandler.Events);
        }
Exemplo n.º 26
0
        public void CanAddAssemblyByUri()
        {
            LoaderFactory.Type = typeof(LoaderMock);
            var recipe   = RecipeFactory.NewRecipe(string.Empty);
            var assembly = GetType().Assembly;
            var url      = new Uri(assembly.CodeBase);

            recipe.AddAssembly(assembly.CodeBase);
            Assert.Equals(1, recipe.Assemblies.Length);
            Assert.Contains(url.LocalPath, recipe.Assemblies[0].Name.CodeBase);
        }
Exemplo n.º 27
0
        public IngReceiptNoteSelfMadeController()
        {
            _factory           = new ReceiptNoteSelfMadeFactory();
            _ingredientFactory = new IngredientFactory();
            _recipeFactory     = new RecipeFactory();
            _inventoryFactory  = new InventoryFactory();

            ViewBag.ListStore = GetListStore();
            lstStore          = ViewBag.ListStore;
            //==========
        }
Exemplo n.º 28
0
        private static string RunRecipe(ConfigurationContainer config, ILogger logger)
        {
            var tempFilePath = Path.GetTempFileName();

            logger?.Trace("Temporary file path is {0} ...", tempFilePath);

            var recipe = RecipeFactory.GetRecipe(config);

            recipe.DownloadFile(tempFilePath, logger);

            return(tempFilePath);
        }
Exemplo n.º 29
0
        public IngRecipesController()
        {
            _factory           = new RecipeFactory();
            _UOMFactory        = new UnitOfMeasureFactory();
            _IngredientFactory = new IngredientFactory();

            ViewBag.ListStore = GetListStore();
            //==========
            lstStore         = ViewBag.ListStore;
            listStoreId      = lstStore.Select(x => x.Value).ToList();
            ViewBag.IsAction = Commons.IsAction;
        }
Exemplo n.º 30
0
        private static void PopulatePlayerRecipes(JObject data, Player player)
        {
            foreach (JToken recipeToken in
                     (JArray)data[nameof(GameSession.CurrentPlayer)][nameof(Player.Recipes)])
            {
                int recipeId = (int)recipeToken[nameof(Recipe.ID)];

                Recipe recipe = RecipeFactory.RecipeByID(recipeId);

                player.Recipes.Add(recipe);
            }
        }