This commit is contained in:
Tomasz Cielecki 2018-01-30 21:46:06 +01:00
Родитель cab6557fec
Коммит 78965653ae
43 изменённых файлов: 768 добавлений и 681 удалений

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

@ -2,11 +2,14 @@
// The .NET Foundation licenses this file to you under the MS-PL license.
// See the LICENSE file in the project root for more information.
using System;
using System.Globalization;
using MvvmCross.Core;
using MvvmCross.Core.Platform;
using MvvmCross.Platform.Core;
using MvvmCross.Platform.IoC;
using MvvmCross.Platform.Logging;
using MvvmCross.Platform.Logging.LogProviders;
namespace MvvmCross.Test
{
@ -29,7 +32,7 @@ namespace MvvmCross.Test
return null;
}
protected virtual void ClearAll()
public virtual void ClearAll()
{
// fake set up of the IoC
Reset();
@ -38,9 +41,10 @@ namespace MvvmCross.Test
InitializeSingletonCache();
InitializeMvxSettings();
AdditionalSetup();
Ioc.RegisterSingleton<IMvxLogProvider>(new ConsoleLogProvider());
}
private static void InitializeSingletonCache()
public void InitializeSingletonCache()
{
MvxSingletonCache.Initialize();
}
@ -55,7 +59,7 @@ namespace MvvmCross.Test
// nothing here..
}
protected void SetInvariantCulture()
public void SetInvariantCulture()
{
var invariantCulture = CultureInfo.InvariantCulture;
CultureInfo.DefaultThreadCurrentCulture = invariantCulture;

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

@ -5,12 +5,15 @@
//
// Project Lead - Stuart Lodge, @slodge, me@slodge.com
using System.Runtime.CompilerServices;
using MvvmCross.Platform;
using MvvmCross.Platform.Logging;
[assembly: InternalsVisibleTo("MvvmCross.UnitTest")]
namespace MvvmCross
{
public static class MvxTestLog
internal static class MvxTestLog
{
internal static IMvxLog Instance { get; } = Mvx.Resolve<IMvxLogProvider>().GetLogFor("MvxTest");
}

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

@ -10,7 +10,6 @@ using System.Globalization;
namespace MvvmCross.Platform.Test.Converters
{
public class MvxDictionaryValueConverterTests : MvxDictionaryValueConverter<MvxDictionaryValueConverterTests.TestStates, string>
{
private Dictionary<TestStates, string> _testStatedictionary;
@ -26,8 +25,7 @@ namespace MvvmCross.Platform.Test.Converters
Failed
}
public void Init()
public MvxDictionaryValueConverterTests()
{
_testStatedictionary = new Dictionary<TestStates, string>
{
@ -36,18 +34,22 @@ namespace MvvmCross.Platform.Test.Converters
};
}
[Theory]
[InlineData(TestStates.Running, StateRunning)]
[InlineData(TestStates.Completed, StateCompleted)]
public string Convert_MatchingKeyIncludeFallback_ReturnsDictionaryValue(TestStates state)
public void Convert_MatchingKeyIncludeFallback_ReturnsDictionaryValue(TestStates state, string expected)
{
return Convert(state, null, new Tuple<IDictionary<TestStates, string>, string, bool>(_testStatedictionary, Fallback, true), CultureInfo.CurrentUICulture);
var converted = Convert(state, null, new Tuple<IDictionary<TestStates, string>, string, bool>(_testStatedictionary, Fallback, true), CultureInfo.CurrentUICulture);
Assert.Equal(expected, converted);
}
[Theory]
[InlineData(TestStates.Running, StateRunning)]
[InlineData(TestStates.Completed, StateCompleted)]
public string Convert_MatchingKeyExcludeFallback_ReturnsDictionaryValue(TestStates state)
public void Convert_MatchingKeyExcludeFallback_ReturnsDictionaryValue(TestStates state, string expected)
{
return Convert(state, null, new Tuple<IDictionary<TestStates, string>, string, bool>(_testStatedictionary, default(string), false), CultureInfo.CurrentUICulture);
var converted = Convert(state, null, new Tuple<IDictionary<TestStates, string>, string, bool>(_testStatedictionary, default(string), false), CultureInfo.CurrentUICulture);
Assert.Equal(expected, converted);
}
[Fact]

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

@ -60,14 +60,14 @@ namespace MvvmCross.Platform.Test
IA a;
var result = Mvx.TryResolve(out a);
Assert.IsTrue(result);
Assert.IsNotNull(a);
Assert.IsInstanceOf<A>(a);
Assert.True(result);
Assert.NotNull(a);
Assert.IsType<A>(a);
var castA = (A)a;
Assert.IsNull(castA.B);
Assert.IsNull(castA.C);
Assert.IsNull(castA.BNever);
Assert.IsNull(castA.CNever);
Assert.Null(castA.B);
Assert.Null(castA.C);
Assert.Null(castA.BNever);
Assert.Null(castA.CNever);
}
[Fact]
@ -89,15 +89,15 @@ namespace MvvmCross.Platform.Test
IA a;
var result = Mvx.TryResolve(out a);
Assert.IsTrue(result);
Assert.IsNotNull(a);
Assert.IsInstanceOf<A>(a);
Assert.True(result);
Assert.NotNull(a);
Assert.IsType<A>(a);
var castA = (A)a;
Assert.IsNotNull(castA.B);
Assert.IsInstanceOf<B>(castA.B);
Assert.IsNull(castA.C);
Assert.IsNull(castA.BNever);
Assert.IsNull(castA.CNever);
Assert.NotNull(castA.B);
Assert.IsType<B>(castA.B);
Assert.Null(castA.C);
Assert.Null(castA.BNever);
Assert.Null(castA.CNever);
}
[Fact]
@ -119,16 +119,16 @@ namespace MvvmCross.Platform.Test
IA a;
var result = Mvx.TryResolve(out a);
Assert.IsTrue(result);
Assert.IsNotNull(a);
Assert.IsInstanceOf<A>(a);
Assert.True(result);
Assert.NotNull(a);
Assert.IsType<A>(a);
var castA = (A)a;
Assert.IsNotNull(castA.B);
Assert.IsInstanceOf<B>(castA.B);
Assert.IsNotNull(castA.C);
Assert.IsInstanceOf<C>(castA.C);
Assert.IsNull(castA.BNever);
Assert.IsNull(castA.CNever);
Assert.NotNull(castA.B);
Assert.IsType<B>(castA.B);
Assert.NotNull(castA.C);
Assert.IsType<C>(castA.C);
Assert.Null(castA.BNever);
Assert.Null(castA.CNever);
}
}
}
}

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

@ -125,8 +125,8 @@ namespace MvvmCross.Platform.Test
IA a;
var result = Mvx.TryResolve(out a);
Assert.IsTrue(result);
Assert.IsNotNull(a);
Assert.True(result);
Assert.NotNull(a);
}
[Fact]
@ -142,8 +142,8 @@ namespace MvvmCross.Platform.Test
IA a;
var result = Mvx.TryResolve(out a);
Assert.IsFalse(result);
Assert.IsNull(a);
Assert.False(result);
Assert.Null(a);
}
[Fact]
@ -158,8 +158,8 @@ namespace MvvmCross.Platform.Test
IA a;
var result = Mvx.TryResolve(out a);
Assert.IsFalse(result);
Assert.IsNull(a);
Assert.False(result);
Assert.Null(a);
}
[Fact]
@ -174,8 +174,8 @@ namespace MvvmCross.Platform.Test
IA a;
var result = Mvx.TryResolve(out a);
Assert.IsTrue(result);
Assert.IsNotNull(a);
Assert.True(result);
Assert.NotNull(a);
}
[Fact]
@ -190,15 +190,15 @@ namespace MvvmCross.Platform.Test
IA a0;
var result = Mvx.TryResolve(out a0);
Assert.IsTrue(result);
Assert.IsNotNull(a0);
Assert.True(result);
Assert.NotNull(a0);
for (int i = 0; i < 100; i++)
{
IA a1;
result = Mvx.TryResolve(out a1);
Assert.IsTrue(result);
Assert.AreSame(a0, a1);
Assert.True(result);
Assert.Equal(a0, a1);
}
}
@ -214,15 +214,15 @@ namespace MvvmCross.Platform.Test
IA a0;
var result = Mvx.TryResolve(out a0);
Assert.IsTrue(result);
Assert.IsNotNull(a0);
Assert.True(result);
Assert.NotNull(a0);
for (int i = 0; i < 100; i++)
{
IA a1;
result = Mvx.TryResolve(out a1);
Assert.IsTrue(result);
Assert.AreSame(a0, a1);
Assert.True(result);
Assert.Equal(a0, a1);
}
}
@ -242,8 +242,8 @@ namespace MvvmCross.Platform.Test
{
IA a1;
var result = Mvx.TryResolve(out a1);
Assert.IsTrue(result);
Assert.IsFalse(previous.ContainsKey(a1));
Assert.True(result);
Assert.False(previous.ContainsKey(a1));
Assert.Equal(i, previous.Count);
previous.Add(a1, true);
}
@ -261,10 +261,10 @@ namespace MvvmCross.Platform.Test
IA a1;
var result = Mvx.TryResolve(out a1);
Assert.IsTrue(result);
Assert.IsNotNull(a1);
Assert.IsNotNull(a1.B);
Assert.IsInstanceOf<B>(a1.B);
Assert.True(result);
Assert.NotNull(a1);
Assert.NotNull(a1.B);
Assert.IsType<B>(a1.B);
}
[Fact]
@ -278,10 +278,10 @@ namespace MvvmCross.Platform.Test
var c1 = Mvx.Resolve<IC>();
var c2 = Mvx.Resolve<IC>();
Assert.IsNotNull(c1);
Assert.IsNotNull(c2);
Assert.NotNull(c1);
Assert.NotNull(c2);
Assert.AreNotEqual(c1, c2);
Assert.NotEqual(c1, c2);
}
[Fact]
@ -295,10 +295,10 @@ namespace MvvmCross.Platform.Test
var c1 = Mvx.Resolve<IC>();
var c2 = Mvx.Resolve<IC>();
Assert.IsNotNull(c1);
Assert.IsNotNull(c2);
Assert.NotNull(c1);
Assert.NotNull(c2);
Assert.AreNotEqual(c1, c2);
Assert.NotEqual(c1, c2);
}
[Fact]
@ -340,9 +340,9 @@ namespace MvvmCross.Platform.Test
IOG<C2> toResolve = null;
Mvx.TryResolve<IOG<C2>>(out toResolve);
Assert.IsNotNull(toResolve);
Assert.IsTrue(toResolve.GetType().GetTypeInfo().ImplementedInterfaces.Any(i => i == typeof(IOG<C2>)));
Assert.IsTrue(toResolve.GetType() == typeof(OG<C2>));
Assert.NotNull(toResolve);
Assert.True(toResolve.GetType().GetTypeInfo().ImplementedInterfaces.Any(i => i == typeof(IOG<C2>)));
Assert.True(toResolve.GetType() == typeof(OG<C2>));
}
[Fact]
@ -356,9 +356,9 @@ namespace MvvmCross.Platform.Test
IOG<C2> toResolve = null;
Mvx.TryResolve<IOG<C2>>(out toResolve);
Assert.IsNotNull(toResolve);
Assert.IsTrue(toResolve.GetType().GetTypeInfo().ImplementedInterfaces.Any(i => i == typeof(IOG<C2>)));
Assert.IsTrue(toResolve.GetType() == typeof(OG<C2>));
Assert.NotNull(toResolve);
Assert.True(toResolve.GetType().GetTypeInfo().ImplementedInterfaces.Any(i => i == typeof(IOG<C2>)));
Assert.True(toResolve.GetType() == typeof(OG<C2>));
}
[Fact]
@ -372,9 +372,9 @@ namespace MvvmCross.Platform.Test
IOG2<C2, C> toResolve = null;
Mvx.TryResolve<IOG2<C2,C>>(out toResolve);
Assert.IsNotNull(toResolve);
Assert.IsTrue(toResolve.GetType().GetTypeInfo().ImplementedInterfaces.Any(i => i == typeof(IOG2<C2, C>)));
Assert.IsTrue(toResolve.GetType() == typeof(OG2<C2, C>));
Assert.NotNull(toResolve);
Assert.True(toResolve.GetType().GetTypeInfo().ImplementedInterfaces.Any(i => i == typeof(IOG2<C2, C>)));
Assert.True(toResolve.GetType() == typeof(OG2<C2, C>));
}
[Fact]
@ -388,9 +388,9 @@ namespace MvvmCross.Platform.Test
IOG2<C2, C> toResolve = null;
Mvx.TryResolve<IOG2<C2, C>>(out toResolve);
Assert.IsNotNull(toResolve);
Assert.IsTrue(toResolve.GetType().GetTypeInfo().ImplementedInterfaces.Any(i => i == typeof(IOG2<C2, C>)));
Assert.IsTrue(toResolve.GetType() == typeof(OG2<C2, C>));
Assert.NotNull(toResolve);
Assert.True(toResolve.GetType().GetTypeInfo().ImplementedInterfaces.Any(i => i == typeof(IOG2<C2, C>)));
Assert.True(toResolve.GetType() == typeof(OG2<C2, C>));
}
[Fact]
@ -403,8 +403,8 @@ namespace MvvmCross.Platform.Test
var isResolved = Mvx.TryResolve<IOG<C2>>(out toResolve);
Assert.IsFalse(isResolved);
Assert.IsNull(toResolve);
Assert.False(isResolved);
Assert.Null(toResolve);
}
[Fact]
@ -419,11 +419,11 @@ namespace MvvmCross.Platform.Test
IHasOGParameter toResolve = null;
Mvx.TryResolve<IHasOGParameter>(out toResolve);
Assert.IsNotNull(toResolve);
Assert.IsTrue(toResolve.GetType().GetTypeInfo().ImplementedInterfaces.Any(i => i == typeof(IHasOGParameter)));
Assert.IsTrue(toResolve.GetType() == typeof(HasOGParameter));
Assert.IsTrue(toResolve.OpenGeneric.GetType().GetTypeInfo().ImplementedInterfaces.Any(i => i == typeof(IOG<C>)));
Assert.IsTrue(toResolve.OpenGeneric.GetType() == typeof(OG<C>));
Assert.NotNull(toResolve);
Assert.True(toResolve.GetType().GetTypeInfo().ImplementedInterfaces.Any(i => i == typeof(IHasOGParameter)));
Assert.True(toResolve.GetType() == typeof(HasOGParameter));
Assert.True(toResolve.OpenGeneric.GetType().GetTypeInfo().ImplementedInterfaces.Any(i => i == typeof(IOG<C>)));
Assert.True(toResolve.OpenGeneric.GetType() == typeof(OG<C>));
}
#endregion
@ -442,17 +442,17 @@ namespace MvvmCross.Platform.Test
var b = childContainer.Create<IB>();
Assert.IsTrue(container.CanResolve<IC>());
Assert.IsFalse(container.CanResolve<IB>());
Assert.IsTrue(childContainer.CanResolve<IC>());
Assert.IsTrue(childContainer.CanResolve<IB>());
Assert.True(container.CanResolve<IC>());
Assert.False(container.CanResolve<IB>());
Assert.True(childContainer.CanResolve<IC>());
Assert.True(childContainer.CanResolve<IB>());
Assert.IsNotNull(b);
Assert.IsNotNull(b.C);
Assert.NotNull(b);
Assert.NotNull(b.C);
}
#endregion
// TODO - there are so many tests we could and should do here!
}
}
}

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

@ -106,7 +106,7 @@ namespace MvvmCross.Platform.Test
public void Test_Reset_Clears_And_Sets_All_Properties()
{
var tokeniser = new Parser();
Assert.IsNull(tokeniser.GetFullText());
Assert.Null(tokeniser.GetFullText());
Assert.Equal(0, tokeniser.GetCurrentIndex());
var testString1 = @"1 test";
tokeniser.CallReset(testString1);
@ -141,7 +141,7 @@ namespace MvvmCross.Platform.Test
tokeniser.CallReset(testString.Key);
var result = tokeniser.CallReadQuotedString();
Assert.Equal(testString.Value, result);
Assert.IsTrue(tokeniser.GetIsComplete());
Assert.True(tokeniser.GetIsComplete());
}
}
@ -162,7 +162,7 @@ namespace MvvmCross.Platform.Test
tokeniser.CallReset(testString.Key);
var result = tokeniser.CallReadUnsignedInteger();
Assert.Equal(testString.Value, result);
Assert.IsTrue(tokeniser.GetIsComplete());
Assert.True(tokeniser.GetIsComplete());
}
}
@ -191,7 +191,7 @@ namespace MvvmCross.Platform.Test
parser.CallReset(input);
var output = parser.CallReadValue();
Assert.Equal(expectedOutput, output);
Assert.IsTrue(parser.GetIsComplete());
Assert.True(parser.GetIsComplete());
}
[Fact]
@ -254,7 +254,7 @@ namespace MvvmCross.Platform.Test
parser.CallReset(input);
var output = parser.CallReadEnumerationValue(enumerationType, true /* ignoreCase */);
Assert.Equal(expectedOutput, output);
Assert.IsTrue(parser.GetIsComplete());
Assert.True(parser.GetIsComplete());
}
[Fact]
@ -291,13 +291,13 @@ namespace MvvmCross.Platform.Test
parser.CallReset(name);
var result = parser.CallReadValidCSharpName();
Assert.Equal(name, result);
Assert.IsTrue(parser.GetIsComplete());
Assert.True(parser.GetIsComplete());
var parser2 = new Parser();
parser2.CallReset("\t " + name + " \r \t");
var result2 = parser2.CallReadValidCSharpName();
Assert.Equal(name, result2);
Assert.IsFalse(parser2.GetIsComplete());
Assert.False(parser2.GetIsComplete());
}
}
@ -325,7 +325,7 @@ namespace MvvmCross.Platform.Test
{
exceptionThrown = true;
}
Assert.IsTrue(exceptionThrown);
Assert.True(exceptionThrown);
}
}
}

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

