public void DotNetCoreAlias_AddNugetSource_Success()
        {
            var feedUrl1  = "testUrl";
            var feedUrl2  = "blahUrl";
            var feedName2 = "blah";

            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            Assert.IsFalse(SingletonFactory.ExistsInCache(typeof(HelperSettings)));

            context.AddDotNetCoreHelperNugetSource(feedUrl1);

            var helperSetting = SingletonFactory.GetHelperSettings();

            Assert.IsNotNull(helperSetting);

            var nugetSources = helperSetting.DotNetCoreSettings.NugetSettings.NugetSources.ToArray();

            Assert.AreEqual(2, nugetSources.Length);
            Assert.IsTrue(nugetSources.Any(t => t.FeedSource == feedUrl1 && string.IsNullOrWhiteSpace(t.FeedName)));

            context.AddDotNetCoreHelperNugetSource(feedUrl2, config =>
            {
                config.FeedName = feedName2;
            });

            nugetSources = helperSetting.DotNetCoreSettings.NugetSettings.NugetSources.ToArray();
            Assert.AreEqual(3, nugetSources.Length);
            Assert.IsTrue(nugetSources.Any(t => t.FeedSource == feedUrl1 && string.IsNullOrWhiteSpace(t.FeedName)));
            Assert.IsTrue(nugetSources.Any(t => t.FeedSource == feedUrl2 && t.FeedName == feedName2));
        }
Exemplo n.º 2
0
        public void TaskHelper_AddTaskDependency_DependentTaskExists()
        {
            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            SingletonFactory.Context = context;

            var settings = SingletonFactory.GetHelperSettings();

            settings.TaskTargetFunc = taskName => { return(new CakeTaskBuilder <ActionTask>(new ActionTask(taskName))); };

            var taskHelper = SingletonFactory.GetTaskHelper();

            Assert.IsNotNull(taskHelper);

            var firstTask = taskHelper.AddTask("test");
            var nextTask  = taskHelper.AddTask("test2");

            Assert.AreEqual(0, firstTask.Task.Dependencies.Count);
            Assert.AreEqual(0, nextTask.Task.Dependencies.Count);

            taskHelper.AddTaskDependency(firstTask, nextTask);

            Assert.AreEqual(1, firstTask.Task.Dependencies.Count);
            Assert.IsTrue(firstTask.Task.Dependencies.Contains("test2"));
            Assert.AreEqual(0, nextTask.Task.Dependencies.Count);

            taskHelper.AddTaskDependency(firstTask, nextTask);

            Assert.AreEqual(1, firstTask.Task.Dependencies.Count);
            Assert.IsTrue(firstTask.Task.Dependencies.Contains("test2"));
            Assert.AreEqual(0, nextTask.Task.Dependencies.Count);
        }
Exemplo n.º 3
0
    public void Damage(Item?itemUsed, Player player)
    {
        if (itemUsed != null && itemUsed == recommendedTool)
        {
            curHp -= maxHp;
        }
        else
        {
            curHp--;
        }

        audioSource.Play();

        if (curHp <= 0)
        {
            if (player != null)
            {
                player.AddResource(givenResource, resourceQuantity);
                SingletonFactory.GetInstance <ParserUtil>().PrintResponse("Added " + resourceQuantity + " " + givenResource + " to inventory");
                player.GetAudioSource().clip = SingletonFactory.GetInstance <PrefabUtil>().pickupClip;
                player.GetAudioSource().Play();
            }

            HideObject();
            Invoke("DestroySelf", 1.0f);
        }
        else
        {
            damageSprite.GetComponent <SpriteRenderer>().sprite = SingletonFactory.GetInstance <PrefabUtil>().damageSprite[maxHp - curHp - 1];
        }
    }
