public void AddMultipleInterfaceNotFullyQualifiedTest() { var editor = new InterfaceEditor { TypeNameWriter = new TypeNameWriter(false), EntityType = MockUtilities.CreateEntityMock().Object, AllElements = new List <IWritableElement> { new InterfaceElement(typeof(IAttributeTaggedEntityConventionDateTimeProperty)), new InterfaceElement(typeof(IAttributeTaggedEntityConventionNullableIntProperty)) } }; var edited = editor.EditEntity(@"using System; public partial class Entity { }"); var expected = @"using System; public partial class Entity : IAttributeTaggedEntityConventionDateTimeProperty, IAttributeTaggedEntityConventionNullableIntProperty { }"; Assert.Equal(expected, edited); }
public void AddNothingTest() { var editor = new InterfaceEditor { TypeNameWriter = new TypeNameWriter(false), EntityType = MockUtilities.CreateEntityMock().Object, AllElements = new List <IWritableElement> { new PropertyAttributeElement() } }; var edited = editor.EditEntity(@"using System; public partial class Entity { }"); var expected = @"using System; public partial class Entity { }"; Assert.Equal(expected, edited); }
public void DoNotAddUsingWhenConflictingNamesUnitTest() { var entityType = MockUtilities.CreateEntityMock(typeof(int?), "Value").Object; var editor = new NamespaceEditor { EntityType = MockUtilities.CreateEntityMock().Object, AllElements = new List <IWritableElement> { new InterfaceElement(typeof(EntityScaffolding.Tests.DummyClasses.MoreAgain.IConflictingName)), new InterfaceElement(typeof(EntityScaffolding.Tests.DummyClasses.More.IConflictingName)) } }; var edited = editor.EditEntity(@"using System; namespace EntityScaffolding.Tests.Models { Class }"); var expected = $@"using System; namespace EntityScaffolding.Tests.Models {{ Class }}"; Assert.Equal(expected, edited); Assert.True(editor.TypeNameWriter.RequiresFullyQualifiedNames); }
public void DoNotAddUsingWhenInNameSpaceUnitTest() { var entityType = MockUtilities.CreateEntityMock(typeof(int?), "Value").Object; var editor = new NamespaceEditor { EntityType = MockUtilities.CreateEntityMock().Object, AllElements = new List <IWritableElement> { new InterfaceElement(typeof(IAttributeTaggedEntityConventionDateTimeProperty)) } }; var edited = editor.EditEntity(@"using System; namespace EntityScaffolding.Tests.DummyClasses.Models { Class }"); var expected = $@"using System; namespace EntityScaffolding.Tests.DummyClasses.Models {{ Class }}"; Assert.Equal(expected, edited); Assert.False(editor.TypeNameWriter.RequiresFullyQualifiedNames); }
public void AddNothingTest() { var entityType = MockUtilities.CreateEntityMock(typeof(int), "Value").Object; var editor = new PropertyAttributeEditor { TypeNameWriter = new TypeNameWriter(false), EntityType = entityType, AllElements = new List <IWritableElement> { new InterfaceElement(typeof(IAttributeTaggedEntityConventionDateTimeProperty)) } }; var edited = editor.EditEntity(@"using System; public partial class Entity { public int Value { get; set; } }"); var expected = @"using System; public partial class Entity { public int Value { get; set; } }"; Assert.Equal(expected, edited); }
public void AddSingleUsingStatement() { var entityType = MockUtilities.CreateEntityMock(typeof(int?), "Value").Object; var editor = new NamespaceEditor { EntityType = MockUtilities.CreateEntityMock().Object, AllElements = new List <IWritableElement> { new PropertyAttributeElement { Attribute = typeof(DummyAttribute) } } }; var edited = editor.EditEntity(@"using System; namespace EntityScaffolding.Tests.Models { Class }"); var expected = $@"using System; using {typeof(DummyAttribute).Namespace}; namespace EntityScaffolding.Tests.Models {{ Class }}"; Assert.Equal(expected, edited); Assert.False(editor.TypeNameWriter.RequiresFullyQualifiedNames); }
public void ApplyingInterfaceWriterSameNamespaceTest() { var helper = new Mock <ICSharpHelper>(); var entityType = MockUtilities.CreateEntityMock(typeof(string), "CustomProperty"); var generator = new ConventionEntityTypeGeneratorMock(helper.Object, @"public partial class Entity { public string CustomProperty { get; set; } }"); var entity = generator.WriteCode(entityType.Object, "EntityScaffolding.Tests.DummyClasses.Models", false); var expected = @"using System; using System.Collections.Generic; namespace EntityScaffolding.Tests.DummyClasses.Models { public partial class Entity : IAttributeTaggedEntityConventionStringProperty { public string CustomProperty { get; set; } } } "; Assert.Equal(expected, entity); }
public void CustomInterfaceConventionPickedUppedAndMatchesEntity (Type propertyType, string propertyName, Type conventionType) { var entityMock = MockUtilities.CreateEntityMock(propertyType, propertyName); var configuration = new ConventionConfiguration(); var elements = configuration.ConventionMatchers.FindApplicableConventions(entityMock.Object).ToList(); Assert.Single(elements); Assert.Equal(conventionType, (elements.Single() as InterfaceElement)?.InterfaceType); }
public void ConventionPickedUppedAndMatchesEntity() { var entityMock = MockUtilities.CreateEntityMock(typeof(string), "Something"); MockEntityInterfaceConventionMatcher.AppliesToEntityFunction = e => e == entityMock.Object ? new InterfaceElement(typeof(IDummyInterface1)) : null; var configuration = new ConventionConfiguration(); var elements = configuration.ConventionMatchers.FindApplicableConventions(entityMock.Object).ToList(); Assert.Single(elements); Assert.Equal(typeof(IDummyInterface1), (elements.Single() as InterfaceElement)?.InterfaceType); }
public void AddMultipleInterfaceNotFullyQualifiedTest() { var entityType = MockUtilities.CreateEntityMock(typeof(int), "Value").Object; var editor = new PropertyAttributeEditor { TypeNameWriter = new TypeNameWriter(false), EntityType = entityType, AllElements = new List <IWritableElement> { new PropertyAttributeElement { Attribute = typeof(DummyAttribute), AttributeValues = new List <string> { "1001", "\"string\"" }, Property = entityType.GetProperties().Single() }, new PropertyAttributeElement { Attribute = typeof(Dummy2Attribute), Property = entityType.GetProperties().Single() } } }; var edited = editor.EditEntity(@"using System; public partial class Entity { public int Value { get; set; } }"); var expected = @"using System; public partial class Entity { [Dummy(1001, ""string"")] [Dummy2] public int Value { get; set; } }"; Assert.Equal(expected, edited); }
public void ApplyingPropertyAttributeParameterWriterTest() { var helper = new Mock <ICSharpHelper>(); var entityType = MockUtilities.CreateEntityMock(typeof(string), "ApplyHere"); MockEntityPropertyAttributeConventionMatcher.AppliesToEntityFunction = e => e == entityType.Object ? new PropertyAttributeElement { Attribute = typeof(DummyAttribute), Property = entityType.Object.GetProperties().Single(), AttributeValues = new List <string> { "1101" } } : null; var generator = new ConventionEntityTypeGeneratorMock(helper.Object, @"public partial class Entity { public string ApplyHere { get; set; } }"); var entity = generator.WriteCode(entityType.Object, "EntityScaffolding.Tests.DummyClasses.Models", false); var expected = @"using System; using System.Collections.Generic; namespace EntityScaffolding.Tests.DummyClasses.Models { public partial class Entity { [Dummy(1101)] public string ApplyHere { get; set; } } } "; Assert.Equal(expected, entity); }