Exemplo n.º 1
0
 public PropertyEnumeration LazyInitialize(PropertyInitializer initializer)
 {
     foreach (Amendment.Property property in this)
     {
         property.LazyInitializerMethod = initializer.Method;
     }
     return(this);
 }
Exemplo n.º 2
0
        public void ItPassesThroughReplay(string testMethodName, string?expectedReplay)
        {
            var testClassType  = typeof(Properties);
            var testMethodInfo = GetMethod(testMethodName);

            var result = PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, new DefaultPropertyFactory());

            result.Parameters.Replay.Should().Be(expectedReplay);
        }
Exemplo n.º 3
0
        public void ItPassesThroughShrinkLimit(string testMethodName, int expectedShrinkLimit)
        {
            var testClassType  = typeof(Properties);
            var testMethodInfo = GetMethod(testMethodName);

            var result = PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, new DefaultPropertyFactory());

            result.Parameters.ShrinkLimit.Should().Be(expectedShrinkLimit);
        }
    protected InitializedBase()
    {
        var initializer = new PropertyInitializer();

        //Initialize all strings
        initializer.Initialize <string>(this, "Juan");
        //Initialize all integers
        initializer.Initialize <int>(this, 31);
    }
Exemplo n.º 5
0
        public void ItDoesNotPassThroughSize(string testMethodName)
        {
            var testClassType  = typeof(Properties);
            var testMethodInfo = GetMethod(testMethodName);

            var result = PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, new DefaultPropertyFactory());

            result.Parameters.Size.Should().Be(null);
        }
Exemplo n.º 6
0
        private void DumpPropertyInitializer(PropertyInitializer propertyInitializer)
        {
            textWriter.Write(SafeName(propertyInitializer.Name));

            if (propertyInitializer.Expression != null)
            {
                textWriter.Write(" = ");
                propertyInitializer.Expression.AcceptCompiler(this);
            }
        }
Exemplo n.º 7
0
        public void AMethodLevelFactoryIsPreferredOverAClassLevelFactory(string testMethodName)
        {
            var mockPropertyFactory = MockPropertyFactory();
            var testClassType       = typeof(PropertiesWithFactoryConfig);
            var testMethodInfo      = GetMethod(testMethodName);

            PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, mockPropertyFactory.Object);

            VerifyFactoryPassedThrough(mockPropertyFactory, typeof(GenFactory1));
        }
Exemplo n.º 8
0
        public void ItPassesThroughTheFactoryFromTheClass(string testMethodName)
        {
            var mockPropertyFactory = MockPropertyFactory();
            var testClassType       = typeof(PropertiesWithFactoryConfig);
            var testMethodInfo      = GetMethod(testMethodName);

            PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, mockPropertyFactory.Object);

            VerifyFactoryPassedThrough(mockPropertyFactory, typeof(GenFactory2));
        }
Exemplo n.º 9
0
        public void WhenClassNorMethodHasFactoryConfig_ItPassesThroughNull(string testMethodName)
        {
            var mockPropertyFactory = MockPropertyFactory();
            var testClassType       = typeof(PropertiesWithoutFactoryConfig);
            var testMethodInfo      = GetMethod(testMethodName);

            PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, mockPropertyFactory.Object);

            VerifyFactoryNotPassedThrough(mockPropertyFactory);
        }
        public void ItPassesThroughGenKeyedToCorrectIndex(string testMethodName, int expectedIndex)
        {
            var mockPropertyFactory = MockPropertyFactory();
            var testClassType       = typeof(Properties);
            var testMethodInfo      = GetMethod(testMethodName);

            PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, mockPropertyFactory.Object);

            VerifyGenPassedThrough(mockPropertyFactory, Gen, expectedIndex);
        }
        public void ItErrorsWhenReferencePropertyIsNotAGen(string testMethodName)
        {
            var testClassType  = typeof(Properties);
            var testMethodInfo = GetMethod(testMethodName);

            Action test = () => PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, new DefaultPropertyFactory());

            test.Should()
            .Throw <Exception>()
            .WithMessage("Expected member 'NotAGen' to be an instance of 'GalaxyCheck.IGen', but it had a value of type 'System.Object'");
        }
Exemplo n.º 12
0
        private void ProcessPropertyInitializer(XmlElement parent, PropertyInitializer initializer)
        {
            XmlElement tmpElement = document.CreateElement("PropertyInitializer");

            parent.AppendChild(tmpElement);
            tmpElement.SetAttribute("Name", initializer.Name);

            if (initializer.Expression != null)
            {
                XmlElement previousElement = currentElement;
                currentElement = document.CreateElement("Value");
                initializer.Expression.AcceptCompiler(this);
                tmpElement.AppendChild(currentElement);
                currentElement = previousElement;
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Recognizes a property's initializer.
        /// </summary>
        /// <returns>A <see cref="PropertyInitializer"/></returns>
        protected PropertyInitializer PropertyInitializer()
        {
            if (!TryMatch(TokenID.Identifier))
            {
                return(null);
            }

            string fieldName = token.ToString();
            Token  first     = token;

            Consume(1);
            Match(TokenID.Equal);
            var fieldValue = Required <Expression>(Expression, Resources.ExpressionRequired);

            var initializer = new PropertyInitializer(fieldName, fieldValue);

            initializer.SetLocation(first.Start, fieldValue.End);
            return(initializer);
        }
Exemplo n.º 14
0
        public override Task <RunSummary> RunAsync(
            IMessageSink diagnosticMessageSink,
            IMessageBus messageBus,
            object[] constructorArguments,
            ExceptionAggregator aggregator,
            CancellationTokenSource cancellationTokenSource)
        {
            messageBus.QueueMessage(new TestCaseStarting(this));

            var startTime        = DateTime.UtcNow;
            var test             = new XunitTest(this, DisplayName);
            var testOutputHelper = constructorArguments
                                   .OfType <TestOutputHelper>()
                                   .FirstOrDefault() ?? new TestOutputHelper();

            testOutputHelper.Initialize(messageBus, test);

            Task <RunSummary> Fail(Exception ex)
            {
                var executionTime = (decimal)((DateTime.UtcNow - startTime).TotalSeconds);

                messageBus.QueueMessage(new TestFailed(test, executionTime, testOutputHelper !.Output, ex));
                return(Task.FromResult(new RunSummary()
                {
                    Failed = 1
                }));
            }

            Task <RunSummary> Pass()
            {
                var executionTime = (decimal)((DateTime.UtcNow - startTime).TotalSeconds);

                messageBus.QueueMessage(new TestPassed(test, executionTime, testOutputHelper !.Output));
                return(Task.FromResult(new RunSummary()
                {
                    Total = 1
                }));
            }

            Task <RunSummary> Skip(string reason)
            {
                messageBus.QueueMessage(new TestSkipped(test, reason));
                return(Task.FromResult(new RunSummary()
                {
                    Skipped = 1
                }));
            }

            PropertyInitializationResult?propertyInitResult;

            try
            {
                propertyInitResult = PropertyInitializer.Initialize(
                    TestMethod.TestClass.Class.ToRuntimeType(),
                    TestMethod.Method.ToRuntimeMethod(),
                    constructorArguments,
                    new DefaultPropertyFactory());
            }
            catch (Exception exception)
            {
                return(Fail(exception));
            }

            if (propertyInitResult.ShouldSkip)
            {
                return(Skip(propertyInitResult.SkipReason !));
            }

            try
            {
                propertyInitResult.Runner.Run(propertyInitResult.Parameters, testOutputHelper);
                return(Pass());
            }
            catch (Exception propertyFailedException)
            {
                return(Fail(propertyFailedException));
            }
        }