Esempio n. 1
0
        public void TestAtIntranetSystemExceptionKanSerialiseresOgDeserialiseres()
        {
            var exception = new IntranetSystemException("Test");

            Assert.That(exception, Is.Not.Null);
            var memoryStream = new MemoryStream();

            try
            {
                var serializer = new SoapFormatter();
                serializer.Serialize(memoryStream, exception);
                Assert.That(memoryStream.Length, Is.GreaterThan(0));

                memoryStream.Seek(0, SeekOrigin.Begin);
                Assert.That(memoryStream.Position, Is.EqualTo(0));

                var deserializedException = (IntranetSystemException)serializer.Deserialize(memoryStream);
                Assert.That(deserializedException, Is.Not.Null);
                Assert.That(deserializedException.Message, Is.Not.Null);
                Assert.That(deserializedException.Message, Is.EqualTo(exception.Message));
            }
            finally
            {
                memoryStream.Close();
            }
        }
Esempio n. 2
0
        public void Add_WhenInfoCollectionIsNotNullAndOneInfoDoesExistWithinCollection_ThrowsIntranetSystemException()
        {
            IInfoCollection <ICreditInfo, Sut> sut = CreateSut();

            IList <ICreditInfo> infoCollection = new List <ICreditInfo>
            {
                _fixture.BuildCreditInfoMock().Object,
                                _fixture.BuildCreditInfoMock().Object,
                                _fixture.BuildCreditInfoMock().Object,
                                _fixture.BuildCreditInfoMock().Object,
                                _fixture.BuildCreditInfoMock().Object,
                                _fixture.BuildCreditInfoMock().Object,
                                _fixture.BuildCreditInfoMock().Object
            };

            ICreditInfo existingInfo = infoCollection[_random.Next(0, infoCollection.Count - 1)];

            sut.Add(existingInfo);

            IntranetSystemException result = Assert.Throws <IntranetSystemException>(() => sut.Add(existingInfo));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.Message.Contains(existingInfo.GetType().Name), Is.True);
            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ObjectAlreadyExists));
            Assert.That(result.InnerException, Is.Null);
            // ReSharper restore PossibleNullReferenceException
        }
Esempio n. 3
0
        public void Add_WhenPostingLineCollectionIsNotNullAndOnePostingLineDoesExistWithinCollection_ThrowsIntranetSystemException()
        {
            IPostingLineCollection sut = CreateSut();

            IList <IPostingLine> postingLineCollection = new List <IPostingLine>
            {
                _fixture.BuildPostingLineMock().Object,
                                 _fixture.BuildPostingLineMock().Object,
                                 _fixture.BuildPostingLineMock().Object,
                                 _fixture.BuildPostingLineMock().Object,
                                 _fixture.BuildPostingLineMock().Object,
                                 _fixture.BuildPostingLineMock().Object,
                                 _fixture.BuildPostingLineMock().Object
            };

            IPostingLine existingPostingLine = postingLineCollection[_random.Next(0, postingLineCollection.Count - 1)];

            sut.Add(existingPostingLine);

            IntranetSystemException result = Assert.Throws <IntranetSystemException>(() => sut.Add(postingLineCollection));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.Message.Contains(existingPostingLine.GetType().Name), Is.True);
            // ReSharper restore PossibleNullReferenceException
            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ObjectAlreadyExists));
            Assert.That(result.InnerException, Is.Null);
        }
        public void Add_WhenAccountCollectionIsNotNullAndOneAccountDoesExistWithinCollection_ThrowsIntranetSystemException()
        {
            IAccountCollectionBase <IAccount, Sut> sut = CreateSut();

            IList <IAccount> accountCollection = new List <IAccount>
            {
                _fixture.BuildAccountMock().Object,
                             _fixture.BuildAccountMock().Object,
                             _fixture.BuildAccountMock().Object,
                             _fixture.BuildAccountMock().Object,
                             _fixture.BuildAccountMock().Object,
                             _fixture.BuildAccountMock().Object,
                             _fixture.BuildAccountMock().Object
            };

            IAccount existingAccount = accountCollection[_random.Next(0, accountCollection.Count - 1)];

            sut.Add(existingAccount);

            IntranetSystemException result = Assert.Throws <IntranetSystemException>(() => sut.Add(accountCollection));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.Message.Contains(existingAccount.GetType().Name), Is.True);
            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ObjectAlreadyExists));
            Assert.That(result.InnerException, Is.Null);
            // ReSharper restore PossibleNullReferenceException
        }
