public void CorrectSelectCommandWithWhere(Type fixtureType, Type tableDescriptorType) { var fixture = Activator.CreateInstance(fixtureType) as CommandBuilderFixtureBase; var commandBuilderFactory = fixture.Connector.GetCommandBuilderFactory(); var tableDescription = new TableTypeDescriptor(tableDescriptorType); using (var selectCommand = commandBuilderFactory.CreateSelectCommandBuilder(tableDescription)) { selectCommand.GetCommand(fixture.SelectWhereClause).CommandText.Should().Be(fixture.SelectWithWhereQuery); } }
public void CorrectSelectOneCommandShouldThrowArgumentNullException(Type fixtureType, Type tableDescriptorType) { var fixture = Activator.CreateInstance(fixtureType) as CommandBuilderFixtureBase; var commandBuilderFactory = fixture.Connector.GetCommandBuilderFactory(); var tableDescription = new TableTypeDescriptor(tableDescriptorType); using (var selectCommand = commandBuilderFactory.CreateSelectOneCommandBuilder(tableDescription)) { Action select = () => selectCommand.GetCommand(null); select.ShouldThrow <ArgumentNullException>(); } }
public void CorrectDeleteCommandTwoEntities(Type fixtureType, Type tableDescriptorType) { var fixture = Activator.CreateInstance(fixtureType) as CommandBuilderFixtureBase; var commandBuilderFactory = fixture.Connector.GetCommandBuilderFactory(); var tableDescription = new TableTypeDescriptor(tableDescriptorType); var entitiesToDelete = new[] { fixture.Entity1, fixture.Entity2 }; var valueProvider = new ClassValueProvider(fixture.Connector, entitiesToDelete.Cast <object>().ToList()); using (var deleteCommand = commandBuilderFactory.CreateDeleteCommandBuilder(tableDescription)) { deleteCommand.GetCommand(valueProvider).CommandText.Should().Be(fixture.DeleteTwoEntitiesQuery); } }
public void CorrectSelectOneCommand(Type fixtureType, Type tableDescriptorType) { var fixture = Activator.CreateInstance(fixtureType) as CommandBuilderFixtureBase; var commandBuilderFactory = fixture.Connector.GetCommandBuilderFactory(); var tableDescription = new TableTypeDescriptor(tableDescriptorType); using (var selectCommand = commandBuilderFactory.CreateSelectOneCommandBuilder(tableDescription)) { var command = selectCommand.GetCommand(723); var parameters = command.Parameters.ToList(); command.CommandText.Should().Be(fixture.SelectOneQuery); parameters.Should().HaveCount(1); parameters[0].Value.Should().Be(723); } }
public void CorrectUpdateCommand(Type fixtureType, Type tableDescriptorType) { var fixture = Activator.CreateInstance(fixtureType) as CommandBuilderFixtureBase; var commandBuilderFactory = fixture.Connector.GetCommandBuilderFactory(); var tableDescription = new TableTypeDescriptor(tableDescriptorType); var entityToUpdate = fixture.Entity1; entityToUpdate.Name = "John Doe Junior"; entityToUpdate.Amount = 7200m; var valueProvider = new ClassValueProvider(fixture.Connector, new List <object> { entityToUpdate }); valueProvider.MoveNext(); using (var updateCommand = commandBuilderFactory.CreateUpdateCommandBuilder(tableDescription)) { var command = updateCommand.GetCommand(valueProvider); var parameters = command.Parameters.ToList(); command.CommandText.Should().Be(fixture.UpdateQuery); if (fixtureType == typeof(CqlCommandBuilderFixture)) { parameters.Should().HaveCount(5); parameters.Sort((x, y) => string.CompareOrdinal(x.ParameterName, y.ParameterName)); parameters[0].Value.Should().Be(7200m); parameters[2].Value.Should().Be(fixture.Entity1.Id); parameters[3].Value.Should().Be(fixture.Entity1.IsActive); parameters[4].Value.Should().Be("John Doe Junior"); } else { parameters.Should().HaveCount(5); parameters.Sort((x, y) => string.CompareOrdinal(x.ParameterName, y.ParameterName)); parameters[0].Value.Should().Be(7200m); parameters[1].Value.Should().Be(fixture.Entity1.CreatedDate); parameters[2].Value.Should().Be(fixture.Entity1.Id); parameters[3].Value.Should().Be(fixture.Entity1.IsActive); parameters[4].Value.Should().Be("John Doe Junior"); } } }
public void CorrectInsertCommand(Type fixtureType, Type tableDescriptorType) { var fixture = Activator.CreateInstance(fixtureType) as CommandBuilderFixtureBase; var commandBuilderFactory = fixture.Connector.GetCommandBuilderFactory(); var tableDescription = new TableTypeDescriptor(tableDescriptorType); var valueProvider = new ClassValueProvider(fixture.Connector, new List <object> { fixture.Entity1 }); valueProvider.MoveNext(); using (var insertCommand = commandBuilderFactory.CreateInsertCommandBuilder(tableDescription)) { var command = insertCommand.GetCommand(valueProvider); var parameters = command.Parameters.ToList(); command.CommandText.Should().Be(fixture.InsertQuery); if (fixtureType == typeof(CqlCommandBuilderFixture)) { parameters.Should().HaveCount(5); parameters.Sort((x, y) => string.CompareOrdinal(x.ParameterName, y.ParameterName)); parameters[0].Value.Should().Be(3600m); parameters[3].Value.Should().Be(true); parameters[4].Value.Should().Be("John Doe"); } else { parameters.Should().HaveCount(4); parameters.Sort((x, y) => string.CompareOrdinal(x.ParameterName, y.ParameterName)); parameters[0].Value.Should().Be(3600m); parameters[1].Value.Should().Be(new DateTime(2017, 5, 23, 13, 55, 43, 0)); parameters[2].Value.Should().Be(true); parameters[3].Value.Should().Be("John Doe"); } } }
public void ShouldInheritPropertyMappings() { var salesOrderDescriptor = new TableTypeDescriptor(typeof(SalesOrder)); var purchaseOrderDescriptor = new TableTypeDescriptor(typeof(PurchaseOrder)); salesOrderDescriptor.AllProperties.Should().HaveCount(7); purchaseOrderDescriptor.AllProperties.Should().HaveCount(7); salesOrderDescriptor.AllProperties[0].PropertyName.Should().Be(nameof(SalesOrder.Number)); salesOrderDescriptor.AllProperties[1].PropertyName.Should().Be(nameof(SalesOrder.CustomerPurchaseOrderNumber)); salesOrderDescriptor.AllProperties[2].PropertyName.Should().Be(nameof(SalesOrder.CustomerName)); salesOrderDescriptor.AllProperties[3].PropertyName.Should().Be(nameof(AuditBase.CreationUserId)); salesOrderDescriptor.AllProperties[4].PropertyName.Should().Be(nameof(AuditBase.CreationDate)); salesOrderDescriptor.AllProperties[5].PropertyName.Should().Be(nameof(AuditBase.ModificationUserId)); salesOrderDescriptor.AllProperties[6].PropertyName.Should().Be(nameof(AuditBase.ModificationDate)); purchaseOrderDescriptor.AllProperties[0].PropertyName.Should().Be(nameof(PurchaseOrder.Number)); purchaseOrderDescriptor.AllProperties[1].PropertyName.Should().Be(nameof(PurchaseOrder.VendorSalesOrderNumber)); purchaseOrderDescriptor.AllProperties[2].PropertyName.Should().Be(nameof(PurchaseOrder.VendorName)); purchaseOrderDescriptor.AllProperties[3].PropertyName.Should().Be(nameof(AuditBase.CreationUserId)); purchaseOrderDescriptor.AllProperties[4].PropertyName.Should().Be(nameof(AuditBase.CreationDate)); purchaseOrderDescriptor.AllProperties[5].PropertyName.Should().Be(nameof(AuditBase.ModificationUserId)); purchaseOrderDescriptor.AllProperties[6].PropertyName.Should().Be(nameof(AuditBase.ModificationDate)); }
public ColumnPropertyDescriptorTest() { // We instantiate a TableTypeDescriptor object because ColumnPropertyDescriptor // is declared as internal, therefore we test it through TableTypeDescriptor ClientTableTypeDescription = new TableTypeDescriptor(typeof(Client)); }
public TableTypeDescriptorTest() { // We set up this as a class property because we use it in almost every test (excepting one) ClientTableTypeDescription = new TableTypeDescriptor(typeof(Client)); }