예제 #1
0
        public void BulkLicenseImportConvertsInsertsNonExistingInstitutionJournals()
        {
            Initialize();
            _controller.Url = HttpContextHelper.CreateUrlHelper();

            var data = UniversityLicenseStubs.Licenses();

            var journalCount = 0;
            var institutionCount = 0;

            var journals = new List<Journal>();
            var institutions = new List<Institution>();

            //var institutions = 1.To(10).Select(i => new Institution { Id = i, Name = $"Test Institution #{i}", ShortName = $"www.{i}.nl"});

            _bulkImporter.Setup(x => x.Execute(_uploadFile.Object.InputStream)).Returns(data);
            _institutionRepository.Setup(x => x.Find(It.IsAny<string>())).Returns<string>(s =>
            {
                var institution = new Institution { Id = ++institutionCount, ShortName = s };
                institutions.Add(institution);

                return institution;
            });
            _journalRepository.Setup(x => x.FindByIssn(It.IsAny<string>())).Returns<string>(s =>
            {
                var journal = new Journal { Id = ++journalCount, ISSN = s };
                journals.Add(journal);

                return journal;
            });

            _controller.BulkImportInstitutionalPrices(_viewModel);

            _institutionJournalRepository.Verify(x => x.InsertOrUpdate(It.IsAny<InstitutionJournal>()), Times.Exactly(16));
        }
        public InstitutionJournalLicenseViewModel(Journal journal, InstitutionJournal institutionJournal, string refererUrl, IEnumerable<SelectListItem> institutions)
        {
            this.JournalTitle = journal.Title;
            this.JournalLink = journal.Link;
            this.JournalPublisher = journal.Publisher.Name;
            this.RefererUrl = refererUrl;
            this.Institutions = institutions;

            if (institutionJournal == null)
            {
                return;
            }

            this.Link = institutionJournal.Link;
            this.Institution = institutionJournal.InstitutionId;
        }
예제 #3
0
        public void BulkLicenseImportDeletesInstitutionJournalsWithEmptyLicenseTexts()
        {
            Initialize();
            _controller.Url = HttpContextHelper.CreateUrlHelper();

            var data = UniversityLicenseStubs.SomeLicensesToDelete();

            var journalCount = 0;
            var institutionCount = 0;

            var journals = new List<Journal>();
            var institutions = new List<Institution>();

            _bulkImporter.Setup(x => x.Execute(_uploadFile.Object.InputStream)).Returns(data);
            _institutionRepository.Setup(x => x.Find(It.IsAny<string>())).Returns<string>(s =>
            {
                var institution = new Institution { Id = ++institutionCount, ShortName = s };
                institutions.Add(institution);

                return institution;
            });
            _journalRepository.Setup(x => x.FindByIssn(It.IsAny<string>())).Returns<string>(s =>
            {
                var journal = new Journal { Id = ++journalCount, ISSN = s };
                journals.Add(journal);

                return journal;
            });

            _institutionJournalRepository.Setup(x => x.Find(It.IsAny<int>(), It.IsAny<int>())).Returns<int, int>((i, j) => new InstitutionJournal
            {
                Journal = journals.SingleOrDefault(journal => journal.Id == j),
                Institution = institutions.SingleOrDefault(insitution => insitution.Id == i),
            });

            _controller.BulkImportInstitutionalPrices(_viewModel);

            _institutionJournalRepository.Verify(x => x.InsertOrUpdate(It.IsAny<InstitutionJournal>()), Times.Exactly(3));
            _institutionJournalRepository.Verify(x => x.Delete(It.Is<InstitutionJournal>(y => y.Journal.ISSN == "0219-3094")), Times.Exactly(1));
        }