Browse Source

Fixed easily-fixable failing tests.

pull/12/merge
Steven Kirk 11 years ago
parent
commit
4370087af6
  1. 95
      Perspex.Controls.UnitTests/ContentControlTests.cs
  2. 6
      Perspex.Controls.UnitTests/Perspex.Controls.UnitTests.csproj
  3. 11
      Perspex.Controls.UnitTests/TemplatedControlTests.cs
  4. 4
      Perspex.Controls.UnitTests/app.config
  5. 2
      Perspex.Controls.UnitTests/packages.config
  6. 13
      Perspex.Layout.UnitTests/FullLayoutTests.cs
  7. BIN
      TestFiles/Direct2D1/Shapes/Path/Path_100px_Triangle_Centered.expected.png
  8. BIN
      TestFiles/Direct2D1/Shapes/Rectangle/Rectangle_1px_Stroke.expected.png
  9. 2
      Windows/Perspex.Direct2D1.RenderTests/TestBase.cs

95
Perspex.Controls.UnitTests/ContentControlTests.cs

@ -13,7 +13,10 @@ namespace Perspex.Controls.UnitTests
using Perspex.Controls;
using Perspex.Controls.Presenters;
using Perspex.Layout;
using Perspex.Platform;
using Perspex.Styling;
using Ploeh.AutoFixture;
using Ploeh.AutoFixture.AutoMoq;
using Splat;
[TestClass]
@ -22,22 +25,27 @@ namespace Perspex.Controls.UnitTests
[TestMethod]
public void Template_Should_Be_Instantiated()
{
var target = new ContentControl();
target.Content = "Foo";
target.Template = this.GetTemplate();
using (var ctx = this.RegisterServices())
{
var target = new ContentControl();
target.Content = "Foo";
target.Template = this.GetTemplate();
target.Measure(new Size(100, 100));
var child = ((IVisual)target).VisualChildren.Single();
Assert.IsInstanceOfType(child, typeof(Border));
child = child.VisualChildren.Single();
Assert.IsInstanceOfType(child, typeof(ContentPresenter));
child = child.VisualChildren.Single();
Assert.IsInstanceOfType(child, typeof(TextBlock));
var child = ((IVisual)target).VisualChildren.Single();
Assert.IsInstanceOfType(child, typeof(Border));
child = child.VisualChildren.Single();
Assert.IsInstanceOfType(child, typeof(ContentPresenter));
child = child.VisualChildren.Single();
Assert.IsInstanceOfType(child, typeof(TextBlock));
}
}
[TestMethod]
public void Templated_Children_Should_Be_Styled()
{
using (Locator.CurrentMutable.WithResolver())
using (var ctx = this.RegisterServices())
{
var root = new TestRoot();
var target = new ContentControl();
@ -57,60 +65,6 @@ namespace Perspex.Controls.UnitTests
}
}
[TestMethod]
public void Setting_Content_To_Control_Should_Set_Parent()
{
throw new NotImplementedException();
////var target = new ContentControl();
////var child = new Border();
////target.Content = child;
////Assert.AreEqual(child.Parent, target);
////Assert.AreEqual(((IVisual)child).VisualParent, target);
////Assert.AreEqual(((ILogical)child).LogicalParent, target);
}
[TestMethod]
public void Setting_Content_To_Control_Should_Set_Logical_Child()
{
throw new NotImplementedException();
////var target = new ContentControl();
////var child = new Border();
////target.Content = child;
////Assert.AreEqual(child, ((ILogical)target).LogicalChildren.Single());
}
[TestMethod]
public void Removing_Control_From_Content_Should_Clear_Parent()
{
throw new NotImplementedException();
////var target = new ContentControl();
////var child = new Border();
////target.Content = child;
////target.Content = "foo";
////Assert.IsNull(child.Parent);
////Assert.IsNull(((IVisual)child).VisualParent);
////Assert.IsNull(((ILogical)child).LogicalParent);
}
[TestMethod]
public void Removing_Control_From_Content_Should_Clear_Logical_Child()
{
throw new NotImplementedException();
////var target = new ContentControl();
////var child = new Border();
////target.Content = child;
////target.Content = "foo";
////Assert.IsFalse(((ILogical)target).LogicalChildren.Any());
}
[TestMethod]
public void ContentPresenter_Should_Have_TemplatedParent_Set()
{
@ -138,9 +92,9 @@ namespace Perspex.Controls.UnitTests
Assert.IsNull(child.TemplatedParent);
}
private void ApplyTemplate(IVisual visual)
private void ApplyTemplate(ILayoutable control)
{
var c = visual.GetVisualDescendents().ToList();
control.Measure(new Size(100, 100));
}
private ControlTemplate GetTemplate()
@ -157,5 +111,14 @@ namespace Perspex.Controls.UnitTests
};
});
}
private IDisposable RegisterServices()
{
var result = Locator.CurrentMutable.WithResolver();
var fixture = new Fixture().Customize(new AutoMoqCustomization());
var renderInterface = fixture.Create<IPlatformRenderInterface>();
Locator.CurrentMutable.RegisterConstant(renderInterface, typeof(IPlatformRenderInterface));
return result;
}
}
}

6
Perspex.Controls.UnitTests/Perspex.Controls.UnitTests.csproj