@ -97,7 +97,7 @@ namespace MvvmCross.Platform.Test
var field = typeof(TestClass).GetField("PublicStaticField", BindingFlags.Public | BindingFlags.Static);
// Assert
Assert.IsNotNull(field);
Assert.NotNull(field);
}
[Fact]
@ -107,7 +107,7 @@ namespace MvvmCross.Platform.Test
var field = typeof(TestClass).GetField("PublicStaticField", BindingFlags.Public | BindingFlags.Instance);
// Assert
Assert.IsNull(field);
Assert.Null(field);
}
[Fact]
@ -117,7 +117,7 @@ namespace MvvmCross.Platform.Test
var field = typeof(TestClass).GetField("PublicInstanceField1", BindingFlags.Public | BindingFlags.Instance);
// Assert
Assert.IsNotNull(field);
Assert.NotNull(field);
}
[Fact]
@ -127,7 +127,7 @@ namespace MvvmCross.Platform.Test
var field = typeof(TestClass).GetField("PublicInstanceField1", BindingFlags.Public | BindingFlags.Static);
// Assert
Assert.IsNull(field);
Assert.Null(field);
}
[Fact]

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

@ -27,10 +27,10 @@ namespace MvvmCross.Platform.Test.UI
for (var i = 0; i < tests.GetUpperBound(0); i++)
{
var c = new MvxColor((int)tests[i, 0]);
Assert.Equal(tests[i, 1], c.A);
Assert.Equal(tests[i, 2], c.R);
Assert.Equal(tests[i, 3], c.G);
Assert.Equal(tests[i, 4], c.B);
Assert.Equal(tests[i, 1], (uint)c.A);
Assert.Equal(tests[i, 2], (uint)c.R);
Assert.Equal(tests[i, 3], (uint)c.G);
Assert.Equal(tests[i, 4], (uint)c.B);
Assert.Equal(tests[i, 0], (uint)c.ARGB);
}
}
@ -54,10 +54,10 @@ namespace MvvmCross.Platform.Test.UI
for (uint alpha = 0; alpha < 256; alpha++)
{
var c = new MvxColor((int)tests[i, 0], (int)alpha);
Assert.Equal(alpha, c.A);
Assert.Equal(tests[i, 1], c.R);
Assert.Equal(tests[i, 2], c.G);
Assert.Equal(tests[i, 3], c.B);
Assert.Equal(alpha, (uint)c.A);
Assert.Equal(tests[i, 1], (uint)c.R);
Assert.Equal(tests[i, 2], (uint)c.G);
Assert.Equal(tests[i, 3], (uint)c.B);
var argb = (tests[i, 0] & 0x00FFFFFF) | ((alpha & 0xFF) << 24);
Assert.Equal(argb, (uint)c.ARGB);
}
@ -81,10 +81,10 @@ namespace MvvmCross.Platform.Test.UI
for (var i = 0; i < tests.GetUpperBound(0); i++)
{
var c = new MvxColor((int)tests[i, 1], (int)tests[i, 2], (int)tests[i, 3], (int)tests[i, 0]);
Assert.Equal(tests[i, 0], c.A);
Assert.Equal(tests[i, 1], c.R);
Assert.Equal(tests[i, 2], c.G);
Assert.Equal(tests[i, 3], c.B);
Assert.Equal(tests[i, 0], (uint)c.A);
Assert.Equal(tests[i, 1], (uint)c.R);
Assert.Equal(tests[i, 2], (uint)c.G);
Assert.Equal(tests[i, 3], (uint)c.B);
var argb = tests[i, 0] & 0xFF;
argb <<= 8;
argb |= tests[i, 1] & 0xFF;
@ -118,9 +118,9 @@ namespace MvvmCross.Platform.Test.UI
c.A = j;
Assert.Equal(j, c.A);
Assert.Equal(tests[i, 1], c.R);
Assert.Equal(tests[i, 2], c.G);
Assert.Equal(tests[i, 3], c.B);
Assert.Equal(tests[i, 1], (uint)c.R);
Assert.Equal(tests[i, 2], (uint)c.G);
Assert.Equal(tests[i, 3], (uint)c.B);
var argb = (uint)j & 0xFF;
argb <<= 8;
argb |= tests[i, 1] & 0xFF;
@ -154,10 +154,10 @@ namespace MvvmCross.Platform.Test.UI
{
c.R = j;
Assert.Equal(tests[i, 0], c.A);
Assert.Equal(tests[i, 0], (uint)c.A);
Assert.Equal(j, c.R);
Assert.Equal(tests[i, 2], c.G);
Assert.Equal(tests[i, 3], c.B);
Assert.Equal(tests[i, 2], (uint)c.G);
Assert.Equal(tests[i, 3], (uint)c.B);
var argb = tests[i, 0] & 0xFF;
argb <<= 8;
argb |= (uint)j & 0xFF;
@ -191,10 +191,10 @@ namespace MvvmCross.Platform.Test.UI
{
c.G = j;
Assert.Equal(tests[i, 0], c.A);
Assert.Equal(tests[i, 1], c.R);
Assert.Equal(tests[i, 0], (uint)c.A);
Assert.Equal(tests[i, 1], (uint)c.R);
Assert.Equal(j, c.G);
Assert.Equal(tests[i, 3], c.B);
Assert.Equal(tests[i, 3], (uint)c.B);
var argb = tests[i, 0] & 0xFF;
argb <<= 8;
argb |= tests[i, 1] & 0xFF;
@ -228,9 +228,9 @@ namespace MvvmCross.Platform.Test.UI
{
c.B = j;
Assert.Equal(tests[i, 0], c.A);
Assert.Equal(tests[i, 1], c.R);
Assert.Equal(tests[i, 2], c.G);
Assert.Equal(tests[i, 0], (uint)c.A);
Assert.Equal(tests[i, 1], (uint)c.R);
Assert.Equal(tests[i, 2], (uint)c.G);
Assert.Equal(j, c.B);
var argb = tests[i, 0] & 0xFF;
argb <<= 8;
@ -244,4 +244,4 @@ namespace MvvmCross.Platform.Test.UI
}
}
}
}
}

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

@ -14,14 +14,21 @@ using MvvmCross.Binding.Bindings.SourceSteps;
using MvvmCross.Binding.Combiners;
using MvvmCross.Binding.Parse.PropertyPath;
using MvvmCross.Platform.Converters;
using MvvmCross.Test.Core;
using MvvmCross.Test;
using Xunit;
namespace MvvmCross.Binding.Test.Binders
{
public class MvxSourceStepTests : MvxIoCSupportingTest
[Collection("MvxTest")]
public class MvxSourceStepTests : IClassFixture<MvxTestFixture>
{
private readonly MvxTestFixture _fixture;
public MvxSourceStepTests(MvxTestFixture fixture)
{
_fixture = fixture;
}
public class BaseSource : INotifyPropertyChanged
{
public int SubscriptionCount { get; private set; }
@ -186,12 +193,6 @@ namespace MvvmCross.Binding.Test.Binders
}
}
[OneTimeSetUp]
public void FixtureSetUp()
{
SetInvariantCulture();
}
private IMvxSourceStep SetupSimpleBindingTest(BaseSource source, string sourceProperty)
{
var realSourceStepFactory = SetupSourceStepFactory();
@ -208,17 +209,17 @@ namespace MvvmCross.Binding.Test.Binders
private MvxSourceStepFactory SetupSourceStepFactory()
{
ClearAll();
MvxBindingSingletonCache.Initialize();
_fixture.Reset();
_fixture.InitializeSingletonCache();
var autoValueConverters = new MvxAutoValueConverters();
Ioc.RegisterSingleton<IMvxAutoValueConverters>(autoValueConverters);
_fixture.Ioc.RegisterSingleton<IMvxAutoValueConverters>(autoValueConverters);
var sourcePropertyParser = new MvxSourcePropertyPathParser();
Ioc.RegisterSingleton<IMvxSourcePropertyPathParser>(sourcePropertyParser);
_fixture.Ioc.RegisterSingleton<IMvxSourcePropertyPathParser>(sourcePropertyParser);
var realSourceBindingFactory = new MvxSourceBindingFactory();
Ioc.RegisterSingleton<IMvxSourceBindingFactory>(realSourceBindingFactory);
_fixture.Ioc.RegisterSingleton<IMvxSourceBindingFactory>(realSourceBindingFactory);
var sourceStepFactory = new MvxSourceStepFactory();
sourceStepFactory.AddOrOverwrite(typeof(MvxPathSourceStepDescription), new MvxPathSourceStepFactory());
@ -226,7 +227,7 @@ namespace MvvmCross.Binding.Test.Binders
new MvxLiteralSourceStepFactory());
sourceStepFactory.AddOrOverwrite(typeof(MvxCombinerSourceStepDescription),
new MvxCombinerSourceStepFactory());
Ioc.RegisterSingleton<IMvxSourceStepFactory>(sourceStepFactory);
_fixture.Ioc.RegisterSingleton<IMvxSourceStepFactory>(sourceStepFactory);
var propertySource = new MvxPropertySourceBindingFactoryExtension();
realSourceBindingFactory.Extensions.Add(propertySource);
@ -559,7 +560,7 @@ namespace MvvmCross.Binding.Test.Binders
sourceStep.DataContext = new MySource();
value = sourceStep.GetValue();
Assert.Equal(null, value);
Assert.Null(value);
source.Property1 = "Changed again 19";
@ -815,4 +816,4 @@ namespace MvvmCross.Binding.Test.Binders
Assert.Equal(MvxBindingConstant.UnsetValue, value);
}
}
}
}

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

@ -12,15 +12,22 @@ using MvvmCross.Binding.Bindings.Target;
using MvvmCross.Binding.Bindings.Target.Construction;
using MvvmCross.Platform.Converters;
using MvvmCross.Platform.Core;
using MvvmCross.Test.Core;
using MvvmCross.Test;
using MvvmCross.Test.Mocks.Dispatchers;
using Xunit;
namespace MvvmCross.Binding.Test.Bindings
{
public class MvxFullBindingConstructionTest : MvxIoCSupportingTest
[Collection("MvxTest")]
public class MvxFullBindingConstructionTest : IClassFixture<MvxTestFixture>
{
private readonly MvxTestFixture _fixture;
public MvxFullBindingConstructionTest(MvxTestFixture fixture)
{
_fixture = fixture;
}
public class MyBinding : MvxFullBinding
{
public MyBinding(MvxBindingRequest bindingRequest)
@ -73,19 +80,19 @@ namespace MvvmCross.Binding.Test.Bindings
private void TestCommon(MvxBindingMode bindingMode, bool expectSourceBinding, bool expectTargetBinding)
{
ClearAll();
MvxBindingSingletonCache.Initialize();
Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(new InlineMockMainThreadDispatcher());
_fixture.InitializeSingletonCache();
_fixture.Reset();
_fixture.Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(new InlineMockMainThreadDispatcher());
var mockSourceBindingFactory = new Mock<IMvxSourceBindingFactory>();
Ioc.RegisterSingleton(mockSourceBindingFactory.Object);
_fixture.Ioc.RegisterSingleton(mockSourceBindingFactory.Object);
var mockTargetBindingFactory = new Mock<IMvxTargetBindingFactory>();
Ioc.RegisterSingleton(mockTargetBindingFactory.Object);
_fixture.Ioc.RegisterSingleton(mockTargetBindingFactory.Object);
var realSourceStepFactory = new MvxSourceStepFactory();
realSourceStepFactory.AddOrOverwrite(typeof(MvxPathSourceStepDescription), new MvxPathSourceStepFactory());
Ioc.RegisterSingleton<IMvxSourceStepFactory>(realSourceStepFactory);
_fixture.Ioc.RegisterSingleton<IMvxSourceStepFactory>(realSourceStepFactory);
var sourceText = "sourceText";
var targetName = "targetName";
@ -134,4 +141,4 @@ namespace MvvmCross.Binding.Test.Bindings
Times.Once());
}
}
}
}

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

@ -10,15 +10,22 @@ using MvvmCross.Binding.Bindings.Target;
using MvvmCross.Binding.Bindings.Target.Construction;
using MvvmCross.Binding.Test.Mocks;
using MvvmCross.Platform.Core;
using MvvmCross.Test.Core;
using MvvmCross.Test;
using MvvmCross.Test.Mocks.Dispatchers;
using Xunit;
namespace MvvmCross.Binding.Test.Bindings
{
public class MvxFullBindingTest : MvxIoCSupportingTest
[Collection("MvxTest")]
public class MvxFullBindingTest : IClassFixture<MvxTestFixture>
{
private readonly MvxTestFixture _fixture;
public MvxFullBindingTest(MvxTestFixture fixture)
{
_fixture = fixture;
}
[Fact]
public void TestTwoWayEventSubscription()
{
@ -320,19 +327,18 @@ namespace MvvmCross.Binding.Test.Bindings
private MvxFullBinding TestSetupCommon(MvxBindingMode mvxBindingMode, MvxBindingMode defaultMode,
out MockSourceBinding mockSource, out MockTargetBinding mockTarget)
{
ClearAll();
MvxBindingSingletonCache.Initialize();
Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(new InlineMockMainThreadDispatcher());
_fixture.ClearAll();
_fixture.Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(new InlineMockMainThreadDispatcher());
var mockSourceBindingFactory = new Mock<IMvxSourceBindingFactory>();
Ioc.RegisterSingleton(mockSourceBindingFactory.Object);
_fixture.Ioc.RegisterSingleton(mockSourceBindingFactory.Object);
var mockTargetBindingFactory = new Mock<IMvxTargetBindingFactory>();
Ioc.RegisterSingleton(mockTargetBindingFactory.Object);
_fixture.Ioc.RegisterSingleton(mockTargetBindingFactory.Object);
var realSourceStepFactory = new MvxSourceStepFactory();
realSourceStepFactory.AddOrOverwrite(typeof(MvxPathSourceStepDescription), new MvxPathSourceStepFactory());
Ioc.RegisterSingleton<IMvxSourceStepFactory>(realSourceStepFactory);
_fixture.Ioc.RegisterSingleton<IMvxSourceStepFactory>(realSourceStepFactory);
var sourceText = "sourceText";
var targetName = "targetName";
@ -373,4 +379,4 @@ namespace MvvmCross.Binding.Test.Bindings
return toTest;
}
}
}
}

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

