public void Add_ProvideValidPackageThatIsNotAlreadyInThePackages_ItShouldBeAdded() { // Arrange var loggerMock = new Mock <ILogger>(); loggerMock.Setup(l => l.Log(It.IsAny <string>())); var packageMock = new Mock <IPackage>(); packageMock.SetupGet(p => p.Name).Returns("PackageOne"); var packageRepository = new PackageRepository(loggerMock.Object); // Act packageRepository.Add(packageMock.Object); var result = packageRepository.GetAll(); // Assert CollectionAssert.Contains(result, packageMock.Object); }
public void AddandDeleteTest() { List <Package> expected = ExpectedPackages(); Package package = new Package() { Id = 3, name = "Cool" }; expected.Add(package); repo.Add(package); List <Package> actual = repo.ReadAll(); Package actuall = actual.Last(); Assert.IsTrue(comparer(package, actuall)); repo.Delete(package.Id); expected.Remove(package); Assert.IsTrue(listcomparer(repo.ReadAll(), expected)); }
public void PackageAlreadyExistMessageLogThreeTimes_WhenThePackageWithTheSameVersionIsAddedAlready() { // Arrange var loggerMock = new Mock <ILogger>(); var packageMock = new Mock <IPackage>(); packageMock.Setup(x => x.CompareTo(It.IsAny <IPackage>())).Returns(0); var collection = new List <IPackage>() { packageMock.Object }; var repository = new PackageRepository(loggerMock.Object, collection); // Act repository.Add(packageMock.Object); // Assert loggerMock.Verify(x => x.Log(It.IsAny <string>()), Times.Exactly(3)); }
public void PackageWithHigherVersionLogTwice_WhenThePackageAddedAlreadyWithHigherVersion() { // Arrange var loggerMock = new Mock <ILogger>(); var packageMock = new Mock <IPackage>(); packageMock.Setup(x => x.CompareTo(It.IsAny <IPackage>())).Returns(-1); var collection = new List <IPackage>() { packageMock.Object }; var repository = new PackageRepository(loggerMock.Object, collection); // Act repository.Add(packageMock.Object); // Assert loggerMock.Verify(x => x.Log(It.IsAny <string>()), Times.Exactly(2)); }
public void Add_ShouldCallUpdateMethod_WhenThePackegeExists_ButWithHigherVersion_lodTwice() { //Arrange var loggerMock = new Mock <ILogger>(); var packagesMock = new Mock <IPackage>(); packagesMock.Setup(x => x.CompareTo(It.IsAny <IPackage>())).Returns(-1); var collection = new List <IPackage>() { packagesMock.Object }; var sut = new PackageRepository(loggerMock.Object, collection); //Act sut.Add(packagesMock.Object); //Assert loggerMock.Verify(x => x.Log(It.IsAny <string>()), Times.Exactly(2)); }
public void LogThreeTimes_WhenThePackageIsAlreadyAdded() { // Arrange var loggerMock = new Mock <ILogger>(); var packageMock = new Mock <IPackage>(); packageMock.Setup(p => p.Name).Returns("Package"); packageMock.Setup(p => p.CompareTo(It.IsAny <IPackage>())).Returns(0); ICollection <IPackage> packages = new List <IPackage>() { packageMock.Object }; PackageRepository packageRepository = new PackageRepository(loggerMock.Object, packages); // Act packageRepository.Add(packageMock.Object); // Assert loggerMock.Verify(l => l.Log(It.IsAny <string>()), Times.Exactly(3)); }
public void ReturnMessangeThatHigherVersionPackageAlreadyExistIfTryingToInstallLower() { //Arrange var packagesMock = Mock.Create <List <IPackage> >(); var loggerMock = Mock.Create <ILogger>(); var packageAlreadyAddedMock = Mock.Create <IPackage>(); Mock.Arrange(() => packageAlreadyAddedMock.Name).Returns("TestPackage"); Mock.Arrange(() => packageAlreadyAddedMock.Version.Major).Returns(3); Mock.Arrange(() => packageAlreadyAddedMock.Version.Minor).Returns(3); Mock.Arrange(() => packageAlreadyAddedMock.Version.Patch).Returns(3); Mock.Arrange(() => packageAlreadyAddedMock.Version.VersionType).Returns(VersionType.final); var packages = new List <IPackage>() { packageAlreadyAddedMock }; var packageToAddMock = Mock.Create <IPackage>(); Mock.Arrange(() => packageToAddMock.Name).Returns("TestPackage"); Mock.Arrange(() => packageToAddMock.Version.Major).Returns(1); Mock.Arrange(() => packageToAddMock.Version.Minor).Returns(1); Mock.Arrange(() => packageToAddMock.Version.Patch).Returns(1); Mock.Arrange(() => packageToAddMock.Version.VersionType).Returns(VersionType.final); var sut = new PackageRepository(loggerMock, packages); sut.Add(packageToAddMock); //Should Check If .Log Method Is Called //Act & Assert //Mock.Assert(() => ) }
public void NotAddPackage_WhenPassedPackageObjWithTheSameVersionExists() { // Arrange var loggerMock = new Mock <ILogger>(); var packages = new HashSet <IPackage>(); var firstPackageMock = new Mock <IPackage>(); var secondPackageMock = new Mock <IPackage>(); secondPackageMock.Setup(x => x.CompareTo(firstPackageMock.Object)).Returns(0); firstPackageMock.Setup(x => x.Name).Returns("golqm paket be"); packages.Add(firstPackageMock.Object); secondPackageMock.Setup(x => x.Name).Returns("golqm paket be"); var repo = new PackageRepository(loggerMock.Object, packages); // Act repo.Add(secondPackageMock.Object); // Assert loggerMock.Verify(x => x.Log($"{secondPackageMock.Object.Name}: Package with the same version is already installed!"), Times.Once); }
public BoolResult AddPackage(Data.Dto.Package package) { return(packageRepository.Add(package)); }
public void Execute() { System.Diagnostics.Trace.WriteLine("\r\nLoading MIF Files", "information"); // If no mif repository exists in the pipeline data segment, create one if (!context.Data.ContainsKey("Mif10Repository")) { context.Data.Add("Mif10Repository", new PackageRepository()); } PackageRepository repository = (PackageRepository)context.Data["Mif10Repository"]; List <Package> loadedPackages = new List <Package>(); // Preserve the stack Stack <String> nonLoadedFiles = new Stack <string>(); Type[] modelTypes = new Type[] { typeof(SerializedStaticModel), typeof(StaticModel.Flat.StaticModel), typeof(VocabularyModel), typeof(DynamicModel.DynamicModel), typeof(Interfaces.CommonModelElementPackage) }; // Load the mif files into a repository structure ;) while (context.InputFiles.Count > 0) { string fileName = context.InputFiles.Pop(); Stream fs = null; System.Diagnostics.Trace.Write(".", "information"); try { fs = File.OpenRead(fileName); // Should we even be looking at this file? XmlDocument tdoc = new XmlDocument(); tdoc.Load(fs); bool loaded = false; if (tdoc.DocumentElement.NamespaceURI == "urn:hl7-org:v3/mif") { foreach (Type t in modelTypes) { try { fs.Seek(0, SeekOrigin.Begin); XmlSerializer xsz = new XmlSerializer(t); Object o = xsz.Deserialize(fs); if (o == null) { throw new NotSupportedException("Loader didn't recognize data as this type"); } else { Package model = o as Package; if (model.PackageLocation == null) { throw new InvalidDataException("This model has no package location, aborting pipeline load"); } loadedPackages.Add(o as Package); loaded = true; break; } } catch (InvalidDataException e) { throw new InvalidDataException(String.Format("Could not load '{0}'", fileName), e); } catch (InvalidOperationException e) { if (!e.Message.Contains(" (1,") && !e.Message.Contains(" (2,")) { System.Diagnostics.Trace.Write(String.Format("{0} -> {1}", e.Message, e.InnerException != null ? e.InnerException.Message : "N/A"), "warn"); } } catch (Exception) { //System.Diagnostics.Trace.Write(e.Message); } } } if (!loaded) { throw new NotSupportedException(String.Format("File format not recognized : '{0}'", fileName)); } } catch (InvalidDataException e) { throw e; } catch (Exception) { //System.Diagnostics.Trace.WriteLine(string.Format("Can't load {0}...", fileName), "warn"); nonLoadedFiles.Push(fileName); //System.Diagnostics.Trace.WriteLine(e.ToString(), "warn"); } if (fs != null) { fs.Close(); } } // Sort loadedPackages.Sort(repository); foreach (Package model in loadedPackages) { repository.Add(model); } // Hand off models we couldn't load back to the input file stack so another loader can load it while (nonLoadedFiles.Count > 0) { context.InputFiles.Push(nonLoadedFiles.Pop()); } }
public void Execute() { System.Diagnostics.Trace.WriteLine("\r\nLoading MIF Files", "information"); // If no mif repository exists in the pipeline data segment, create one if (!context.Data.ContainsKey("MIF20Repository")) { context.Data.Add("MIF20Repository", new PackageRepository()); } PackageRepository repository = (PackageRepository)context.Data["MIF20Repository"]; List <PackageArtifact> loadedPackages = new List <PackageArtifact>(); // Preserve the stack Stack <String> nonLoadedFiles = new Stack <string>(); Type[] modelTypes = new Type[] { typeof(StaticModel.Flat.GlobalStaticModel), typeof(DynamicModel.GlobalInteraction), typeof(Vocabulary.GlobalCodeSystem), typeof(Vocabulary.GlobalCodeSystemSupplement), typeof(Vocabulary.GlobalValueSet), typeof(Vocabulary.GlobalVocabularyModel), typeof(Interfaces.CommonModelElementPackage), typeof(SerializedStaticModel) }; MifTransformer transformer = new MifTransformer(); // Load the mif files into a repository structure ;) while (context.InputFiles.Count > 0) { string fileName = context.InputFiles.Pop(); Stream fs = null; System.Diagnostics.Trace.Write(".", "information"); try { // JF: Revised so that we can load multiple versions of the MIF using compiler transforms fs = transformer.GetFile(fileName); if (fs == null) { continue; } // Validate if (fs.CanSeek) { ValidateMifFile(fs, fileName); fs.Seek(0, SeekOrigin.Begin); } bool loaded = false; foreach (Type t in modelTypes) { try { fs.Seek(0, SeekOrigin.Begin); XmlSerializer xsz = new XmlSerializer(t); Object o = xsz.Deserialize(fs); if (o == null) { throw new NotSupportedException("Loader didn't recognize data as this type"); } else { PackageArtifact model = o as PackageArtifact; if (model.PackageLocation == null) { throw new InvalidDataException("This model has no package location, aborting pipeline load"); } loadedPackages.Add(o as PackageArtifact); loaded = true; break; } } catch (InvalidDataException e) { throw new InvalidDataException(String.Format("Could not load '{0}'", fileName), e); } catch (InvalidOperationException e) { if (!e.Message.Contains(" (1,") && !e.Message.Contains(" (2,")) { System.Diagnostics.Trace.Write(String.Format("{0} -> {1}", e.Message, e.InnerException != null ? e.InnerException.Message : "N/A"), "warn"); } if (e.InnerException != null && e.InnerException is OperationCanceledException) { throw e.InnerException; } } catch (OperationCanceledException e) { throw e; } catch (Exception) { //System.Diagnostics.Trace.Write(e.Message); } } if (!loaded) { throw new NotSupportedException(String.Format("File format not recognized : '{0}'", fileName)); } } catch (InvalidDataException e) { throw e; } catch (OperationCanceledException e) { throw new OperationCanceledException(String.Format("Can't load MIF file '{0}' into repository", fileName), e); } catch (XmlSchemaException e) { throw e; } catch (Exception e) { System.Diagnostics.Debug.WriteLine(string.Format("Can't load {0}...", fileName), "warn1"); nonLoadedFiles.Push(fileName); System.Diagnostics.Trace.WriteLine(e.ToString(), "warn1"); } if (fs != null) { fs.Close(); } } // Sort loadedPackages.Sort(repository); foreach (PackageArtifact model in loadedPackages) { repository.Add(model); } // Warn if a transform has been applied if (transformer.DidTransform) { Trace.WriteLine("\r\n--!! TRANSFORM APPLIED, MIF CONTENTS IN PIPELINE MAY NOT MATCH PHYSICAL FILE !!--\r\n", "warn"); } // Hand off models we couldn't load back to the input file stack so another loader can load it while (nonLoadedFiles.Count > 0) { context.InputFiles.Push(nonLoadedFiles.Pop()); } }
private static async Task RunAdd(AddOptions options) { var packageRepo = new PackageRepository(options.RepositoryOptions); await packageRepo.Add(options.Source); }
public void Add_WithValidInputs() { _repo.Add(_package); _mockDbSet.Received().Add(_package); }
/// <summary> /// 添加套餐 /// </summary> /// <param name="package"></param> /// <returns></returns> public bool AddPackage(Package package) { repository.Add(package); return(true); }