housekeeping: Added IBuilder and Extensions (#2019)

This commit is contained in:
Rodney Littles II 2019-05-06 22:47:01 -05:00 коммит произвёл Glenn
Родитель 8fdca6979f
Коммит 7da21d1d13
12 изменённых файлов: 681 добавлений и 63 удалений

Просмотреть файл

@ -1,4 +1,4 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.15
MinimumVisualStudioVersion = 10.0.40219.1
@ -28,6 +28,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReactiveUI.Fody.Helpers", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReactiveUI.Fody.Tests", "ReactiveUI.Fody.Tests\ReactiveUI.Fody.Tests.csproj", "{404B0F3F-7343-4E54-A863-F27B99FE788B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactiveUI.Testing.Tests", "ReactiveUI.Testing.Tests\ReactiveUI.Testing.Tests.csproj", "{6591097A-342A-4EA0-AFF6-D2B3207F3E09}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Ad-Hoc|Any CPU = Ad-Hoc|Any CPU
@ -468,6 +470,62 @@ Global
{404B0F3F-7343-4E54-A863-F27B99FE788B}.Release|x64.Build.0 = Release|Any CPU
{404B0F3F-7343-4E54-A863-F27B99FE788B}.Release|x86.ActiveCfg = Release|Any CPU
{404B0F3F-7343-4E54-A863-F27B99FE788B}.Release|x86.Build.0 = Release|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Ad-Hoc|Mixed Platforms.ActiveCfg = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Ad-Hoc|Mixed Platforms.Build.0 = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Ad-Hoc|x64.Build.0 = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Ad-Hoc|x86.Build.0 = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.AppStore|Any CPU.Build.0 = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.AppStore|ARM.ActiveCfg = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.AppStore|ARM.Build.0 = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.AppStore|iPhone.Build.0 = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.AppStore|Mixed Platforms.ActiveCfg = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.AppStore|Mixed Platforms.Build.0 = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.AppStore|x64.ActiveCfg = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.AppStore|x64.Build.0 = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.AppStore|x86.ActiveCfg = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.AppStore|x86.Build.0 = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Debug|ARM.ActiveCfg = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Debug|ARM.Build.0 = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Debug|iPhone.Build.0 = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Debug|x64.ActiveCfg = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Debug|x64.Build.0 = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Debug|x86.ActiveCfg = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Debug|x86.Build.0 = Debug|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Release|Any CPU.Build.0 = Release|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Release|ARM.ActiveCfg = Release|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Release|ARM.Build.0 = Release|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Release|iPhone.ActiveCfg = Release|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Release|iPhone.Build.0 = Release|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Release|x64.ActiveCfg = Release|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Release|x64.Build.0 = Release|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Release|x86.ActiveCfg = Release|Any CPU
{6591097A-342A-4EA0-AFF6-D2B3207F3E09}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Просмотреть файл

@ -0,0 +1,17 @@
<Project Sdk="MSBuild.Sdk.Extras">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TargetFrameworks);net461</TargetFrameworks>
<FodyTargetFramework>netstandard2.0</FodyTargetFramework>
<FodyTargetFramework Condition=" $(TargetFramework.StartsWith('net4')) ">$(TargetFramework)</FodyTargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ReactiveUI.Testing\ReactiveUI.Testing.csproj" />
</ItemGroup>
<ItemGroup>
<None Include="API\**\*.txt" CopyToOutputDirectory="PreserveNewest" LinkBase="/" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,35 @@
// 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>
/// Test fixture.
/// </summary>
public class TestFixture
{
/// <summary>
/// Gets or sets the count.
/// </summary>
public int Count { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
public string Name { get; set; }
/// <summary>
/// Gets or sets the tests.
/// </summary>
public IEnumerable<string> Tests { get; set; }
/// <summary>
/// Gets or sets the variables.
/// </summary>
public Dictionary<string, string> Variables { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,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
};
}
}

Просмотреть файл

