public void BulkLicenseImportUpdatesExisting()
        {
            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>();

            _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(16));
        }
        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));
        }