Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHilus committed Mar 27, 2017
1 parent 22a49fd commit ab0dc28
Show file tree
Hide file tree
Showing 7 changed files with 537 additions and 3 deletions.
48 changes: 48 additions & 0 deletions src/Nitrolize.Tests/ComplexGraphTypeExtensionsSpecification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using FluentAssertions;
using GraphQL.Types;
using Machine.Fakes;
using Machine.Specifications;
using Nitrolize.Extensions;
using Nitrolize.Types;
using System;

namespace Nitrolize.Tests
{
[Subject(typeof(ComplexGraphTypeExtensions))]
public class ComplexGraphTypeExtensionsSpecification : WithSubject<Object>
{
public class TestGraphType : ObjectGraphType
{
}

public class SomeModel
{
public Guid Id { get; set; }
}

protected static TestGraphType Result;

Establish context = () => Result = new TestGraphType();
}

public class When_adding_a_single_field : ComplexGraphTypeExtensionsSpecification
{
Because of = () => Result.AddSingleField<SomeModel, NodeObjectType<SomeModel>>(context => null);

It should_have_added_the_single_field = () => Result.Fields.Should().Contain(f => f.Name == "someModel");
}

public class When_adding_a_list_field : ComplexGraphTypeExtensionsSpecification
{
Because of = () => Result.AddListField<SomeModel, NodeObjectType<SomeModel>>();

It should_have_added_the_list_field = () => Result.Fields.Should().Contain(f => f.Name == "someModels");
}

public class When_adding_a_connection_field : ComplexGraphTypeExtensionsSpecification
{
Because of = () => Result.AddConnectionField<SomeModel, NodeObjectType<SomeModel>>(context => null);

It should_have_added_the_list_field = () => Result.Fields.Should().Contain(f => f.Name == "someModels");
}
}
44 changes: 44 additions & 0 deletions src/Nitrolize.Tests/EnumerationTypeSpecification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using FluentAssertions;
using Machine.Fakes;
using Machine.Specifications;
using Nitrolize.Types;
using System.Linq;

namespace Nitrolize.Tests
{
public enum ExampleEnum
{
ExampleValue = 10,
EliteValue = 1337,
FailValue = 1338
}

[Subject(typeof(EnumerationType<ExampleEnum>))]
public class EnumerationTypeSpecification : WithSubject<EnumerationType<ExampleEnum>>
{
}

public class When_creating_the_type : EnumerationTypeSpecification
{
protected static EnumerationType<ExampleEnum> Result;

Because of = () =>
{
Result = new EnumerationType<ExampleEnum>();
};

It should_set_correct_name = () => Result.Name.Should().Be("ExampleEnum");

It should_create_all_values = () =>
{
Result.Values.ToList()[0].Name.ShouldBeEquivalentTo("ExampleValue");
Result.Values.ToList()[0].Value.ShouldBeEquivalentTo(10);

Result.Values.ToList()[1].Name.ShouldBeEquivalentTo("EliteValue");
Result.Values.ToList()[1].Value.ShouldBeEquivalentTo(1337);

Result.Values.ToList()[2].Name.ShouldBeEquivalentTo("FailValue");
Result.Values.ToList()[2].Value.ShouldBeEquivalentTo(1338);
};
}
}
31 changes: 31 additions & 0 deletions src/Nitrolize.Tests/InputGraphTypeExtensionsSpecification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using FluentAssertions;
using Machine.Fakes;
using Machine.Specifications;
using Nitrolize.Extensions;
using Nitrolize.Types.Input;
using System;

namespace Nitrolize.Tests
{
[Subject(typeof(InputObjectGraphTypeExtensions))]
public class InputObjectGraphTypeExtensionsSpecification : WithSubject<Object>
{
public class TestGraphType : InputType<SomeModel>
{
}

public class SomeModel
{
public string SomeProperty { get; set; }
}

protected static TestGraphType Result;
}

public class When_instantiating_an_input_type : InputObjectGraphTypeExtensionsSpecification
{
Because of = () => Result = new TestGraphType();

It should_have_added_all_simple_fields_from_its_model = () => Result.Fields.Should().Contain(f => f.Name == "someProperty");
}
}
7 changes: 4 additions & 3 deletions src/Nitrolize.Tests/Nitrolize.Tests.xproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>969334e4-92f2-442d-a347-cb31f1e21e8a</ProjectGuid>
Expand All @@ -13,9 +12,11 @@
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
</Project>
116 changes: 116 additions & 0 deletions src/Nitrolize.Tests/ObjectExtensionsSpecification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using FluentAssertions;
using Machine.Fakes;
using Machine.Specifications;
using Nitrolize.Extensions;
using Nitrolize.Identification;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;

