Beispiel #1
0
        public void ShouldUpdateAppGit()
        {
            List <object> objectArr = new List <object>();

            objectArr.Add(new Dictionary <string, object> {
                { "name", "file1" }, { "download_url", "file1url" }
            });
            objectArr.Add(new Dictionary <string, object> {
                { "name", "excludeme" }
            });

            var copyedFiles = new List <string>();

            var httpEngine = Mock.Create <IHttpEngine>();

            Mock.Arrange(() => httpEngine.GetHttpResponseObjectAsync(Arg.AnyString)).Returns(() => Task.Run(() => (object)objectArr.ToArray())).OccursOnce();

            Mock.Arrange(() => httpEngine.DownLoadFileAsync(Arg.AnyString, Arg.AnyString)).DoInstead((string url, string downloadFilePath) => { copyedFiles.Add(url); }).OccursOnce();

            var sut = new GitHubAppUpdater(httpEngine, new AppUpdateDetail(string.Empty, string.Empty, new[] { "excludeme" }));

            sut.UpdateApp();

            var foundKya = copyedFiles.FirstOrDefault(x => x.Equals("excludeme"));

            Assert.IsNull(foundKya);
            Assert.AreEqual(copyedFiles.Count, objectArr.Count - 1);
            Assert.AreEqual(copyedFiles.FirstOrDefault(), "file1url");
            Mock.AssertAll(httpEngine);
        }
Beispiel #2
0
        public void ShouldGetCorrectVersionNumber()
        {
            var sut          = new GitHubAppUpdater(GetAppUpdateDetail());
            var latestVerion = sut.GetLatestVesrion();

            Assert.AreEqual("1.0.0.11", latestVerion);
        }
Beispiel #3
0
        public void ShouldThrowExceptionWhenSourceIsNotReachableGit()
        {
            var httpEngine = Mock.Create <IHttpEngine>();

            Mock.Arrange(() => httpEngine.GetHttpResponseAsync(Arg.AnyString)).Throws(new AggregateException("Unit Test"));

            var sut = new GitHubAppUpdater(httpEngine, new AppUpdateDetail(string.Empty, string.Empty));

            Assert.Throws <LocationNotReachableException>(() => sut.GetLatestVesrion());
        }
Beispiel #4
0
        public void ShouldThrowExceptionWhenSourceIsNotReachableGit()
        {
            var gitHub = Mock.Create <IGitHub>();

            Mock.Arrange(() => gitHub.ReadAllTextAysnc(Arg.AnyString)).Throws(new AggregateException("Unit Test"));

            var sut = new GitHubAppUpdater(gitHub, new AppUpdateDetail(string.Empty, string.Empty));

            Assert.Throws <LocationNotReachableException>(() => sut.GetLatestVesrion());
        }
Beispiel #5
0
        public void ShouldUpdateAppGit()
        {
            var gitHub = Mock.Create <IGitHub>();

            Mock.Arrange(() => gitHub.PullFolderServer(string.Empty, string.Empty, null)).IgnoreArguments().OccursOnce();
            var sut = new GitHubAppUpdater(gitHub, new AppUpdateDetail(string.Empty, string.Empty, Enumerable.Empty <string>()));

            sut.UpdateApp();

            Mock.AssertAll(gitHub);
        }
Beispiel #6
0
        public void ShouldUpdateApp()
        {
            var appUpdateDetail = GetAppUpdateDetail();

            var sut = new GitHubAppUpdater(_gitHub, appUpdateDetail);

            sut.UpdateApp();

            var foundKya = Directory.GetFiles(appUpdateDetail.LocalDestination).FirstOrDefault(x => Path.GetFileName(x).Equals(appUpdateDetail.ExcludeFiles.FirstOrDefault()));

            Assert.IsNull(foundKya);

            var files = (object[])new HttpEngine().GetHttpResponseObjectAsync(appUpdateDetail.RemoteSource).Result;

            Assert.AreEqual(Directory.GetFiles(appUpdateDetail.LocalDestination).Count(), files.Count() - 1);
        }
Beispiel #7
0
        public void ShouldGetCorrectVersionNumberGit()
        {
            var httpEngine = Mock.Create <IGitHub>();

            var dic = new Dictionary <string, object> {
                { "download_url", "urlfortest" }
            };

            Mock.Arrange(() => httpEngine.ReadAllTextAysnc(Arg.AnyString)).Returns(() => Task.Run(() => "1.0.0.11")).OccursOnce();

            var sut          = new GitHubAppUpdater(httpEngine, new AppUpdateDetail(string.Empty, string.Empty));
            var latestVerion = sut.GetLatestVesrion();

            Assert.AreEqual("1.0.0.11", latestVerion);

            Mock.AssertAll(httpEngine);
        }
Beispiel #8
0
        public void ShouldUpdateApp()
        {
            var appUpdateDetail = GetAppUpdateDetail();

            var sut = new GitHubAppUpdater(appUpdateDetail);

            var exludeFile = "Version.txt";

            sut.UpdateApp(new[] { exludeFile });

            var foundKya = Directory.GetFiles(appUpdateDetail.Destination).FirstOrDefault(x => Path.GetFileName(x).Equals(exludeFile));

            Assert.IsNull(foundKya);

            var files = (object[])new HttpEngine().GetHttpResponseObjectAsync(appUpdateDetail.Source).Result;

            Assert.AreEqual(Directory.GetFiles(appUpdateDetail.Destination).Count(), files.Count() - 1);
        }
Beispiel #9
0
        public void ShouldThrowExceptionWhenSourceIsNotReachable()
        {
            var sut = new GitHubAppUpdater(new AppUpdateDetail(@"https://api.github.com/repos/MrBailwal/Repo", ""));

            Assert.Throws <LocationNotReachable>(() => sut.GetLatestVesrion());
        }