-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22a49fd
commit ab0dc28
Showing
7 changed files
with
537 additions
and
3 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/Nitrolize.Tests/ComplexGraphTypeExtensionsSpecification.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
src/Nitrolize.Tests/InputGraphTypeExtensionsSpecification.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
48
src/Nitrolize.Tests/ObjectGraphTypeExtensionsSpecification.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}; | ||
} | ||
} |
Oops, something went wrong.