@ -14,16 +14,23 @@ using MvvmCross.Binding.Bindings.Target.Construction;
using MvvmCross.Binding.Test.Mocks;
using MvvmCross.Platform.Converters;
using MvvmCross.Platform.Core;
using MvvmCross.Test.Core;
using MvvmCross.Test;
using MvvmCross.Test.Mocks.Dispatchers;
using Xunit;
namespace MvvmCross.Binding.Test.Bindings
{
public class MvxFullBindingValueConversionTest : MvxIoCSupportingTest
[Collection("MvxTest")]
public class MvxFullBindingValueConversionTest : IClassFixture<MvxTestFixture>
{
[Fact]
private readonly MvxTestFixture _fixture;
public MvxFullBindingValueConversionTest(MvxTestFixture fixture)
{
_fixture = fixture;
}
[Fact]
public void TestConverterIsUsedForConvert()
{
MockSourceBinding mockSource;
@ -206,7 +213,7 @@ namespace MvvmCross.Binding.Test.Bindings
Assert.Equal(0, mockValueConverter.ConversionsBackRequested.Count);
Assert.Equal(1, mockTarget.Values.Count);
Assert.Equal(null, mockTarget.Values[0]);
Assert.Null(mockTarget.Values[0]);
mockSource.TryGetValueValue = "Fred";
mockSource.FireSourceChanged();
@ -215,7 +222,7 @@ namespace MvvmCross.Binding.Test.Bindings
Assert.Equal(0, mockValueConverter.ConversionsBackRequested.Count);
Assert.Equal(2, mockTarget.Values.Count);
Assert.Equal(null, mockTarget.Values[1]);
Assert.Null(mockTarget.Values[1]);
mockSource.TryGetValueValue = "Betty";
mockSource.FireSourceChanged();
@ -224,7 +231,7 @@ namespace MvvmCross.Binding.Test.Bindings
Assert.Equal(0, mockValueConverter.ConversionsBackRequested.Count);
Assert.Equal(3, mockTarget.Values.Count);
Assert.Equal(null, mockTarget.Values[2]);
Assert.Null(mockTarget.Values[2]);
}
[Fact]
@ -282,7 +289,7 @@ namespace MvvmCross.Binding.Test.Bindings
Assert.Equal(0, mockValueConverter.ConversionsBackRequested.Count);
Assert.Equal(1, mockTarget.Values.Count);
Assert.Equal(null, mockTarget.Values[0]);
Assert.Null(mockTarget.Values[0]);
mockSource.TryGetValueValue = "Fred";
mockSource.FireSourceChanged();
@ -291,7 +298,7 @@ namespace MvvmCross.Binding.Test.Bindings
Assert.Equal(0, mockValueConverter.ConversionsBackRequested.Count);
Assert.Equal(2, mockTarget.Values.Count);
Assert.Equal(null, mockTarget.Values[1]);
Assert.Null(mockTarget.Values[1]);
mockSource.TryGetValueValue = "Betty";
mockSource.FireSourceChanged();
@ -300,7 +307,7 @@ namespace MvvmCross.Binding.Test.Bindings
Assert.Equal(0, mockValueConverter.ConversionsBackRequested.Count);
Assert.Equal(3, mockTarget.Values.Count);
Assert.Equal(null, mockTarget.Values[2]);
Assert.Null(mockTarget.Values[2]);
}
[Fact]
@ -329,7 +336,7 @@ namespace MvvmCross.Binding.Test.Bindings
Assert.Equal(0, mockValueConverter.ConversionsBackRequested.Count);
Assert.Equal(2, mockTarget.Values.Count);
Assert.Equal(null, mockTarget.Values[1]);
Assert.Null(mockTarget.Values[1]);
mockSource.TryGetValueResult = false;
mockSource.FireSourceChanged();
@ -338,7 +345,7 @@ namespace MvvmCross.Binding.Test.Bindings
Assert.Equal(0, mockValueConverter.ConversionsBackRequested.Count);
Assert.Equal(3, mockTarget.Values.Count);
Assert.Equal(null, mockTarget.Values[2]);
Assert.Null(mockTarget.Values[2]);
mockSource.TryGetValueValue = "Fred";
mockSource.TryGetValueResult = true;
@ -424,7 +431,7 @@ namespace MvvmCross.Binding.Test.Bindings
Assert.Equal(0, mockValueConverter.ConversionsBackRequested.Count);
Assert.Equal(2, mockTarget.Values.Count);
Assert.Equal(null, mockTarget.Values[1]);
Assert.Null(mockTarget.Values[1]);
mockSource.TryGetValueResult = false;
mockSource.FireSourceChanged();
@ -433,7 +440,7 @@ namespace MvvmCross.Binding.Test.Bindings
Assert.Equal(0, mockValueConverter.ConversionsBackRequested.Count);
Assert.Equal(3, mockTarget.Values.Count);
Assert.Equal(null, mockTarget.Values[2]);
Assert.Null(mockTarget.Values[2]);
mockSource.TryGetValueResult = false;
mockSource.FireSourceChanged();
@ -442,7 +449,7 @@ namespace MvvmCross.Binding.Test.Bindings
Assert.Equal(0, mockValueConverter.ConversionsBackRequested.Count);
Assert.Equal(4, mockTarget.Values.Count);
Assert.Equal(null, mockTarget.Values[3]);
Assert.Null(mockTarget.Values[3]);
}
private MvxFullBinding TestSetupCommon(IMvxValueConverter valueConverter, object converterParameter,
@ -454,19 +461,18 @@ namespace MvvmCross.Binding.Test.Bindings
private MvxFullBinding TestSetupCommon(IMvxValueConverter valueConverter, object converterParameter, object fallbackValue,
Type targetType, out MockSourceBinding mockSource, out MockTargetBinding mockTarget)
{
ClearAll();
MvxBindingSingletonCache.Initialize();
Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(new InlineMockMainThreadDispatcher());
_fixture.ClearAll();
_fixture.Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(new InlineMockMainThreadDispatcher());
var mockSourceBindingFactory = new Mock<IMvxSourceBindingFactory>();
Ioc.RegisterSingleton(mockSourceBindingFactory.Object);
_fixture.Ioc.RegisterSingleton(mockSourceBindingFactory.Object);
var mockTargetBindingFactory = new Mock<IMvxTargetBindingFactory>();
Ioc.RegisterSingleton(mockTargetBindingFactory.Object);
_fixture.Ioc.RegisterSingleton(mockTargetBindingFactory.Object);
var realSourceStepFactory = new MvxSourceStepFactory();
realSourceStepFactory.AddOrOverwrite(typeof(MvxPathSourceStepDescription), new MvxPathSourceStepFactory());
Ioc.RegisterSingleton<IMvxSourceStepFactory>(realSourceStepFactory);
_fixture.Ioc.RegisterSingleton<IMvxSourceStepFactory>(realSourceStepFactory);
var sourceText = "sourceText";
var targetName = "targetName";
@ -506,4 +512,4 @@ namespace MvvmCross.Binding.Test.Bindings
return toTest;
}
}
}
}

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

@ -13,14 +13,21 @@ using MvvmCross.Binding.Bindings;
using MvvmCross.Binding.Bindings.SourceSteps;
using MvvmCross.Binding.ExpressionParse;
using MvvmCross.Platform.Converters;
using MvvmCross.Test.Core;
using MvvmCross.Test;
using Xunit;
namespace MvvmCross.Binding.Test.ExpressionParse
{
public class MvxExpressionBindingTest : MvxIoCSupportingTest
[Collection("MvxTest")]
public class MvxExpressionBindingTest : IClassFixture<MvxTestFixture>
{
private readonly MvxTestFixture _fixture;
public MvxExpressionBindingTest(MvxTestFixture fixture)
{
_fixture = fixture;
}
public class Child
{
public string Value { get; set; }
@ -407,8 +414,7 @@ namespace MvvmCross.Binding.Test.ExpressionParse
Func<MockBindingContext, object> findTargetObjectFunc,
MvxBindingDescription expectedDescription)
{
ClearAll();
MvxBindingSingletonCache.Initialize();
_fixture.ClearAll();
var dataContext = new TestDataContext();
@ -433,13 +439,13 @@ namespace MvvmCross.Binding.Test.ExpressionParse
BindingDescription = descriptions.First()
});
});
Ioc.RegisterSingleton(binder.Object);
_fixture.Ioc.RegisterSingleton(binder.Object);
Ioc.RegisterSingleton<IMvxPropertyExpressionParser>(new MvxPropertyExpressionParser());
_fixture.Ioc.RegisterSingleton<IMvxPropertyExpressionParser>(new MvxPropertyExpressionParser());
var converterLookup = new MvxValueConverterRegistry();
converterLookup.AddOrOverwrite("SampleConv", new SampleValueConverter());
Ioc.RegisterSingleton<IMvxValueConverterLookup>(converterLookup);
_fixture.Ioc.RegisterSingleton<IMvxValueConverterLookup>(converterLookup);
var testTarget = new MockBindingContext
{
@ -456,9 +462,9 @@ namespace MvvmCross.Binding.Test.ExpressionParse
Assert.Equal(dataContext, callback.Source);
var desc = callback.BindingDescription;
Assert.IsTrue(expectedDescription.Source is MvxPathSourceStepDescription);
Assert.True(expectedDescription.Source is MvxPathSourceStepDescription);
var path = desc.Source as MvxPathSourceStepDescription;
Assert.IsTrue(desc.Source is MvxPathSourceStepDescription);
Assert.True(desc.Source is MvxPathSourceStepDescription);
var expectedPath = expectedDescription.Source as MvxPathSourceStepDescription;
Assert.Equal(expectedPath.ConverterParameter, path.ConverterParameter);
Assert.Equal(expectedPath.FallbackValue, path.FallbackValue);
@ -466,9 +472,9 @@ namespace MvvmCross.Binding.Test.ExpressionParse
Assert.Equal(expectedDescription.Mode, desc.Mode);
Assert.Equal(expectedDescription.TargetName, desc.TargetName);
if (expectedPath.Converter == null)
Assert.IsNull(path.Converter);
Assert.Null(path.Converter);
else
Assert.Equal(expectedPath.Converter.GetType(), path.Converter.GetType());
}
}
}
}

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

@ -7,14 +7,21 @@ using MvvmCross.Binding.Binders;
using MvvmCross.Binding.ExtensionMethods;
using MvvmCross.Platform;
using MvvmCross.Platform.Converters;
using MvvmCross.Test.Core;
using MvvmCross.Test;
using Xunit;
namespace MvvmCross.Binding.Test.ExtensionMethods
{
public class MakeSafeValueTest : MvxIoCSupportingTest
public class MakeSafeValueTest : IClassFixture<MvxTestFixture>
{
private readonly MvxTestFixture _fixture;
public MakeSafeValueTest(MvxTestFixture fixture)
{
_fixture = fixture;
}
public class MockAutoValueConverters : IMvxAutoValueConverters
{
public IMvxValueConverter Find(Type viewModelType, Type viewType)
@ -31,15 +38,14 @@ namespace MvvmCross.Binding.Test.ExtensionMethods
[Fact]
public void TestIntValues()
{
ClearAll();
MvxBindingSingletonCache.Initialize();
_fixture.ClearAll();
Mvx.RegisterSingleton<IMvxAutoValueConverters>(new MockAutoValueConverters());
Assert.Equal(0, typeof(int).MakeSafeValue(0));
Assert.Equal(0, typeof(int).MakeSafeValue(null));
Assert.Equal(1, typeof(int).MakeSafeValue(1));
Assert.Equal(0, typeof(int?).MakeSafeValue(0));
Assert.Equal(null, typeof(int?).MakeSafeValue(null));
Assert.Null(typeof(int?).MakeSafeValue(null));
Assert.Equal(1, typeof(int?).MakeSafeValue(1));
Assert.Equal(0, typeof(int?).MakeSafeValue(0.0));
Assert.Equal(1, typeof(int?).MakeSafeValue(1.0));
@ -48,15 +54,14 @@ namespace MvvmCross.Binding.Test.ExtensionMethods
[Fact]
public void TestDoubleValues()
{
ClearAll();
MvxBindingSingletonCache.Initialize();
_fixture.ClearAll();
Mvx.RegisterSingleton<IMvxAutoValueConverters>(new MockAutoValueConverters());
Assert.Equal(0.0, typeof(double).MakeSafeValue(0.0));
Assert.Equal(0.0, typeof(double).MakeSafeValue(null));
Assert.Equal(1.0, typeof(double).MakeSafeValue(1.0));
Assert.Equal(0.0, typeof(double?).MakeSafeValue(0.0));
Assert.Equal(null, typeof(double?).MakeSafeValue(null));
Assert.Null(typeof(double?).MakeSafeValue(null));
Assert.Equal(1.0, typeof(double?).MakeSafeValue(1.0));
Assert.Equal(1.0, typeof(double).MakeSafeValue(1));
Assert.Equal(0.0, typeof(double?).MakeSafeValue(0));
@ -65,15 +70,14 @@ namespace MvvmCross.Binding.Test.ExtensionMethods
[Fact]
public void TestFloatValues()
{
ClearAll();
MvxBindingSingletonCache.Initialize();
_fixture.ClearAll();
Mvx.RegisterSingleton<IMvxAutoValueConverters>(new MockAutoValueConverters());
Assert.Equal(0.0f, typeof(double).MakeSafeValue(0.0f));
Assert.Equal(0.0f, typeof(double).MakeSafeValue(null));
Assert.Equal(1.0f, typeof(double).MakeSafeValue(1.0f));
Assert.Equal(0.0f, typeof(double?).MakeSafeValue(0.0f));
Assert.Equal(null, typeof(double?).MakeSafeValue(null));
Assert.Null(typeof(double?).MakeSafeValue(null));
Assert.Equal(1.0f, typeof(double?).MakeSafeValue(1.0f));
Assert.Equal(1.0f, typeof(double).MakeSafeValue(1f));
Assert.Equal(0.0f, typeof(double?).MakeSafeValue(0f));
@ -90,12 +94,11 @@ namespace MvvmCross.Binding.Test.ExtensionMethods
[Fact]
public void TestStringValues()
{
ClearAll();
MvxBindingSingletonCache.Initialize();
_fixture.ClearAll();
Mvx.RegisterSingleton<IMvxAutoValueConverters>(new MockAutoValueConverters());
Assert.Equal("0", typeof(string).MakeSafeValue(0.0));
Assert.Equal(null, typeof(string).MakeSafeValue(null));
Assert.Null(typeof(string).MakeSafeValue(null));
Assert.Equal("1", typeof(string).MakeSafeValue(1.0));
Assert.Equal("Hello", typeof(string).MakeSafeValue("Hello"));
Assert.Equal("Hello", typeof(string).MakeSafeValue(new MyTest()));
@ -111,8 +114,7 @@ namespace MvvmCross.Binding.Test.ExtensionMethods
[Fact]
public void TestEnumValues()
{
ClearAll();
MvxBindingSingletonCache.Initialize();
_fixture.ClearAll();
Mvx.RegisterSingleton<IMvxAutoValueConverters>(new MockAutoValueConverters());
Assert.Equal(SampleEnum.Defaulto, typeof(SampleEnum).MakeSafeValue(0));
@ -125,25 +127,25 @@ namespace MvvmCross.Binding.Test.ExtensionMethods
[Fact]
public void TestBoolValues()
{
ClearAll();
MvxBindingSingletonCache.Initialize();
_fixture.Reset();
_fixture.InitializeSingletonCache();
Mvx.RegisterSingleton<IMvxAutoValueConverters>(new MockAutoValueConverters());
Assert.Equal(false, typeof(bool).MakeSafeValue(0));
Assert.Equal(false, typeof(bool).MakeSafeValue(null));
Assert.Equal(true, typeof(bool).MakeSafeValue(1));
Assert.Equal(true, typeof(bool).MakeSafeValue(-1.0));
Assert.Equal(true, typeof(bool).MakeSafeValue(1.0));
Assert.Equal(true, typeof(bool).MakeSafeValue("Dos"));
Assert.Equal(true, typeof(bool).MakeSafeValue("dOs"));
Assert.False((bool)typeof(bool).MakeSafeValue(0));
Assert.False((bool)typeof(bool).MakeSafeValue(null));
Assert.True((bool)typeof(bool).MakeSafeValue(1));
Assert.True((bool)typeof(bool).MakeSafeValue(-1.0));
Assert.True((bool)typeof(bool).MakeSafeValue(1.0));
Assert.True((bool)typeof(bool).MakeSafeValue("Dos"));
Assert.True((bool)typeof(bool).MakeSafeValue("dOs"));
Assert.Equal(false, typeof(bool?).MakeSafeValue(0));
Assert.Equal(null, typeof(bool?).MakeSafeValue(null));
Assert.Equal(true, typeof(bool?).MakeSafeValue(1));
Assert.Equal(true, typeof(bool?).MakeSafeValue(-1.0));
Assert.Equal(true, typeof(bool?).MakeSafeValue(1.0));
Assert.Equal(true, typeof(bool?).MakeSafeValue("Dos"));
Assert.Equal(true, typeof(bool?).MakeSafeValue("dOs"));
Assert.False((bool?)typeof(bool?).MakeSafeValue(0));
Assert.Null((bool?)typeof(bool?).MakeSafeValue(null));
Assert.True((bool?)typeof(bool?).MakeSafeValue(1));
Assert.True((bool?)typeof(bool?).MakeSafeValue(-1.0));
Assert.True((bool?)typeof(bool?).MakeSafeValue(1.0));
Assert.True((bool?)typeof(bool?).MakeSafeValue("Dos"));
Assert.True((bool?)typeof(bool?).MakeSafeValue("dOs"));
}
public class FooBase
@ -157,16 +159,15 @@ namespace MvvmCross.Binding.Test.ExtensionMethods
[Fact]
public void TestObjectValues()
{
ClearAll();
MvxBindingSingletonCache.Initialize();
_fixture.ClearAll();
Mvx.RegisterSingleton<IMvxAutoValueConverters>(new MockAutoValueConverters());
var foo = new Foo();
Assert.AreSame(foo, typeof(FooBase).MakeSafeValue(foo));
Assert.Equal(foo, typeof(FooBase).MakeSafeValue(foo));
var fooBase = new FooBase();
Assert.AreSame(fooBase, typeof(FooBase).MakeSafeValue(fooBase));
Assert.Equal(fooBase, typeof(FooBase).MakeSafeValue(fooBase));
fooBase = null;
Assert.IsNull(typeof(FooBase).MakeSafeValue(null));
Assert.Null(typeof(FooBase).MakeSafeValue(null));
}
}
}
}

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

@ -28,7 +28,7 @@ namespace MvvmCross.Binding.Test.Parse.Binding.Lang
var language = new MvxLanguageBindingParser();
MvxSerializableBindingSpecification result;
var parsed = language.TryParseBindingSpecification(testPair.Key, out result);
Assert.IsTrue(parsed, "Failed to parse " + testPair.Key);
Assert.True(parsed, "Failed to parse " + testPair.Key);
Assert.Equal(1, result.Count);
var keyAndDescription = testPair.Value.First();
var resultKeyAndDescription = result.First();

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

@ -2,22 +2,26 @@
// The .NET Foundation licenses this file to you under the MS-PL license.
// See the LICENSE file in the project root for more information.
using MvvmCross.Binding.Parse.Binding;
using MvvmCross.Test.Core;
using MvvmCross.Binding.Parse.Binding;
using MvvmCross.Test;
using Xunit;
namespace MvvmCross.Binding.Test.Parse.Binding
{
public abstract class MvxBindingTest
: MvxIoCSupportingTest
[Collection("MvxTest")]
public abstract class MvxBindingTest : IClassFixture<MvxTestFixture>
{
public MvxBindingTest(MvxTestFixture fixture)
{
}
protected void AssertAreEquivalent(MvxSerializableBindingSpecification expected,
MvxSerializableBindingSpecification actual)
{
Assert.Equal(expected.Count, actual.Count);
foreach (var kvp in expected)
{
Assert.IsTrue(actual.ContainsKey(kvp.Key));
Assert.True(actual.ContainsKey(kvp.Key));
AssertAreEquivalent(kvp.Value, actual[kvp.Key]);
}
}
@ -33,7 +37,7 @@ namespace MvvmCross.Binding.Test.Parse.Binding
Assert.Equal(expected.Function, actual.Function);
Assert.Equal(expected.Literal, actual.Literal);
if (expected.Sources == null)
Assert.IsNull(actual.Sources);
Assert.Null(actual.Sources);
else
{
Assert.Equal(expected.Sources.Count, actual.Sources.Count);
@ -42,4 +46,4 @@ namespace MvvmCross.Binding.Test.Parse.Binding
}
}
}
}
}

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

@ -405,7 +405,7 @@ namespace MvvmCross.Binding.Test.Parse.Binding.Swiss
var result = theParser.TryParseBindingSpecification(text, out specification);
if (!result)
Debug.WriteLine("Failed on: " + text);
Assert.IsTrue(result);
Assert.True(result);
AssertAreEquivalent(expectedLookup, specification);
}
}

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

@ -19,7 +19,7 @@ namespace MvvmCross.Binding.Test.Parse.PropertyPath
{
var result = Tokenise(test);
Assert.Equal(1, result.Count);
Assert.IsInstanceOf<MvxEmptyPropertyToken>(result[0]);
Assert.IsType<MvxEmptyPropertyToken>(result[0]);
}
}
@ -28,7 +28,7 @@ namespace MvvmCross.Binding.Test.Parse.PropertyPath
{
var result = Tokenise(" \t\r \n ");
Assert.Equal(1, result.Count);
Assert.IsInstanceOf<MvxEmptyPropertyToken>(result[0]);
Assert.IsType<MvxEmptyPropertyToken>(result[0]);
}
[Fact]
@ -175,14 +175,14 @@ namespace MvvmCross.Binding.Test.Parse.PropertyPath
private static void AssertIsSimplePropertyToken(MvxPropertyToken token, string text)
{
Assert.IsInstanceOf<MvxPropertyNamePropertyToken>(token);
Assert.IsType<MvxPropertyNamePropertyToken>(token);
Assert.Equal(text, ((MvxPropertyNamePropertyToken)token).PropertyName);
}
private static void AssertIsIndexerPropertyToken<T, TSpecific>(MvxPropertyToken token, T value)
{
Assert.IsInstanceOf<MvxIndexerPropertyToken<T>>(token);
Assert.IsInstanceOf<TSpecific>(token);
Assert.IsType<MvxIndexerPropertyToken<T>>(token);
Assert.IsType<TSpecific>(token);
Assert.Equal(value, ((MvxIndexerPropertyToken<T>)token).Key);
}
@ -192,4 +192,4 @@ namespace MvvmCross.Binding.Test.Parse.PropertyPath
return tokeniser.Parse(text);
}
}
}
}

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