Exemplo n.º 4
0
        public void GetHelperSettings_Success()
        {
            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            SingletonFactory.Context = context;

            var settings = SingletonFactory.GetHelperSettings();

            Assert.IsNotNull(settings);
            Assert.IsNotNull(settings.Context);
            Assert.IsFalse(settings.RunAllDependencies);

            Assert.IsNotNull(settings.DotNetCoreSettings);

            Assert.IsNotNull(settings.DotNetCoreSettings.NugetSettings);
            Assert.IsNotNull(settings.DotNetCoreSettings.NugetSettings.Context);
            Assert.AreEqual(1, settings.DotNetCoreSettings.NugetSettings.NugetSources.Count());

            Assert.IsNotNull(settings.DotNetCoreSettings.BuildSettings);
            Assert.AreEqual("./BuildTemp", settings.DotNetCoreSettings.BuildSettings.BuildTempFolder);

            Assert.IsNotNull(settings.DotNetCoreSettings.TestSettings);
            Assert.AreEqual("./TestTemp", settings.DotNetCoreSettings.TestSettings.TestTempFolder);

            var newSettings = SingletonFactory.GetHelperSettings();

            Assert.AreEqual(settings, newSettings);
        }
Exemplo n.º 5
0
    private void GetNextAction()
    {
        Vector3   ray       = SingletonFactory.GetInstance <Player>().transform.position - transform.position;
        Direction direction = GetDirectionFromVector(ray);

        RaycastHit2D hit = GetBlockingObject(direction);

        if (hit.collider != null)
        {
            Obstacle obstacle = hit.collider.GetComponent <Obstacle>();
            if (obstacle != null)
            {
                verbStack.Add(Verb.USE);
                directionStack.Add(direction);
            }
            else
            {
                Player player = hit.collider.GetComponent <Player>();
                if (player != null)
                {
                    verbStack.Add(Verb.USE);
                    directionStack.Add(direction);
                }
            }
        }
        else
        {
            verbStack.Add(Verb.MOVE);
            directionStack.Add(direction);
        }
    }
Exemplo n.º 6
0
    private void GenerateMap()
    {
        for (int x = -maxMapBound; x < maxMapBound + 1; x++)
        {
            for (int y = -maxMapBound; y < maxMapBound + 1; y++)
            {
                if ((x != 0 || y != 0) && Random.value < 0.1f)
                {
                    float      resourceType = Random.value * 3.0f;
                    GameObject resource;
                    PrefabUtil prefabUtil = SingletonFactory.GetInstance <PrefabUtil>();

                    if (resourceType < 1.0f)
                    {
                        resource = prefabUtil.treePre;
                    }
                    else if (resourceType < 2.0f)
                    {
                        resource = prefabUtil.stonePre;
                    }
                    else
                    {
                        resource = prefabUtil.ironPre;
                    }

                    Instantiate(resource, new Vector3(x, y, 0), Quaternion.identity);
                }
            }
        }
    }
Exemplo n.º 7
0
    public virtual void Damage(Item?equippedItem, Player player)
    {
        if (equippedItem != null && equippedItem == recommendedTool)
        {
            curHp -= maxHp;
        }
        else
        {
            curHp--;
        }

        audioSource.Play();

        if (curHp <= 0)
        {
            if (player != null && Random.Range(0.0f, 1.0f) < dropRate)
            {
                player.AddItem(givenItem);
                SingletonFactory.GetInstance <ParserUtil>().PrintResponse("Added " + givenItem + " to inventory");
                player.GetAudioSource().clip = SingletonFactory.GetInstance <PrefabUtil>().pickupClip;
                player.GetAudioSource().Play();
            }

            HideObject();
            Invoke("DestroySelf", 1.0f);
        }
    }
Exemplo n.º 8
0
        private bool LoadGame(string fileName)
        {
            SingletonFactory <GameController> .Instance.CreateNewGame();

            UserInfo info;

            if (!string.IsNullOrEmpty(fileName))
            {
                fileName = m_DefaultFileName;
            }

            if (string.IsNullOrEmpty(fileName))
            {
                fileName = "autosave";
            }

            info = FileUtil.LoadData <UserInfo>(string.Format(".\\{0}.txt", fileName));
            if (info != null)
            {
                SingletonFactory <UserInfo> .ResetInstance(info);

                m_DefaultFileName = fileName;
                return(true);
            }
            return(false);
        }
Exemplo n.º 9
0
        void Run()
        {
            try
            {
                do
                {
                    Token.ThrowIfCancellationRequested();
                    Instance.Run();

                    var Factory = SingletonFactory.GetInstance <ThreadFactory>();
                    Factory.Dispatch(d => d.Run(Instance));
                }while (Instance.Loop || Running);
            }
            catch (TaskCanceledException) { }
            catch (OperationCanceledException) { }
            catch (Exception ex)
            {
                LoggerFactory.GetLogger().LogFatal(ex);
            }
            finally
            {
                Instance.End();
                var Factory = SingletonFactory.GetInstance <ThreadFactory>();
                Factory.Dispatch(d => d.End(Instance));
            }
        }
