Пример #1
0
        public async Task IsEmptyWhenCacheCorrupt(string cacheJson)
        {
            var program = Substitute.For <IProgram>();

            program.ApplicationName.Returns("GHfVS");
            var operatingSystem = Substitute.For <IOperatingSystem>();

            operatingSystem.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData)
            .Returns(@"c:\fake");
            operatingSystem.File.Exists(@"c:\fake\GHfVS\ghfvs.connections").Returns(true);
            operatingSystem.File.ReadAllText(@"c:\fake\GHfVS\ghfvs.connections", Encoding.UTF8).Returns(cacheJson);
            var cache = new JsonConnectionCache(program, operatingSystem);

            var connections = (await cache.Load()).ToList();

            Assert.Empty(connections);
            operatingSystem.File.Received().Delete(@"c:\fake\GHfVS\ghfvs.connections");
        }
Пример #2
0
        public async Task IsSavedToDisk()
        {
            var program = Substitute.For <IProgram>();

            program.ApplicationName.Returns("GHfVS");
            var operatingSystem = Substitute.For <IOperatingSystem>();

            operatingSystem.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData)
            .Returns(@"c:\fake");
            operatingSystem.File.Exists(@"c:\fake\GHfVS\ghfvs.connections").Returns(true);
            operatingSystem.File.ReadAllText(@"c:\fake\GHfVS\ghfvs.connections", Encoding.UTF8).Returns("");
            var cache       = new JsonConnectionCache(program, operatingSystem);
            var connections = (await cache.Load()).ToList();

            connections.Add(new ConnectionDetails(HostAddress.GitHubDotComHostAddress, "coolio"));
            await cache.Save(connections);

            operatingSystem.File.Received().WriteAllText(@"c:\fake\GHfVS\ghfvs.connections",
                                                         @"{""connections"":[{""HostUrl"":""https://github.com/"",""UserName"":""coolio""}]}");
        }
Пример #3
0
        public async Task IsLoadedFromCache()
        {
            const string cacheData = @"{""connections"":[{""HostUrl"":""https://github.com"", ""UserName"":""shana""},{""HostUrl"":""https://github.enterprise"", ""UserName"":""haacked""}]}";
            var          program   = Substitute.For <IProgram>();

            program.ApplicationName.Returns("GHfVS");
            var operatingSystem = Substitute.For <IOperatingSystem>();

            operatingSystem.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData)
            .Returns(@"c:\fake");
            operatingSystem.File.Exists(@"c:\fake\GHfVS\ghfvs.connections").Returns(true);
            operatingSystem.File.ReadAllText(@"c:\fake\GHfVS\ghfvs.connections", Encoding.UTF8).Returns(cacheData);
            var cache = new JsonConnectionCache(program, operatingSystem);

            var connections = (await cache.Load()).ToList();

            Assert.Equal(2, connections.Count);
            Assert.Equal(new Uri("https://api.github.com"), connections[0].HostAddress.ApiUri);
            Assert.Equal(new Uri("https://github.enterprise/api/v3/"), connections[1].HostAddress.ApiUri);
        }