@ -0,0 +1,13 @@
using MvvmCross.Test;
using Xunit;
namespace MvvmCross.Plugins.Color.Test
{
[CollectionDefinition("MvxTest")]
public class MvxTestCollection : ICollectionFixture<MvxTestFixture>
{
// This class has no code, and is never created. Its purpose is simply
// to be the place to apply [CollectionDefinition] and all the
// ICollectionFixture<> interfaces.
}
}

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

@ -7,10 +7,9 @@ using Xunit;
namespace MvvmCross.Test.Navigation
{
public class NavigationCacheTests
{
[Fact]
[Theory]
[InlineData("a", 1, 1)]
[InlineData("a", -1, -1)]
[InlineData("a", int.MaxValue, int.MaxValue)]
@ -22,7 +21,7 @@ namespace MvvmCross.Test.Navigation
SimpleTest(new MvxNavigationCache(), key, value, expected);
}
[Fact]
[Theory]
[InlineData("a", 1.0, 1.0)]
[InlineData("a", -1.0, -1.0)]
[InlineData("a", double.MaxValue, double.MaxValue)]
@ -34,7 +33,7 @@ namespace MvvmCross.Test.Navigation
SimpleTest(new MvxNavigationCache(), key, value, expected);
}
[Fact]
[Theory]
[InlineData("a", "a", "a")]
[InlineData("a", "", "")]
[InlineData("a", null, null)]
@ -45,7 +44,7 @@ namespace MvvmCross.Test.Navigation
private static void SimpleTest<T>(IMvxNavigationCache cache, string key, T value, T expected)
{
Assert.IsTrue(cache.AddValue(key, value));
Assert.True(cache.AddValue(key, value));
var addedValue = cache.GetValueOrDefault<T>(key);
Assert.Equal(expected, addedValue);
}
@ -72,17 +71,17 @@ namespace MvvmCross.Test.Navigation
cache.AddValue("c", 0);
cache.AddValue("d", 0);
Assert.IsTrue(cache.Contains("a"));
Assert.IsTrue(cache.Contains("b"));
Assert.IsTrue(cache.Contains("c"));
Assert.IsTrue(cache.Contains("d"));
Assert.True(cache.Contains("a"));
Assert.True(cache.Contains("b"));
Assert.True(cache.Contains("c"));
Assert.True(cache.Contains("d"));
cache.Clear();
Assert.IsFalse(cache.Contains("a"));
Assert.IsFalse(cache.Contains("b"));
Assert.IsFalse(cache.Contains("c"));
Assert.IsFalse(cache.Contains("d"));
Assert.False(cache.Contains("a"));
Assert.False(cache.Contains("b"));
Assert.False(cache.Contains("c"));
Assert.False(cache.Contains("d"));
}
[Fact]
@ -94,17 +93,17 @@ namespace MvvmCross.Test.Navigation
cache.AddValue("g", 0);
cache.AddValue("h", 0);
Assert.IsTrue(cache.Contains("e"));
Assert.IsTrue(cache.Contains("f"));
Assert.IsTrue(cache.Contains("g"));
Assert.IsTrue(cache.Contains("h"));
Assert.True(cache.Contains("e"));
Assert.True(cache.Contains("f"));
Assert.True(cache.Contains("g"));
Assert.True(cache.Contains("h"));
cache.Remove("g");
Assert.IsFalse(cache.Contains("g"));
Assert.IsTrue(cache.Contains("e"));
Assert.IsTrue(cache.Contains("f"));
Assert.IsTrue(cache.Contains("h"));
Assert.False(cache.Contains("g"));
Assert.True(cache.Contains("e"));
Assert.True(cache.Contains("f"));
Assert.True(cache.Contains("h"));
}
public class TestObject

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

@ -2,40 +2,37 @@
// The .NET Foundation licenses this file to you under the MS-PL license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
using Moq;
using MvvmCross.Core.Navigation;
using MvvmCross.Core.Platform;
using MvvmCross.Core.ViewModels;
using MvvmCross.Test.Core;
using MvvmCross.Test.Mocks.Dispatchers;
using MvvmCross.Test.Mocks.ViewModels;
using Xunit;
namespace MvvmCross.Test.Navigation
{
[Collection("MvxTest")]
public class NavigationServiceTests
: MvxIoCSupportingTest
: IClassFixture<MvxTestFixture>
{
private readonly MvxTestFixture _fixture;
public NavigationServiceTests(MvxTestFixture fixture)
{
_fixture = fixture;
AdditionalSetup(fixture);
}
protected Mock<NavigationMockDispatcher> MockDispatcher { get; set; }
protected Mock<IMvxViewModelLoader> MockLoader { get; set; }
public void SetupTest()
private void AdditionalSetup(MvxTestFixture fixture)
{
Setup();
SetInvariantCulture();
}
protected override void AdditionalSetup()
{
base.AdditionalSetup();
MockLoader = new Mock<IMvxViewModelLoader>();
MockLoader.Setup(
l => l.LoadViewModel(It.Is<MvxViewModelRequest>(val => val.ViewModelType == typeof(SimpleTestViewModel)), It.IsAny<IMvxBundle>()))
@ -90,14 +87,14 @@ namespace MvvmCross.Test.Navigation
{
ViewDispatcher = MockDispatcher.Object,
};
Ioc.RegisterSingleton<IMvxNavigationService>(navigationService);
Ioc.RegisterSingleton<IMvxStringToTypeParser>(new MvxStringToTypeParser());
fixture.Ioc.RegisterSingleton<IMvxNavigationService>(navigationService);
fixture.Ioc.RegisterSingleton<IMvxStringToTypeParser>(new MvxStringToTypeParser());
}
[Fact]
public async Task Test_NavigateNoBundle()
{
var navigationService = Ioc.Resolve<IMvxNavigationService>();
var navigationService = _fixture.Ioc.Resolve<IMvxNavigationService>();
await navigationService.Navigate<SimpleTestViewModel>();
@ -112,7 +109,7 @@ namespace MvvmCross.Test.Navigation
[Fact]
public async Task Test_NavigateWithBundle()
{
var navigationService = Ioc.Resolve<IMvxNavigationService>();
var navigationService = _fixture.Ioc.Resolve<IMvxNavigationService>();
var mockVm = new Mock<SimpleTestViewModel>();
@ -128,7 +125,7 @@ namespace MvvmCross.Test.Navigation
[Fact]
public async Task Test_NavigateViewModelInstance()
{
var navigationService = Ioc.Resolve<IMvxNavigationService>();
var navigationService = _fixture.Ioc.Resolve<IMvxNavigationService>();
var mockVm = new Mock<SimpleTestViewModel>();
@ -141,13 +138,13 @@ namespace MvvmCross.Test.Navigation
x => x.ShowViewModel(It.Is<MvxViewModelInstanceRequest>(t => t.ViewModelInstance == mockVm.Object)),
Times.Once);
Assert.IsTrue(MockDispatcher.Object.Requests.Count > 0);
Assert.True(MockDispatcher.Object.Requests.Count > 0);
}
[Fact]
public async Task Test_NavigateWithParameter()
{
var navigationService = Ioc.Resolve<IMvxNavigationService>();
var navigationService = _fixture.Ioc.Resolve<IMvxNavigationService>();
var parameter = "hello";
await navigationService.Navigate<SimpleParameterTestViewModel, string>(parameter);
@ -159,13 +156,13 @@ namespace MvvmCross.Test.Navigation
x => x.ShowViewModel(It.Is<MvxViewModelRequest>(t => t.ViewModelType == typeof(SimpleParameterTestViewModel))),
Times.Once);
Assert.IsTrue(MockDispatcher.Object.Requests.Count > 0);
Assert.True(MockDispatcher.Object.Requests.Count > 0);
}
[Fact]
public async Task Test_NavigateViewModelInstanceWithParameter()
{
var navigationService = Ioc.Resolve<IMvxNavigationService>();
var navigationService = _fixture.Ioc.Resolve<IMvxNavigationService>();
var mockVm = new Mock<SimpleParameterTestViewModel>();
@ -179,13 +176,13 @@ namespace MvvmCross.Test.Navigation
x => x.ShowViewModel(It.Is<MvxViewModelInstanceRequest>(t => t.ViewModelInstance == mockVm.Object)),
Times.Once);
Assert.IsTrue(MockDispatcher.Object.Requests.Count > 0);
Assert.True(MockDispatcher.Object.Requests.Count > 0);
}
[Fact]
public async Task Test_NavigateTypeOfNoBundle()
{
var navigationService = Ioc.Resolve<IMvxNavigationService>();
var navigationService = _fixture.Ioc.Resolve<IMvxNavigationService>();
await navigationService.Navigate(typeof(SimpleTestViewModel));
@ -200,7 +197,7 @@ namespace MvvmCross.Test.Navigation
[Fact]
public async Task Test_NavigateTypeOfWithBundle()
{
var navigationService = Ioc.Resolve<IMvxNavigationService>();
var navigationService = _fixture.Ioc.Resolve<IMvxNavigationService>();
var bundle = new MvxBundle();
bundle.Write(new { hello = "world" });
@ -214,7 +211,7 @@ namespace MvvmCross.Test.Navigation
[Fact]
public async Task Test_NavigateTypeOfWithParameter()
{
var navigationService = Ioc.Resolve<IMvxNavigationService>();
var navigationService = _fixture.Ioc.Resolve<IMvxNavigationService>();
var parameter = "hello";
await navigationService.Navigate<string>(typeof(SimpleParameterTestViewModel), parameter);
@ -226,13 +223,13 @@ namespace MvvmCross.Test.Navigation
x => x.ShowViewModel(It.Is<MvxViewModelRequest>(t => t.ViewModelType == typeof(SimpleParameterTestViewModel))),
Times.Once);
Assert.IsTrue(MockDispatcher.Object.Requests.Count > 0);
Assert.True(MockDispatcher.Object.Requests.Count > 0);
}
[Fact]
public async Task Test_NavigateForResult()
{
var navigationService = Ioc.Resolve<IMvxNavigationService>();
var navigationService = _fixture.Ioc.Resolve<IMvxNavigationService>();
var result = await navigationService.Navigate<SimpleResultTestViewModel, bool>();
@ -243,14 +240,14 @@ namespace MvvmCross.Test.Navigation
x => x.ShowViewModel(It.Is<MvxViewModelRequest>(t => t.ViewModelType == typeof(SimpleResultTestViewModel))),
Times.Once);
Assert.IsTrue(MockDispatcher.Object.Requests.Count > 0);
Assert.IsTrue(result);
Assert.True(MockDispatcher.Object.Requests.Count > 0);
Assert.True(result);
}
[Fact]
public async Task Test_NavigateCallbacks()
{
var navigationService = Ioc.Resolve<IMvxNavigationService>();
var navigationService = _fixture.Ioc.Resolve<IMvxNavigationService>();
int beforeNavigate = 0;
int afterNavigate = 0;
@ -266,14 +263,14 @@ namespace MvvmCross.Test.Navigation
tasks.Add(navigationService.Navigate<SimpleParameterTestViewModel, string>("hello", new MvxBundle()));
await Task.WhenAll(tasks);
Assert.IsTrue(beforeNavigate == 6);
Assert.IsTrue(afterNavigate == 6);
Assert.True(beforeNavigate == 6);
Assert.True(afterNavigate == 6);
}
[Fact]
public async Task Test_CloseCallbacks()
{
var navigationService = Ioc.Resolve<IMvxNavigationService>();
var navigationService = _fixture.Ioc.Resolve<IMvxNavigationService>();
int beforeClose = 0;
int afterClose = 0;
@ -285,14 +282,14 @@ namespace MvvmCross.Test.Navigation
tasks.Add(navigationService.Close<bool>(new SimpleResultTestViewModel(), false));
await Task.WhenAll(tasks);
Assert.IsTrue(beforeClose == 2);
Assert.IsTrue(afterClose == 2);
Assert.True(beforeClose == 2);
Assert.True(afterClose == 2);
}
[Fact]
public void Test_ChangePresentationCallbacks()
{
var navigationService = Ioc.Resolve<IMvxNavigationService>();
var navigationService = _fixture.Ioc.Resolve<IMvxNavigationService>();
int beforeChangePresentation = 0;
int afterChangePresentation = 0;
@ -301,8 +298,8 @@ namespace MvvmCross.Test.Navigation
navigationService.ChangePresentation(new MvxClosePresentationHint(new SimpleTestViewModel()));
Assert.IsTrue(beforeChangePresentation == 1);
Assert.IsTrue(afterChangePresentation == 1);
Assert.True(beforeChangePresentation == 1);
Assert.True(afterChangePresentation == 1);
}
}
}

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

