private IPackageSourceStore GetSessionStore() { object store = Session.Get(SourceListVariable); if (store == null) { InMemorySourceStore newStore = new InMemorySourceStore(); Session.Set(SourceListVariable, newStore); return newStore; } IPackageSourceStore convertedStore = store as IPackageSourceStore; return convertedStore ?? new NullSourceStore(); }
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 WithNoScope_AddsSourceToSessionScope() { // Arrange AddPackageSourceCommand cmd = new AddPackageSourceCommand().AutoConfigure(); var mockService = new Mock<PackageSourceService>(MockBehavior.Strict) { CallBase = true }; InMemorySourceStore sessionStore = new InMemorySourceStore(); cmd.SourceService = mockService.Object; mockService.Setup(s => s.SessionStore).Returns(sessionStore); cmd.Name = "Foo"; cmd.Source = "http://foo.bar"; // Act cmd.Execute(); // Assert Assert.Equal(new PackageSource("http://foo.bar", "Foo"), sessionStore.Sources.Single()); }
public void WithNoScope_RemovesSourceFromSessionScope() { // Arrange RemovePackageSourceCommand cmd = new RemovePackageSourceCommand().AutoConfigure(); var mockService = new Mock<PackageSourceService>(MockBehavior.Strict) { CallBase = true }; InMemorySourceStore sessionStore = new InMemorySourceStore(new[] { new PackageSource("http://foo.bar", "Foo") }); cmd.SourceService = mockService.Object; mockService.Setup(s => s.SessionStore).Returns(sessionStore); cmd.Name = "Foo"; // Act cmd.Execute(); // Assert Assert.False(sessionStore.Sources.Any()); }