예제 #1
0
        public void TestCheckForUpdateAndDownloadUpdateNoAuth()
        {
            //lets pretend that this game is already installed.
            FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game").Create();
            FileSystem.Current.GetFile("c:\\program files\\MGDF\\game\\game.json").WriteText(ReadTextFile("console.json"));

            var newGameData = GenerateDataBlock(65536);
            var gameMd5 = GenerateMd5Hash(newGameData);

            ((MockHttpRequestManager)HttpRequestManager.Current).ExpectResponse("http://www.junkship.net/downloads/console.zip", newGameData);
            ((MockHttpRequestManager)HttpRequestManager.Current).ExpectResponse("http://games.junkship.org/gamesource.asmx", @"{
            ""Latest"":{
            ""Version"":""1.1.2.4"",
            ""Url"":""http://www.junkship.net/downloads/console.zip"",
            ""MD5"":""" + gameMd5 + @"""
            }
            }");

            Game game = new Game("c:\\program files\\MGDF\\game\\game.json");
            var update = UpdateChecker.CheckForUpdate(game);

            Assert.IsNotNull(update);
            Assert.IsNotNull(update.Game);
            Assert.AreEqual("http://www.junkship.net/downloads/console.zip", update.Game.Url);
            Assert.AreEqual(gameMd5, update.Game.MD5);
            Assert.AreEqual("1.1.2.4", update.Game.Version);

            Assert.IsFalse(FileSystem.Current.GetFile("c:\\temp.zip").Exists);

            //now download the actual update.
            GameDownloader downloader = new GameDownloader(game,"http://www.junkship.net/downloads/console.zip", "c:\\temp.zip", gameMd5, null);
            downloader.Start();

            Assert.IsTrue(FileSystem.Current.GetFile("c:\\temp.zip").Exists);
            Assert.AreEqual(65536, FileSystem.Current.GetFile("c:\\temp.zip").Length);
        }
예제 #2
0
        public void TestCheckForUpdateAndDownloadUpdateWithAuthCachedCredentials()
        {
            Resources.InitUserDirectory("Console", false);

            //lets pretend that this game is already installed.
            FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game").Create();
            FileSystem.Current.GetFile("c:\\program files\\MGDF\\game\\game.json").WriteText(ReadTextFile("console.json"));

            SettingsManager.Instance.Settings = new GameSettings();
            SettingsManager.Instance.Settings.GameUid = "Console";
            SettingsManager.Instance.Settings.UserName = "******";
            SettingsManager.Instance.Settings.Password = "******";
            SettingsManager.Instance.Save();

            var newGameData = GenerateDataBlock(65536);
            var gameMd5 = GenerateMd5Hash(newGameData);

            ((MockHttpRequestManager)HttpRequestManager.Current).SetCredentials("http://www.junkship.net/downloads/console.zip", "user", "password1");
            ((MockHttpRequestManager)HttpRequestManager.Current).ExpectResponse("http://www.junkship.net/downloads/console.zip", newGameData);
            ((MockHttpRequestManager)HttpRequestManager.Current).ExpectResponse("http://games.junkship.org/gamesource.asmx", @"{
            ""Latest"":{
            ""Version"":""1.1.2.4"",
            ""Url"":""http://www.junkship.net/downloads/console.zip"",
            ""MD5"":""" + gameMd5 + @"""
            }
            }");

            Game game = new Game("c:\\program files\\MGDF\\game\\game.json");
            var update = UpdateChecker.CheckForUpdate(game);

            Assert.IsNotNull(update);
            Assert.IsNotNull(update.Game);
            Assert.AreEqual("http://www.junkship.net/downloads/console.zip", update.Game.Url);
            Assert.AreEqual(gameMd5, update.Game.MD5);
            Assert.AreEqual("1.1.2.4", update.Game.Version);

            Assert.IsFalse(FileSystem.Current.GetFile("c:\\temp.zip").Exists);

            //now download the actual update.
            GameDownloader downloader = new GameDownloader(game, "http://www.junkship.net/downloads/console.zip", "c:\\temp.zip", gameMd5, args=>
                                           {
                                               Assert.Fail("With correct cached credentials the credentials callback shouldn't be invoked.");
                                               return false;
                                           });
            downloader.Start();

            Assert.IsTrue(FileSystem.Current.GetFile("c:\\temp.zip").Exists);
            Assert.AreEqual(65536, FileSystem.Current.GetFile("c:\\temp.zip").Length);
        }