8000 Remove RepositoryHost(s) by grokys · Pull Request #1283 · github/VisualStudio · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Remove RepositoryHost(s) #1283

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Insert AccountCacheItem for connection.
When creating a `ModelService`, ensure that the correct `AccountCacheItem` is inserted.
  • Loading branch information
grokys committed Nov 7, 2017
commit 7e57621d56ec6489a38b4e11d3843ef4cf1d1e7c
3 changes: 3 additions & 0 deletions src/GitHub.App/Factories/ModelServiceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.ComponentModel.Composition;
using System.Threading;
using System.Threading.Tasks;
using GitHub.Caches;
using GitHub.Models;
using GitHub.Services;
using Microsoft.VisualStudio.Shell;
Expand Down Expand Up @@ -44,6 +45,8 @@ public async Task<IModelService> CreateAsync(IConnection connection)
await apiClientFactory.Create(connection.HostAddress),
await hostCacheFactory.Create(connection.HostAddress),
avatarProvider);
result.InsertUser(AccountCacheItem.Create(connection.User));
cache.Add(connection, result);
}
}
finally
Expand Down
85 changes: 85 additions & 0 deletions src/UnitTests/GitHub.App/Factories/ModelServiceFactoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.Threading.Tasks;
using GitHub.Caches;
using GitHub.Extensions;
using GitHub.Factories;
using GitHub.Models;
using GitHub.Primitives;
using GitHub.Services;
using NSubstitute;
using Xunit;

namespace UnitTests.GitHub.App.Factories
{
public class ModelServiceFactoryTests : TestBaseClass
{
public class TheCreateAsyncMethod
{
[Fact]
public async Task ShouldCreateDifferentModelServiceForDifferentHost()
{
var target = CreateTarget();
var instance1 = await target.CreateAsync(CreateConnection("https://github.com"));
var instance2 = await target.CreateAsync(CreateConnection("https://another.com"));

Assert.NotSame(instance1, instance2);
}

[Fact]
public async Task ShouldCreateDifferentModelServiceForDifferentConnectionsWithSameAddress()
{
var target = CreateTarget();
var instance1 = await target.CreateAsync(CreateConnection("https://github.com"));
var instance2 = await target.CreateAsync(CreateConnection("https://github.com"));

Assert.NotSame(instance1, instance2);
}

[Fact]
public async Task ShouldCacheModelServiceForHost()
{
var target = CreateTarget();
var connection = CreateConnection("https://github.com");
var instance1 = await target.CreateAsync(connection);
var instance2 = await target.CreateAsync(connection);

Assert.Same(instance1, instance2);
}

[Fact]
public async Task ShouldInsertUser()
{
var hostCacheFactory = Substitute.For<IHostCacheFactory>();
var target = CreateTarget(hostCacheFactory: hostCacheFactory);
var connection = CreateConnection("https://github.com");
var hostCache = await hostCacheFactory.Create(connection.HostAddress);
var modelService = await target.CreateAsync(connection);

hostCache.Received().Insert("GitHub.Caches.AccountCacheItem___user", Arg.Any<byte[]>());
}
}

static ModelServiceFactory CreateTarget(
IHostCacheFactory hostCacheFactory = null)
{
var apiClientFactory = Substitute.For<IApiClientFactory>();
var avatarProvider = Substitute.For<IAvatarProvider>();

hostCacheFactory = hostCacheFactory ?? Substitute.For<IHostCacheFactory>();

return new ModelServiceFactory(
apiClientFactory,
hostCacheFactory,
avatarProvider);
}

static IConnection CreateConnection(string address, string login = "user")
{
var result = Substitute.For<IConnection>();
var user = CreateOctokitUser(login, address);
result.HostAddress.Returns(HostAddress.Create(address));
result.User.Returns(user);
return result;
}
}
}
1 change: 1 addition & 0 deletions src/UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@
<Compile Include="GitHub.Api\SimpleApiClientTests.cs" />
<Compile Include="GitHub.App\Caches\ImageCacheTests.cs" />
<Compile Include="GitHub.App\Controllers\UIProviderTests.cs" />
<Compile Include="GitHub.App\Factories\ModelServiceFactoryTests.cs" />
<Compile Include="GitHub.App\Models\AccountModelTests.cs" />
<Compile Include="GitHub.App\Models\ModelServiceTests.cs" />
<Compile Include="GitHub.App\Controllers\UIControllerTests.cs" />
Expand Down
0