@ -0,0 +1,167 @@
// 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;
using Shouldly;
using Xunit;
namespace ReactiveUI.Testing.Tests
{
/// <summary>
/// Test for <see cref="IBuilderExtensions"/>.
/// </summary>
public sealed class TestFixtureBuilderExtensionTests
{
/// <summary>
/// Gets data for the test execution.
/// </summary>
public static IEnumerable<object[]> Data =>
new List<object[]>
{
new object[] { "testing", string.Empty, string.Empty },
new object[] { "testing", "testing", string.Empty },
new object[] { "testing", "testing", "one" },
new object[] { "testing", "one", "two" }
};
/// <summary>
/// Gets key value for the test execution.
/// </summary>
public static IEnumerable<object[]> KeyValues =>
new List<object[]>
{
new object[] { "testing", string.Empty },
new object[] { "testing", "one" },
new object[] { "testing", "two" },
new object[] { "testing", "one two" }
};
/// <summary>
/// Gets key value pairs for the test execution.
/// </summary>
public static IEnumerable<object[]> KeyValuePairs => new List<object[]>
{
new object[] { new KeyValuePair<string, string>("latch", "key") },
new object[] { new KeyValuePair<string, string>("skeleton", "key") },
new object[] { new KeyValuePair<string, string>("electronic", "key") },
new object[] { new KeyValuePair<string, string>("rsa", "key") }
};
/// <summary>
/// A test to verify the a dictionary is added to the <see cref="TestFixture"/>.
/// </summary>
[Fact]
public void Should_Add_Dictionary()
{
// Given, When
var dictionary = new Dictionary<string, string>
{
{ "check", "one" },
{ "testing", "two" }
};
TestFixture builder =
new TestFixtureBuilder()
.WithDictionary(dictionary);
// Then
builder.Variables.ShouldBe(dictionary);
Assert.Equal(dictionary, builder.Variables);
}
/// <summary>
/// A test to verify the key value pairs are added to the <see cref="TestFixture"/>.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
[Theory]
[MemberData(nameof(KeyValues))]
public void Should_Add_Key_Value(string key, string value)
{
// Given, When
TestFixture builder = new TestFixtureBuilder().WithKeyValue(key, value);
// Then
builder.Variables[key].ShouldBe(value);
}
/// <summary>
/// A test to verify the key value pairs are added to the <see cref="TestFixture"/>.
/// </summary>
/// <param name="keyValuePair">The key value pair.</param>
[Theory]
[MemberData(nameof(KeyValuePairs))]
public void Should_Add_Key_Value_Pair(KeyValuePair<string, string> keyValuePair)
{
// Given, When
TestFixture builder = new TestFixtureBuilder().WithKeyValue(keyValuePair);
// Then
builder.Variables[keyValuePair.Key].ShouldBe(keyValuePair.Value);
}
/// <summary>
/// A test to verify a range of values are added to the <see cref="TestFixture"/>.
/// </summary>
/// <param name="test1">The first test.</param>
/// <param name="test2">The second test.</param>
/// <param name="test3">The third test.</param>
[Theory]
[MemberData(nameof(Data))]
public void Should_Add_Range_To_List(string test1, string test2, string test3)
{
// Given, When
TestFixture builder = new TestFixtureBuilder().WithTests(new[] { test1, test2, test3 });
// Then
builder.Tests.ShouldBe(new[] { test1, test2, test3 });
}
/// <summary>
/// A test to verify a value added to a list of tests on the <see cref="TestFixture"/>.
/// </summary>
[Fact]
public void Should_Add_Value_To_List()
{
// Given, When
TestFixture builder = new TestFixtureBuilder().WithTest("testing");
// Then
builder.Tests.ShouldBe(new[] { "testing" });
}
/// <summary>
/// A test to verify the <see cref="TestFixture"/> count.
/// </summary>
/// <param name="count">The count.</param>
[Theory]
[InlineData(1)]
[InlineData(100)]
[InlineData(1000)]
[InlineData(10000)]
[InlineData(100000)]
public void Should_Return_Count(int count)
{
// Given, When
TestFixture builder = new TestFixtureBuilder().WithCount(count);
// Then
builder.Count.ShouldBe(count);
}
[Theory]
[InlineData("ReactiveUI")]
[InlineData("Splat")]
[InlineData("Sextant")]
[InlineData("Akavache")]
public void Should_Return_Name(string name)
{
// Given, When
TestFixture builder = new TestFixtureBuilder().WithName(name);
// Then
builder.Name.ShouldBe(name);
}
}
}

Просмотреть файл

