public void GetPackageInfo_PackageListExists_MatchModeIdContains_Contains() { MatchMode matchMode = MatchMode.IdContains; string packageId = "mytestPackage"; string searchString = "testP"; var package = CreateLockedTestPackage(packageId); var packages = new PackagesBuilder().AddPackage(package).Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); var packageInfos = sut.GetPackageInfo(searchString, ListMode.LimitOutput, matchMode); Assert.That(packageInfos, Is.Not.Null); Assert.That(packageInfos, Is.Not.Null); Assert.That(packageInfos.Count, Is.EqualTo(1)); var packageInfo = packageInfos.ElementAt(0); Assert.That(packageInfo.PackageId, Is.EqualTo(package.PackageId)); Assert.That(packageInfo.PackageVersion, Is.EqualTo(package.PackageVersion)); Assert.That(packageInfo.LockedByAction, Is.Null); Assert.That(packageInfo.LockedByProcess, Is.Null); Assert.That(packageInfo.Created, Is.Null); Assert.That(packageInfo.LastUpdated, Is.Null); }
public void GetPackageInfo_MatchModeIdExact_CaseInsensitive() { MatchMode matchMode = MatchMode.IdExact; var nameInXml = "mYtESTpaCKage"; var searchId = "myTestPackage"; var package = CreateLockedTestPackage(inputPackageId: nameInXml); var packages = new PackagesBuilder().AddPackage(package).Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); var packageInfos = sut.GetPackageInfo(searchId, ListMode.LimitOutput, matchMode); Assert.That(packageInfos, Is.Not.Null); Assert.That(packageInfos.Count, Is.EqualTo(1)); var packageInfo = packageInfos.ElementAt(0); Assert.That(packageInfo.PackageId, Is.EqualTo(package.PackageId)); Assert.That(packageInfo.PackageVersion, Is.EqualTo(package.PackageVersion)); Assert.That(packageInfo.LockedByAction, Is.Null); Assert.That(packageInfo.LockedByProcess, Is.Null); Assert.That(packageInfo.Created, Is.Null); Assert.That(packageInfo.LastUpdated, Is.Null); }
public void GetPackageInfo_MultipleEntriesExists_MatchModeAll() { MatchMode matchMode = MatchMode.All; string firstPackageId = "myTestPackage"; string secondPackageId = "AnotherTestPackage"; string thirdPackageId = "AnotherPackage"; string searchString = "TestPackage"; var firstPackage = CreateLockedTestPackage(firstPackageId); var secondPackage = CreateLockedTestPackage(secondPackageId); var thirdPackage = CreateLockedTestPackage(thirdPackageId); var packages = new PackagesBuilder() .AddPackage(firstPackage) .AddPackage(secondPackage) .AddPackage(thirdPackage) .Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); var packageInfos = sut.GetPackageInfo(searchString, ListMode.LimitOutput, matchMode); Assert.That(packageInfos, Is.Not.Null); Assert.That(packageInfos.Count, Is.EqualTo(3)); Assert.That(packageInfos.Where(x => x.PackageId.Equals(firstPackageId)).ToArray().Length, Is.EqualTo(1)); Assert.That(packageInfos.Where(x => x.PackageId.Equals(secondPackageId)).ToArray().Length, Is.EqualTo(1)); Assert.That(packageInfos.Where(x => x.PackageId.Equals(thirdPackageId)).ToArray().Length, Is.EqualTo(1)); }
public async Task GetPackageInfo_FileIsUsedByAnotherProcess_FileIsTemporaryLockedForWriteOperation_EndActionOnPackageRetries() { var package = CreateNonLockedTestPackage(); var packages = new PackagesBuilder().AddPackage(package).Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); using (var fileStream = sut.OpenPackageListForWriteOperation()) { var task = Task.Run(() => sut.EndActionOnPackage(package.PackageId, new Version(package.PackageVersion))); Thread.Sleep(1000); fileStream.Close(); await task; }; var packageInfos = sut.GetPackageInfo(package.PackageId, ListMode.Full, MatchMode.IdExact); Assert.That(packageInfos, Is.Not.Null); Assert.That(packageInfos.Count, Is.EqualTo(1)); var packageInfo = packageInfos.ElementAt(0); Assert.That(packageInfo.LockedByProcess, Is.Not.Null); }
public void FileIsUsedByAnotherProcess_FileIsLockedForWriteOperation_FileCanBeOpenedForGetPackageInfo() { var package = CreateNonLockedTestPackage(); var packages = new PackagesBuilder().AddPackage(package).Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); using (sut.OpenPackageListForWriteOperation()) { sut.GetPackageInfo(package.PackageId, ListMode.LimitOutput, MatchMode.IdExact); }; }
public void GetSinglePackageInfo_FileIsUsedByAnotherProcess_FileIsLockedForReadOperation_GetPackageInfoWorks() { var package = CreateNonLockedTestPackage(); var packages = new PackagesBuilder().AddPackage(package).Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); using (var fileStream = sut.OpenPackageListForReadOperation()) { var packageInfo = sut.GetSinglePackageInfo(package.PackageId); Assert.That(packageInfo, Is.Not.Null); }; }
public void GetSinglePackageInfo_PackageListExists_MatchModeIdExact_NotMatchExact() { string packageId = "mytestPackage"; string searchString = packageId + " "; var package = CreateLockedTestPackage(packageId); var packages = new PackagesBuilder().AddPackage(package).Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); var packageInfo = sut.GetSinglePackageInfo(searchString); Assert.That(packageInfo, Is.Null); }
public void FileIsUsedByAnotherProcess_FileIsLockedForWriteOperation_GetPackageInfoWorks() { var package = CreateNonLockedTestPackage(); var packages = new PackagesBuilder().AddPackage(package).Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); using (var fileStream = sut.OpenPackageListForWriteOperation()) { var packageInfo = sut.GetPackageInfo(package.PackageId, ListMode.LimitOutput, MatchMode.IdExact); Assert.That(packageInfo, Is.Not.Null); }; }
public void PackageIsLocked_CanNotBeLockedByAnotherProcess() { var package = CreateLockedTestPackage(); var packages = new PackagesBuilder().AddPackage(package).Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); var exception = Assert.Throws <InvalidOperationException>(() => sut.StartActionOnPackage(package.PackageId, new Version(package.PackageVersion))); StringAssert.Contains(package.PackageId, exception.Message); StringAssert.Contains(package.PackageLockedByProcess, exception.Message); StringAssert.Contains(package.PackageLockedByAction, exception.Message); }
public void GetPackageInfo_PackageListExists_MatchModeIdContain_NotContains() { MatchMode matchMode = MatchMode.IdContains; string packageId = "mytestPackage"; string searchString = "iamnotthere"; var package = CreateLockedTestPackage(packageId); var packages = new PackagesBuilder().AddPackage(package).Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); var packageInfo = sut.GetPackageInfo(searchString, ListMode.LimitOutput, matchMode); Assert.That(packageInfo, Is.Empty); }
public void GetSinglePackageInfo_LastUpdateIsNull() { Nullable <DateTimeOffset> lastUpdated = null; var package = CreateLockedTestPackage(); package.SetLastUpdated(lastUpdated); var packages = new PackagesBuilder().AddPackage(package).Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); var packageInfo = sut.GetSinglePackageInfo(package.PackageId); Assert.That(packageInfo, Is.Not.Null); Assert.That(packageInfo.LastUpdated, Is.EqualTo(lastUpdated)); }
public void PackageIsLocked_CanBeListedByAnotherProcess() { var package = CreateLockedTestPackage(); var packages = new PackagesBuilder().AddPackage(package).Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); var packageInfos = sut.GetPackageInfo(package.PackageId, ListMode.LimitOutput, MatchMode.IdExact); Assert.That(packageInfos, Is.Not.Null); Assert.That(packageInfos.Count, Is.EqualTo(1)); var packageInfo = packageInfos.ElementAt(0); Assert.That(packageInfo.PackageId, Is.EqualTo(package.PackageId)); }
public void Migration_RemovePackage_PackageListIsNotMigratedAndVersionIsNotAddedIfVersionExists() { var expectedVersion = "myversion"; var sut = CreateSystemUnderTest(new[] { new AddVersionAttributeIfNotExists() }); var previous = new PackagesBuilder().SetPackagesVersion(expectedVersion).Build(); CreatePackageList(previous); sut.RemovePackage("mytestpackage"); var xmlDocument = ReadPackageList(); var version = xmlDocument.Element(HoneyLibrary.PackageLists.PackageList.XmlRoot).Attribute(HoneyLibrary.PackageLists.PackageList.XmlPackageVersion).Value; Assert.That(version, Is.EqualTo(expectedVersion)); }
public void Migration_StartActionOnPackage_PackageListIsMigratedAndVersionIsAddedIfNoVersionExists() { var expectedVersion = "1.0"; var sut = CreateSystemUnderTest(new[] { new AddVersionAttributeIfNotExists() }); var previous = new PackagesBuilder().SetPackagesVersion(string.Empty).Build(); CreatePackageList(previous); sut.StartActionOnPackage("mytestpackage", new Version(1, 2, 3)); var xmlDocument = ReadPackageList(); var version = xmlDocument.Element(HoneyLibrary.PackageLists.PackageList.XmlRoot).Attribute(HoneyLibrary.PackageLists.PackageList.XmlPackageVersion).Value; Assert.That(version, Is.EqualTo(expectedVersion)); }
public void FileIsUsedByAnotherProcess_FileIsLockedForWriteOperation_FileCanNotBeOpenedForEndActionOnPackage() { var package = CreateNonLockedTestPackage(); var packages = new PackagesBuilder().AddPackage(package).Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); using (sut.OpenPackageListForWriteOperation()) { var exception = Assert.Throws <PackageFileCanNotBeAccessedException>(() => sut.EndActionOnPackage(package.PackageId, new Version(package.PackageVersion))); Assert.That(exception.InnerExceptions, Is.Not.Null); Assert.That(exception.InnerExceptions.Count, Is.GreaterThan(2)); StringAssert.Contains(TestPackageListFileName(), exception.Message); }; }
public void GetSinglePackageInfo_FileIsUsedByAnotherProcess_FileIsLockedForReadOperation_StartActionOnPackageWorks() { var package = CreateNonLockedTestPackage(); var packages = new PackagesBuilder().AddPackage(package).Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); using (var fileStream = sut.OpenPackageListForReadOperation()) { sut.StartActionOnPackage(package.PackageId, new Version(package.PackageVersion)); }; var packageInfo = sut.GetSinglePackageInfo(package.PackageId, ListMode.Full); Assert.That(packageInfo.LockedByProcess, Is.EqualTo(Process.GetCurrentProcess().Id.ToString())); }
public void GetSinglePackageInfo_PackageListExists_ListModeFull() { var package = CreateLockedTestPackage(); var packages = new PackagesBuilder().AddPackage(package).Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); var packageInfo = sut.GetSinglePackageInfo(package.PackageId, ListMode.Full); Assert.That(packageInfo, Is.Not.Null); Assert.That(packageInfo.PackageId, Is.EqualTo(package.PackageId)); Assert.That(packageInfo.PackageVersion, Is.EqualTo(package.PackageVersion)); Assert.That(packageInfo.LockedByAction, Is.EqualTo(package.PackageLockedByAction)); Assert.That(packageInfo.LockedByProcess, Is.EqualTo(package.PackageLockedByProcess)); Assert.That(packageInfo.Created, Is.EqualTo(package.PackageCreated)); Assert.That(packageInfo.LastUpdated, Is.EqualTo(package.PackageLastUpdated)); }
public void GetSinglePackageInfo_FileIsUsedByAnotherProcess_FileIsLockedForReadOperation_EndActionOnPackageWork() { var package = CreateNonLockedTestPackage(); var packages = new PackagesBuilder().AddPackage(package).Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); using (var fileStream = sut.OpenPackageListForReadOperation()) { sut.EndActionOnPackage(package.PackageId, new Version(package.PackageVersion)); }; var packageInfo = sut.GetSinglePackageInfo(package.PackageId, ListMode.Full); Assert.That(packageInfo.LastUpdated, Is.Not.Null); }
public void GetSinglePackageInfo_MultipleEntriesWithSameIdExists_ThrowsException() { string firstPackageId = "myTestPackage"; string secondPackageId = "myTestPackage"; var firstPackage = CreateLockedTestPackage(firstPackageId); var secondPackage = CreateLockedTestPackage(secondPackageId); var packages = new PackagesBuilder() .AddPackage(firstPackage) .AddPackage(secondPackage) .Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); var exception = Assert.Throws <InvalidOperationException>(() => sut.GetSinglePackageInfo(firstPackageId)); StringAssert.Contains(firstPackageId, exception.Message); }
public void GetPackageInfo_MultipleEntriesWithSameIdExists_ReturnsBoth() { MatchMode matchMode = MatchMode.IdContains; string firstPackageId = "myTestPackage"; string secondPackageId = "myTestPackage"; var firstPackage = CreateLockedTestPackage(firstPackageId); var secondPackage = CreateLockedTestPackage(secondPackageId); var packages = new PackagesBuilder() .AddPackage(firstPackage) .AddPackage(secondPackage) .Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); var packageInfos = sut.GetPackageInfo(firstPackageId, ListMode.LimitOutput, matchMode); Assert.That(packageInfos, Is.Not.Null); Assert.That(packageInfos.Count, Is.EqualTo(2)); }
public void GetSinglePackageInfo_CaseInsensitive() { var nameInXml = "mYtESTpaCKage"; var searchId = "myTestPackage"; var package = CreateLockedTestPackage(inputPackageId: nameInXml); var packages = new PackagesBuilder().AddPackage(package).Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); var packageInfo = sut.GetSinglePackageInfo(searchId, ListMode.LimitOutput); Assert.That(packageInfo, Is.Not.Null); Assert.That(packageInfo.PackageId, Is.EqualTo(nameInXml)); Assert.That(packageInfo.PackageVersion, Is.EqualTo(package.PackageVersion)); Assert.That(packageInfo.LockedByAction, Is.Null); Assert.That(packageInfo.LockedByProcess, Is.Null); Assert.That(packageInfo.Created, Is.Null); Assert.That(packageInfo.LastUpdated, Is.Null); }
public void GetSinglePackageInfo_PackageListExists_MatchModeIdExact_MatchExact() { string packageId = "mytestPackage"; string searchString = packageId; var package = CreateLockedTestPackage(packageId); var packages = new PackagesBuilder().AddPackage(package).Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); var packageInfo = sut.GetSinglePackageInfo(searchString); Assert.That(packageInfo, Is.Not.Null); Assert.That(packageInfo.PackageId, Is.EqualTo(package.PackageId)); Assert.That(packageInfo.PackageVersion, Is.EqualTo(package.PackageVersion)); Assert.That(packageInfo.LockedByAction, Is.Null); Assert.That(packageInfo.LockedByProcess, Is.Null); Assert.That(packageInfo.Created, Is.Null); Assert.That(packageInfo.LastUpdated, Is.Null); }
public async Task GetSinglePackageInfo_FileIsUsedByAnotherProcess_FileIsTemporaryLockedForWriteOperation_StartActionOnPackageRetries() { var package = CreateNonLockedTestPackage(); var packages = new PackagesBuilder().AddPackage(package).Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); using (var fileStream = sut.OpenPackageListForWriteOperation()) { var task = Task.Run(() => sut.StartActionOnPackage(package.PackageId, new Version(package.PackageVersion))); Thread.Sleep(1000); fileStream.Close(); await task; }; var packageInfo = sut.GetSinglePackageInfo(package.PackageId, ListMode.Full); Assert.That(packageInfo.LockedByProcess, Is.EqualTo(Process.GetCurrentProcess().Id.ToString())); }
public void GetPackageInfo_LastUpdateIsNull() { Nullable <DateTimeOffset> lastUpdated = null; ListMode listMode = ListMode.Full; var package = CreateLockedTestPackage(); package.SetLastUpdated(lastUpdated); var packages = new PackagesBuilder().AddPackage(package).Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); var packageInfos = sut.GetPackageInfo(package.PackageId, listMode, MatchMode.IdExact); Assert.That(packageInfos, Is.Not.Null); Assert.That(packageInfos.Count, Is.EqualTo(1)); var packageInfo = packageInfos.ElementAt(0); Assert.That(packageInfo.LastUpdated, Is.EqualTo(lastUpdated)); }
public void GetPackageInfo_PackageListExists_ListModeFull() { ListMode listMode = ListMode.Full; var package = CreateLockedTestPackage(); var packages = new PackagesBuilder().AddPackage(package).Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); var packageInfos = sut.GetPackageInfo(package.PackageId, listMode, MatchMode.IdExact); Assert.That(packageInfos, Is.Not.Null); Assert.That(packageInfos.Count, Is.EqualTo(1)); var packageInfo = packageInfos.ElementAt(0); Assert.That(packageInfo.PackageId, Is.EqualTo(package.PackageId)); Assert.That(packageInfo.PackageVersion, Is.EqualTo(package.PackageVersion)); Assert.That(packageInfo.LockedByAction, Is.EqualTo(package.PackageLockedByAction)); Assert.That(packageInfo.LockedByProcess, Is.EqualTo(package.PackageLockedByProcess)); Assert.That(packageInfo.Created, Is.EqualTo(package.PackageCreated)); Assert.That(packageInfo.LastUpdated, Is.EqualTo(package.PackageLastUpdated)); }
public void GetPackageInfo_IsCaseInsensitive_MatchModeIdContains_Contains() { MatchMode matchMode = MatchMode.IdContains; string firstPackageId = "mytestPackage"; string secondPackageId = "AnotherTestPackage"; string searchPattern = "TEstpACkAgE"; var firstPackage = CreateLockedTestPackage(firstPackageId); var secondPackage = CreateLockedTestPackage(secondPackageId); var packages = new PackagesBuilder() .AddPackage(firstPackage) .AddPackage(secondPackage) .Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); var packageInfos = sut.GetPackageInfo(searchPattern, ListMode.LimitOutput, matchMode); Assert.That(packageInfos, Is.Not.Null); Assert.That(packageInfos.Count, Is.EqualTo(2)); Assert.That(packageInfos.Where(x => x.PackageId.Equals(firstPackageId)).ToArray().Length, Is.EqualTo(1)); Assert.That(packageInfos.Where(x => x.PackageId.Equals(secondPackageId)).ToArray().Length, Is.EqualTo(1)); }
public void EndActionOnPackage_PackageListExists() { var package = CreateNonLockedTestPackage(); var packages = new PackagesBuilder().AddPackage(package).Build(); CreatePackageList(packages); var sut = CreateSystemUnderTest(); sut.EndActionOnPackage(package.PackageId, new Version(package.PackageVersion)); var packageInfos = sut.GetPackageInfo(package.PackageId, ListMode.Full, MatchMode.IdExact); Assert.That(packageInfos, Is.Not.Null); Assert.That(packageInfos.Count, Is.EqualTo(1)); var packageInfo = packageInfos.ElementAt(0); Assert.That(packageInfo.PackageId, Is.EqualTo(package.PackageId)); Assert.That(packageInfo.PackageVersion, Is.EqualTo(package.PackageVersion)); Assert.That(packageInfo.LockedByAction, Is.EqualTo(string.Empty)); Assert.That(packageInfo.LockedByProcess, Is.EqualTo(string.Empty)); Assert.That(packageInfo.Created, Is.Not.Null); Assert.That(packageInfo.LastUpdated, Is.Not.Null); }