public void TestCount_ShouldReturnNumberOfFilesRead()
        {
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"data\vm2014-person1.toml"), new MockFileData("[info]\nuser=\"foo1\"") },
                { XFS.Path(@"data\vm2014-person2.toml"), new MockFileData("[info]\nuser=\"foo2\"") },
                { XFS.Path(@"data\vm2014-person3.toml"), new MockFileData("[info]\nuser=\"foo3\"") },
                { XFS.Path(@"data\vm2014-person4.toml"), new MockFileData("[info]\nuser=\"foo4\"") },
                { XFS.Path(@"data\vm2014-person5.toml"), new MockFileData("[info]\nuser=\"foo5\"") }
            });
            var bets = new SubmittedBets(fileSystem);

            bets.LoadAll("data");
            bets.Count.ShouldBe(5);

            fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"data\vm2014-person1.toml"), new MockFileData("[info]\nuser=\"foo1\"") },
                { XFS.Path(@"data\vm2014-person4.toml"), new MockFileData("[info]\nuser=\"foo4\"") },
                { XFS.Path(@"data\vm2014-person5.toml"), new MockFileData("[info]\nuser=\"foo5\"") }
            });
            bets = new SubmittedBets(fileSystem);
            bets.LoadAll("data");
            bets.Count.ShouldBe(3);
        }
Exemple #2
0
        protected override void ConfigureApplicationContainer(TinyIoCContainer container)
        {
            string dataPath       = ConfigurationManager.AppSettings["DataPath"].ToString();
            string tournamentFile = ConfigurationManager.AppSettings["TournamentFile"].ToString();
            string resultsFile    = ConfigurationManager.AppSettings["ResultsFile"].ToString();

            // Register our app dependency as a normal singletons
            var tournament = new Tournament();

            tournament.Load(Path.Combine(dataPath, tournamentFile));
            container.Register <ITournament, Tournament>(tournament);

            var bets = new SubmittedBets();

            bets.TournamentFile    = tournamentFile;
            bets.ActualResultsFile = resultsFile;
            bets.LoadAll(dataPath);
            container.Register <ISubmittedBets, SubmittedBets>(bets);

            var resultCollection = new ResultCollection();

            resultCollection.Current = new Results();
            resultCollection.Current.Load(Path.Combine(dataPath, resultsFile));
            resultCollection.Previous = new Results();
            resultCollection.Previous.Load(Path.Combine(dataPath, resultsFile + ".bak"));
            container.Register <IResultCollection, ResultCollection>(resultCollection);
        }
        public void TestLoadAll_ShouldFail_IfFolderDoesNotExist()
        {
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"data\vm2014-person1.toml"), new MockFileData("foo") },
            });
            var  bets    = new SubmittedBets(fileSystem);
            bool success = bets.LoadAll("dont-exist");

            success.ShouldBe(false);
        }
        public void TestLoadAll_ShouldSucceed_IfFolderIsExist()
        {
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"data\vm2014-person1.toml"), new MockFileData("[info]\nuser=\"foo\"") },
            });
            var  bets    = new SubmittedBets(fileSystem);
            bool success = bets.LoadAll("data");

            success.ShouldBe(true);
        }
        public void Test_LoadAll_ShouldSkipFile_IfNotToml()
        {
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"data\vm2014-person1.toml"), new MockFileData("[info]\nuser=\"foo1\"") },
                { XFS.Path(@"data\vm2014-person2.toml"), new MockFileData("[info]\nuser=\"foo2\"") },
                { XFS.Path(@"data\vm2014-person3.toml"), new MockFileData("[info]\nuser=\"foo3\"") },
                { XFS.Path(@"data\.DS_store"), new MockFileData("garbage and not\nnot toml format") },
                { XFS.Path(@"data\vm2014-person5.toml"), new MockFileData("[info]\nuser=\"foo5\"") }
            });
            var bets = new SubmittedBets(fileSystem);

            bets.LoadAll("data");
            bets.Count.ShouldBe(4);
        }
        public void TestLoadAll_ShouldSkipActualResultsConfigFile()
        {
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"data\vm2014-person1.toml"), new MockFileData("[info]\nuser=\"foo1\"") },
                { XFS.Path(@"data\vm2014-person2.toml"), new MockFileData("[info]\nuser=\"foo2\"") },
                { XFS.Path(@"data\vm2014-person3.toml"), new MockFileData("[info]\nuser=\"foo3\"") },
                { XFS.Path(@"data\vm2014-actual.toml"), new MockFileData("[info]\nuser=\"actual\"") },
                { XFS.Path(@"data\vm2014-person5.toml"), new MockFileData("[info]\nuser=\"foo5\"") }
            });
            var bets = new SubmittedBets(fileSystem);

            bets.ActualResultsFile = XFS.Path(@"data\vm2014-actual.toml");
            bets.LoadAll("data");
            bets.Count.ShouldBe(4);
        }
        public void TestGetSingleBet_ShouldReturnBet_WhenGivenUserExists()
        {
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"data\vm2014-person1.toml"), new MockFileData("[info]\nuser=\"foo1\"") },
                { XFS.Path(@"data\vm2014-person2.toml"), new MockFileData("[info]\nuser=\"foo2\"") },
                { XFS.Path(@"data\vm2014-person3.toml"), new MockFileData("[info]\nuser=\"foo3\"") },
                { XFS.Path(@"data\vm2014-person4.toml"), new MockFileData("[info]\nuser=\"foo4\"") },
                { XFS.Path(@"data\vm2014-person5.toml"), new MockFileData("[info]\nuser=\"foo5\"") }
            });
            var bets = new SubmittedBets(fileSystem);

            bets.LoadAll("data");
            var bet = bets.GetSingleBet("foo2");

            Assert.That(bet.GetInfo().user, Is.EqualTo("foo2"));
        }
        public void TestGetBetters_ShouldReturnNamesOfAllBetters()
        {
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"data\vm2014-person1.toml"), new MockFileData("[info]\nuser = \"person1\"") },
                { XFS.Path(@"data\vm2014-person4.toml"), new MockFileData("[info]\nuser = \"person2\"") },
                { XFS.Path(@"data\vm2014-person5.toml"), new MockFileData("[info]\nuser = \"person3\"") }
            });
            var bets = new SubmittedBets(fileSystem);

            bets.LoadAll("data");
            var betters = bets.GetBetters();

            betters.Count.ShouldBe(3);
            betters.ShouldContain("person1");
            betters.ShouldContain("person2");
            betters.ShouldContain("person3");
        }