@ -0,0 +1,144 @@
// 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
{
#pragma warning disable SA1402, SA1649, CA1040
/// <summary>
/// An interface for building.
/// </summary>
public interface IBuilder
{
}
/// <summary>
/// Default methods for the <see cref="IBuilder"/> abstraction.
/// </summary>
public static class IBuilderExtensions
{
/// <summary>
/// Adds the specified field to the builder.
/// </summary>
/// <typeparam name="TBuilder">The type of the builder.</typeparam>
/// <typeparam name="TField">The type of the field.</typeparam>
/// <param name="builder">This builder.</param>
/// <param name="field">The field.</param>
/// <param name="value">The value.</param>
/// <returns>The builder.</returns>
public static TBuilder With<TBuilder, TField>(this TBuilder builder, ref TField field, TField value)
where TBuilder : IBuilder
{
field = value;
return builder;
}
/// <summary>
/// Adds the specified list of fields to the builder.
/// </summary>
/// <typeparam name="TBuilder">The type of the builder.</typeparam>
/// <typeparam name="TField">The type of the field.</typeparam>
/// <param name="builder">This builder.</param>
/// <param name="field">The field.</param>
/// <param name="values">The values.</param>
/// <returns>The builder.</returns>
public static TBuilder With<TBuilder, TField>(
this TBuilder builder,
ref List<TField> field,
IEnumerable<TField> values)
where TBuilder : IBuilder
{
if (values == null)
{
field = null;
}
else
{
field.AddRange(values);
}
return builder;
}
/// <summary>
/// Adds the specified field to the builder.
/// </summary>
/// <typeparam name="TBuilder">The type of the builder.</typeparam>
/// <typeparam name="TField">The type of the field.</typeparam>
/// <param name="builder">This builder.</param>
/// <param name="field">The field.</param>
/// <param name="value">The value.</param>
/// <returns>The builder.</returns>
public static TBuilder With<TBuilder, TField>(this TBuilder builder, ref List<TField> field, TField value)
where TBuilder : IBuilder
{
field.Add(value);
return builder;
}
/// <summary>
/// Adds the specified key value pair to the provided dictionary.
/// </summary>
/// <typeparam name="TBuilder">The type of the builder.</typeparam>
/// <typeparam name="TKey">The type of the key.</typeparam>
/// <typeparam name="TField">The type of the field.</typeparam>
/// <param name="builder">This builder.</param>
/// <param name="dictionary">The dictionary.</param>
/// <param name="keyValuePair">The key value pair.</param>
/// <returns>The builder.</returns>
public static TBuilder With<TBuilder, TKey, TField>(
this TBuilder builder,
ref Dictionary<TKey, TField> dictionary,
KeyValuePair<TKey, TField> keyValuePair)
where TBuilder : IBuilder
{
dictionary.Add(keyValuePair.Key, keyValuePair.Value);
return builder;
}
/// <summary>
/// Adds the specified key and value to the provided dictionary.
/// </summary>
/// <typeparam name="TBuilder">The type of the builder.</typeparam>
/// <typeparam name="TKey">The type of the key.</typeparam>
/// <typeparam name="TField">The type of the field.</typeparam>
/// <param name="builder">This builder.</param>
/// <param name="dictionary">The dictionary.</param>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
/// <returns>The builder.</returns>
public static TBuilder With<TBuilder, TKey, TField>(
this TBuilder builder,
ref Dictionary<TKey, TField> dictionary,
TKey key,
TField value)
where TBuilder : IBuilder
{
dictionary.Add(key, value);
return builder;
}
/// <summary>
/// Adds the specified dictionary to the provided dictionary.
/// </summary>
/// <typeparam name="TBuilder">The type of the builder.</typeparam>
/// <typeparam name="TKey">The type of the key.</typeparam>
/// <typeparam name="TField">The type of the field.</typeparam>
/// <param name="builder">This builder.</param>
/// <param name="dictionary">The dictionary.</param>
/// <param name="keyValuePair">The key value pair.</param>
/// <returns> The builder.</returns>
public static TBuilder With<TBuilder, TKey, TField>(
this TBuilder builder,
ref Dictionary<TKey, TField> dictionary,
IDictionary<TKey, TField> keyValuePair)
{
dictionary = (Dictionary<TKey, TField>)keyValuePair;
return builder;
}
}
#pragma warning restore SA1402, SA1649, CA1040
}

Просмотреть файл