@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
@ -11,7 +10,7 @@ using Moq;
using MvvmCross.Core.Navigation;
using MvvmCross.Core.Platform;
using MvvmCross.Core.ViewModels;
using MvvmCross.Test.Core;
using MvvmCross.Platform.Exceptions;
using MvvmCross.Test.Mocks.Dispatchers;
using MvvmCross.Test.Mocks.TestViewModels;
using MvvmCross.Test.Mocks.ViewModels;
@ -25,37 +24,27 @@ using Xunit;
namespace MvvmCross.Test.Navigation
{
[Collection("MvxTest")]
public class RoutingServiceTests
: MvxIoCSupportingTest
: IClassFixture<MvxTestFixture>
{
protected Mock<NavigationMockDispatcher> MockDispatcher;
protected IMvxNavigationService RoutingService;
private readonly MvxTestFixture _fixture;
[OneTimeSetUp]
public static void SetupFixture()
public RoutingServiceTests(MvxTestFixture fixture)
{
_fixture = fixture;
MvxNavigationService.LoadRoutes(new[] { typeof(RoutingServiceTests).Assembly });
}
public void SetupTest()
{
// ReSharper disable once AssignNullToNotNullAttribute
Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
//Debug.Listeners.Clear();
//Debug.Listeners.Add(new ConsoleTraceListener());
//Trace.Listeners.Clear();
//Trace.Listeners.Add(new ConsoleTraceListener());
Setup();
AdditionalSetup(fixture);
}
protected override void AdditionalSetup()
private void AdditionalSetup(MvxTestFixture fixture)
{
base.AdditionalSetup();
var mockLocator = new Mock<IMvxViewModelLocator>();
mockLocator.Setup(
m => m.Load(It.IsAny<Type>(), It.IsAny<IMvxBundle>(), It.IsAny<IMvxBundle>())).Returns(() => new SimpleTestViewModel());
@ -66,7 +55,7 @@ namespace MvvmCross.Test.Navigation
mockCollection.Setup(m => m.FindViewModelLocator(It.IsAny<MvxViewModelRequest>()))
.Returns(() => mockLocator.Object);
Ioc.RegisterSingleton(mockLocator.Object);
fixture.Ioc.RegisterSingleton(mockLocator.Object);
var loader = new MvxViewModelLoader(mockCollection.Object);
MockDispatcher = new Mock<NavigationMockDispatcher>(MockBehavior.Loose) { CallBase = true };
@ -74,8 +63,8 @@ namespace MvvmCross.Test.Navigation
{
ViewDispatcher = MockDispatcher.Object,
};
Ioc.RegisterSingleton(navigationService);
Ioc.RegisterSingleton<IMvxStringToTypeParser>(new MvxStringToTypeParser());
fixture.Ioc.RegisterSingleton(navigationService);
fixture.Ioc.RegisterSingleton<IMvxStringToTypeParser>(new MvxStringToTypeParser());
}
[Fact]
@ -84,12 +73,9 @@ namespace MvvmCross.Test.Navigation
var url = "mvx://fail/?id=" + Guid.NewGuid();
var canNavigate = await RoutingService.CanNavigate(url);
Assert.That(canNavigate, Is.False);
Assert.False(canNavigate);
Assert.CatchAsync(async () =>
{
await RoutingService.Navigate(url);
});
await Assert.ThrowsAsync<MvxException>(() => RoutingService.Navigate(url));
MockDispatcher.Verify(x => x.ShowViewModel(It.IsAny<MvxViewModelRequest>()), Times.Never);
}

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

@ -6,20 +6,26 @@ using System.Collections.Generic;
using MvvmCross.Core.Parse.StringDictionary;
using MvvmCross.Core.ViewModels;
using MvvmCross.Platform;
using MvvmCross.Test.Core;
using MvvmCross.Test.Mocks.TestViewModels;
using Xunit;
namespace MvvmCross.Test.Parse
{
[Collection("MvxTest")]
public class MvxStringDictionaryTextSerializerTest
: MvxIoCSupportingTest
: IClassFixture<MvxTestFixture>
{
private readonly MvxTestFixture _fixture;
public MvxStringDictionaryTextSerializerTest(MvxTestFixture fixture)
{
_fixture = fixture;
}
[Fact]
public void Test_Round_Trip_Works_For_Normal_ViewModel_Requests()
{
ClearAll();
_fixture.ClearAll();
var viewModelNameLookup = new MvxViewModelByNameLookup();
viewModelNameLookup.AddAll(GetType().Assembly);
@ -42,7 +48,7 @@ namespace MvvmCross.Test.Parse
Assert.Equal("1'\\", deserialized.ParameterValues["On'e"]);
Assert.Equal("2", deserialized.ParameterValues["Two"]);
Assert.Equal("3\"\'\\", deserialized.PresentationValues["Thre\"\'\\e"]);
Assert.Equal(null, deserialized.PresentationValues["Four"]);
Assert.Null(deserialized.PresentationValues["Four"]);
}
[Fact]
@ -63,4 +69,4 @@ namespace MvvmCross.Test.Parse
Assert.Equal(0, deserialized.ParameterValues.Count);
}
}
}
}

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

@ -4,19 +4,19 @@
using System.Collections.Generic;
using MvvmCross.Core.Platform;
using MvvmCross.Test.Core;
using Xunit;
namespace MvvmCross.Test.Platform
{
public class MvxSimplePropertyDictionaryExtensionMethodsTests : MvxIoCSupportingTest
[Collection("MvxTest")]
public class MvxSimplePropertyDictionaryExtensionMethodsTests : IClassFixture<MvxTestFixture>
{
public void SetUp()
private readonly MvxTestFixture _fixture;
public MvxSimplePropertyDictionaryExtensionMethodsTests(MvxTestFixture fixture)
{
ClearAll();
Ioc.RegisterSingleton<IMvxStringToTypeParser>(new MvxStringToTypeParser());
_fixture = fixture;
fixture.Ioc.RegisterSingleton<IMvxStringToTypeParser>(new MvxStringToTypeParser());
}
[Fact]
@ -48,4 +48,4 @@ namespace MvvmCross.Test.Platform
public string BasePropertyPublicSet { get; set; }
}
}
}
}

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

@ -3,40 +3,42 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using MvvmCross.Core.Platform;
using MvvmCross.Test.Core;
using Xunit;
namespace MvvmCross.Test.Platform
{
public class MvxStringToTypeParserTest : MvxIoCSupportingTest
[Collection("MvxTest")]
public class MvxStringToTypeParserTest : IClassFixture<MvxTestFixture>
{
[OneTimeSetUp]
public void FixtureSetUp()
private readonly MvxTestFixture _fixture;
public MvxStringToTypeParserTest(MvxTestFixture fixture)
{
SetInvariantCulture();
_fixture = fixture;
_fixture.SetInvariantCulture();
}
[Fact]
public void Test_AllTypesAreSupported()
{
var parser = new MvxStringToTypeParser();
Assert.IsTrue(parser.TypeSupported(typeof(string)));
Assert.IsTrue(parser.TypeSupported(typeof(int)));
Assert.IsTrue(parser.TypeSupported(typeof(long)));
Assert.IsTrue(parser.TypeSupported(typeof(short)));
Assert.IsTrue(parser.TypeSupported(typeof(float)));
Assert.IsTrue(parser.TypeSupported(typeof(uint)));
Assert.IsTrue(parser.TypeSupported(typeof(ulong)));
Assert.IsTrue(parser.TypeSupported(typeof(ushort)));
Assert.IsTrue(parser.TypeSupported(typeof(double)));
Assert.IsTrue(parser.TypeSupported(typeof(bool)));
Assert.IsTrue(parser.TypeSupported(typeof(Guid)));
Assert.IsTrue(parser.TypeSupported(typeof(StringSplitOptions)));
Assert.True(parser.TypeSupported(typeof(string)));
Assert.True(parser.TypeSupported(typeof(int)));
Assert.True(parser.TypeSupported(typeof(long)));
Assert.True(parser.TypeSupported(typeof(short)));
Assert.True(parser.TypeSupported(typeof(float)));
Assert.True(parser.TypeSupported(typeof(uint)));
Assert.True(parser.TypeSupported(typeof(ulong)));
Assert.True(parser.TypeSupported(typeof(ushort)));
Assert.True(parser.TypeSupported(typeof(double)));
Assert.True(parser.TypeSupported(typeof(bool)));
Assert.True(parser.TypeSupported(typeof(Guid)));
Assert.True(parser.TypeSupported(typeof(StringSplitOptions)));
}
[Fact]
[Theory]
[InlineData("Hello, World")]
[InlineData("Foo Bar Baz")]
[InlineData("Z͚̭͖͟A͖̘̪L̻̯̥̬ͅG̞̰̭͍͖ͅͅO̘!̜")]
@ -48,7 +50,7 @@ namespace MvvmCross.Test.Platform
Assert.Equal(testData, parser.ReadValue(testData, typeof(string), "ignored"));
}
[Fact]
[Theory]
[InlineData("-123", -123.0)]
[InlineData("1.23", 1.23)]
[InlineData("1,23", 123.0)]
@ -63,7 +65,7 @@ namespace MvvmCross.Test.Platform
Assert.Equal(expected, parser.ReadValue(testData, typeof(double), "ignored"));
}
[Fact]
[Theory]
[InlineData("-123", -123.0f)]
[InlineData("1.23", 1.23f)]
[InlineData("1,23", 123.0f)]
@ -78,7 +80,7 @@ namespace MvvmCross.Test.Platform
Assert.Equal(expected, parser.ReadValue(testData, typeof(float), "ignored"));
}
[Fact]
[Theory]
[InlineData("-123", -123)]
[InlineData("123", 123)]
[InlineData("1.23", 0)]
@ -91,7 +93,7 @@ namespace MvvmCross.Test.Platform
Assert.Equal(expected, parser.ReadValue(testData, typeof(int), "ignored"));
}
[Fact]
[Theory]
[InlineData("-123", -123L)]
[InlineData("123", 123L)]
[InlineData("1.23", 0L)]
@ -104,7 +106,7 @@ namespace MvvmCross.Test.Platform
Assert.Equal(expected, parser.ReadValue(testData, typeof(long), "ignored"));
}
[Fact]
[Theory]
[InlineData("123", 123ul)]
[InlineData("1.23", 0ul)]
[InlineData("garbage", 0ul)]
@ -116,7 +118,7 @@ namespace MvvmCross.Test.Platform
Assert.Equal(expected, parser.ReadValue(testData, typeof(ulong), "ignored"));
}
[Fact]
[Theory]
[InlineData("123", (ushort)123)]
[InlineData("1.23", (ushort)0)]
[InlineData("garbage", (ushort)0)]
@ -128,7 +130,7 @@ namespace MvvmCross.Test.Platform
Assert.Equal(expected, parser.ReadValue(testData, typeof(ushort), "ignored"));
}
[Fact]
[Theory]
[InlineData("true", true)]
[InlineData("True", true)]
[InlineData("tRue", true)]
@ -152,25 +154,27 @@ namespace MvvmCross.Test.Platform
Assert.Equal(expected, parser.ReadValue(testData, typeof(bool), "ignored"));
}
private static object[] _guidCases =
public static IEnumerable<object[]> GuidCases()
{
new object[] { "{C3CF9078-0122-41BD-9E2D-D3199E937285}", Guid.Parse("{C3CF9078-0122-41BD-9E2D-D3199E937285}") },
new object[] { "{C3CF9078-0122-41BD-9E2D-D3199E937285}".ToLowerInvariant(), Guid.Parse("{C3CF9078-0122-41BD-9E2D-D3199E937285}") },
new object[] { "{8-0122-41BD-9E2D-D3199E937285}", Guid.Empty }, // invalid
new object[] { Guid.Empty.ToString(), Guid.Empty },
new object[] { "", Guid.Empty },
new object[] { "garbage", Guid.Empty },
new object[] { null, Guid.Empty }
};
yield return new object[] { "{C3CF9078-0122-41BD-9E2D-D3199E937285}", Guid.Parse("{C3CF9078-0122-41BD-9E2D-D3199E937285}") };
yield return new object[] { "{C3CF9078-0122-41BD-9E2D-D3199E937285}".ToLowerInvariant(), Guid.Parse("{C3CF9078-0122-41BD-9E2D-D3199E937285}") };
yield return new object[] { "{8-0122-41BD-9E2D-D3199E937285}", Guid.Empty }; // invalid
yield return new object[] { Guid.Empty.ToString(), Guid.Empty };
yield return new object[] { "", Guid.Empty };
yield return new object[] { "garbage", Guid.Empty };
yield return new object[] { null, Guid.Empty };
}
[Test, TestCaseSource(nameof(_guidCases))]
[Theory]
[MemberData(nameof(GuidCases))]
public void Test_GuidCanBeRead(string testData, Guid expected)
{
var parser = new MvxStringToTypeParser();
Assert.Equal(expected, parser.ReadValue(testData, typeof(Guid), "ignored"));
}
[Fact]
[Theory]
[InlineData("RemoveEmptyEntries", StringSplitOptions.RemoveEmptyEntries)]
[InlineData("None", StringSplitOptions.None)]
[InlineData("none", StringSplitOptions.None)]

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