Esempio n. 5
0
 /// <summary>
 /// Asserts that an IntranetSystemException is valid.
 /// </summary>
 /// <param name="intranetSystemException">The IntranetSystemException to assert on.</param>
 /// <param name="expectedExceptionMessage">The expected exception message.</param>
 /// <param name="expectedArguments">The expected arguments for the exception message.</param>
 public static void AssertIntranetSystemExceptionIsValid(IntranetSystemException intranetSystemException, ExceptionMessage expectedExceptionMessage, params object[] expectedArguments)
 {
     Assert.That(intranetSystemException, Is.Not.Null);
     Assert.That(intranetSystemException.Message, Is.Not.Null);
     Assert.That(intranetSystemException.Message, Is.Not.Empty);
     Assert.That(intranetSystemException.Message, Is.EqualTo(Resource.GetExceptionMessage(expectedExceptionMessage, expectedArguments)));
     Assert.That(intranetSystemException.InnerException, Is.Null);
 }
Esempio n. 6
0
        public void GenerateUserSpecificKeyAsync_WhenKeyElementCollectionHasKeyElementsAndNoMailAddressAndNoNameIdentifierWasReturnedFromClaimResolver_ThrowsIntranetSystemException()
        {
            IKeyGenerator sut = CreateSut(hasMailAddress: false, hasNameIdentifier: false);

            IntranetSystemException result = Assert.ThrowsAsync <IntranetSystemException>(async() => await sut.GenerateUserSpecificKeyAsync(_fixture.CreateMany <string>(_random.Next(1, 5)).ToArray()));

            Assert.That(result, Is.Not.Null);
        }
Esempio n. 7
0
        public void TestAtCreateIntranetSystemFaultKasterArgumentNullExceptionHvisIntranetSystemExceptionErNull()
        {
            var service = new TestSerivce();

            Assert.That(service, Is.Not.Null);
            IntranetSystemException intranetSystemException = null;

            Assert.Throws <ArgumentNullException>(() => service.GetIntranetSystemFault(intranetSystemException));
        }
Esempio n. 8
0
        public void UpdateAccount_WhenAccountViewModelIsInvalid_ThrowsIntranetSystemExceptionWhereInnerExceptionIsNull()
        {
            Controller sut = CreateSut(false);

            IntranetSystemException result = Assert.ThrowsAsync <IntranetSystemException>(async() => await sut.UpdateAccount(CreateAccountViewModel()));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.InnerException, Is.Null);
            // ReSharper restore PossibleNullReferenceException
        }
Esempio n. 9
0
        public void GenerateUserSpecificKeyAsync_WhenKeyElementCollectionHasKeyElementsAndNoMailAddressAndNoNameIdentifierWasReturnedFromClaimResolver_ThrowsIntranetSystemExceptionWhereInnerExceptionIsNull()
        {
            IKeyGenerator sut = CreateSut(hasMailAddress: false, hasNameIdentifier: false);

            IntranetSystemException result = Assert.ThrowsAsync <IntranetSystemException>(async() => await sut.GenerateUserSpecificKeyAsync(_fixture.CreateMany <string>(_random.Next(1, 5)).ToArray()));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.InnerException, Is.Null);
            // ReSharper restore PossibleNullReferenceException
        }
Esempio n. 10
0
        public void UpdateAccount_WhenAccountViewModelIsInvalid_ThrowsIntranetSystemExceptionWhereErrorCodeIsEqualToInternalError()
        {
            Controller sut = CreateSut(false);

            IntranetSystemException result = Assert.ThrowsAsync <IntranetSystemException>(async() => await sut.UpdateAccount(CreateAccountViewModel()));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.InternalError));
            // ReSharper restore PossibleNullReferenceException
        }
Esempio n. 11
0
        public void UpdateAccount_WhenAccountViewModelIsInvalid_ThrowsIntranetSystemExceptionWhereMessageEndsWithErrorMessagesFromModelState()
        {
            string     errorMessage = _fixture.Create <string>();
            Controller sut          = CreateSut(false, errorMessage: errorMessage);

            IntranetSystemException result = Assert.ThrowsAsync <IntranetSystemException>(async() => await sut.UpdateAccount(CreateAccountViewModel()));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.Message.EndsWith(errorMessage), Is.True);
            // ReSharper restore PossibleNullReferenceException
        }
        public void ExecuteAsync_WhenCalledAndExistingClientIdentifierDoesNotExist_ThrowsIntranetSystemException()
        {
            CommandHandler sut = CreateSut(false);

            IUpdateClientSecretIdentityCommand command = CreateCommandMock().Object;
            IntranetSystemException            result  = Assert.ThrowsAsync <IntranetSystemException>(async() => await sut.ExecuteAsync(command));

            Assert.That(result.Message.Contains("existingClientSecretIdentity"), Is.True);
            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ObjectIsNull));
            Assert.That(result.InnerException, Is.Null);
        }