@ -0,0 +1,69 @@
// 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;
using System.Reactive.Disposables;
using System.Threading;
namespace ReactiveUI.Testing
{
/// <summary>
/// Message bus testing extensions.
/// </summary>
public static class MessageBusExtensions
{
private static readonly object mbGate = 42;
/// <summary>
/// Override the default Message Bus during the specified block.
/// </summary>
/// <typeparam name="TRet">The return type.</typeparam>
/// <param name="messageBus">The message bus to use for the block.</param>
/// <param name="block">The function to execute.</param>
/// <returns>The return value of the function.</returns>
public static TRet With<TRet>(this IMessageBus messageBus, Func<TRet> block)
{
using (messageBus.WithMessageBus())
{
return block();
}
}
/// <summary>
/// WithMessageBus allows you to override the default Message Bus
/// implementation until the object returned is disposed. If a
/// message bus is not specified, a default empty one is created.
/// </summary>
/// <param name="messageBus">The message bus to use, or null to create
/// a new one using the default implementation.</param>
/// <returns>An object that when disposed, restores the original
/// message bus.</returns>
public static IDisposable WithMessageBus(this IMessageBus messageBus)
{
var origMessageBus = MessageBus.Current;
Monitor.Enter(mbGate);
MessageBus.Current = messageBus ?? new MessageBus();
return Disposable.Create(() =>
{
MessageBus.Current = origMessageBus;
Monitor.Exit(mbGate);
});
}
/// <summary>
/// Override the default Message Bus during the specified block.
/// </summary>
/// <param name="messageBus">The message bus to use for the block.</param>
/// <param name="block">The action to execute.</param>
public static void With(this IMessageBus messageBus, Action block)
{
using (messageBus.WithMessageBus())
{
block();
}
}
}
}

Просмотреть файл

@ -15,11 +15,10 @@ using ReactiveUI;
namespace ReactiveUI.Testing
{
#pragma warning disable SA1600 // Elements should be documented
public static class TestUtils
public static class SchedulerExtensions
#pragma warning restore SA1600 // Elements should be documented
{
private static readonly AutoResetEvent schedGate = new AutoResetEvent(true);
private static readonly object mbGate = 42;
/// <summary>
/// WithScheduler overrides the default Deferred and Taskpool schedulers
@ -47,28 +46,6 @@ namespace ReactiveUI.Testing
});
}
/// <summary>
/// WithMessageBus allows you to override the default Message Bus
/// implementation until the object returned is disposed. If a
/// message bus is not specified, a default empty one is created.
/// </summary>
/// <param name="messageBus">The message bus to use, or null to create
/// a new one using the default implementation.</param>
/// <returns>An object that when disposed, restores the original
/// message bus.</returns>
public static IDisposable WithMessageBus(this IMessageBus messageBus)
{
var origMessageBus = MessageBus.Current;
Monitor.Enter(mbGate);
MessageBus.Current = messageBus ?? new MessageBus();
return Disposable.Create(() =>
{
MessageBus.Current = origMessageBus;
Monitor.Exit(mbGate);
});
}
/// <summary>
/// With is an extension method that uses the given scheduler as the
/// default Deferred and Taskpool schedulers for the given Func. Use
@ -150,34 +127,6 @@ namespace ReactiveUI.Testing
});
}
/// <summary>
/// Override the default Message Bus during the specified block.
/// </summary>
/// <typeparam name="TRet">The return type.</typeparam>
/// <param name="messageBus">The message bus to use for the block.</param>
/// <param name="block">The function to execute.</param>
/// <returns>The return value of the function.</returns>
public static TRet With<TRet>(this IMessageBus messageBus, Func<TRet> block)
{
using (messageBus.WithMessageBus())
{
return block();
}
}
/// <summary>
/// Override the default Message Bus during the specified block.
/// </summary>
/// <param name="messageBus">The message bus to use for the block.</param>
/// <param name="block">The action to execute.</param>
public static void With(this IMessageBus messageBus, Action block)
{
using (messageBus.WithMessageBus())
{
block();
}
}
/// <summary>
/// AdvanceToMs moves the TestScheduler to the specified time in
/// milliseconds.

Просмотреть файл