Exemplo n.º 10
0
    public void Craft(Item item, int quantity)
    {
        ParserUtil parserUtil = SingletonFactory.GetInstance <ParserUtil>();
        ItemUtil   itemUtil   = SingletonFactory.GetInstance <ItemUtil>();
        Dictionary <Resource, int> requiredResources = itemUtil.GetRequiredResources(item);

        int numCrafted = 0;

        for (int i = 0; i < quantity; i++)
        {
            if (HasRequiredResources(requiredResources))
            {
                foreach (KeyValuePair <Resource, int> requiredResource in requiredResources)
                {
                    resourceInventory[requiredResource.Key] -= requiredResource.Value;
                }

                AddItem(item);
                numCrafted++;
            }
            else
            {
                parserUtil.PrintResponse("Not enough resources to craft '" + item.ToString() + "'");
                break;
            }
        }

        if (numCrafted > 0)
        {
            parserUtil.PrintResponse("Crafted " + numCrafted + " '" + item.ToString() + (numCrafted > 1 ? "s" : "") + "'");
        }
    }
        public void DotNetCoreAlias_AddProject_Default_NoTestFilters()
        {
            var context    = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());
            var defaultSln = SolutionFixture.GetDefaultSolution(context.FileSystem);

            context.AddDotNetCoreProject(defaultSln.SlnFile.Path.FullPath);

            var helperSetting = SingletonFactory.GetHelperSettings();

            Assert.IsNotNull(helperSetting);

            helperSetting.DotNetCoreSettings.TestSettings.TestProjectNameFilters.Clear();
            var projects = helperSetting.DotNetCoreSettings.Projects.ToArray();

            Assert.AreEqual(1, projects.Length);
            Assert.IsTrue(projects.Any(t => t.ProjectAlias == "CakeHelpers"));

            var slnProj = projects.FirstOrDefault();

            Assert.IsNotNull(slnProj);
            Assert.AreEqual("CakeHelpers", slnProj.ProjectAlias);
            slnProj.ProjectAlias = "Test";
            Assert.AreEqual("Test", slnProj.ProjectAlias);
            Assert.IsTrue(string.IsNullOrWhiteSpace(slnProj.Configuration));
            Assert.IsTrue(string.IsNullOrWhiteSpace(slnProj.Framework));
            Assert.IsTrue(string.IsNullOrWhiteSpace(slnProj.Platform));
            Assert.AreEqual(2, slnProj.AllProjects.Count());
            Assert.AreEqual(2, slnProj.SrcProjects.Count());
            Assert.AreEqual(0, slnProj.TestProjects.Count());
        }
Exemplo n.º 12
0
        public void HelperTask_Category_TaskType_Success()
        {
            var taskName = "Blah";
            var category = "UnitTest";
            var taskType = "UnitTest";

            var context  = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());
            var settings = this.GetSettings(context);
            var task     = context.HelperTask(taskName, true, category, taskType);

            Assert.IsNotNull(task);

            var taskHelper = SingletonFactory.GetTaskHelper();

            Assert.IsNotNull(task);
            Assert.AreEqual(taskName, task.Task.Name);

            var helperTask = taskHelper.Tasks.FirstOrDefault(t => t.Task == task.Task);

            Assert.IsNotNull(helperTask);
            Assert.AreEqual(taskName, helperTask.TaskName);
            Assert.AreEqual(true, helperTask.IsTarget);
            Assert.AreEqual(category, helperTask.Category);
            Assert.AreEqual(taskType, helperTask.TaskType);
        }
Exemplo n.º 13
0
        public void TaskHelper_RunTarget_Task_Success()
        {
            var target = "Test Target";

            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            SingletonFactory.Context = context;
            var settings = SingletonFactory.GetHelperSettings();

            var targetRanSuccess = false;

            settings.TaskTargetFunc = taskName => { return(new CakeTaskBuilder <ActionTask>(new ActionTask(taskName))); };

            settings.RunTargetFunc = targ =>
            {
                targetRanSuccess = targ == target;
                return(new CakeReport());
            };

            var targetTaskBuilder = context.HelperTask(target);

            var taskHelper = SingletonFactory.GetTaskHelper();

            Assert.IsNotNull(taskHelper);

            var helperTask = taskHelper.Tasks.FirstOrDefault(t => t.Task == targetTaskBuilder.Task);

            Assert.IsNotNull(helperTask);

            var report = taskHelper.RunTarget(helperTask);

            Assert.IsNotNull(report);
            Assert.IsTrue(targetRanSuccess);
        }