@ -4,50 +4,56 @@
using System;
using MvvmCross.Core.ViewModels;
using MvvmCross.Test.Core;
using MvvmCross.Test.Mocks.TestViewModels;
using Xunit;
namespace MvvmCross.Test.Platform
{
public class MvxViewModelByNameLookupTest : MvxIoCSupportingTest
[Collection("MvxTest")]
public class MvxViewModelByNameLookupTest : IClassFixture<MvxTestFixture>
{
private readonly MvxTestFixture _fixture;
public MvxViewModelByNameLookupTest(MvxTestFixture fixture)
{
_fixture = fixture;
}
[Fact]
public void Test_ViewModelByName_Finds_Expected_ViewModel()
{
ClearAll();
_fixture.ClearAll();
var assembly = GetType().Assembly;
var finder = new MvxViewModelByNameLookup();
finder.AddAll(assembly);
Type result;
Assert.IsTrue(finder.TryLookupByName("Test1ViewModel", out result));
Assert.True(finder.TryLookupByName("Test1ViewModel", out result));
Assert.Equal(typeof(Test1ViewModel), result);
Assert.IsTrue(finder.TryLookupByName("Test2ViewModel", out result));
Assert.True(finder.TryLookupByName("Test2ViewModel", out result));
Assert.Equal(typeof(Test2ViewModel), result);
Assert.IsTrue(finder.TryLookupByName("Test3ViewModel", out result));
Assert.True(finder.TryLookupByName("Test3ViewModel", out result));
Assert.Equal(typeof(Test3ViewModel), result);
Assert.IsFalse(finder.TryLookupByName("AbstractTest1ViewModel", out result));
Assert.IsNull(result);
Assert.IsFalse(finder.TryLookupByName("NoWayTestViewModel", out result));
Assert.IsNull(result);
Assert.IsTrue(finder.TryLookupByFullName("MvvmCross.Test.Mocks.TestViewModels.Test1ViewModel",
Assert.False(finder.TryLookupByName("AbstractTest1ViewModel", out result));
Assert.Null(result);
Assert.False(finder.TryLookupByName("NoWayTestViewModel", out result));
Assert.Null(result);
Assert.True(finder.TryLookupByFullName("MvvmCross.Test.Mocks.TestViewModels.Test1ViewModel",
out result));
Assert.Equal(typeof(Test1ViewModel), result);
Assert.IsTrue(finder.TryLookupByFullName("MvvmCross.Test.Mocks.TestViewModels.Test2ViewModel",
Assert.True(finder.TryLookupByFullName("MvvmCross.Test.Mocks.TestViewModels.Test2ViewModel",
out result));
Assert.Equal(typeof(Test2ViewModel), result);
Assert.IsTrue(finder.TryLookupByFullName("MvvmCross.Test.Mocks.TestViewModels.Test3ViewModel",
Assert.True(finder.TryLookupByFullName("MvvmCross.Test.Mocks.TestViewModels.Test3ViewModel",
out result));
Assert.Equal(typeof(Test3ViewModel), result);
Assert.IsFalse(
Assert.False(
finder.TryLookupByFullName("MvvmCross.Test.Mocks.TestViewModels.AbstractTest1ViewModel",
out result));
Assert.IsNull(result);
Assert.IsFalse(finder.TryLookupByFullName(
Assert.Null(result);
Assert.False(finder.TryLookupByFullName(
"MvvmCross.Test.Mocks.TestViewModels.NoWayTestViewModel", out result));
Assert.IsNull(result);
Assert.Null(result);
}
}
}
}

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

@ -3,27 +3,33 @@
// See the LICENSE file in the project root for more information.
using MvvmCross.Core.ViewModels;
using MvvmCross.Test.Core;
using MvvmCross.Test.Mocks.TestViewModels;
using MvvmCross.Test.Mocks.TestViews;
using Xunit;
namespace MvvmCross.Test.Platform
{
public class MvxViewModelViewLookupBuilderTest : MvxIoCSupportingTest
[Collection("MvxTest")]
public class MvxViewModelViewLookupBuilderTest : IClassFixture<MvxTestFixture>
{
private readonly MvxTestFixture _fixture;
public MvxViewModelViewLookupBuilderTest(MvxTestFixture fixture)
{
_fixture = fixture;
}
[Fact]
public void Test_Builder()
{
ClearAll();
_fixture.ClearAll();
var assembly = GetType().Assembly;
var viewModelNameLookup = new MvxViewModelByNameLookup();
viewModelNameLookup.AddAll(assembly);
var nameMapping = new MvxPostfixAwareViewToViewModelNameMapping("View", "Oddness");
var finder = new MvxViewModelViewTypeFinder(viewModelNameLookup, nameMapping);
Ioc.RegisterSingleton<IMvxViewModelTypeFinder>(finder);
_fixture.Ioc.RegisterSingleton<IMvxViewModelTypeFinder>(finder);
var builder = new MvxViewModelViewLookupBuilder();
var result = builder.Build(new[] { assembly });
@ -35,4 +41,4 @@ namespace MvvmCross.Test.Platform
Assert.Equal(typeof(OddNameOddness), result[typeof(OddNameViewModel)]);
}
}
}
}

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

@ -3,20 +3,26 @@
// See the LICENSE file in the project root for more information.
using MvvmCross.Core.ViewModels;
using MvvmCross.Test.Core;
using MvvmCross.Test.Mocks.TestViewModels;
using MvvmCross.Test.Mocks.TestViews;
using Xunit;
namespace MvvmCross.Test.Platform
{
public class MvxViewModelViewTypeFinderTest : MvxIoCSupportingTest
[Collection("MvxTest")]
public class MvxViewModelViewTypeFinderTest : IClassFixture<MvxTestFixture>
{
private readonly MvxTestFixture _fixture;
public MvxViewModelViewTypeFinderTest(MvxTestFixture fixture)
{
_fixture = fixture;
}
[Fact]
public void Test_MvxViewModelViewTypeFinder()
{
ClearAll();
_fixture.ClearAll();
var assembly = GetType().Assembly;
var viewModelNameLookup = new MvxViewModelByNameLookup();
@ -36,9 +42,9 @@ namespace MvvmCross.Test.Platform
// test for negatives
result = test.FindTypeOrNull(typeof(AbstractTest1View));
Assert.IsNull(result);
Assert.Null(result);
result = test.FindTypeOrNull(typeof(NotReallyAView));
Assert.IsNull(result);
Assert.Null(result);
}
}
}
}

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

@ -6,21 +6,26 @@ using System;
using System.Linq;
using MvvmCross.Core.Platform;
using MvvmCross.Core.ViewModels;
using MvvmCross.Test.Core;
using MvvmCross.Test.Mocks.TestViewModels;
using Xunit;
namespace MvvmCross.Test.ViewModels
{
public class MvxBundleTest : MvxIoCSupportingTest
[Collection("MvxTest")]
public class MvxBundleTest : IClassFixture<MvxTestFixture>
{
private readonly MvxTestFixture _fixture;
public MvxBundleTest(MvxTestFixture fixture)
{
_fixture = fixture;
}
[Fact]
public void Test_RoundTrip()
{
ClearAll();
Ioc.RegisterSingleton<IMvxStringToTypeParser>(new MvxStringToTypeParser());
_fixture.ClearAll();
_fixture.Ioc.RegisterSingleton<IMvxStringToTypeParser>(new MvxStringToTypeParser());
var testObject = new BundleObject
{
@ -56,9 +61,8 @@ namespace MvvmCross.Test.ViewModels
[Fact]
public void Test_FillArguments()
{
ClearAll();
Ioc.RegisterSingleton<IMvxStringToTypeParser>(new MvxStringToTypeParser());
_fixture.ClearAll();
_fixture.Ioc.RegisterSingleton<IMvxStringToTypeParser>(new MvxStringToTypeParser());
var testObject = new BundleObject
{
@ -92,4 +96,4 @@ namespace MvvmCross.Test.ViewModels
Assert.Equal(expected, output);
}
}
}
}

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

@ -6,15 +6,21 @@ using System.ComponentModel;
using System.Windows.Input;
using MvvmCross.Core.ViewModels;
using MvvmCross.Platform.Core;
using MvvmCross.Test.Core;
using MvvmCross.Test.Mocks.Dispatchers;
using Xunit;
namespace MvvmCross.Test.ViewModels
{
public class MvxCommandCollectionTest : MvxIoCSupportingTest
[Collection("MvxTest")]
public class MvxCommandCollectionTest : IClassFixture<MvxTestFixture>
{
private MvxTestFixture _fixture;
public MvxCommandCollectionTest(MvxTestFixture fixture)
{
_fixture = fixture;
}
public class CommandTestClass : INotifyPropertyChanged
{
public int CountMyCommandCalled { get; set; }
@ -145,14 +151,14 @@ namespace MvvmCross.Test.ViewModels
[Fact]
public void Test_Conventional_Command()
{
ClearAll();
_fixture.ClearAll();
var testObject = new CommandTestClass();
var collection = new MvxCommandCollectionBuilder()
.BuildCollectionFor(testObject);
var myCommand = collection["My"];
Assert.IsNotNull(myCommand);
Assert.NotNull(myCommand);
CheckCounts(testObject);
myCommand.Execute();
CheckCounts(testObject, 1, 1);
@ -165,14 +171,14 @@ namespace MvvmCross.Test.ViewModels
[Fact]
public void Test_Conventional_Command_CanExecute()
{
ClearAll();
_fixture.ClearAll();
var testObject = new CommandTestClass();
var collection = new MvxCommandCollectionBuilder()
.BuildCollectionFor(testObject);
var myCommand = collection["My"];
Assert.IsNotNull(myCommand);
Assert.NotNull(myCommand);
CheckCounts(testObject);
var result = myCommand.CanExecute();
CheckCounts(testObject, countCanExecuteMyCalled: 1);
@ -185,14 +191,14 @@ namespace MvvmCross.Test.ViewModels
[Fact]
public void Test_Conventional_Parameter_Command()
{
ClearAll();
_fixture.ClearAll();
var testObject = new CommandTestClass();
var collection = new MvxCommandCollectionBuilder()
.BuildCollectionFor(testObject);
var myCommand = collection["MyEx"];
Assert.IsNotNull(myCommand);
Assert.NotNull(myCommand);
CheckCounts(testObject);
myCommand.Execute();
CheckCounts(testObject, countMyExCalled: 1, countCanExecuteMyExCalled: 1);
@ -205,14 +211,14 @@ namespace MvvmCross.Test.ViewModels
[Fact]
public void Test_Conventional_Parameter_Command_CanExecute()
{
ClearAll();
_fixture.ClearAll();
var testObject = new CommandTestClass();
var collection = new MvxCommandCollectionBuilder()
.BuildCollectionFor(testObject);
var myCommand = collection["MyEx"];
Assert.IsNotNull(myCommand);
Assert.NotNull(myCommand);
CheckCounts(testObject);
var result = myCommand.CanExecute();
CheckCounts(testObject, countCanExecuteMyExCalled: 1);
@ -225,14 +231,14 @@ namespace MvvmCross.Test.ViewModels
[Fact]
public void Test_IntReturning_Command()
{
ClearAll();
_fixture.ClearAll();
var testObject = new CommandTestClass();
var collection = new MvxCommandCollectionBuilder()
.BuildCollectionFor(testObject);
var myCommand = collection["AnIntReturning"];
Assert.IsNotNull(myCommand);
Assert.NotNull(myCommand);
CheckCounts(testObject);
myCommand.Execute();
CheckCounts(testObject, countIntReturningCalled: 1);
@ -245,14 +251,14 @@ namespace MvvmCross.Test.ViewModels
[Fact]
public void Test_Attribute1_Command()
{
ClearAll();
_fixture.ClearAll();
var testObject = new CommandTestClass();
var collection = new MvxCommandCollectionBuilder()
.BuildCollectionFor(testObject);
var myCommand = collection["CalledByAttr"];
Assert.IsNotNull(myCommand);
Assert.NotNull(myCommand);
CheckCounts(testObject);
myCommand.Execute();
CheckCounts(testObject, countAttributedCalled: 1);
@ -265,14 +271,14 @@ namespace MvvmCross.Test.ViewModels
[Fact]
public void Test_Attribute2_Command()
{
ClearAll();
_fixture.ClearAll();
var testObject = new CommandTestClass();
var collection = new MvxCommandCollectionBuilder()
.BuildCollectionFor(testObject);
var myCommand = collection["CalledByAttr2"];
Assert.IsNotNull(myCommand);
Assert.NotNull(myCommand);
CheckCounts(testObject);
myCommand.Execute();
CheckCounts(testObject, countAttributed2Called: 1, countCanExecuteAttributed2Called: 1);
@ -285,14 +291,14 @@ namespace MvvmCross.Test.ViewModels
[Fact]
public void Test_Attribute2_Command_CanExecute()
{
ClearAll();
_fixture.ClearAll();
var testObject = new CommandTestClass();
var collection = new MvxCommandCollectionBuilder()
.BuildCollectionFor(testObject);
var myCommand = collection["CalledByAttr2"];
Assert.IsNotNull(myCommand);
Assert.NotNull(myCommand);
CheckCounts(testObject);
var result = myCommand.CanExecute();
CheckCounts(testObject, countCanExecuteAttributed2Called: 1);
@ -305,32 +311,32 @@ namespace MvvmCross.Test.ViewModels
[Fact]
public void Test_PropertyChanged_Raises_CanExecuteChange()
{
ClearAll();
_fixture.ClearAll();
var dispatcher = new InlineMockMainThreadDispatcher();
Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(dispatcher);
_fixture.Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(dispatcher);
var testObject = new CommandTestClass();
var collection = new MvxCommandCollectionBuilder()
.BuildCollectionFor(testObject);
var myCommand = collection["My"];
Assert.IsNotNull(myCommand);
Assert.NotNull(myCommand);
var countMy = 0;
myCommand.CanExecuteChanged += (sender, args) => countMy++;
var myExCommand = collection["MyEx"];
Assert.IsNotNull(myExCommand);
Assert.NotNull(myExCommand);
var countMyEx = 0;
myExCommand.CanExecuteChanged += (sender, args) => countMyEx++;
var calledByAttrCommand = collection["CalledByAttr"];
Assert.IsNotNull(calledByAttrCommand);
Assert.NotNull(calledByAttrCommand);
var countAttr = 0;
calledByAttrCommand.CanExecuteChanged += (sender, args) => countAttr++;
var calledByAttr2Command = collection["CalledByAttr2"];
Assert.IsNotNull(calledByAttr2Command);
Assert.NotNull(calledByAttr2Command);
var countAttr2 = 0;
calledByAttr2Command.CanExecuteChanged += (sender, args) => countAttr2++;
@ -379,22 +385,22 @@ namespace MvvmCross.Test.ViewModels
[Fact]
public void Test_PropertyChanged_Raises_Multiple_CanExecuteChange()
{
ClearAll();
_fixture.ClearAll();
var dispatcher = new InlineMockMainThreadDispatcher();
Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(dispatcher);
_fixture.Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(dispatcher);
var testObject = new SharedCommandTestClass();
var collection = new MvxCommandCollectionBuilder()
.BuildCollectionFor(testObject);
var calledByAttrCommand = collection["CalledByAttr"];
Assert.IsNotNull(calledByAttrCommand);
Assert.NotNull(calledByAttrCommand);
var countAttr = 0;
calledByAttrCommand.CanExecuteChanged += (sender, args) => countAttr++;
var calledByAttr2Command = collection["CalledByAttr2"];
Assert.IsNotNull(calledByAttr2Command);
Assert.NotNull(calledByAttr2Command);
var countAttr2 = 0;
calledByAttr2Command.CanExecuteChanged += (sender, args) => countAttr2++;
@ -430,4 +436,4 @@ namespace MvvmCross.Test.ViewModels
Assert.Equal(countIntReturningCalled, testObject.CountAnIntReturningCalled);
}
}
}
}

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

@ -6,24 +6,30 @@ using System;
using MvvmCross.Core.Platform;
using MvvmCross.Core.ViewModels;
using MvvmCross.Platform.Exceptions;
using MvvmCross.Test.Core;
using MvvmCross.Test.Mocks.TestViewModels;
using Xunit;
namespace MvvmCross.Test.ViewModels
{
public class MvxDefaultViewModelLocatorTest : MvxIoCSupportingTest
[Collection("MvxTest")]
public class MvxDefaultViewModelLocatorTest : IClassFixture<MvxTestFixture>
{
private readonly MvxTestFixture _fixture;
public MvxDefaultViewModelLocatorTest(MvxTestFixture fixture)
{
_fixture = fixture;
}
[Fact]
public void Test_NoReloadState()
{
ClearAll();
_fixture.ClearAll();
Ioc.RegisterSingleton<IMvxStringToTypeParser>(new MvxStringToTypeParser());
_fixture.Ioc.RegisterSingleton<IMvxStringToTypeParser>(new MvxStringToTypeParser());
var testThing = new MockTestThing();
Ioc.RegisterSingleton<ITestThing>(testThing);
_fixture.Ioc.RegisterSingleton<ITestThing>(testThing);
var testObject = new BundleObject
{
@ -43,31 +49,31 @@ namespace MvvmCross.Test.ViewModels
IMvxViewModel viewModel = toTest.Load(typeof(Test1ViewModel), bundle, null);
Assert.IsNotNull(viewModel);
Assert.NotNull(viewModel);
var typedViewModel = (Test1ViewModel)viewModel;
Assert.AreSame(bundle, typedViewModel.BundleInit);
Assert.IsNull(typedViewModel.BundleState);
Assert.AreSame(testThing, typedViewModel.Thing);
Assert.Equal(bundle, typedViewModel.BundleInit);
Assert.Null(typedViewModel.BundleState);
Assert.Equal(testThing, typedViewModel.Thing);
Assert.Equal(testObject, typedViewModel.TheInitBundleSet);
Assert.IsNull(typedViewModel.TheReloadBundleSet);
Assert.Null(typedViewModel.TheReloadBundleSet);
Assert.Equal(testObject.TheGuid1, typedViewModel.TheInitGuid1Set);
Assert.Equal(testObject.TheGuid2, typedViewModel.TheInitGuid2Set);
Assert.Equal(testObject.TheString1, typedViewModel.TheInitString1Set);
Assert.Equal(Guid.Empty, typedViewModel.TheReloadGuid1Set);
Assert.Equal(Guid.Empty, typedViewModel.TheReloadGuid2Set);
Assert.Equal(null, typedViewModel.TheReloadString1Set);
Assert.IsTrue(typedViewModel.StartCalled);
Assert.Null(typedViewModel.TheReloadString1Set);
Assert.True(typedViewModel.StartCalled);
}
[Fact]
public void Test_WithReloadState()
{
ClearAll();
_fixture.ClearAll();
Ioc.RegisterSingleton<IMvxStringToTypeParser>(new MvxStringToTypeParser());
_fixture.Ioc.RegisterSingleton<IMvxStringToTypeParser>(new MvxStringToTypeParser());
var testThing = new MockTestThing();
Ioc.RegisterSingleton<ITestThing>(testThing);
_fixture.Ioc.RegisterSingleton<ITestThing>(testThing);
var initBundleObject = new BundleObject
{
@ -100,11 +106,11 @@ namespace MvvmCross.Test.ViewModels
var toTest = new MvxDefaultViewModelLocator();
IMvxViewModel viewModel = toTest.Load(typeof(Test1ViewModel), initBundle, reloadBundle);
Assert.IsNotNull(viewModel);
Assert.NotNull(viewModel);
var typedViewModel = (Test1ViewModel)viewModel;
Assert.AreSame(initBundle, typedViewModel.BundleInit);
Assert.AreSame(reloadBundle, typedViewModel.BundleState);
Assert.AreSame(testThing, typedViewModel.Thing);
Assert.Equal(initBundle, typedViewModel.BundleInit);
Assert.Equal(reloadBundle, typedViewModel.BundleState);
Assert.Equal(testThing, typedViewModel.Thing);
Assert.Equal(initBundleObject, typedViewModel.TheInitBundleSet);
Assert.Equal(reloadBundleObject, typedViewModel.TheReloadBundleSet);
Assert.Equal(initBundleObject.TheGuid1, typedViewModel.TheInitGuid1Set);
@ -113,60 +119,54 @@ namespace MvvmCross.Test.ViewModels
Assert.Equal(reloadBundleObject.TheGuid1, typedViewModel.TheReloadGuid1Set);
Assert.Equal(reloadBundleObject.TheGuid2, typedViewModel.TheReloadGuid2Set);
Assert.Equal(reloadBundleObject.TheString1, typedViewModel.TheReloadString1Set);
Assert.IsTrue(typedViewModel.StartCalled);
Assert.True(typedViewModel.StartCalled);
}
[Fact]
public void Test_MissingDependency()
{
ClearAll();
_fixture.ClearAll();
var bundle = new MvxBundle();
var toTest = new MvxDefaultViewModelLocator();
Assert.That(
() => {
IMvxViewModel viewModel = toTest.Load(typeof(Test4ViewModel), bundle, null);
},
Throws.TypeOf<MvxException>().With.Message.StartWith("Problem creating viewModel"));
Assert.Throws<MvxException>(() => {
IMvxViewModel viewModel = toTest.Load(typeof(Test4ViewModel), bundle, null);
});
}
[Fact]
public void Test_FailingDependency()
{
ClearAll();
_fixture.ClearAll();
Ioc.RegisterSingleton<ITestThing>(() => new FailingMockTestThing());
_fixture.Ioc.RegisterSingleton<ITestThing>(() => new FailingMockTestThing());
var bundle = new MvxBundle();
var toTest = new MvxDefaultViewModelLocator();
Assert.That(
() => {
IMvxViewModel viewModel = toTest.Load(typeof(Test4ViewModel), bundle, null);
},
Throws.TypeOf<MvxException>().With.Message.StartWith("Problem creating viewModel"));
Assert.Throws<MvxException>(() => {
IMvxViewModel viewModel = toTest.Load(typeof(Test4ViewModel), bundle, null);
});
}
[Fact]
public void Test_FailingInitialisation()
{
ClearAll();
_fixture.ClearAll();
var testThing = new MockTestThing();
Ioc.RegisterSingleton<ITestThing>(testThing);
_fixture.Ioc.RegisterSingleton<ITestThing>(testThing);
var bundle = new MvxBundle();
var toTest = new MvxDefaultViewModelLocator();
Assert.That(
() => {
IMvxViewModel viewModel = toTest.Load(typeof(Test4ViewModel), bundle, null);
},
Throws.TypeOf<MvxException>().With.Message.StartWith("Problem running viewModel lifecycle"));
Assert.Throws<MvxException>(() => {
IMvxViewModel viewModel = toTest.Load(typeof(Test4ViewModel), bundle, null);
});
}
}
}
}

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

@ -7,15 +7,21 @@ using System.Collections.Generic;
using System.ComponentModel;
using MvvmCross.Core.ViewModels;
using MvvmCross.Platform.Core;
using MvvmCross.Test.Core;
using MvvmCross.Test.Mocks.Dispatchers;
using Xunit;
namespace MvvmCross.Test.ViewModels
{
public class MvxNotifyPropertyChangedTest : MvxIoCSupportingTest
public class MvxNotifyPropertyChangedTest : IClassFixture<MvxTestFixture>
{
private readonly MvxTestFixture _fixture;
public MvxNotifyPropertyChangedTest(MvxTestFixture fixture)
{
_fixture = fixture;
}
public class TestInpc : MvxNotifyPropertyChanged
{
public string Foo { get; set; }
@ -24,57 +30,57 @@ namespace MvvmCross.Test.ViewModels
[Fact]
public void Test_RaisePropertyChangedForExpression()
{
ClearAll();
_fixture.ClearAll();
var dispatcher = new InlineMockMainThreadDispatcher();
Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(dispatcher);
_fixture.Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(dispatcher);
var notified = new List<string>();
var t = new TestInpc();
t.PropertyChanged += (sender, args) => notified.Add(args.PropertyName);
t.RaisePropertyChanged(() => t.Foo);
Assert.That(notified.Count == 1);
Assert.That(notified[0] == "Foo");
Assert.True(notified.Count == 1);
Assert.True(notified[0] == "Foo");
}
[Fact]
public void Test_RaisePropertyChangedForName()
{
ClearAll();
_fixture.ClearAll();
var dispatcher = new InlineMockMainThreadDispatcher();
Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(dispatcher);
_fixture.Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(dispatcher);
var notified = new List<string>();
var t = new TestInpc();
t.PropertyChanged += (sender, args) => notified.Add(args.PropertyName);
t.RaisePropertyChanged("Foo");
Assert.That(notified.Count == 1);
Assert.That(notified[0] == "Foo");
Assert.True(notified.Count == 1);
Assert.True(notified[0] == "Foo");
}
[Fact]
public void Test_RaisePropertyChangedDirect()
{
ClearAll();
_fixture.ClearAll();
var dispatcher = new InlineMockMainThreadDispatcher();
Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(dispatcher);
_fixture.Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(dispatcher);
var notified = new List<string>();
var t = new TestInpc();
t.PropertyChanged += (sender, args) => notified.Add(args.PropertyName);
t.RaisePropertyChanged(new PropertyChangedEventArgs("Foo"));
Assert.That(notified.Count == 1);
Assert.That(notified[0] == "Foo");
Assert.True(notified.Count == 1);
Assert.True(notified[0] == "Foo");
}
[Fact]
public void Test_TurnOffUIThread()
{
ClearAll();
_fixture.ClearAll();
var dispatcher = new CountingMockMainThreadDispatcher();
Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(dispatcher);
_fixture.Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(dispatcher);
var notified = new List<string>();
var t = new TestInpc();
@ -82,16 +88,16 @@ namespace MvvmCross.Test.ViewModels
t.ShouldAlwaysRaiseInpcOnUserInterfaceThread(false);
t.RaisePropertyChanged(new PropertyChangedEventArgs("Foo"));
Assert.That(dispatcher.Count == 0);
Assert.That(notified.Count == 1);
Assert.That(notified[0] == "Foo");
Assert.True(dispatcher.Count == 0);
Assert.True(notified.Count == 1);
Assert.True(notified[0] == "Foo");
t.ShouldAlwaysRaiseInpcOnUserInterfaceThread(true);
t.RaisePropertyChanged(new PropertyChangedEventArgs("Foo"));
Assert.Equal(1, dispatcher.Count);
Assert.That(notified.Count == 1);
Assert.That(notified[0] == "Foo");
Assert.True(notified.Count == 1);
Assert.True(notified[0] == "Foo");
}
public class Interceptor : IMvxInpcInterceptor
@ -107,13 +113,13 @@ namespace MvvmCross.Test.ViewModels
[Fact]
public void Test_Interceptor()
{
ClearAll();
_fixture.ClearAll();
var dispatcher = new CountingMockMainThreadDispatcher();
Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(dispatcher);
_fixture.Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(dispatcher);
var interceptor = new Interceptor();
Ioc.RegisterSingleton<IMvxInpcInterceptor>(interceptor);
_fixture.Ioc.RegisterSingleton<IMvxInpcInterceptor>(interceptor);
var notified = new List<string>();
var t = new TestInpc();
@ -121,17 +127,17 @@ namespace MvvmCross.Test.ViewModels
interceptor.Handler = (s, e) => MvxInpcInterceptionResult.RaisePropertyChanged;
t.RaisePropertyChanged(new PropertyChangedEventArgs("Foo"));
Assert.That(dispatcher.Count == 1);
Assert.True(dispatcher.Count == 1);
interceptor.Handler = (s, e) => MvxInpcInterceptionResult.DoNotRaisePropertyChanged;
t.RaisePropertyChanged(new PropertyChangedEventArgs("Foo"));
Assert.That(dispatcher.Count == 1);
Assert.True(dispatcher.Count == 1);
interceptor.Handler = (s, e) => MvxInpcInterceptionResult.RaisePropertyChanged;
t.RaisePropertyChanged(new PropertyChangedEventArgs("Foo"));
Assert.That(dispatcher.Count == 2);
Assert.True(dispatcher.Count == 2);
}
}
}
}

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

@ -6,21 +6,27 @@ using System;
using System.Collections.Generic;
using MvvmCross.Core.Platform;
using MvvmCross.Core.ViewModels;
using MvvmCross.Test.Core;
using MvvmCross.Test.Mocks.TestViewModels;
using Xunit;
namespace MvvmCross.Test.ViewModels
{
public class MvxSaveStateTest : MvxIoCSupportingTest
[Collection("MvxTest")]
public class MvxSaveStateTest : IClassFixture<MvxTestFixture>
{
private readonly MvxTestFixture _fixture;
public MvxSaveStateTest(MvxTestFixture fixture)
{
_fixture = fixture;
}
[Fact]
public void Test_SaveState()
{
ClearAll();
_fixture.ClearAll();
Ioc.RegisterSingleton<IMvxStringToTypeParser>(new MvxStringToTypeParser());
_fixture.Ioc.RegisterSingleton<IMvxStringToTypeParser>(new MvxStringToTypeParser());
var viewModel = new Test3ViewModel
{
@ -53,7 +59,7 @@ namespace MvvmCross.Test.ViewModels
[Fact]
public void Test_NullSaveState()
{
ClearAll();
_fixture.ClearAll();
var viewModel = new Test3ViewModel();
@ -61,4 +67,4 @@ namespace MvvmCross.Test.ViewModels
Assert.Equal(0, bundle.Data.Count);
}
}
}
}

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

@ -7,32 +7,39 @@ using System.Collections.Generic;
using Moq;
using MvvmCross.Core.ViewModels;
using MvvmCross.Platform.Exceptions;
using MvvmCross.Test.Core;
using MvvmCross.Test.Mocks.TestViewModels;
using Xunit;
namespace MvvmCross.Test.ViewModels
{
public class MvxViewModelLoaderTest : MvxIoCSupportingTest
[Collection("MvxTest")]
public class MvxViewModelLoaderTest : IClassFixture<MvxTestFixture>
{
private readonly MvxTestFixture _fixture;
public MvxViewModelLoaderTest(MvxTestFixture fixture)
{
_fixture = fixture;
}
[Fact]
public void Test_LoaderForNull()
{
ClearAll();
_fixture.ClearAll();
var request = new MvxViewModelRequest<MvxNullViewModel>(null, null);
var state = new MvxBundle();
var loader = new MvxViewModelLoader(null);
var viewModel = loader.LoadViewModel(request, state);
Assert.IsInstanceOf<MvxNullViewModel>(viewModel);
Assert.IsType<MvxNullViewModel>(viewModel);
}
[Fact]
public void Test_NormalViewModel()
{
ClearAll();
_fixture.ClearAll();
IMvxViewModel outViewModel = new Test2ViewModel();
@ -51,13 +58,13 @@ namespace MvvmCross.Test.ViewModels
var loader = new MvxViewModelLoader(mockCollection.Object);
var viewModel = loader.LoadViewModel(request, state);
Assert.AreSame(outViewModel, viewModel);
Assert.Equal(outViewModel, viewModel);
}
[Fact]
public void Test_FailedViewModel()
{
ClearAll();
_fixture.ClearAll();
var mockLocator = new Mock<IMvxViewModelLocator>();
mockLocator.Setup(
@ -80,7 +87,7 @@ namespace MvvmCross.Test.ViewModels
[Fact]
public void Test_FailedViewModelLocatorCollection()
{
ClearAll();
_fixture.ClearAll();
var mockCollection = new Mock<IMvxViewModelLocatorCollection>();
mockCollection.Setup(m => m.FindViewModelLocator(It.IsAny<MvxViewModelRequest>()))
@ -96,4 +103,4 @@ namespace MvvmCross.Test.ViewModels
});
}
}
}
}

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

@ -0,0 +1,20 @@
// MvxColorValueConverterTest.cs
// (c) Copyright Cirrious Ltd. http://www.cirrious.com
// MvvmCross is licensed using Microsoft Public License (Ms-PL)
// Contributions and inspirations noted in readme.md and license.txt
//
// Project Lead - Stuart Lodge, @slodge, me@slodge.com
using MvvmCross.Test;
using Xunit;
namespace MvvmCross.Plugins.Color.Test
{
[CollectionDefinition("Color")]
public class ColorCollection : ICollectionFixture<MvxTestFixture>
{
// This class has no code, and is never created. Its purpose is simply
// to be the place to apply [CollectionDefinition] and all the
// ICollectionFixture<> interfaces.
}
}

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

@ -36,12 +36,4 @@ namespace MvvmCross.Plugins.Color.Test
}
}
}
[CollectionDefinition("Color")]
public class DatabaseCollection : ICollectionFixture<MvxTestFixture>
{
// This class has no code, and is never created. Its purpose is simply
// to be the place to apply [CollectionDefinition] and all the
// ICollectionFixture<> interfaces.
}
}

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

@ -5,25 +5,12 @@
using System.Collections.Generic;
using MvvmCross.Plugins.JsonLocalization.Tests.Mocks;
using Xunit;
using NUnit.Framework.Internal;
namespace MvvmCross.Plugins.JsonLocalization.Tests
{
public class MvxDictionaryTextProviderTest
{
public void Setup()
{
}
[TearDown]
public void TearDown()
{
}
#region Tests covertin the 'GetText' method
[Fact]
public void GetTextWithExistingValueReturnsTheValueWhenMaskingErrors()
{
@ -77,17 +64,13 @@ namespace MvvmCross.Plugins.JsonLocalization.Tests
"NonExistingKey"));
}
#endregion
#region Tests covering the 'TryGetText' method
[Fact]
public void TryGetTextForExistingValueReturnsTrueWhenMaskingErrors()
{
var textProvider = TestDictionaryTextProvider.CreateAndInitializeWithDummyData(true);
string value;
Assert.IsTrue(textProvider.TryGetText(out value, TestDictionaryTextProvider.LocalizationNamespace, TestDictionaryTextProvider.TypeKey, "DummyKey"));
Assert.True(textProvider.TryGetText(out value, TestDictionaryTextProvider.LocalizationNamespace, TestDictionaryTextProvider.TypeKey, "DummyKey"));
}
[Fact]
@ -96,7 +79,7 @@ namespace MvvmCross.Plugins.JsonLocalization.Tests
var textProvider = TestDictionaryTextProvider.CreateAndInitializeWithDummyData(false);
string value;
Assert.IsTrue(textProvider.TryGetText(out value, TestDictionaryTextProvider.LocalizationNamespace, TestDictionaryTextProvider.TypeKey, "DummyKey"));
Assert.True(textProvider.TryGetText(out value, TestDictionaryTextProvider.LocalizationNamespace, TestDictionaryTextProvider.TypeKey, "DummyKey"));
}
[Fact]
@ -105,7 +88,7 @@ namespace MvvmCross.Plugins.JsonLocalization.Tests
var textProvider = TestDictionaryTextProvider.CreateAndInitializeWithDummyData(true);
string value;
Assert.IsFalse(textProvider.TryGetText(out value, TestDictionaryTextProvider.LocalizationNamespace, TestDictionaryTextProvider.TypeKey, "NonExistingKey"));
Assert.False(textProvider.TryGetText(out value, TestDictionaryTextProvider.LocalizationNamespace, TestDictionaryTextProvider.TypeKey, "NonExistingKey"));
}
[Fact]
@ -114,7 +97,7 @@ namespace MvvmCross.Plugins.JsonLocalization.Tests
var textProvider = TestDictionaryTextProvider.CreateAndInitializeWithDummyData(false);
string value;
Assert.IsFalse(textProvider.TryGetText(out value, TestDictionaryTextProvider.LocalizationNamespace, TestDictionaryTextProvider.TypeKey, "NonExistingKey"));
Assert.False(textProvider.TryGetText(out value, TestDictionaryTextProvider.LocalizationNamespace, TestDictionaryTextProvider.TypeKey, "NonExistingKey"));
}
[Fact]
@ -144,7 +127,5 @@ namespace MvvmCross.Plugins.JsonLocalization.Tests
Assert.Equal(expected, actual);
}
#endregion
}
}

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

@ -45,15 +45,15 @@ namespace MvvmCross.Plugins.Messenger.Test
var messageReceived = false;
messenger.Subscribe<TestMessage>(m =>
{
Assert.That(m, Is.EqualTo(message));
Assert.That(m.Sender, Is.EqualTo(this));
messageReceived = true;
});
{
Assert.Equal(message, m);
Assert.Equal(this, m.Sender);
messageReceived = true;
});
messenger.Publish(message);
Assert.IsTrue(messageReceived);
Assert.True(messageReceived);
}
[Fact]
@ -65,19 +65,19 @@ namespace MvvmCross.Plugins.Messenger.Test
var messageReceived = 0;
messenger.Subscribe<TestMessage>(m =>
{
Assert.That(m, Is.EqualTo(message));
Assert.That(m.Sender, Is.EqualTo(this));
messageReceived++;
});
{
Assert.Equal(message, m);
Assert.Equal(this, m.Sender);
messageReceived++;
});
var otherMessageReceived = 0;
messenger.Subscribe<OtherTestMessage>(m =>
{
Assert.That(m, Is.EqualTo(otherMessage));
Assert.That(m.Sender, Is.EqualTo(this));
otherMessageReceived++;
});
{
Assert.Equal(otherMessage, m);
Assert.Equal(this, m.Sender);
otherMessageReceived++;
});
messenger.Publish(otherMessage);
Assert.Equal(0, messageReceived);
@ -104,7 +104,7 @@ namespace MvvmCross.Plugins.Messenger.Test
public void UnsubscribePreventsMessagesBeingReceived()
{
var messenger = new MvxMessengerHub();
Action<TestMessage> action = _ => Assert.That(false, "This event should not fire!");
Action<TestMessage> action = _ => Assert.True(false, "This event should not fire!");
var id = messenger.Subscribe(action);
messenger.Unsubscribe<TestMessage>(id);
@ -115,7 +115,7 @@ namespace MvvmCross.Plugins.Messenger.Test
public void DisposeTokenPreventsMessagesBeingReceived()
{
var messenger = new MvxMessengerHub();
Action<TestMessage> action = _ => Assert.That(false, "This event should not fire!");
Action<TestMessage> action = _ => Assert.True(false, "This event should not fire!");
var id = messenger.Subscribe(action);
id.Dispose();
@ -165,28 +165,28 @@ namespace MvvmCross.Plugins.Messenger.Test
public void HasSubscriptionsForIsCorrect()
{
var messenger = new MvxMessengerHub();
Assert.Equal(false, messenger.HasSubscriptionsFor<MvxSubscriberChangeMessage>());
Assert.Equal(false, messenger.HasSubscriptionsFor<TestMessage>());
Assert.False(messenger.HasSubscriptionsFor<MvxSubscriberChangeMessage>());
Assert.False(messenger.HasSubscriptionsFor<TestMessage>());
var changeToken = messenger.Subscribe<MvxSubscriberChangeMessage>(message => { });
Assert.Equal(true, messenger.HasSubscriptionsFor<MvxSubscriberChangeMessage>());
Assert.Equal(false, messenger.HasSubscriptionsFor<TestMessage>());
Assert.True(messenger.HasSubscriptionsFor<MvxSubscriberChangeMessage>());
Assert.False(messenger.HasSubscriptionsFor<TestMessage>());
var token = messenger.Subscribe<TestMessage>(m =>
{
// stuff
});
Assert.Equal(true, messenger.HasSubscriptionsFor<MvxSubscriberChangeMessage>());
Assert.Equal(true, messenger.HasSubscriptionsFor<TestMessage>());
Assert.True(messenger.HasSubscriptionsFor<MvxSubscriberChangeMessage>());
Assert.True(messenger.HasSubscriptionsFor<TestMessage>());
messenger.Unsubscribe<TestMessage>(token);
Assert.Equal(true, messenger.HasSubscriptionsFor<MvxSubscriberChangeMessage>());
Assert.Equal(false, messenger.HasSubscriptionsFor<TestMessage>());
Assert.True(messenger.HasSubscriptionsFor<MvxSubscriberChangeMessage>());
Assert.False(messenger.HasSubscriptionsFor<TestMessage>());
}
[Fact]
public void CountSubscriptionsForIsCorrect()
{
var messenger = new MvxMessengerHub();
Assert.Equal(false, messenger.HasSubscriptionsFor<MvxSubscriberChangeMessage>());
Assert.Equal(false, messenger.HasSubscriptionsFor<TestMessage>());
Assert.False(messenger.HasSubscriptionsFor<MvxSubscriberChangeMessage>());
Assert.False(messenger.HasSubscriptionsFor<TestMessage>());
var changeToken = messenger.Subscribe<MvxSubscriberChangeMessage>(message => { });
Assert.Equal(1, messenger.CountSubscriptionsFor<MvxSubscriberChangeMessage>());
Assert.Equal(0, messenger.CountSubscriptionsFor<TestMessage>());
@ -216,32 +216,32 @@ namespace MvvmCross.Plugins.Messenger.Test
var testTag = "TestTag";
var notExistingTag = "NotExistingTag";
var messenger = new MvxMessengerHub();
Assert.Equal(false, messenger.HasSubscriptionsFor<MvxSubscriberChangeMessage>());
Assert.Equal(false, messenger.HasSubscriptionsForTag<MvxSubscriberChangeMessage>(testTag));
Assert.Equal(false, messenger.HasSubscriptionsFor<TestMessage>());
Assert.Equal(false, messenger.HasSubscriptionsForTag<TestMessage>(null));
Assert.Equal(false, messenger.HasSubscriptionsForTag<TestMessage>(notExistingTag));
Assert.False(messenger.HasSubscriptionsFor<MvxSubscriberChangeMessage>());
Assert.False(messenger.HasSubscriptionsForTag<MvxSubscriberChangeMessage>(testTag));
Assert.False(messenger.HasSubscriptionsFor<TestMessage>());
Assert.False(messenger.HasSubscriptionsForTag<TestMessage>(null));
Assert.False(messenger.HasSubscriptionsForTag<TestMessage>(notExistingTag));
var changeToken = messenger.Subscribe<MvxSubscriberChangeMessage>(message => { });
Assert.Equal(true, messenger.HasSubscriptionsForTag<MvxSubscriberChangeMessage>(null));
Assert.Equal(false, messenger.HasSubscriptionsForTag<MvxSubscriberChangeMessage>(testTag));
Assert.Equal(false, messenger.HasSubscriptionsForTag<TestMessage>(testTag));
Assert.Equal(false, messenger.HasSubscriptionsForTag<TestMessage>(null));
Assert.Equal(false, messenger.HasSubscriptionsForTag<TestMessage>(notExistingTag));
Assert.True(messenger.HasSubscriptionsForTag<MvxSubscriberChangeMessage>(null));
Assert.False(messenger.HasSubscriptionsForTag<MvxSubscriberChangeMessage>(testTag));
Assert.False(messenger.HasSubscriptionsForTag<TestMessage>(testTag));
Assert.False(messenger.HasSubscriptionsForTag<TestMessage>(null));
Assert.False(messenger.HasSubscriptionsForTag<TestMessage>(notExistingTag));
var token = messenger.Subscribe<TestMessage>(m =>
{
// stuff
}, tag: testTag);
Assert.Equal(true, messenger.HasSubscriptionsForTag<MvxSubscriberChangeMessage>(null));
Assert.Equal(false, messenger.HasSubscriptionsForTag<MvxSubscriberChangeMessage>(testTag));
Assert.Equal(true, messenger.HasSubscriptionsForTag<TestMessage>(testTag));
Assert.Equal(false, messenger.HasSubscriptionsForTag<TestMessage>(null));
Assert.Equal(false, messenger.HasSubscriptionsForTag<TestMessage>(notExistingTag));
Assert.True(messenger.HasSubscriptionsForTag<MvxSubscriberChangeMessage>(null));
Assert.False(messenger.HasSubscriptionsForTag<MvxSubscriberChangeMessage>(testTag));
Assert.True(messenger.HasSubscriptionsForTag<TestMessage>(testTag));
Assert.False(messenger.HasSubscriptionsForTag<TestMessage>(null));
Assert.False(messenger.HasSubscriptionsForTag<TestMessage>(notExistingTag));
messenger.Unsubscribe<TestMessage>(token);
Assert.Equal(true, messenger.HasSubscriptionsForTag<MvxSubscriberChangeMessage>(null));
Assert.Equal(false, messenger.HasSubscriptionsForTag<MvxSubscriberChangeMessage>(testTag));
Assert.Equal(false, messenger.HasSubscriptionsForTag<TestMessage>(testTag));
Assert.Equal(false, messenger.HasSubscriptionsForTag<TestMessage>(null));
Assert.Equal(false, messenger.HasSubscriptionsForTag<TestMessage>(notExistingTag));
Assert.True(messenger.HasSubscriptionsForTag<MvxSubscriberChangeMessage>(null));
Assert.False(messenger.HasSubscriptionsForTag<MvxSubscriberChangeMessage>(testTag));
Assert.False(messenger.HasSubscriptionsForTag<TestMessage>(testTag));
Assert.False(messenger.HasSubscriptionsForTag<TestMessage>(null));
Assert.False(messenger.HasSubscriptionsForTag<TestMessage>(notExistingTag));
}
[Fact]
@ -315,18 +315,18 @@ namespace MvvmCross.Plugins.Messenger.Test
var testTag1 = "TestTag1";
var testTag2 = "TestTag2";
var messenger = new MvxMessengerHub();
Assert.IsEmpty(messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>());
Assert.IsEmpty(messenger.GetSubscriptionTagsFor<TestMessage>());
Assert.Empty(messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>());
Assert.Empty(messenger.GetSubscriptionTagsFor<TestMessage>());
var changeToken = messenger.Subscribe<MvxSubscriberChangeMessage>(message => { });
Assert.Equal(1, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>().Count);
Assert.Equal(null, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>()[0]);
Assert.IsEmpty(messenger.GetSubscriptionTagsFor<TestMessage>());
Assert.Null(messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>()[0]);
Assert.Empty(messenger.GetSubscriptionTagsFor<TestMessage>());
var token = messenger.Subscribe<TestMessage>(m =>
{
// stuff
}, tag: testTag1);
Assert.Equal(1, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>().Count);
Assert.Equal(null, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>()[0]);
Assert.Null(messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>()[0]);
Assert.Equal(1, messenger.GetSubscriptionTagsFor<TestMessage>().Count);
Assert.Equal(testTag1, messenger.GetSubscriptionTagsFor<TestMessage>()[0]);
var token2 = messenger.Subscribe<TestMessage>(m =>
@ -334,7 +334,7 @@ namespace MvvmCross.Plugins.Messenger.Test
// stuff
}, tag: testTag1);
Assert.Equal(1, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>().Count);
Assert.Equal(null, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>()[0]);
Assert.Null(messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>()[0]);
Assert.Equal(2, messenger.GetSubscriptionTagsFor<TestMessage>().Count);
Assert.Equal(testTag1, messenger.GetSubscriptionTagsFor<TestMessage>()[0]);
Assert.Equal(testTag1, messenger.GetSubscriptionTagsFor<TestMessage>()[1]);
@ -343,25 +343,25 @@ namespace MvvmCross.Plugins.Messenger.Test
// stuff
}, tag: testTag2);
Assert.Equal(1, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>().Count);
Assert.Equal(null, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>()[0]);
Assert.Null(messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>()[0]);
Assert.Equal(3, messenger.GetSubscriptionTagsFor<TestMessage>().Count);
Assert.Equal(2, messenger.GetSubscriptionTagsFor<TestMessage>().Where(x => x == testTag1).Count());
Assert.Equal(1, messenger.GetSubscriptionTagsFor<TestMessage>().Where(x => x == testTag2).Count());
messenger.Unsubscribe<TestMessage>(token);
Assert.Equal(1, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>().Count);
Assert.Equal(null, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>()[0]);
Assert.Null(messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>()[0]);
Assert.Equal(2, messenger.GetSubscriptionTagsFor<TestMessage>().Count);
Assert.Equal(1, messenger.GetSubscriptionTagsFor<TestMessage>().Where(x => x == testTag1).Count());
Assert.Equal(1, messenger.GetSubscriptionTagsFor<TestMessage>().Where(x => x == testTag2).Count());
messenger.Unsubscribe<TestMessage>(token2);
Assert.Equal(1, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>().Count);
Assert.Equal(null, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>()[0]);
Assert.Null(messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>()[0]);
Assert.Equal(1, messenger.GetSubscriptionTagsFor<TestMessage>().Count);
Assert.Equal(0, messenger.GetSubscriptionTagsFor<TestMessage>().Where(x => x == testTag1).Count());
Assert.Equal(1, messenger.GetSubscriptionTagsFor<TestMessage>().Where(x => x == testTag2).Count());
messenger.Unsubscribe<TestMessage>(token3);
Assert.Equal(1, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>().Count);
Assert.Equal(null, messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>()[0]);
Assert.Null(messenger.GetSubscriptionTagsFor<MvxSubscriberChangeMessage>()[0]);
Assert.Equal(0, messenger.GetSubscriptionTagsFor<TestMessage>().Count);
}
@ -419,4 +419,4 @@ namespace MvvmCross.Plugins.Messenger.Test
#warning TODO - weak references need more testing here really
#warning TODO - async and ui threading need testing here really
}
}
}

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