@ -1,7 +1,28 @@
[assembly: System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.6.1", FrameworkDisplayName=".NET Framework 4.6.1")]
namespace ReactiveUI.Testing
{
public class static TestUtils
public interface IBuilder { }
public class static IBuilderExtensions
{
public static TBuilder With<TBuilder, TField>(this TBuilder builder, ref TField field, TField value)
where TBuilder : ReactiveUI.Testing.IBuilder { }
public static TBuilder With<TBuilder, TField>(this TBuilder builder, ref System.Collections.Generic.List<> field, System.Collections.Generic.IEnumerable<TField> values)
where TBuilder : ReactiveUI.Testing.IBuilder { }
public static TBuilder With<TBuilder, TField>(this TBuilder builder, ref System.Collections.Generic.List<> field, TField value)
where TBuilder : ReactiveUI.Testing.IBuilder { }
public static TBuilder With<TBuilder, TKey, TField>(this TBuilder builder, ref System.Collections.Generic.Dictionary<, > dictionary, System.Collections.Generic.KeyValuePair<TKey, TField> keyValuePair)
where TBuilder : ReactiveUI.Testing.IBuilder { }
public static TBuilder With<TBuilder, TKey, TField>(this TBuilder builder, ref System.Collections.Generic.Dictionary<, > dictionary, TKey key, TField value)
where TBuilder : ReactiveUI.Testing.IBuilder { }
public static TBuilder With<TBuilder, TKey, TField>(this TBuilder builder, ref System.Collections.Generic.Dictionary<, > dictionary, System.Collections.Generic.IDictionary<TKey, TField> keyValuePair) { }
}
public class static MessageBusExtensions
{
public static TRet With<TRet>(this ReactiveUI.IMessageBus messageBus, System.Func<TRet> block) { }
public static void With(this ReactiveUI.IMessageBus messageBus, System.Action block) { }
public static System.IDisposable WithMessageBus(this ReactiveUI.IMessageBus messageBus) { }
}
public class static SchedulerExtensions
{
public static void AdvanceByMs(this Microsoft.Reactive.Testing.TestScheduler sched, double milliseconds) { }
public static void AdvanceToMs(this Microsoft.Reactive.Testing.TestScheduler sched, double milliseconds) { }
@ -13,13 +34,10 @@ namespace ReactiveUI.Testing
where T : System.Reactive.Concurrency.IScheduler { }
public static void With<T>(this T sched, System.Action<T> block)
where T : System.Reactive.Concurrency.IScheduler { }
public static TRet With<TRet>(this ReactiveUI.IMessageBus messageBus, System.Func<TRet> block) { }
public static void With(this ReactiveUI.IMessageBus messageBus, System.Action block) { }
public static System.Threading.Tasks.Task<TRet> WithAsync<T, TRet>(this T sched, System.Func<T, System.Threading.Tasks.Task<TRet>> block)
where T : System.Reactive.Concurrency.IScheduler { }
public static System.Threading.Tasks.Task WithAsync<T>(this T sched, System.Func<T, System.Threading.Tasks.Task> block)
where T : System.Reactive.Concurrency.IScheduler { }
public static System.IDisposable WithMessageBus(this ReactiveUI.IMessageBus messageBus) { }
public static System.IDisposable WithScheduler(System.Reactive.Concurrency.IScheduler sched) { }
}
}

Просмотреть файл

@ -1,7 +1,28 @@
[assembly: System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v2.0", FrameworkDisplayName="")]
namespace ReactiveUI.Testing
{
public class static TestUtils
public interface IBuilder { }
public class static IBuilderExtensions
{
public static TBuilder With<TBuilder, TField>(this TBuilder builder, ref TField field, TField value)
where TBuilder : ReactiveUI.Testing.IBuilder { }
public static TBuilder With<TBuilder, TField>(this TBuilder builder, ref System.Collections.Generic.List<> field, System.Collections.Generic.IEnumerable<TField> values)
where TBuilder : ReactiveUI.Testing.IBuilder { }
public static TBuilder With<TBuilder, TField>(this TBuilder builder, ref System.Collections.Generic.List<> field, TField value)
where TBuilder : ReactiveUI.Testing.IBuilder { }
public static TBuilder With<TBuilder, TKey, TField>(this TBuilder builder, ref System.Collections.Generic.Dictionary<, > dictionary, System.Collections.Generic.KeyValuePair<TKey, TField> keyValuePair)
where TBuilder : ReactiveUI.Testing.IBuilder { }
public static TBuilder With<TBuilder, TKey, TField>(this TBuilder builder, ref System.Collections.Generic.Dictionary<, > dictionary, TKey key, TField value)
where TBuilder : ReactiveUI.Testing.IBuilder { }
public static TBuilder With<TBuilder, TKey, TField>(this TBuilder builder, ref System.Collections.Generic.Dictionary<, > dictionary, System.Collections.Generic.IDictionary<TKey, TField> keyValuePair) { }
}
public class static MessageBusExtensions
{
public static TRet With<TRet>(this ReactiveUI.IMessageBus messageBus, System.Func<TRet> block) { }
public static void With(this ReactiveUI.IMessageBus messageBus, System.Action block) { }
public static System.IDisposable WithMessageBus(this ReactiveUI.IMessageBus messageBus) { }
}
public class static SchedulerExtensions
{
public static void AdvanceByMs(this Microsoft.Reactive.Testing.TestScheduler sched, double milliseconds) { }
public static void AdvanceToMs(this Microsoft.Reactive.Testing.TestScheduler sched, double milliseconds) { }
@ -13,13 +34,10 @@ namespace ReactiveUI.Testing
where T : System.Reactive.Concurrency.IScheduler { }
public static void With<T>(this T sched, System.Action<T> block)
where T : System.Reactive.Concurrency.IScheduler { }
public static TRet With<TRet>(this ReactiveUI.IMessageBus messageBus, System.Func<TRet> block) { }
public static void With(this ReactiveUI.IMessageBus messageBus, System.Action block) { }
public static System.Threading.Tasks.Task<TRet> WithAsync<T, TRet>(this T sched, System.Func<T, System.Threading.Tasks.Task<TRet>> block)
where T : System.Reactive.Concurrency.IScheduler { }
public static System.Threading.Tasks.Task WithAsync<T>(this T sched, System.Func<T, System.Threading.Tasks.Task> block)
where T : System.Reactive.Concurrency.IScheduler { }
public static System.IDisposable WithMessageBus(this ReactiveUI.IMessageBus messageBus) { }
public static System.IDisposable WithScheduler(System.Reactive.Concurrency.IScheduler sched) { }
}
}

Просмотреть файл

@ -18,7 +18,7 @@ namespace ReactiveUI.Tests.API
[Fact]
public void Testing()
{
CheckApproval(typeof(Testing.TestUtils).Assembly);
CheckApproval(typeof(Testing.SchedulerExtensions).Assembly);
}
[Fact]

Просмотреть файл

@ -1,4 +1,4 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.15
MinimumVisualStudioVersion = 10.0.40219.1
@ -38,6 +38,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReactiveUI.Fody.Tests", "Re
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReactiveUI.Splat.Tests", "ReactiveUI.Splat.Tests\ReactiveUI.Splat.Tests.csproj", "{7ED6D69F-138F-40BD-9F37-3E4050E4D19B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactiveUI.Testing.Tests", "ReactiveUI.Testing.Tests\ReactiveUI.Testing.Tests.csproj", "{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Ad-Hoc|Any CPU = Ad-Hoc|Any CPU
@ -758,6 +760,62 @@ Global
{7ED6D69F-138F-40BD-9F37-3E4050E4D19B}.Release|x64.Build.0 = Release|Any CPU
{7ED6D69F-138F-40BD-9F37-3E4050E4D19B}.Release|x86.ActiveCfg = Release|Any CPU
{7ED6D69F-138F-40BD-9F37-3E4050E4D19B}.Release|x86.Build.0 = Release|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Ad-Hoc|Mixed Platforms.ActiveCfg = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Ad-Hoc|Mixed Platforms.Build.0 = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Ad-Hoc|x64.Build.0 = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Ad-Hoc|x86.Build.0 = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.AppStore|Any CPU.Build.0 = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.AppStore|ARM.ActiveCfg = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.AppStore|ARM.Build.0 = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.AppStore|iPhone.Build.0 = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.AppStore|Mixed Platforms.ActiveCfg = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.AppStore|Mixed Platforms.Build.0 = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.AppStore|x64.ActiveCfg = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.AppStore|x64.Build.0 = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.AppStore|x86.ActiveCfg = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.AppStore|x86.Build.0 = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Debug|ARM.ActiveCfg = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Debug|ARM.Build.0 = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Debug|iPhone.Build.0 = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Debug|x64.ActiveCfg = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Debug|x64.Build.0 = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Debug|x86.ActiveCfg = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Debug|x86.Build.0 = Debug|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Release|Any CPU.Build.0 = Release|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Release|ARM.ActiveCfg = Release|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Release|ARM.Build.0 = Release|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Release|iPhone.ActiveCfg = Release|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Release|iPhone.Build.0 = Release|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Release|x64.ActiveCfg = Release|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Release|x64.Build.0 = Release|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Release|x86.ActiveCfg = Release|Any CPU
{CD8B19A9-316E-4FBC-8F0C-87ADC6AAD684}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE