public void SetUp() { Func <IAggregateRootEntity> sutFactory = () => (IAggregateRootEntity)null; var thens = new[] { new object(), new object() }; _sut = new EventCentricAggregateConstructorTestSpecification( sutFactory, thens); }
public void SetUp() { Func<IAggregateRootEntity> sutFactory = () => (IAggregateRootEntity)null; var thens = new[] { new object(), new object() }; _sut = new EventCentricAggregateConstructorTestSpecification( sutFactory, thens); }
/// <summary> /// Initializes a new instance of the <see cref="EventCentricTestResult"/> class. /// </summary> /// <param name="specification">The specification.</param> /// <param name="state">The state.</param> /// <param name="actualEvents">The actual events.</param> /// <param name="actualException">The actual exception.</param> internal EventCentricAggregateConstructorTestResult( EventCentricAggregateConstructorTestSpecification specification, TestResultState state, Optional<object[]> actualEvents, Optional<Exception> actualException) { _specification = specification; _state = state; _actualEvents = actualEvents; _actualException = actualException; }
/// <summary> /// Initializes a new instance of the <see cref="EventCentricTestResult"/> class. /// </summary> /// <param name="specification">The specification.</param> /// <param name="state">The state.</param> /// <param name="actualEvents">The actual events.</param> /// <param name="actualException">The actual exception.</param> internal EventCentricAggregateConstructorTestResult( EventCentricAggregateConstructorTestSpecification specification, TestResultState state, Optional <object[]> actualEvents, Optional <Exception> actualException) { _specification = specification; _state = state; _actualEvents = actualEvents; _actualException = actualException; }
public void RunReturnsExpectedResultWhenFailedBecauseOfNoEvents() { var specification = new EventCentricAggregateConstructorTestSpecification( () => new FailNoEventCase(), new[] { new object() }); var result = _sut.Run(specification); Assert.That(result.Passed, Is.False); Assert.That(result.Failed, Is.True); Assert.That(result.ButEvents, Is.EqualTo(new Optional<object[]>(FailNoEventCase.TheEvents))); Assert.That(result.ButException, Is.EqualTo(Optional<Exception>.Empty)); }
public void UsingDefaultCtorReturnsInstanceWithExpectedProperties() { Func <IAggregateRootEntity> sutFactory = () => (IAggregateRootEntity)null; var thens = new[] { new object(), new object() }; var sut = new EventCentricAggregateConstructorTestSpecification( sutFactory, thens); Assert.That(sut.SutFactory, Is.SameAs(sutFactory)); Assert.That(sut.Thens, Is.EquivalentTo(thens)); }
public void RunReturnsExpectedResultWhenFailedBecauseExceptionOccurred() { var specification = new EventCentricAggregateConstructorTestSpecification( () => new FailExceptionCase(), new object[0]); var result = _sut.Run(specification); Assert.That(result.Passed, Is.False); Assert.That(result.Failed, Is.True); Assert.That(result.ButEvents, Is.EqualTo(Optional <object[]> .Empty)); Assert.That(result.ButException, Is.EqualTo(new Optional <Exception>(FailExceptionCase.TheException))); }
/// <summary> /// Runs the specified test specification. /// </summary> /// <param name="specification">The test specification to run.</param> /// <returns> /// The result of running the test specification. /// </returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="specification"/> is <c>null</c>.</exception> public EventCentricAggregateConstructorTestResult Run(EventCentricAggregateConstructorTestSpecification specification) { if (specification == null) throw new ArgumentNullException("specification"); IAggregateRootEntity sut = null; var result = Catch.Exception(() => sut = specification.SutFactory()); if (result.HasValue) { return specification.Fail(result.Value); } var actualEvents = sut.GetChanges().ToArray(); if (!actualEvents.SequenceEqual(specification.Thens, new WrappedEventComparerEqualityComparer(_comparer))) { return specification.Fail(actualEvents); } return specification.Pass(); }
/// <summary> /// Runs the specified test specification. /// </summary> /// <param name="specification">The test specification to run.</param> /// <returns> /// The result of running the test specification. /// </returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="specification"/> is <c>null</c>.</exception> public EventCentricAggregateConstructorTestResult Run(EventCentricAggregateConstructorTestSpecification specification) { if (specification == null) { throw new ArgumentNullException(nameof(specification)); } IAggregateRootEntity sut = null; var result = Catch.Exception(() => sut = specification.SutFactory()); if (result.HasValue) { return(specification.Fail(result.Value)); } #if NET20 var actualEvents = new List <object>(sut.GetChanges()).ToArray(); #else var actualEvents = sut.GetChanges().ToArray(); #endif if (!actualEvents.SequenceEqual(specification.Thens, new WrappedEventComparerEqualityComparer(_comparer))) { return(specification.Fail(actualEvents)); } return(specification.Pass()); }
public void RunReturnsExpectedResultWhenPassed() { var specification = new EventCentricAggregateConstructorTestSpecification( () => new PassCase(), new object[0]); var result = _sut.Run(specification); Assert.That(result.Passed, Is.True); Assert.That(result.Failed, Is.False); Assert.That(result.ButEvents, Is.EqualTo(Optional<object[]>.Empty)); Assert.That(result.ButException, Is.EqualTo(Optional<Exception>.Empty)); }
public void UsingDefaultCtorReturnsInstanceWithExpectedProperties() { Func<IAggregateRootEntity> sutFactory = () => (IAggregateRootEntity)null; var thens = new[] { new object(), new object() }; var sut = new EventCentricAggregateConstructorTestSpecification( sutFactory, thens); Assert.That(sut.SutFactory, Is.SameAs(sutFactory)); Assert.That(sut.Thens, Is.EquivalentTo(thens)); }