public void TestAtIntranetRepositoryExceptionKanSerialiseresOgDeserialiseres() { var exception = new IntranetRepositoryException("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 = (IntranetRepositoryException)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(); } }
/// <summary> /// Asserts that an IntranetRepositoryException is valid. /// </summary> /// <param name="intranetRepositoryException">The IntranetRepositoryException 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 AssertIntranetRepositoryExceptionIsValid(IntranetRepositoryException intranetRepositoryException, ExceptionMessage expectedExceptionMessage, params object [] expectedArguments) { Assert.That(intranetRepositoryException, Is.Not.Null); Assert.That(intranetRepositoryException.Message, Is.Not.Null); Assert.That(intranetRepositoryException.Message, Is.Not.Empty); Assert.That(intranetRepositoryException.Message, Is.EqualTo(Resource.GetExceptionMessage(expectedExceptionMessage, expectedArguments))); Assert.That(intranetRepositoryException.InnerException, Is.Null); }
public void Build_WhenCalledForIntranetRepositoryExceptionWithoutMethodBase_AssertMethodBaseIsNull() { IIntranetExceptionBuilder sut = CreateSut(ErrorCode.RepositoryError, _fixture.Create <string>(), _fixture.Create <string>()); IntranetRepositoryException result = (IntranetRepositoryException)sut.Build(); Assert.That(result.MethodBase, Is.Null); }
public void Build_WhenCalledForIntranetRepositoryExceptionWithMethodBase_AssertMethodBaseIsCorrect() { IIntranetExceptionBuilder sut = CreateSut(ErrorCode.RepositoryError, _fixture.Create <string>(), _fixture.Create <string>()); MethodBase methodBase = MethodBase.GetCurrentMethod(); IntranetRepositoryException result = (IntranetRepositoryException)sut.WithMethodBase(methodBase).Build(); Assert.That(result.MethodBase, Is.EqualTo(methodBase)); }
public void QueryAsync_WhenSupportingQueryHandlerThrowsIntranetExceptionBase_ThrowsIntranetExceptionBase() { IntranetRepositoryException intranetException = _fixture.Create <IntranetRepositoryException>(); Mock <IQueryHandler <TestQuery, object> > queryHandlerMock = CreateQueryHandlerMock <TestQuery, object>(_fixture.Create <object>(), intranetException); IQueryBus sut = CreateSut(CreateQueryHandlerMockCollection(queryHandlerMock.Object)); IntranetRepositoryException result = Assert.ThrowsAsync <IntranetRepositoryException>(async() => await sut.QueryAsync <TestQuery, object>(new TestQuery())); Assert.That(result, Is.EqualTo(intranetException)); }
public void PublishAsync_WhenSupportingCommandHandlerThrowsIntranetExceptionBase_ThrowsIntranetExceptionBase() { IntranetRepositoryException intranetException = _fixture.Create <IntranetRepositoryException>(); Mock <ICommandHandler <TestCommand, object> > commandHandlerMock = CreateCommandHandlerMockWithResult <TestCommand, object>(_fixture.Create <object>(), intranetException); ICommandBus sut = CreateSut(CreateCommandHandlerMockCollection(commandHandlerMock.Object)); IntranetRepositoryException result = Assert.ThrowsAsync <IntranetRepositoryException>(async() => await sut.PublishAsync <TestCommand, object>(new TestCommand())); Assert.That(result, Is.EqualTo(intranetException)); }
public void TestThatDeleteRelationsThrowsIntranetRepositoryExceptionWhenIdentifierIsNull() { IFoodItemGroupProxy sut = CreateSut(); Assert.That(sut, Is.Not.Null); Assert.That(sut.Identifier, Is.Null); Assert.That(sut.Identifier.HasValue, Is.False); IntranetRepositoryException result = Assert.Throws <IntranetRepositoryException>(() => sut.DeleteRelations(CreateFoodWasteDataProvider())); TestHelper.AssertIntranetRepositoryExceptionIsValid(result, ExceptionMessage.IllegalValue, sut.Identifier, "Identifier"); }
public void TestAtAftaleGetAllBySystemKasterIntranetRepositoryExceptionVedException() { Exception exception = _fixture.Create <Exception>(); IKalenderRepository sut = CreateSut(exception: exception); Assert.That(sut, Is.Not.Null); IntranetRepositoryException result = Assert.Throws <IntranetRepositoryException>(() => sut.AftaleGetAllBySystem(_fixture.Create <int>(), DateTime.Now.AddDays(_random.Next(1, 30) * -1))); TestHelper.AssertIntranetRepositoryExceptionIsValid(result, exception, ExceptionMessage.RepositoryError, "AftaleGetAllBySystem", exception.Message); }
public void TestAtBrugerGetAllBySystemKasterIntranetRepositoryExceptionVedException() { Exception exception = _fixture.Create <Exception>(); IKalenderRepository sut = CreateSut(exception: exception); Assert.That(sut, Is.Not.Null); IntranetRepositoryException result = Assert.Throws <IntranetRepositoryException>(() => sut.BrugerGetAllBySystem(_fixture.Create <int>())); TestHelper.AssertIntranetRepositoryExceptionIsValid(result, exception, ExceptionMessage.RepositoryError, "BrugerGetAllBySystem", exception.Message); }
public void TestThatSaveRelationsThrowsIntranetRepositoryExceptionWhenIdentifierIsNull() { IMemberOfHouseholdProxy sut = CreateSut(); Assert.That(sut, Is.Not.Null); Assert.That(sut.Identifier, Is.Null); Assert.That(sut.Identifier.HasValue, Is.False); IntranetRepositoryException result = Assert.Throws <IntranetRepositoryException>(() => sut.SaveRelations(CreateFoodWasteDataProvider(), _fixture.Create <bool>())); TestHelper.AssertIntranetRepositoryExceptionIsValid(result, ExceptionMessage.IllegalValue, sut.Identifier, "Identifier"); }
public void TestThatHouseholdMemberGetByMailAddressThrowsIntranetRepositoryExceptionWhenExceptionOccurs() { Exception exceptionToThrow = _fixture.Create <Exception>(); IHouseholdDataRepository sut = CreateSut(exception: exceptionToThrow); Assert.That(sut, Is.Not.Null); IntranetRepositoryException result = Assert.Throws <IntranetRepositoryException>(() => sut.HouseholdMemberGetByMailAddress(_fixture.Create <string>())); TestHelper.AssertIntranetRepositoryExceptionIsValid(result, exceptionToThrow, ExceptionMessage.RepositoryError, "HouseholdMemberGetByMailAddress", exceptionToThrow.Message); }
public void TestAtSystemGetAllKasterIntranetRepositoryExceptionVedException() { Exception exception = _fixture.Create <Exception>(); IMySqlDataProvider mySqlDataProvider = CreateMySqlDataProvider(exception: exception); IFællesRepository sut = new FællesRepository(CreateChannelFactory(), mySqlDataProvider, CreateDomainObjectBuilder()); Assert.That(sut, Is.Not.Null); IntranetRepositoryException result = Assert.Throws <IntranetRepositoryException>(() => sut.SystemGetAll()); TestHelper.AssertIntranetRepositoryExceptionIsValid(result, exception, ExceptionMessage.RepositoryError, "SystemGetAll", exception.Message); }
public void TestThatUniqueIdGetterThrowsIntranetRepositoryExceptionWhenFoodItemGroupProxyHasNoIdentifier() { IFoodItemGroupProxy sut = CreateSut(); Assert.That(sut, Is.Not.Null); // ReSharper disable UnusedVariable IntranetRepositoryException result = Assert.Throws <IntranetRepositoryException>(() => { var uniqueId = sut.UniqueId; }); // ReSharper restore UnusedVariable TestHelper.AssertIntranetRepositoryExceptionIsValid(result, ExceptionMessage.IllegalValue, sut.Identifier, "Identifier"); }
public void TestThatHouseholdMemberGetByMailAddressThrowsIntranetRepositoryExceptionWhenIntranetRepositoryExceptionOccurs() { IntranetRepositoryException exceptionToThrow = _fixture.Create <IntranetRepositoryException>(); IHouseholdDataRepository sut = CreateSut(exception: exceptionToThrow); Assert.That(sut, Is.Not.Null); IntranetRepositoryException result = Assert.Throws <IntranetRepositoryException>(() => sut.HouseholdMemberGetByMailAddress(_fixture.Create <string>())); Assert.That(result, Is.Not.Null); Assert.That(result, Is.EqualTo(exceptionToThrow)); }
public void TestAtBrugerGetAllBySystemKasterIntranetRepositoryExceptionVedIntranetRepositoryException() { IntranetRepositoryException intranetRepositoryException = _fixture.Create <IntranetRepositoryException>(); IKalenderRepository sut = CreateSut(exception: intranetRepositoryException); Assert.That(sut, Is.Not.Null); IntranetRepositoryException result = Assert.Throws <IntranetRepositoryException>(() => sut.BrugerGetAllBySystem(_fixture.Create <int>())); Assert.That(result, Is.Not.Null); Assert.That(result, Is.EqualTo(intranetRepositoryException)); }
public void TestAtAftaleGetAllBySystemKasterIntranetRepositoryExceptionVedIntranetRepositoryException() { IntranetRepositoryException intranetRepositoryException = _fixture.Create <IntranetRepositoryException>(); IKalenderRepository sut = CreateSut(exception: intranetRepositoryException); Assert.That(sut, Is.Not.Null); IntranetRepositoryException result = Assert.Throws <IntranetRepositoryException>(() => sut.AftaleGetAllBySystem(_fixture.Create <int>(), DateTime.Now.AddDays(_random.Next(1, 30) * -1))); Assert.That(result, Is.Not.Null); Assert.That(result, Is.EqualTo(intranetRepositoryException)); }
private static void AddMethodBase(IntranetExceptionBase intranetException, MethodBase methodBase) { NullGuard.NotNull(intranetException, nameof(intranetException)) .NotNull(methodBase, nameof(methodBase)); IntranetRepositoryException intranetRepositoryException = intranetException as IntranetRepositoryException; if (intranetRepositoryException == null) { return; } intranetRepositoryException.MethodBase = methodBase; }
public void TestAtIntranetRepositoryExceptionKanInstantieres() { var exception = new IntranetRepositoryException("Test"); Assert.That(exception, Is.Not.Null); Assert.That(exception.Message, Is.EqualTo("Test")); Assert.That(exception.InnerException, Is.Null); exception = new IntranetRepositoryException("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))); }
public void TestAtSystemGetAllKasterIntranetRepositoryExceptionVedIntranetRepositoryException() { IntranetRepositoryException intranetRepositoryException = _fixture.Create <IntranetRepositoryException>(); IMySqlDataProvider mySqlDataProvider = CreateMySqlDataProvider(exception: intranetRepositoryException); IFællesRepository sut = new FællesRepository(CreateChannelFactory(), mySqlDataProvider, CreateDomainObjectBuilder()); Assert.That(sut, Is.Not.Null); IntranetRepositoryException result = Assert.Throws <IntranetRepositoryException>(() => sut.SystemGetAll()); Assert.That(result, Is.Not.Null); Assert.That(result, Is.EqualTo(intranetRepositoryException)); }
public void TestAtGetKasterIntranetRepositoryExceptionHvisIdIkkeFindes() { using (IMySqlDataProvider sut = CreateSut()) { Assert.That(sut, Is.Not.Null); int systemNo = _random.Next(1, 9) * -1; MyDataProxy queryForDataProxy = new MyDataProxy { SystemNo = systemNo }; IntranetRepositoryException result = Assert.Throws <IntranetRepositoryException>(() => sut.Get(queryForDataProxy)); TestHelper.AssertIntranetRepositoryExceptionIsValid(result, ExceptionMessage.CantFindObjectById, queryForDataProxy.GetType().Name, systemNo); } }
public void TestThatUniqueIdGetterThrowsIntranetRepositoryExceptionWhenStorageHasNoIdentifier() { IStorageProxy sut = CreateSut(); Assert.That(sut, Is.Not.Null); Assert.That(sut.Identifier, Is.Null); Assert.That(sut.Identifier.HasValue, Is.False); // ReSharper disable ReturnValueOfPureMethodIsNotUsed IntranetRepositoryException result = Assert.Throws <IntranetRepositoryException>(() => sut.UniqueId.ToUpper()); // ReSharper restore ReturnValueOfPureMethodIsNotUsed TestHelper.AssertIntranetRepositoryExceptionIsValid(result, ExceptionMessage.IllegalValue, sut.Identifier, "Identifier"); }
public void TestAtCreateIntranetRepositoryFaultDannerIntranetRepositoryFault() { var service = new TestSerivce(); Assert.That(service, Is.Not.Null); var exception = new IntranetRepositoryException("Test", new NotSupportedException()); var fault = service.GetIntranetRepositoryFault(exception); Assert.That(fault, Is.Not.Null); Assert.That(fault, Is.TypeOf(typeof(FaultException <IntranetRepositoryFault>))); 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 TestThatCreateUpdateCommandThrowsIntranetRepositoryExceptionWhenFoodGroupIdentifierOnFoodItemGroupHasNoValue() { FoodItemProxy foodItemProxy = BuildFoodItemProxy(); FoodGroupProxy foodGroupProxy = BuildFoodGroupProxy(false); IFoodItemGroupProxy sut = CreateSut(Guid.NewGuid(), foodItemProxy, foodGroupProxy, _fixture.Create <bool>()); Assert.That(sut, Is.Not.Null); // ReSharper disable UnusedVariable IntranetRepositoryException result = Assert.Throws <IntranetRepositoryException>(() => { var updateCommand = sut.CreateUpdateCommand(); }); // ReSharper restore UnusedVariable TestHelper.AssertIntranetRepositoryExceptionIsValid(result, ExceptionMessage.IllegalValue, sut.FoodGroupIdentifier, "FoodGroupIdentifier"); }
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); }
/// <summary> /// Returnerer en fault for en fejl i repositories. /// </summary> /// <param name="exception">Exception fra repositories.</param> /// <returns>Fault.</returns> public FaultException <IntranetRepositoryFault> GetIntranetRepositoryFault(IntranetRepositoryException exception) { return(CreateIntranetRepositoryFault(exception)); }
/// <summary> /// Danner en fault for en fejl, som er opstået i repositories under OS Intranet. /// </summary> /// <param name="exception">Exception, som er opstået i repositories.</param> /// <returns>Fault.</returns> protected FaultException <IntranetRepositoryFault> CreateIntranetRepositoryFault(IntranetRepositoryException exception) { if (exception == null) { throw new ArgumentNullException("exception"); } var fault = new IntranetRepositoryFault { Message = exception.Message, ExceptionMessages = FormatExceptionMessage(exception) }; return(new FaultException <IntranetRepositoryFault>(fault, new FaultReason(exception.Message))); }