public void AddMultipleCharactersThenClear()
        {
            var fakeStaticWrapper = A.Fake <IStaticWrapper>();

            A.CallTo(fakeStaticWrapper).WithReturnType <ContributionDefinition>()
            .Returns(new ContributionDefinition {
                ContributionValue = 1, ContributionId = 1
            });

            var contributionManager = new ContributionManager(
                new ConcurrentDictionary <uint, List <PlayerContribution> >(),
                ContributionFactorReferenceList);

            contributionManager.UpdateContribution(100, 1);
            contributionManager.UpdateContribution(102, 2);
            contributionManager.UpdateContribution(104, 2);
            contributionManager.UpdateContribution(104, 1);

            contributionManager.RemoveCharacter(102);
            var result = contributionManager.GetContributionValue(102);

            Assert.IsTrue(result == 0);

            contributionManager.Clear();
            var result2 = contributionManager.GetContributionValue(102);

            Assert.IsTrue(result2 == 0);
            var result3 = contributionManager.GetContributionValue(104);

            Assert.IsTrue(result3 == 0);
        }
        public void GetContributionValueWithNoFactorList()
        {
            var contributionManager = new ContributionManager(new ConcurrentDictionary <uint, List <PlayerContribution> >(), null);
            var result = contributionManager.GetContributionValue(0);

            Assert.IsTrue(result == 0);
        }
        public void GetContributionValueOnEmptyManager()
        {
            var contributionManager = new ContributionManager(new ConcurrentDictionary <uint, List <World.Battlefronts.Bounty.PlayerContribution> >(), ContributionFactorReferenceList);
            var result = contributionManager.GetContributionValue(0);

            Assert.IsTrue(result == 0);
        }
        public void AddNewPlayerGetContribution()
        {
            var contributionManager = new ContributionManager(new ConcurrentDictionary <uint, List <PlayerContribution> >(), ContributionFactorReferenceList);

            contributionManager.AddCharacter(100);
            var result = contributionManager.GetContributionValue(100);

            Assert.IsTrue(result == 0);
        }
        public void RemoveCharacterFromNotEmptyWrongId()
        {
            var contributionManager = new ContributionManager(new ConcurrentDictionary <uint, List <PlayerContribution> >(), ContributionFactorReferenceList);

            contributionManager.AddCharacter(100);
            Assert.IsFalse(contributionManager.RemoveCharacter(101));

            contributionManager.UpdateContribution(100, 1);
            var result = contributionManager.GetContributionValue(100);

            Assert.IsTrue(result == 1);

            Assert.IsTrue(contributionManager.RemoveCharacter(100));


            contributionManager.UpdateContribution(100, 1);
            var result2 = contributionManager.GetContributionValue(100);

            Assert.IsTrue(result2 == 1);
        }
        public void AddNewPlayerAddContribution()
        {
            var contributionManager = new ContributionManager(new ConcurrentDictionary <uint, List <PlayerContribution> >(), ContributionFactorReferenceList);

            contributionManager.AddCharacter(100);
            contributionManager.UpdateContribution(100, 1);
            var result = contributionManager.GetContributionValue(100);

            Assert.IsTrue(result == 1);

            contributionManager.UpdateContribution(100, 1);
            var result2 = contributionManager.GetContributionValue(100);

            Assert.IsTrue(result2 == 2);

            // Has a value of 3
            contributionManager.UpdateContribution(100, 2);
            var result3 = contributionManager.GetContributionValue(100);

            Assert.IsTrue(result3 == 5);
        }
        public void UpdateCharacterNoAdd()
        {
            var contributionManager = new ContributionManager(new ConcurrentDictionary <uint, List <PlayerContribution> >(), ContributionFactorReferenceList);

            contributionManager.UpdateContribution(100, 1);
            contributionManager.UpdateContribution(100, 2);
            contributionManager.UpdateContribution(100, 2);
            contributionManager.UpdateContribution(100, 1);

            var result = contributionManager.GetContributionValue(100);

            Assert.IsTrue(result == 8);
        }
        public void TimingOnLargeSetUpdates()
        {
            var contributionManager = new ContributionManager(new ConcurrentDictionary <uint, List <PlayerContribution> >(), ContributionFactorReferenceList);

            contributionManager.UpdateContribution(100, 1);
            contributionManager.UpdateContribution(102, 2);
            Stopwatch sw = new Stopwatch();

            sw.Start();
            var result2 = contributionManager.GetContributionValue(102);

            Assert.IsTrue(result2 == 3);
            sw.Stop();

            contributionManager.UpdateContribution(104, 2);
            contributionManager.UpdateContribution(104, 1);
            for (uint i = 0; i < 2000; i++)
            {
                contributionManager.UpdateContribution(i + 200, 1);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 1);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 1);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 1);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 1);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 1);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
                contributionManager.UpdateContribution(i + 200, 2);
            }

            var result = contributionManager.GetContributionValue(102);

            Assert.IsTrue(result == 3);
            sw.Start();
            var result4 = contributionManager.GetContributionValue(200);

            sw.Stop();
            var elapsed = sw.ElapsedMilliseconds;
        }