@ -39,6 +39,12 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Moq.4.2.1409.1722\lib\net40\Moq.dll</HintPath>
</Reference>
<Reference Include="Ploeh.AutoFixture">
<HintPath>..\packages\AutoFixture.3.21.1\lib\net40\Ploeh.AutoFixture.dll</HintPath>
</Reference>
<Reference Include="Ploeh.AutoFixture.AutoMoq">
<HintPath>..\packages\AutoFixture.AutoMoq.3.21.1\lib\net40\Ploeh.AutoFixture.AutoMoq.dll</HintPath>
</Reference>
<Reference Include="Splat, Version=1.5.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Splat.1.5.1\lib\Net45\Splat.dll</HintPath>

11
Perspex.Controls.UnitTests/TemplatedControlTests.cs

@ -38,7 +38,7 @@ namespace Perspex.Controls.UnitTests
}
[TestMethod]
public void Template_Gets_Executed_On_Reading_Visual_Children()
public void Template_Gets_Executed_On_Measure()
{
bool executed = false;
@ -53,7 +53,7 @@ namespace Perspex.Controls.UnitTests
Template = template,
};
var children = ((IVisual)target).VisualChildren.ToArray();
target.Measure(new Size(100, 100));
Assert.IsTrue(executed);
}
@ -73,7 +73,8 @@ namespace Perspex.Controls.UnitTests
Template = template,
};
var children = ((IVisual)target).VisualChildren.ToArray();
target.Measure(new Size(100, 100));
var children = target.GetVisualChildren().ToList();
CollectionAssert.AreEqual(new[] { templateResult }, children);
}
@ -93,7 +94,7 @@ namespace Perspex.Controls.UnitTests
Template = template,
};
var children = ((IVisual)target).VisualChildren.ToArray();
target.Measure(new Size(100, 100));
Assert.AreEqual(target, templateResult.TemplatedParent);
}
@ -109,7 +110,7 @@ namespace Perspex.Controls.UnitTests
})
};
var children = ((IVisual)target).VisualChildren.ToArray();
target.Measure(new Size(100, 100));
Assert.IsTrue(target.OnTemplateAppliedCalled);
}

4
Perspex.Controls.UnitTests/app.config

@ -14,6 +14,10 @@
<assemblyIdentity name="System.Reactive.Linq" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.30214.0" newVersion="2.1.30214.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Moq" publicKeyToken="69f491c39445e920" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.1409.1722" newVersion="4.2.1409.1722" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

2
Perspex.Controls.UnitTests/packages.config

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AutoFixture" version="3.21.1" targetFramework="net45" />
<package id="AutoFixture.AutoMoq" version="3.21.1" targetFramework="net45" />
<package id="Moq" version="4.2.1409.1722" targetFramework="net45" />
<package id="Splat" version="1.5.1" targetFramework="net45" />
</packages>

13
Perspex.Layout.UnitTests/FullLayoutTests.cs

@ -79,6 +79,7 @@ namespace Perspex.Layout.UnitTests
{
Width = 200,
Height = 200,
CanScrollHorizontally = true,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Content = (textBlock = new TextBlock
@ -127,23 +128,25 @@ namespace Perspex.Layout.UnitTests
{
var fixture = new Fixture().Customize(new AutoMoqCustomization());
var l = Locator.CurrentMutable;
var windowImpl = new Mock<IWindowImpl>();
var renderManager = fixture.Create<IRenderManager>();
var formattedText = fixture.Create<IFormattedTextImpl>();
var globalStyles = new Mock<IGlobalStyles>();
var renderInterface = fixture.Create<IPlatformRenderInterface>();
var renderManager = fixture.Create<IRenderManager>();
var theme = new DefaultTheme();
var windowImpl = new Mock<IWindowImpl>();
globalStyles.Setup(x => x.Styles).Returns(theme);
windowImpl.Setup(x => x.ClientSize).Returns(new Size(800, 600));
l.RegisterConstant(new Mock<IInputManager>().Object, typeof(IInputManager));
l.RegisterConstant(globalStyles.Object, typeof(IGlobalStyles));
l.RegisterConstant(new LayoutManager(), typeof(ILayoutManager));
l.RegisterConstant(new Mock<IPlatformRenderInterface>().Object, typeof(IPlatformRenderInterface));
l.RegisterConstant(renderInterface, typeof(IPlatformRenderInterface));
l.RegisterConstant(new Mock<IPlatformThreadingInterface>().Object, typeof(IPlatformThreadingInterface));
l.RegisterConstant(renderManager, typeof(IRenderManager));
l.RegisterConstant(new Styler(), typeof(IStyler));
l.RegisterConstant(globalStyles.Object, typeof(IGlobalStyles));
l.RegisterConstant(windowImpl.Object, typeof(IWindowImpl));
l.RegisterConstant(new Mock<IFormattedTextImpl>().Object, typeof(IFormattedTextImpl));
}
}
}

BIN
TestFiles/Direct2D1/Shapes/Path/Path_100px_Triangle_Centered.expected.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
TestFiles/Direct2D1/Shapes/Rectangle/Rectangle_1px_Stroke.expected.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 663 B

After

Width:  |  Height:  |  Size: 628 B

2
Windows/Perspex.Direct2D1.RenderTests/TestBase.cs

@ -22,7 +22,7 @@ namespace Perspex.Direct2D1.RenderTests
public TestBase(string outputPath)
{
string testFiles = Path.GetFullPath(@"..\..\..\TestFiles\Direct2D1");
string testFiles = Path.GetFullPath(@"..\..\..\..\TestFiles\Direct2D1");
this.OutputPath = Path.Combine(testFiles, outputPath);
}

Loading…
Cancel
Save