Skip to content

Commit

Permalink
Add base reflection test
Browse files Browse the repository at this point in the history
  • Loading branch information
toxis committed Oct 10, 2016
1 parent 135ba9b commit 586cee8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
4 changes: 2 additions & 2 deletions CSharpWorkspace/BaseTests/BaseTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
<Otherwise />
</Choose>
<ItemGroup>
<Compile Include="Delegates\Entity.cs" />
<Compile Include="Common\Entity.cs" />
<Compile Include="Delegates\Test.cs" />
<Compile Include="NUnitTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Reflections\Test.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Reflections\" />
<Folder Include="Tasks\" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace BaseTests.Delegates
namespace BaseTests.Common
{
public class Entity<T>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using NUnit.Framework;
using BaseTests.Common;

namespace BaseTests.Delegates
{
Expand Down
39 changes: 39 additions & 0 deletions CSharpWorkspace/BaseTests/Reflections/BaseReflectionTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using BaseTests.Common;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BaseTests.Reflections
{
[TestFixture]
public class Test
{
private Entity<string> _entity;
private const string HelloReflection = "Hello Reflection";

[SetUp]
public void Setup()
{
_entity = new Entity<string>();
_entity.Data = HelloReflection;
}

[Test]
public void PropertyTest()
{
var properties = _entity.GetType().GetProperties();
Assert.AreEqual(properties.Count(), 1);
var propertyInfo = properties.Single();
Assert.AreEqual(propertyInfo.Name, nameof(_entity.Data));
var value = propertyInfo.GetValue(_entity);
Assert.AreEqual(value, HelloReflection);

var newValue = "New Value";
propertyInfo.SetValue(_entity, newValue);
Assert.AreEqual(newValue, _entity.Data);
}
}
}

0 comments on commit 586cee8

Please sign in to comment.