@ -0,0 +1,20 @@
// SimpleRestTest.cs
// (c) Copyright Cirrious Ltd. http://www.cirrious.com
// MvvmCross is licensed using Microsoft Public License (Ms-PL)
// Contributions and inspirations noted in readme.md and license.txt
//
// Project Lead - Stuart Lodge, @slodge, me@slodge.com
using MvvmCross.Test;
using Xunit;
namespace MvvmCross.Plugins.Network.Test
{
[CollectionDefinition("Rest")]
public class RestCollection : ICollectionFixture<MvxTestFixture>
{
// This class has no code, and is never created. Its purpose is simply
// to be the place to apply [CollectionDefinition] and all the
// ICollectionFixture<> interfaces.
}
}

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

@ -8,25 +8,17 @@ using System.Threading.Tasks;
using MvvmCross.Plugins.Json;
using MvvmCross.Plugins.Network.Rest;
using MvvmCross.Plugins.Network.Test.TestClasses.GoogleBooks;
using MvvmCross.Test.Core;
using Xunit;
namespace MvvmCross.Plugins.Network.Test
{
public class SimpleRestTest
: MvxIoCSupportingTest
{
public void SetUp()
{
}
[Collection("Rest")]
public class SimpleRestTest
{
[Fact]
public async Task GetDataFromGoogleBooks()
{
ClearAll();
// not a real test yet....
var url = BooksService.GetSearchUrl("MonoTouch");
@ -40,12 +32,12 @@ namespace MvvmCross.Plugins.Network.Test
Exception exception = null;
theResponse = await client.MakeRequestForAsync<BookSearchResult>(request);
Assert.IsNotNull(theResponse);
Assert.IsNull(exception);
Assert.IsNotNull(theResponse.Result);
Assert.NotNull(theResponse);
Assert.Null(exception);
Assert.NotNull(theResponse.Result);
Assert.Equal(HttpStatusCode.OK, theResponse.StatusCode);
Assert.IsTrue(theResponse.Result.items.Count == 10);
Assert.IsTrue(theResponse.Result.items[0].ToString().Contains("MonoTouch"));
Assert.True(theResponse.Result.items.Count == 10);
Assert.True(theResponse.Result.items[0].ToString().Contains("MonoTouch"));
}
}
}
}

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