Esempio n. 13
0
        public void TestAtIntranetSystemExceptionKanInstantieres()
        {
            var exception = new IntranetSystemException("Test");

            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.Message, Is.EqualTo("Test"));
            Assert.That(exception.InnerException, Is.Null);

            exception = new IntranetSystemException("Test", new Exception());
            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.Message, Is.EqualTo("Test"));
            Assert.That(exception.InnerException, Is.Not.Null);
            Assert.That(exception.InnerException.GetType(), Is.EqualTo(typeof(Exception)));
        }
        /// <summary>
        /// Danner en fault for en systemfejl, som er opstået i OS Intranet.
        /// </summary>
        /// <param name="exception">Exception, som er opstået som systemfejl.</param>
        /// <returns>Fault.</returns>
        protected FaultException <IntranetSystemFault> CreateIntranetSystemFault(IntranetSystemException exception)
        {
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }
            var fault = new IntranetSystemFault
            {
                Message           = exception.Message,
                ExceptionMessages = FormatExceptionMessage(exception)
            };

            return(new FaultException <IntranetSystemFault>(fault, new FaultReason(exception.Message)));
        }
Esempio n. 15
0
        public void TestAtCreateIntranetSystemFaultDannerIntranetSystemFault()
        {
            var service = new TestSerivce();

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

            var exception = new IntranetSystemException("Test", new NotSupportedException());
            var fault     = service.GetIntranetSystemFault(exception);

            Assert.That(fault, Is.Not.Null);
            Assert.That(fault, Is.TypeOf(typeof(FaultException <IntranetSystemFault>)));
            Assert.That(fault.Reason, Is.Not.Null);
            Assert.That(fault.Reason, Is.TypeOf(typeof(FaultReason)));
            Assert.That(fault.Reason.ToString(), Is.EqualTo(exception.Message));
        }
        public void Add_WhenAccountIsNotNullAndDoesExistWithinCollection_ThrowsIntranetSystemException()
        {
            IAccountCollectionBase <IAccount, Sut> sut = CreateSut();

            IAccount account = _fixture.BuildAccountMock().Object;

            sut.Add(account);

            IntranetSystemException result = Assert.Throws <IntranetSystemException>(() => sut.Add(account));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.Message.Contains(account.GetType().Name), Is.True);
            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ObjectAlreadyExists));
            Assert.That(result.InnerException, Is.Null);
            // ReSharper restore PossibleNullReferenceException
        }
Esempio n. 17
0
        public void Add_WhenPostingLineIsNotNullAndDoesExistWithinCollection_ThrowsIntranetSystemException()
        {
            IPostingLineCollection sut = CreateSut();

            IPostingLine postingLine = _fixture.BuildPostingLineMock().Object;

            sut.Add(postingLine);

            IntranetSystemException result = Assert.Throws <IntranetSystemException>(() => sut.Add(postingLine));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.Message.Contains(postingLine.GetType().Name), Is.True);
            // ReSharper restore PossibleNullReferenceException
            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ObjectAlreadyExists));
            Assert.That(result.InnerException, Is.Null);
        }
Esempio n. 18
0
        public void Add_WhenInfoIsNotNullAndDoesExistWithinCollection_ThrowsIntranetSystemException()
        {
            IInfoCollection <ICreditInfo, Sut> sut = CreateSut();

            ICreditInfo creditInfo = _fixture.BuildCreditInfoMock().Object;

            sut.Add(creditInfo);

            IntranetSystemException result = Assert.Throws <IntranetSystemException>(() => sut.Add(creditInfo));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.Message.Contains(creditInfo.GetType().Name), Is.True);
            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ObjectAlreadyExists));
            Assert.That(result.InnerException, Is.Null);
            // ReSharper restore PossibleNullReferenceException
        }
Esempio n. 19
0
 /// <summary>
 /// Returnerer en fault for en systemfejl.
 /// </summary>
 /// <param name="exception">Exception for systemfejl.</param>
 /// <returns>Fault.</returns>
 public FaultException <IntranetSystemFault> GetIntranetSystemFault(IntranetSystemException exception)
 {
     return(CreateIntranetSystemFault(exception));
 }