Exemplo n.º 14
0
        public void TaskHelper_RunTarget_String_Success()
        {
            var target = "Test Target";

            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            SingletonFactory.Context = context;
            var settings = SingletonFactory.GetHelperSettings();

            var targetRanSuccess = false;

            settings.RunTargetFunc = targ =>
            {
                targetRanSuccess = targ == target;
                return(new CakeReport());
            };

            var taskHelper = SingletonFactory.GetTaskHelper();

            Assert.IsNotNull(taskHelper);

            var report = taskHelper.RunTarget(target);

            Assert.IsNotNull(report);
            Assert.IsTrue(targetRanSuccess);
        }
Exemplo n.º 15
0
        public void TaskHelper_AddTask_ExistsInCache()
        {
            var target = "Test Target";

            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            SingletonFactory.Context = context;
            var settings = SingletonFactory.GetHelperSettings();

            var targetRanSuccess = false;

            settings.TaskTargetFunc = taskName => { return(new CakeTaskBuilder <ActionTask>(new ActionTask(taskName))); };

            settings.RunTargetFunc = targ =>
            {
                targetRanSuccess = targ == target;
                return(new CakeReport());
            };

            var taskHelper = SingletonFactory.GetTaskHelper();

            Assert.IsNotNull(taskHelper);

            var firstTask = taskHelper.AddTask(target);

            Assert.IsNotNull(firstTask);

            var nextTask = taskHelper.AddTask(target);

            Assert.IsNotNull(nextTask);
            Assert.AreEqual(firstTask, nextTask);
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            ReplacableSingleton replacableSingleton = SingletonFactory.Get();
            Client client = new Client(replacableSingleton);

            client.SetSingleton(replacableSingleton);
        }
        public void HelperSettings_Setup_Success()
        {
            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            SingletonFactory.Context = context;

            var dotNetCoreHelper = SingletonFactory.GetDotNetCoreHelper();

            Assert.IsNotNull(dotNetCoreHelper);
            var coreHelperType = dotNetCoreHelper.GetType();

            Assert.IsTrue(SingletonFactory.ExistsInCache(coreHelperType));

            SingletonFactory.ClearFactory();
            SingletonFactory.Context = context;
            Assert.IsFalse(SingletonFactory.ExistsInCache(coreHelperType));

            var helperSetting = new HelperSettings();

            ((DotNetCoreHelperSettings)helperSetting.DotNetCoreSettings).IsActive = true;

            helperSetting.SetupSetting();
            Assert.IsTrue(SingletonFactory.ExistsInCache(coreHelperType));

            var newDotNetCoreHelper = SingletonFactory.GetDotNetCoreHelper();

            Assert.IsNotNull(newDotNetCoreHelper);
            Assert.AreNotEqual(dotNetCoreHelper, newDotNetCoreHelper);
        }
Exemplo n.º 18
0
    public System.Type GetValueType(string value)
    {
        if (SingletonFactory.GetInstance <NumberUtil>().IsNumber(value))
        {
            return(typeof(Number));
        }
        else if (IsValueOfType <Verb>(value))
        {
            return(typeof(Verb));
        }
        else if (IsValueOfType <Item>(value))
        {
            return(typeof(Item));
        }
        else if (IsValueOfType <Resource>(value))
        {
            return(typeof(Resource));
        }
        else if (IsValueOfType <Direction>(value))
        {
            return(typeof(Direction));
        }

        return(typeof(Undefined));
    }
Exemplo n.º 19
0
 // Use this for initialization
 void Start()
 {
     for (int i = 0; i < 20; i++)
     {
         Instantiate(SingletonFactory.GetInstance <PrefabUtil>().zombiePre, new Vector3(105, 0, 0), Quaternion.identity);
     }
 }