namespace Nitrolize.Tests
{
[Subject(typeof(ObjectExtensions))]
public class ObjectExtensionsSpecification : WithSubject<Object>
{
}

public class When_cloning_an_opject : ObjectExtensionsSpecification
{
[TypeDescriptionProvider(typeof(Guid))]
public class ModelA
{
public string Id { get; set; }
public double DoubleValue { get; set; }
public List<ItemA> Items { get; set; }
public List<ItemA> NullItems { get; set; }

private string privateField = "private field";
public string PrivateField
{
get
{
return this.privateField;
}
}

private List<ItemA> fieldItems = new[] { new ItemA { Id = GlobalId.ToGlobalId("ItemB", "1338"), Value = 1338 } }.ToList();
public List<ItemA> FieldItems
{
get
{
return this.fieldItems;
}
}
}

[TypeDescriptionProvider(typeof(int))]
public class ItemA
{
public string Id { get; set; }
public int Value { get; set; }
}

public class ModelB
{
public Guid Id { get; set; }
public double DoubleValue { get; set; }
public List<ItemB> Items { get; set; }
public List<ItemB> NullItems { get; set; }

private string privateField;
public string PrivateField
{
get
{
return this.privateField;
}
}

private List<ItemB> fieldItems;
public List<ItemB> FieldItems
{
get
{
return fieldItems;
}
}
}

public class ItemB
{
public int Id { get; set; }
public int Value { get; set; }
}

protected static ModelA A;

Establish context = () => A = new ModelA
{
Id = GlobalId.ToGlobalId("ModelB", "0a25a77b-d43f-4744-8095-ff5567797082"),
DoubleValue = 13.37,
Items = new[] { new ItemA { Id = GlobalId.ToGlobalId("ItemB", "1337"), Value = 1337 } }.ToList()
};

protected static ModelB Result;

Because of = () => Result = A.CloneAs<ModelB>();

It should_have_converted_simple_properties = () => Result.DoubleValue.Should().Be(13.37);

It should_have_converted_id_property = () => Result.Id.Should().Be(Guid.Parse("0a25a77b-d43f-4744-8095-ff5567797082"));

It should_have_cloned_list_properties = () => Result.Items.Should().NotBeNull();

It should_have_cloned_list_items = () => Result.Items.Should().NotBeEmpty();

It should_have_cloned_properties_of_list_items = () => Result.Items[0].Value.Should().Be(1337);

It should_have_skipped_null_lists = () => Result.NullItems.Should().BeNull();

It should_have_cloned_fields = () => Result.PrivateField.Should().Be("private field");

It should_have_cloned_field_lists = () => Result.FieldItems.Should().NotBeNull();
}
}
48 changes: 48 additions & 0 deletions src/Nitrolize.Tests/ObjectGraphTypeExtensionsSpecification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using FluentAssertions;
using Machine.Fakes;
using Machine.Specifications;
using Nitrolize.Extensions;
using Nitrolize.Types;
using System;

namespace Nitrolize.Tests
{
[Subject(typeof(ObjectGraphTypeExtensions))]
public class ObjectGraphTypeExtensionsSpecification : WithSubject<Object>
{
public class TestGraphType : NodeObjectType<SomeModel>
{
}

public class SomeModel
{
public bool BoolProperty { get; set; }
public Guid GuidProperty { get; set; }
public string StringProperty { get; set; }
public int IntProperty { get; set; }
public decimal DecimalProperty { get; set; }
public float FloatProperty { get; set; }
public double DoubleProperty { get; set; }
public DateTime DateTimeProperty { get; set; }
}

protected static TestGraphType Result;
}

public class When_instantiating_an_object_type : ObjectGraphTypeExtensionsSpecification
{
Because of = () => Result = new TestGraphType();

It should_have_added_all_primitive_fields_from_its_model = () =>
{
Result.Fields.Should().Contain(f => f.Name == "boolProperty");
Result.Fields.Should().Contain(f => f.Name == "guidProperty");
Result.Fields.Should().Contain(f => f.Name == "stringProperty");
Result.Fields.Should().Contain(f => f.Name == "intProperty");
Result.Fields.Should().Contain(f => f.Name == "decimalProperty");
Result.Fields.Should().Contain(f => f.Name == "floatProperty");
Result.Fields.Should().Contain(f => f.Name == "doubleProperty");
Result.Fields.Should().Contain(f => f.Name == "dateTimeProperty");
};
}
}
Loading

0 comments on commit ab0dc28

Please # to comment.