/
TestFixtureBuilder.cs
85 lines (74 loc) · 3.33 KB
/
TestFixtureBuilder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
using System.Collections.Generic;
namespace ReactiveUI.Testing.Tests
{
/// <summary>
/// An <see cref="IBuilder"/> that constructs a <see cref="TestFixture"/>.
/// </summary>
public class TestFixtureBuilder : IBuilder
{
private int _count;
private string _name;
private List<string> _tests = new List<string>();
private Dictionary<string, string> _variables = new Dictionary<string, string>();
/// <summary>
/// Performs an implicit conversion from <see cref="TestFixtureBuilder"/> to <see cref="TestFixture"/>.
/// </summary>
/// <param name="builder">The builder.</param>
/// <returns>The test fixture.</returns>
public static implicit operator TestFixture(TestFixtureBuilder builder) => builder.Build();
/// <summary>
/// Adds the count to the builder.
/// </summary>
/// <param name="count">The count.</param>
/// <returns>The builder.</returns>
public TestFixtureBuilder WithCount(int count) => this.With(ref _count, count);
/// <summary>
/// Adds the dictionary to the builder.
/// </summary>
/// <param name="variables">The dictionary.</param>
/// <returns>The builder.</returns>
public TestFixtureBuilder WithDictionary(Dictionary<string, string> variables) => this.With(ref _variables, variables);
/// <summary>
/// Adds the key value pair to the builder.
/// </summary>
/// <param name="keyValuePair">The key value pair.</param>
/// <returns>The builder.</returns>
public TestFixtureBuilder WithKeyValue(KeyValuePair<string, string> keyValuePair) => this.With(ref _variables, keyValuePair);
/// <summary>
/// Adds a key value pair to the builder.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
/// <returns>The builder.</returns>
public TestFixtureBuilder WithKeyValue(string key, string value) => this.With(ref _variables, key, value);
/// <summary>
/// Adds a name to the builder.
/// </summary>
/// <param name="name">The name.</param>
/// <returns>The builder.</returns>
public TestFixtureBuilder WithName(string name) => this.With(ref _name, name);
/// <summary>
/// Adds a test to the builder.
/// </summary>
/// <param name="test">The test.</param>
/// <returns>The builder.</returns>
public TestFixtureBuilder WithTest(string test) => this.With(ref _tests, test);
/// <summary>
/// Adds tests to the builder.
/// </summary>
/// <param name="tests">The tests.</param>
/// <returns>The builder.</returns>
public TestFixtureBuilder WithTests(IEnumerable<string> tests) => this.With(ref _tests, tests);
private TestFixture Build() => new TestFixture
{
Name = _name,
Count = _count,
Tests = _tests,
Variables = _variables
};
}
}