public void Constructor_DeserializesIsSemVer2(string serialized, bool expected) { // Arrange var cacheFile = "{\"SchemaVersion\":\"3.0.0\",\"Packages\":[{\"Id\":\"" + PackageId + "\",\"Version\":\"" + SemVer2VersionString + "\",\"IsSemVer2\":" + serialized + "}]}"; var fileSystem = new Mock <IFileSystem>(); fileSystem .Setup(x => x.FileExists(CacheFileName)) .Returns(true); fileSystem .Setup(x => x.OpenFile(CacheFileName)) .Returns(() => new MemoryStream(Encoding.UTF8.GetBytes(cacheFile))); // Act var actual = new ServerPackageCache(fileSystem.Object, CacheFileName); // Assert Assert.Equal(1, actual.GetAll().Count()); var package = actual.GetAll().First(); Assert.Equal(expected, package.IsSemVer2); }
public void Constructor_LeavesValidCacheFile(string content, int count) { // Arrange var fileSystem = new Mock <IFileSystem>(); fileSystem .Setup(x => x.FileExists(CacheFileName)) .Returns(true); fileSystem .Setup(x => x.OpenFile(CacheFileName)) .Returns(() => new MemoryStream(Encoding.UTF8.GetBytes(content))); // Act var actual = new ServerPackageCache(fileSystem.Object, CacheFileName); // Assert Assert.Equal(count, actual.GetAll().Count()); fileSystem.Verify(x => x.DeleteFile(It.IsAny <string>()), Times.Never); }
public void Constructor_IgnoresAndDeletesInvalidCacheFile(string content) { // Arrange var fileSystem = new Mock <IFileSystem>(); fileSystem .Setup(x => x.FileExists(CacheFileName)) .Returns(true); fileSystem .Setup(x => x.OpenFile(CacheFileName)) .Returns(() => new MemoryStream(Encoding.UTF8.GetBytes(content))); // Act var actual = new ServerPackageCache(fileSystem.Object, CacheFileName); // Assert Assert.Empty(actual.GetAll()); fileSystem.Verify(x => x.DeleteFile(CacheFileName), Times.Once); }
public void Remove_SupportsDisabledUnlisting() { // Arrange var fileSystem = new Mock <IFileSystem>(); fileSystem .Setup(x => x.FileExists(CacheFileName)) .Returns(true); fileSystem .Setup(x => x.OpenFile(CacheFileName)) .Returns(() => new MemoryStream(Encoding.UTF8.GetBytes(MinimalCacheFile))); var target = new ServerPackageCache(fileSystem.Object, CacheFileName); // Act target.Remove(PackageId, PackageVersion, enableDelisting: false); // Assert Assert.Empty(target.GetAll()); }
public void Remove_NoOpsWhenPackageDoesNotExist() { // Arrange var fileSystem = new Mock <IFileSystem>(); fileSystem .Setup(x => x.FileExists(CacheFileName)) .Returns(true); fileSystem .Setup(x => x.OpenFile(CacheFileName)) .Returns(() => new MemoryStream(Encoding.UTF8.GetBytes(MinimalCacheFile))); var target = new ServerPackageCache(fileSystem.Object, CacheFileName); // Act target.Remove("Foo", PackageVersion, enableDelisting: false); // Assert var package = target.GetAll().FirstOrDefault(); Assert.NotNull(package); Assert.Equal(PackageId, package.Id); Assert.Equal(PackageVersion, package.Version); }