public void PocoTypeBuilder_AddPropertyAfterCreateType_ShouldThrowInvalidOperationException() { // Arrange PocoModuleBuilder pocoModuleBuilder = new PocoModuleBuilder(); ModuleBuilder moduleBuilder = pocoModuleBuilder.ModuleBuilder; string typeName = "MyType"; PocoTypeBuilder pocoTypeBuilder = new PocoTypeBuilder(moduleBuilder, typeName); string property1Name = "ID"; Type property1Type = typeof(int); string property2Name = "Name"; Type property2Type = typeof(string); // Act + Assert pocoTypeBuilder.AddProperty(property1Name, property1Type); var type = pocoTypeBuilder.CreateType(); Assert.Throws <InvalidOperationException>(() => { pocoTypeBuilder.AddProperty(property2Name, property2Type); }); // Assert Assert.IsNotNull(type); Assert.IsTrue(type.IsClass); Assert.IsFalse(type.IsAbstract); Assert.IsFalse(type.IsSealed); Assert.IsFalse(type.IsGenericType); Assert.AreEqual(typeName, type.Name); Assert.AreEqual(1, type.GetProperties().Length); Assert.AreEqual(property1Name, type.GetProperties()[0].Name); Assert.AreEqual(property1Type, type.GetProperties()[0].PropertyType); }
public void PocoInstanceBuilder_CreateInstance_WithEmptyDictionaryWithReferentTypes_ShouldReturnValidObject() { // Arrange PocoModuleBuilder pocoModuleBuilder = new PocoModuleBuilder(); ModuleBuilder moduleBuilder = pocoModuleBuilder.ModuleBuilder; string typeName = "MyType"; string property1Name = "ID"; object property1Value = new { id = 1 }; Type property1Type = property1Value.GetType(); string property2Name = "Name"; object property2Value = new { name = "My Name" }; Type property2Type = property2Value.GetType(); PocoTypeBuilder pocoTypeBuilder = new PocoTypeBuilder(moduleBuilder, typeName); pocoTypeBuilder.AddProperty(property1Name, property1Type); pocoTypeBuilder.AddProperty(property2Name, property2Type); Type type = pocoTypeBuilder.CreateType(); PocoInstanceBuilder pocoInstanceBuilder = new PocoInstanceBuilder(type); // Act var instance = pocoInstanceBuilder.CreateInstance(new Dictionary <string, object>()); // Assert Assert.IsNotNull(instance); Assert.IsNull(pocoInstanceBuilder.GetValue(instance, property1Name)); Assert.IsNull(pocoInstanceBuilder.GetValue(instance, property2Name)); TestContext.WriteLine($"{instance}"); }
public void PocoInstanceBuilder_CreateInstance_WithNoParameters_ShouldReturnValidObject() { // Arrange PocoModuleBuilder pocoModuleBuilder = new PocoModuleBuilder(); ModuleBuilder moduleBuilder = pocoModuleBuilder.ModuleBuilder; string typeName = "MyType"; string property1Name = "ID"; Type property1Type = typeof(int); string property2Name = "Name"; Type property2Type = typeof(string); PocoTypeBuilder pocoTypeBuilder = new PocoTypeBuilder(moduleBuilder, typeName); pocoTypeBuilder.AddProperty(property1Name, property1Type); pocoTypeBuilder.AddProperty(property2Name, property2Type); Type type = pocoTypeBuilder.CreateType(); PocoInstanceBuilder pocoInstanceBuilder = new PocoInstanceBuilder(type); // Act var instance = pocoInstanceBuilder.CreateInstance(); // Assert Assert.IsNotNull(instance); TestContext.WriteLine($"{instance}"); }
public void PocoTypeBuilder_CreateType_WithTwoProperties_ShouldReturnValidType() { // Arrange PocoModuleBuilder pocoModuleBuilder = new PocoModuleBuilder(); ModuleBuilder moduleBuilder = pocoModuleBuilder.ModuleBuilder; string typeName = "MyType"; PocoTypeBuilder pocoTypeBuilder = new PocoTypeBuilder(moduleBuilder, typeName); string property1Name = "ID"; Type property1Type = typeof(int); string property2Name = "Name"; Type property2Type = typeof(string); // Act pocoTypeBuilder.AddProperty(property1Name, property1Type); pocoTypeBuilder.AddProperty(property2Name, property2Type); var type = pocoTypeBuilder.CreateType(); // Assert Assert.IsNotNull(type); Assert.IsTrue(type.IsClass); Assert.IsFalse(type.IsAbstract); Assert.IsFalse(type.IsSealed); Assert.IsFalse(type.IsGenericType); Assert.AreEqual(typeName, type.Name); Assert.AreEqual(2, type.GetProperties().Length); Assert.AreEqual(property1Name, type.GetProperties()[0].Name); Assert.AreEqual(property1Type, type.GetProperties()[0].PropertyType); Assert.AreEqual(property2Name, type.GetProperties()[1].Name); Assert.AreEqual(property2Type, type.GetProperties()[1].PropertyType); TestContext.WriteLine(type.Name); TestContext.WriteLine(type.FullName); }
public void PocoModuleBuilder_WithDefaultConstructor_ShouldReturnObjectWithValidAssemblyName() { // Arrange + Act var instance = new PocoModuleBuilder(); // Assert Assert.IsFalse(string.IsNullOrWhiteSpace(instance.AssemblyName.Name)); }
public void PocoModuleBuilder_WithDefaultConstructor_ShouldReturnValidObject() { // Arrange + Act var instance = new PocoModuleBuilder(); // Assert Assert.IsNotNull(instance); }
public void PocoModuleBuilder_WithDefaultConstructor_ShouldReturnObjectWithValidProperties() { // Arrange + Act var instance = new PocoModuleBuilder(); // Assert Assert.IsNotNull(instance.AssemblyName); Assert.IsNotNull(instance.AssemblyBuilder); Assert.IsNotNull(instance.ModuleBuilder); }
public void PocoModuleBuilder_WithConstructorWithValidName_ShouldReturnObjectWithValidAssemblyName() { // Arrange string name = "MyAssembly"; // Act var instance = new PocoModuleBuilder(name); // Assert Assert.AreEqual(name, instance.AssemblyName.Name); }
public void PocoModuleBuilder_WithConstructorWithValidName_ShouldReturnValidObject() { // Arrange string name = "MyAssembly"; // Act var instance = new PocoModuleBuilder(name); // Assert Assert.IsNotNull(instance); }
public void PocoModuleBuilder_WithConstructorWithValidAssemblyName_ShouldReturnObjectWithValidAssemblyName() { // Arrange AssemblyName assemblyName = new AssemblyName("MyAssembly"); // Act var instance = new PocoModuleBuilder(assemblyName); // Assert Assert.AreEqual(assemblyName.FullName, instance.AssemblyName.Name); Assert.AreSame(assemblyName, instance.AssemblyName); }
public void PocoTypeBuilder_ConstructorWithValidModuleBuilder_ShouldReturnValidObject() { // Arrange PocoModuleBuilder pocoModuleBuilder = new PocoModuleBuilder(); ModuleBuilder moduleBuilder = pocoModuleBuilder.ModuleBuilder; // Act var instance = new PocoTypeBuilder(moduleBuilder); // Assert Assert.IsNotNull(instance); }
public void PocoModuleBuilder_WithConstructorWithNullAssemblyName_ShouldThrowArgumentNullException() { // Arrange AssemblyName name = null; // Act + Assert var ex = Assert.Catch <ArgumentNullException>(() => { _ = new PocoModuleBuilder(name); }); Assert.AreEqual("assemblyName", ex.ParamName); }
public void PocoModuleBuilder_WithConstructorWithValidAssemblyName_ShouldReturnObjectWithValidProperties() { // Arrange AssemblyName assemblyName = new AssemblyName("MyAssembly"); // Act var instance = new PocoModuleBuilder(assemblyName); // Assert Assert.IsNotNull(instance.AssemblyName); Assert.IsNotNull(instance.AssemblyBuilder); Assert.IsNotNull(instance.ModuleBuilder); }
public void PocoTypeBuilder_ConstructorWithValidModuleBuilderAndEmptyTypeName_ShouldThrowArgumentNullException() { // Arrange PocoModuleBuilder pocoModuleBuilder = new PocoModuleBuilder(); ModuleBuilder moduleBuilder = pocoModuleBuilder.ModuleBuilder; string typeName = string.Empty; // Act + Assert var ex = Assert.Throws <ArgumentNullException>(() => { _ = new PocoTypeBuilder(moduleBuilder, typeName); }); Assert.AreEqual("typeName", ex.ParamName); }
public void PocoTypeBuilder_AddProperty_WithValidPropertyNameAndValidPropertyType_ShouldWork() { // Arrange PocoModuleBuilder pocoModuleBuilder = new PocoModuleBuilder(); ModuleBuilder moduleBuilder = pocoModuleBuilder.ModuleBuilder; string typeName = "MyType"; PocoTypeBuilder pocoTypeBuilder = new PocoTypeBuilder(moduleBuilder, typeName); string propertyName = "ID"; Type propertyType = typeof(int); // Act + Assert Assert.DoesNotThrow(() => { pocoTypeBuilder.AddProperty(propertyName, propertyType); }); }
public void PocoTypeBuilder_AddProperty_WithEmptyPropertyNameAndNullPropertyType_ShouldThrowArgumentNullException() { // Arrange PocoModuleBuilder pocoModuleBuilder = new PocoModuleBuilder(); ModuleBuilder moduleBuilder = pocoModuleBuilder.ModuleBuilder; string typeName = "MyType"; PocoTypeBuilder pocoTypeBuilder = new PocoTypeBuilder(moduleBuilder, typeName); string propertyName = string.Empty; Type propertyType = null; // Act + Assert var ex = Assert.Throws <ArgumentNullException>(() => { pocoTypeBuilder.AddProperty(propertyName, propertyType); }); Assert.AreEqual("propertyName", ex.ParamName); }
public void PocoTypeBuilder_CreateType_WithNoProperties_ShouldReturnValidType() { // Arrange PocoModuleBuilder pocoModuleBuilder = new PocoModuleBuilder(); ModuleBuilder moduleBuilder = pocoModuleBuilder.ModuleBuilder; string typeName = "MyType"; PocoTypeBuilder pocoTypeBuilder = new PocoTypeBuilder(moduleBuilder, typeName); // Act var type = pocoTypeBuilder.CreateType(); // Assert Assert.IsNotNull(type); Assert.IsTrue(type.IsClass); Assert.IsFalse(type.IsAbstract); Assert.IsFalse(type.IsSealed); Assert.IsFalse(type.IsGenericType); Assert.AreEqual(typeName, type.Name); TestContext.WriteLine(type.Name); TestContext.WriteLine(type.FullName); }
public void PocoInstanceBuilder_CreateInstance_WithValidDictionary_ShouldReturnValidObject() { // Arrange PocoModuleBuilder pocoModuleBuilder = new PocoModuleBuilder(); ModuleBuilder moduleBuilder = pocoModuleBuilder.ModuleBuilder; string typeName = "MyType"; string property1Name = "ID"; Type property1Type = typeof(int); object property1Value = 1; string property2Name = "Name"; Type property2Type = typeof(string); object property2Value = "My Name"; PocoTypeBuilder pocoTypeBuilder = new PocoTypeBuilder(moduleBuilder, typeName); pocoTypeBuilder.AddProperty(property1Name, property1Type); pocoTypeBuilder.AddProperty(property2Name, property2Type); Type type = pocoTypeBuilder.CreateType(); PocoInstanceBuilder pocoInstanceBuilder = new PocoInstanceBuilder(type); // Act var instance = pocoInstanceBuilder.CreateInstance(new Dictionary <string, object> { { property2Name, property2Value }, { property1Name, property1Value }, }); // Assert Assert.IsNotNull(instance); Assert.AreEqual(property1Value, pocoInstanceBuilder.GetValue(instance, property1Name)); Assert.AreEqual(property2Value, pocoInstanceBuilder.GetValue(instance, property2Name)); TestContext.WriteLine($"{instance}"); }