Exemple #1
0
        public AndConstraint <ServiceCollectionAssertions> BeRegistered(Type serviceType, Type implementationType, ServiceLifetime lifetime, string because = "", params object[] becauseArgs)
        {
            AssertionScope scope = Execute.Assertion;

            scope.AddReportable("lifetime", lifetime.ToString().ToLowerInvariant());
            scope
            .BecauseOf(because, becauseArgs)
            .WithExpectation("Expected {context:service collection} to contain a {lifetime} registration for {0} implemented by {1}{reason}, ", serviceType, implementationType)
            // Match service and lifetime
            .Given(() => Subject.Where(d => d.ServiceType == serviceType))
            .ForCondition(reg => reg.Any())
            .FailWith("but the service was not found.")
            .Then
            .ForCondition(reg => reg.Any(d => d.Lifetime == lifetime))
            .FailWith("but found {0}.", reg => reg.Select(d => d.Lifetime).Distinct())
            .Then
            .Given(reg => reg.FirstOrDefault(d => d.Lifetime == lifetime))
            .ForCondition(r =>
                          // Match implementation, instance or factory
                          r.ImplementationType == implementationType ||
                          r.ImplementationInstance != null && implementationType.IsInstanceOfType(r.ImplementationInstance) ||
                          r.ImplementationFactory != null
                          )
            .FailWith("but it does not.")
            ;

            return(new AndConstraint <ServiceCollectionAssertions>(this));
        }
Exemple #2
0
        public AndConstraint <ServiceProviderAssertions> Resolve(Type serviceType, string because = "", params object[] becauseArgs)
        {
            AssertionScope scope = Execute.Assertion;

            scope
            .BecauseOf(because, becauseArgs)
            .WithExpectation("Expected to resolve {0} from {context:service provider}{reason}, ", serviceType)
            .Given(() =>
            {
                try
                {
                    return(Subject.GetService(serviceType));
                }
                catch (Exception ex)
                {
                    return(ex);
                }
            })
            .ForCondition(value => !(value is Exception))
            .FailWith("but threw with {0}.", ex => ex)
            .Then
            .ForCondition(value => value != null)
            .FailWith("but failed.")
            ;

            return(new AndConstraint <ServiceProviderAssertions>(this));
        }
Exemple #3
0
        public void AssertEquality(EquivalencyValidationContext context)
        {
            using (var scope = new AssertionScope())
            {
                scope.AddReportable("configuration", config.ToString());
                scope.AddNonReportable("objects", new ObjectTracker(config.CyclicReferenceHandling));

                scope.BecauseOf(context.Because, context.BecauseArgs);

                AssertEqualityUsing(context);
            }
        }
        public void AssertEquality(EquivalencyValidationContext context)
        {
            using (var scope = new AssertionScope())
            {
                scope.AddReportable("configuration", config.ToString());
                scope.AddNonReportable("objects", new ObjectTracker(config.CyclicReferenceHandling));

                scope.BecauseOf(context.Reason, context.ReasonArgs);

                AssertEqualityUsing(context);
            }
        }
        public void When_formatting_reason_arguments_it_should_ignore_culture()
        {
            // Arrange
            var scope = new AssertionScope();

            // Act
            scope.BecauseOf("{0}", 1.234)
            .FailWith("{reason}");

            // Assert
            scope.Invoking(e => e.Dispose()).Should().Throw <XunitException>()
            .WithMessage("*1.234*", "it should always use . as decimal separator");
        }
        public void AssertEquality(EquivalencyValidationContext context)
        {
            using var scope = new AssertionScope();
            scope.AddReportable("configuration", config.ToString());

            scope.BecauseOf(context.Because, context.BecauseArgs);

            AssertEqualityUsing(context);

            if (context.Tracer != null)
            {
                scope.AddReportable("trace", context.Tracer.ToString());
            }
        }
Exemple #7
0
        public void AssertEquality(Comparands comparands, EquivalencyValidationContext context)
        {
            using var scope = new AssertionScope();

            scope.AssumeSingleCaller();
            scope.AddReportable("configuration", context.Options.ToString());
            scope.BecauseOf(context.Reason);

            RecursivelyAssertEquality(comparands, context);

            if (context.TraceWriter is not null)
            {
                scope.AddReportable("trace", context.TraceWriter.ToString());
            }
        }