public void TestAtBrevhovedGetAllHenterAlleBrevhoveder()
        {
            IEnumerable <BrevhovedView> letterHeadViewCollection = _fixture.CreateMany <BrevhovedView>(_random.Next(3, 7)).ToList();
            IChannelFactory             channelFactory           = CreateChannelFactory(letterHeadViewCollection);

            IEnumerable <Brevhoved> letterHeadCollection = _fixture.CreateMany <Brevhoved>(letterHeadViewCollection.Count()).ToList();
            IDomainObjectBuilder    domainObjectBuilder  = CreateDomainObjectBuilder(letterHeadCollection);

            IFællesRepository sut = new FællesRepository(channelFactory, CreateMySqlDataProvider(), domainObjectBuilder);

            Assert.That(sut, Is.Not.Null);

            IEnumerable <Brevhoved> letterheads = sut.BrevhovedGetAll();

            // ReSharper disable PossibleMultipleEnumeration
            Assert.That(letterheads, Is.Not.Null);
            Assert.That(letterheads, Is.Not.Empty);
            Assert.That(letterheads.Count(), Is.EqualTo(letterHeadCollection.Count()));
            Assert.That(letterheads, Is.EqualTo(letterHeadCollection));
            // ReSharper restore PossibleMultipleEnumeration

            channelFactory.AssertWasCalled(m => m.CreateChannel <IFællesRepositoryService>(Arg <string> .Is.Anything), opt => opt.Repeat.Once());
            domainObjectBuilder.AssertWasCalled(m => m.BuildMany <BrevhovedView, Brevhoved>(Arg <IEnumerable <BrevhovedView> > .Is.Equal(letterHeadViewCollection)), opt => opt.Repeat.Once());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Evaluerer kommando til oprettelse af en bogføringslinje.
        /// </summary>
        /// <param name="command">Kommando til oprettelse af en bogføringslinje.</param>
        /// <param name="konto">Returnering af konto, hvorpå bogføringslinjen skal bogføres.</param>
        /// <param name="budgetkonto">Returnering af budgetkonto, hvorpå bogføringslinjen skal bogføres.</param>
        /// <param name="adressekonto">Returnering af adressekonto, hvorpå bogføringslinjen skal bogføres.</param>
        private void EvaluateCommand(BogføringslinjeOpretCommand command, out Konto konto, out Budgetkonto budgetkonto, out AdresseBase adressekonto)
        {
            var adresselisteHelper   = new AdresselisteHelper(AdresseRepository.AdresseGetAll());
            var brevhovedlisteHelper = new BrevhovedlisteHelper(FællesRepository.BrevhovedGetAll());
            var regnskab             = Repository.RegnskabGet(command.Regnskabsnummer, brevhovedlisteHelper.GetById, adresselisteHelper.GetById);

            var currentTime = DateTime.Now;

            if (command.Dato.Date < currentTime.AddDays(_konfigurationRepository.DageForBogføringsperiode * -1).Date)
            {
                throw new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.BalanceLineDateToOld, _konfigurationRepository.DageForBogføringsperiode));
            }
            if (command.Dato.Date > currentTime.Date)
            {
                throw new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.BalanceLineDateIsForwardInTime));
            }

            if (string.IsNullOrEmpty(command.Kontonummer))
            {
                throw new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.BalanceLineAccountNumberMissing));
            }
            try
            {
                konto = regnskab.Konti.OfType <Konto>().Single(m => String.Compare(m.Kontonummer, command.Kontonummer, StringComparison.Ordinal) == 0);
            }
            catch (InvalidOperationException ex)
            {
                throw new IntranetRepositoryException(Resource.GetExceptionMessage(ExceptionMessage.CantFindObjectById, typeof(Konto).Name, command.Kontonummer), ex);
            }

            if (string.IsNullOrEmpty(command.Tekst))
            {
                throw new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.BalanceLineTextMissing));
            }

            budgetkonto = null;
            if (!string.IsNullOrEmpty(command.Budgetkontonummer))
            {
                try
                {
                    budgetkonto = regnskab.Konti.OfType <Budgetkonto>().Single(m => String.Compare(m.Kontonummer, command.Budgetkontonummer, StringComparison.Ordinal) == 0);
                }
                catch (InvalidOperationException ex)
                {
                    throw new IntranetRepositoryException(Resource.GetExceptionMessage(ExceptionMessage.CantFindObjectById, typeof(Budgetkonto).Name, command.Budgetkontonummer), ex);
                }
            }

            if (command.Debit < 0M)
            {
                throw new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.BalanceLineValueBelowZero));
            }
            if (command.Kredit < 0M)
            {
                throw new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.BalanceLineValueBelowZero));
            }
            if (command.Debit == 0M && command.Kredit == 0M)
            {
                throw new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.BalanceLineValueMissing));
            }

            adressekonto = null;
            if (command.Adressekonto == 0)
            {
                return;
            }
            adressekonto = adresselisteHelper.GetById(command.Adressekonto);
        }
        public void TestAtBrevhovedGetAllKasterIntranetRepositoryExceptionVedFaultException()
        {
            FaultException  faultException = new FaultException(_fixture.Create <FaultReason>());
            IChannelFactory channelFactory = CreateChannelFactory(exception: faultException);

            IFællesRepository sut = new FællesRepository(channelFactory, CreateMySqlDataProvider(), CreateDomainObjectBuilder());

            Assert.That(sut, Is.Not.Null);

            IntranetRepositoryException result = Assert.Throws <IntranetRepositoryException>(() => sut.BrevhovedGetAll());

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Message, Is.Not.Null);
            Assert.That(result.Message, Is.Not.Empty);
            Assert.That(result.Message, Is.EqualTo(faultException.Message));
            Assert.That(result.InnerException, Is.Null);
        }
        public void TestAtBrevhovedGetAllKasterIntranetRepositoryExceptionVedException()
        {
            Exception       exception      = _fixture.Create <Exception>();
            IChannelFactory channelFactory = CreateChannelFactory(exception: exception);

            IFællesRepository sut = new FællesRepository(channelFactory, CreateMySqlDataProvider(), CreateDomainObjectBuilder());

            Assert.That(sut, Is.Not.Null);

            IntranetRepositoryException result = Assert.Throws <IntranetRepositoryException>(() => sut.BrevhovedGetAll());

            TestHelper.AssertIntranetRepositoryExceptionIsValid(result, exception, ExceptionMessage.RepositoryError, "BrevhovedGetAll", exception.Message);
        }
        public void TestAtBrevhovedGetAllKasterIntranetRepositoryExceptionVedIntranetRepositoryException()
        {
            IntranetRepositoryException intranetRepositoryException = _fixture.Create <IntranetRepositoryException>();
            IChannelFactory             channelFactory = CreateChannelFactory(exception: intranetRepositoryException);

            IFællesRepository sut = new FællesRepository(channelFactory, CreateMySqlDataProvider(), CreateDomainObjectBuilder());

            Assert.That(sut, Is.Not.Null);

            IntranetRepositoryException result = Assert.Throws <IntranetRepositoryException>(() => sut.BrevhovedGetAll());

            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.EqualTo(intranetRepositoryException));
        }