public IPackageSourceStore GetSource(PackageSourceScope scope) { switch(scope) { case PackageSourceScope.Machine: return MachineStore; case PackageSourceScope.User: return UserStore; default: return SessionStore; } }
public void WhenScopeParameterSpecified_AddsSourceToMatchingList(PackageSourceScope scope, Expression<Func<PackageSourceService, IPackageSourceStore>> storeSelector) { // Arrange AddPackageSourceCommand cmd = new AddPackageSourceCommand().AutoConfigure(); var mockService = new Mock<PackageSourceService>() { CallBase = true }; cmd.SourceService = mockService.Object; cmd.Scope = scope; InMemorySourceStore store = new InMemorySourceStore(); mockService.Setup(storeSelector).Returns(store); cmd.Source = "http://foo.bar"; cmd.Name = "Foo"; // Act cmd.Execute(); // Assert Assert.Equal(new PackageSource("http://foo.bar", "Foo"), store.Sources.Single()); }
public void WhenNoMatchingSourceInList_ThrowsKeyNotFoundException(PackageSourceScope scope, Expression<Func<PackageSourceService, IPackageSourceStore>> storeSelector) { // Arrange RemovePackageSourceCommand cmd = new RemovePackageSourceCommand().AutoConfigure(); var mockService = new Mock<PackageSourceService>() { CallBase = true }; cmd.SourceService = mockService.Object; cmd.Scope = scope; InMemorySourceStore store = new InMemorySourceStore(new[] { new PackageSource("http://foo.bar", "Bar") }); mockService.Setup(storeSelector).Returns(store); cmd.Name = "Foo"; // Act Assert.Throws<KeyNotFoundException>(() => cmd.Execute()); // Assert Assert.Equal(new PackageSource("http://foo.bar", "Bar"), store.Sources.Single()); }
public void WhenScopeParameterSpecified_WritesSourceList(PackageSourceScope scope, Expression<Func<PackageSourceService, IPackageSourceStore>> storeSelector) { // Arrange GetPackageSourceCommand cmd = new GetPackageSourceCommand().AutoConfigure(); var mockService = new Mock<PackageSourceService>() { CallBase = true }; cmd.SourceService = mockService.Object; cmd.Scope = scope; PackageSource[] expected = new[] { new PackageSource("http://foo.bar", "Foo"), new PackageSource("http://bar.baz", "Bar"), new PackageSource("http://baz.boz", "Baz") }; mockService.Setup(storeSelector).Returns(new InMemorySourceStore(expected)); // Act PackageSource[] actual = cmd.Execute().ObjectStream.Cast<PackageSource>().ToArray(); // Assert Assert.Equal(expected, actual); }