Exemplo n.º 20
0
    public void DisplayInventory()
    {
        ParserUtil parserUtil = SingletonFactory.GetInstance <ParserUtil>();

        string inventory = ResourceInventoryToString() + "\n\n" + ItemInventoryToString();

        parserUtil.PrintResponse(inventory);
    }
        public void DotNetCoreAlias_BuildHelperSettings_NoContext()
        {
            ICakeContext context = null;

            Assert.IsFalse(SingletonFactory.ExistsInCache(typeof(HelperSettings)));

            Assert.ThrowsException <ArgumentNullException>(() => context.DotNetCoreBuildHelperSettings());
        }
        public void SetupSetting()
        {
            var coreHelper = SingletonFactory.GetDotNetCoreHelper();

            foreach (var projectConfig in this.Projects)
            {
                coreHelper.AddProjectConfiguration(projectConfig);
            }
        }
        /*============================================================================*/
        /* Public Functions                                                           */
        /*============================================================================*/

        public void Extend(IContext context)
        {
            _injector = context.injector;

            _singletonFactory = new SingletonFactory(_injector);

            context.BeforeInitializing(BeforeInitializing);
            context.BeforeDestroying(BeforeDestroying);
        }
Exemplo n.º 24
0
        public void Stop()
        {
            Source.Cancel();
            Running = false;

            var Factory = SingletonFactory.GetInstance <ThreadFactory>();

            Factory.Dispatch(d => d.Stop(Instance));
        }
Exemplo n.º 25
0
        public static IDotNetCoreTestHelperSettings DotNetCoreTestHelperSettings(this ICakeContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            SingletonFactory.Context = context;
            return(SingletonFactory.GetHelperSettings().DotNetCoreSettings.TestSettings);
        }
Exemplo n.º 26
0
        public void Build_returns_instance_that_has_default_constructor()
        {
            var builder   = new SingletonFactory();
            var container = Mock.Of <IContainer>();

            var instance = builder.BuildUpService(typeof(Calculator), container);

            Assert.NotNull(instance);
            Assert.IsAssignableFrom <ICalculator>(instance);
        }
Exemplo n.º 27
0
        public void Build_returns_instance_that_has_primative_parameters_only()
        {
            var builder   = new SingletonFactory();
            var container = Mock.Of <IContainer>();

            var instance = builder.BuildUpService(typeof(ConcreteClass), container);

            Assert.NotNull(instance);
            Assert.IsAssignableFrom <BaseClass>(instance);
        }
Exemplo n.º 28
0
        public static ITaskHelper TaskHelper(this ICakeContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            SingletonFactory.Context = context;
            return(SingletonFactory.GetTaskHelper());
        }
Exemplo n.º 29
0
        public void ItshouldReturnSameInstance()
        {
            constructorResolver.Setup(r => r.GetConstructor(It.IsAny <Type>())).Returns(ParameterlessClass.GetParameterlessConstructor()).Verifiable();
            dependencyResolver.Setup(r => r.Resolve(It.IsAny <ConstructorInfo>())).Returns(new object[] { });
            var factory = new SingletonFactory(typeof(ParameterlessClass), constructorResolver.Object, dependencyResolver.Object);

            var object1 = factory.Build();
            var object2 = factory.Build();

            Assert.Same(object1, object2);
        }
Exemplo n.º 30
0
 public void Equip(Item item)
 {
     if (HasSpecifiedItem(item))
     {
         equippedItem = item;
         SingletonFactory.GetInstance <ParserUtil>().PrintResponse("Equipped '" + item.ToString() + "'");
     }
     else
     {
         SingletonFactory.GetInstance <ParserUtil>().PrintResponse("No '" + item.ToString() + "' in inventory");
     }
 }
Exemplo n.º 31
0
        public void SingletonFactoryShouldCreateTheSameInstanceOnce()
        {
            var factory = new SingletonFactory<ISerializable>(createInstance);
            var container = new ServiceContainer();

            var request = new FactoryRequest()
                              {
                                  ServiceName = null,
                                  Arguments = new object[0],
                                  Container = container,
                                  ServiceType = typeof(ISerializable)
                              };

            ISerializable first = factory.CreateInstance(request);
            ISerializable second = factory.CreateInstance(request);

            // Both instances must be the same
            Assert.AreSame(first, second);
            Assert.IsNotNull(first);
            Assert.IsNotNull(second);
        }