public async Task SetUp()
        {
            Repository.ApplyGivenEvents(Given().ToList());
            var handler = OnHandler();

            try
            {
                await handler.Handle(When());

                var expected  = Expect().ToList();
                var published = Repository.Events;
                CompareEvents(expected, published);
            }
            catch (AssertActualExpectedException)             //If is an assert exception, throw it to the sky
            {
                throw;
            }
            catch (Exception exception)             //Otherwise should be something expected
            {
                if (ExpectedException == null)
                {
                    Assert.True(false, $"{exception.GetType()}: {exception.Message}\n{exception.StackTrace}");
                }
                Assert.True(exception.GetType() == ExpectedException.GetType(),
                            $"Exception type {exception.GetType()} differs from expected type {ExpectedException.GetType()}");
                Assert.True(exception.Message == ExpectedException.Message,
                            $"Exception message \"{exception.Message}\" differs from expected message \"{ExpectedException.GetType()}\"");
            }
        }
Пример #2
0
        public override bool Check()
        {
            try
            {
                var type = Property.DeclaringType;

                // ReSharper disable PossibleNullReferenceException
                if (type.IsAbstract)
                {
                    // ReSharper restore PossibleNullReferenceException
                    type = Property.ReflectedType;
                }

                var parameters = new[]
                {
                    Value
                };
                Property.GetSetMethod(true).Invoke(
                    Activator.CreateInstance(type, true),
                    parameters);

                if (null != ExpectedException)
                {
                    throw new UnitTestException(string.Format(CultureInfo.InvariantCulture, Resources.PropertySetterTestException_Message, Property.ReflectedType.Name, Property.Name, ExpectedException.Name));
                }
            }
            catch (TargetInvocationException exception)
            {
                if (null == ExpectedException)
                {
                    throw;
                }

                // ReSharper disable PossibleMistakenCallToGetType.2
                if (ExpectedException.GetType() == exception.InnerException.GetType())
                {
                    // ReSharper restore PossibleMistakenCallToGetType.2
                    throw;
                }
            }

            return(true);
        }