public void SetProperties(CkanPackage unsavedPackage, CkanGroup ckanGroup, ProfileParameters parameters,
     IndicatorMetadata indicatorMetadata, TimeRange timeRange)
 {
     SetMetadataProperties(unsavedPackage, indicatorMetadata);
     SetPackageProperties(unsavedPackage, ckanGroup, parameters);
     SetDateProperties(unsavedPackage, timeRange);
 }
 public void RunOnceBeforeEachTest()
 {
     package = new CkanPackage
     {
         Id = PackageId
     };
 }
        private static void SetDateProperties(CkanPackage package, TimeRange timeRange)
        {
            package.CoverageStartDate = timeRange.FirstTimePeriod.Year + "-01-01";

            TimePeriod timePeriod = timeRange.LastTimePeriod;
            package.CoverageEndDate = (timePeriod.Year + timePeriod.YearRange - 1) + "-12-31";
            package.Frequency = new List<string> { new CkanFrequency(timePeriod).Frequency };
        }
 private static void SetMetadataProperties(CkanPackage package, IndicatorMetadata indicatorMetadata)
 {
     var htmlCleaner = new HtmlCleaner();
     IDictionary<string, string> descriptiveMetadata = indicatorMetadata.Descriptive;
     package.Title = descriptiveMetadata[IndicatorMetadataTextColumnNames.Name];
     package.Notes = htmlCleaner.RemoveHtml(descriptiveMetadata[IndicatorMetadataTextColumnNames.Definition]);
     package.Origin = htmlCleaner.RemoveHtml(descriptiveMetadata[IndicatorMetadataTextColumnNames.Source]);
 }
 public void RunBeforeEachTest()
 {
     resource1 = new CkanResource { Name = "1" };
     resource2 = new CkanResource { Name = "2" };
     package = new CkanPackage
     {
         Id = packageId,
         Resources = new List<CkanResource>()
     };
 }
 private static void SetPackageProperties(CkanPackage package, 
     CkanGroup group, ProfileParameters parameters)
 {
     string homePage = parameters.ProfileUrl;
     package.Source = homePage;
     package.Homepage = homePage;
     package.LicenseId = parameters.LicenceId;
     string emailAddress = AuthorDetails.GetEmailAddress(parameters.ProfileId);
     package.Author = emailAddress;
     package.AuthorEmail = emailAddress;
     package.Maintainer = emailAddress;
     package.MaintainerEmail = emailAddress;
     package.OwnerOrganization = parameters.OrganisationId;
     package.Resources = new List<CkanResource>();
     package.Groups = new List<CkanGroup> { @group.GetMinimalGroupForSendingToCkan() };
 }
 public CkanPackage CreateOrUpdate(CkanPackage ckanPackage)
 {
     return ckanPackage.IsInstanceFromRepository
         ? ckanApi.UpdatePackage(ckanPackage)
         : ckanApi.CreatePackage(ckanPackage);
 }
        public void GetUpdatePackage_Returns_Package()
        {
            // Arrange: mock HTTP client
            var mock = new Moq.Mock<ICkanHttpClient>();
            var json = CkanTestHelper.GetExampleResponseFromFile("update_package.json");
            var requestPackage = new CkanPackage();
            mock.Setup(x => x.PostAction(ActionNames.PackageUpdate, requestPackage))
                .Returns(json);

            // Act: get package
            var package = new CkanApi(mock.Object).UpdatePackage(requestPackage);

            // Assert
            Assert.AreEqual("phe-indicator-19-22402", package.Name);
        }
        public void TestCreatePackage()
        {
            var ckan = CkanApi();

            // Create a random name
            var guid = Guid.NewGuid().ToString().Substring(0, 8);
            var packageName = "phe-test-package-" + guid;

            var group = ckan.GetGroup(GroupName);

            var unsavedPackage = new CkanPackage
            {
                Name = packageName,
                Title = PackageTitle + " " + guid,
                Author = "PHE author",
                AuthorEmail = "PHE author email",
                Maintainer = "PHE maintainer",
                MaintainerEmail = "PHE MaintainerEmail",
                Notes = "notes for the package",
                Version = "4.2",
                Groups = new List<CkanGroup> {group.GetMinimalGroupForSendingToCkan()},
                OwnerOrganization = OrganisationName
            };
            var savedPackage = ckan.CreatePackage(unsavedPackage);

            // Check package
            Assert.IsNotNull(savedPackage);
            Assert.AreEqual(savedPackage.Name, packageName);
        }
 public void TestIsInstanceFromRepository_True()
 {
     var package = new CkanPackage{MetadataCreated = DateTime.Now};
     Assert.IsTrue(package.IsInstanceFromRepository);
 }
 public void TestIsInstanceFromRepository_False()
 {
     var package = new CkanPackage();
     Assert.IsFalse(package.IsInstanceFromRepository);
 }