@ -13,18 +13,11 @@ namespace MvvmCross.Plugins.ResxLocalization.Tests
private MockResourceManager _resourceManager;
public void SetUp()
public MvxResxTextProviderTests()
{
_resourceManager = new MockResourceManager();
}
[TearDown]
public void TearDown()
{
}
#region Tests covering the 'GetText' method
[Fact]
public void GetTextForExistingValueSupplyingNameOnlyReturnsDummyName()
{
@ -71,13 +64,9 @@ namespace MvvmCross.Plugins.ResxLocalization.Tests
var textProvider = new MvxResxTextProvider(_resourceManager);
var actual = textProvider.GetText(null, null, "NonExistingKey");
Assert.IsNull(actual);
Assert.Null(actual);
}
#endregion
#region Tests covering the 'TryGetText' method
[Fact]
public void TryGetTextForExistingValueSupplyingNameOnlyReturnsTrue()
{
@ -85,7 +74,7 @@ namespace MvvmCross.Plugins.ResxLocalization.Tests
var expected = MockResourceManager.DummyName;
string actual;
Assert.IsTrue(textProvider.TryGetText(out actual, null, null, MockResourceManager.DummyName));
Assert.True(textProvider.TryGetText(out actual, null, null, MockResourceManager.DummyName));
Assert.Equal(expected, actual);
}
@ -96,7 +85,7 @@ namespace MvvmCross.Plugins.ResxLocalization.Tests
var expected = $"{MockResourceManager.LocalizationNamespace}.{MockResourceManager.DummyName}";
string actual;
Assert.IsTrue(textProvider.TryGetText(out actual, MockResourceManager.LocalizationNamespace, null, MockResourceManager.DummyName));
Assert.True(textProvider.TryGetText(out actual, MockResourceManager.LocalizationNamespace, null, MockResourceManager.DummyName));
Assert.Equal(expected, actual);
}
@ -107,7 +96,7 @@ namespace MvvmCross.Plugins.ResxLocalization.Tests
var expected = $"{MockResourceManager.TypeKey}.{MockResourceManager.DummyName}";
string actual;
Assert.IsTrue(textProvider.TryGetText(out actual, null, MockResourceManager.TypeKey, MockResourceManager.DummyName));
Assert.True(textProvider.TryGetText(out actual, null, MockResourceManager.TypeKey, MockResourceManager.DummyName));
Assert.Equal(expected, actual);
}
@ -118,7 +107,7 @@ namespace MvvmCross.Plugins.ResxLocalization.Tests
var expected = $"{MockResourceManager.LocalizationNamespace}.{MockResourceManager.TypeKey}.{MockResourceManager.DummyName}";
string actual;
Assert.IsTrue(textProvider.TryGetText(out actual, MockResourceManager.LocalizationNamespace, MockResourceManager.TypeKey, MockResourceManager.DummyName));
Assert.True(textProvider.TryGetText(out actual, MockResourceManager.LocalizationNamespace, MockResourceManager.TypeKey, MockResourceManager.DummyName));
Assert.Equal(expected, actual);
}
@ -128,10 +117,8 @@ namespace MvvmCross.Plugins.ResxLocalization.Tests
var textProvider = new MvxResxTextProvider(_resourceManager);
string actual;
Assert.IsFalse(textProvider.TryGetText(out actual, null, null, "NonExistingKey"));
Assert.IsNull(actual);
Assert.False(textProvider.TryGetText(out actual, null, null, "NonExistingKey"));
Assert.Null(actual);
}
#endregion
}
}

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

@ -115,7 +115,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Playground.Droid", "Project
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Playground.Forms.Droid", "Projects\Playground\Playground.Forms.Droid\Playground.Forms.Droid.csproj", "{A8A8B9B3-34FA-4769-AE81-4D80F9BDC3BB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MvvmCross.Test", "MvvmCross.Tests\MvvmCross.Test\MvvmCross.Test.csproj", "{8DFE6A59-AD7D-4916-ABF3-D2D1B0F55858}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MvvmCross.Test", "MvvmCross.Tests\MvvmCross.Test\MvvmCross.Test.csproj", "{8DFE6A59-AD7D-4916-ABF3-D2D1B0F55858}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

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

@ -5,9 +5,12 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Text;
using MvvmCross.Platform.Logging;
[assembly: InternalsVisibleTo("MvvmCross.Test")]
namespace MvvmCross.Platform.Logging.LogProviders
{
internal sealed class ConsoleLogProvider : MvxBaseLogProvider