Ejemplo n.º 1
0
    public static IFixture CreateFixtureWithContainer(Type fixtureInstanceType, string methodName)
    {
        var container = new FixtureContainer(fixtureInstanceType);

        container.Add(CreateFixture(fixtureInstanceType, methodName));
        return(container);
    }
        public void Populate(params Assembly[] dataFixtureAssemblies)
        {
            var fixtureContainer = new FixtureContainer();

            foreach (var dataFixtureType in dataFixtureAssemblies.SelectMany(dataFixtureAssembly => dataFixtureAssembly.GetTypes().Where(t => typeof (DataFixture).IsAssignableFrom(t))))
                fixtureContainer.AddDataFixture((DataFixture) Activator.CreateInstance(dataFixtureType));

            var fixtureVertices = fixtureContainer.All.ToDictionary(fixture => fixture.GetType(), fixture => new Vertex(() =>
            {
                using (var session = new Session(_sessionFactory.OpenSession()))
                using (var transaction = session.BeginTransaction())
                {
                    foreach (var entity in fixture.GetEntities(fixtureContainer))
                        session.Save(entity);

                    transaction.Commit();
                }
            }));

            foreach (var dataFixtureType in fixtureVertices.Keys)
            {
                var dataFixture = fixtureContainer.Get(dataFixtureType);
                var vertex = fixtureVertices[dataFixtureType];

                vertex.AddDependencies(dataFixture.Dependencies.Select(d => fixtureVertices[d]).ToArray());
            }

            var graph = new DirectedAcyclicGraph(fixtureVertices.Values);
            var graphExecutive = new ConcurrentGraphExecutive(graph);

            graphExecutive.ExecuteAndWait();

            if (graphExecutive.VerticesFailed.Any())
                throw new AggregateException(graphExecutive.VerticesFailed.Select(e=>e.Value));
        }
    void Ex01(Type containerType, FixtureDescriptorWithBackgroundAssertion expectedDescriptor)
    {
        IFixture container = new FixtureContainer(containerType);
        var      result    = container.Run(null, new FixtureStepRunnerFactory());

        Expect($"the descriptor of the result should be as follows:{expectedDescriptor.ToDescription()}", () => FixtureDescriptorWithBackgroundAssertion.Of(result !.FixtureDescriptor) == expectedDescriptor);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Builds a fixture with the specified fixture type.
    /// </summary>
    /// <param name="fixtureType">The fixture type to build.</param>
    /// <returns>
    /// The fixture that is built with the specified fixture type.
    /// </returns>
    protected virtual IFixture Build(Type fixtureType)
    {
        var fixtureContainer = new FixtureContainer(fixtureType);

        fixtureContainer.AddRange(
            fixtureType.GetCustomAttribute <FixtureAttribute>()?.Fixtures
            .Where(TypeFilter)
            .Select(Build) ?? Enumerable.Empty <IFixture>()
            );
        fixtureContainer.AddRange(
            fixtureType.GetRuntimeFields()
            .Where(FiledFilter)
            .Select(f => Build(f.FieldType))
            );
        fixtureContainer.AddRange(
            fixtureType.GetRuntimeProperties()
            .Where(PropertyFilter)
            .Select(p => Build(p.PropertyType))
            );
        fixtureContainer.AddRange(
            fixtureType.GetTypeInfo().DeclaredNestedTypes
            .Where(NestedTypeFilter)
            .Select(t => Build(t.AsType()))
            );
        fixtureContainer.AddRange(
            fixtureType.GetRuntimeMethods()
            .Where(MethodFilter)
            .Select(m => Build(fixtureType, m))
            );
        return(fixtureContainer);
    }
    public FixtureContainerSpec_RunFixtures()
    {
        Container = new FixtureContainer(typeof(TestFixtures.SimpleFixture));

        Container.FixtureRunning += (_, e) => FixtureRunningResult = e.Result;
        Container.FixtureRun     += (_, e) => FixtureRunResult = e.Result;

        ((FixtureContainer)Container).AddRange(new[] {
            TestFixtures.CreateFixture <TestFixtures.SimpleFixture>("FixtureMethod"),
            TestFixtures.CreateFixture <TestFixtures.SimpleDisposableFixture>("FixtureMethod"),
            TestFixtures.CreateFixture <TestFixtures.SimpleFixtureSteppable>("FixtureMethod")
        });

        Filter = Substitute.For <IFixtureFilter>();

        TestFixtures.CalledFixtureMethods.Clear();
    }
Ejemplo n.º 6
0
 public FixtureContainerSpec_EnsureParent()
 {
     ParentContainer = new FixtureContainer("FixtureContainer", new NamespaceFixtureAttribute());
     Container       = new FixtureContainer(typeof(TestFixtures.SimpleFixture));
     ((FixtureContainer)ParentContainer).Add(Container);
 }
Ejemplo n.º 7
0
 public FixtureContainerSpec_Ready()
 {
     Container = new FixtureContainer(typeof(TestFixtures.SimpleFixture));
 }
Ejemplo n.º 8
0
 public FixtureContainerSpec_CanRun()
 {
     Container = new FixtureContainer(typeof(TestFixtures.SimpleFixture));
     Filter    = Substitute.For <IFixtureFilter>();
 }