本文整理汇总了C#中MicroLite.Tests.TestEntities.Customer类的典型用法代码示例。如果您正苦于以下问题:C# Customer类的具体用法?C# Customer怎么用?C# Customer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Customer类属于MicroLite.Tests.TestEntities命名空间,在下文中一共展示了Customer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteInstanceReturnsFalseIfNoRecordsDeleted
public void DeleteInstanceReturnsFalseIfNoRecordsDeleted()
{
var customer = new Customer
{
Id = 14556
};
var mockCommand = new Mock<IDbCommand>();
mockCommand.Setup(x => x.ExecuteNonQuery()).Returns(0);
mockCommand.As<IDisposable>().Setup(x => x.Dispose());
var mockSqlDialect = new Mock<ISqlDialect>();
mockSqlDialect.Setup(x => x.BuildDeleteSqlQuery(It.IsNotNull<IObjectInfo>(), customer.Id)).Returns(new SqlQuery(""));
var mockDbDriver = new Mock<IDbDriver>();
mockDbDriver.Setup(x => x.GetConnection(ConnectionScope.PerTransaction)).Returns(new Mock<IDbConnection>().Object);
mockDbDriver.Setup(x => x.BuildCommand(It.IsNotNull<SqlQuery>())).Returns(mockCommand.Object);
var session = new Session(
ConnectionScope.PerTransaction,
mockSqlDialect.Object,
mockDbDriver.Object,
new IListener[0]);
Assert.False(session.Delete(customer));
mockSqlDialect.VerifyAll();
mockDbDriver.VerifyAll();
mockCommand.VerifyAll();
}
示例2: InsertInstanceQueryForIdentifierStrategyAssigned
public void InsertInstanceQueryForIdentifierStrategyAssigned()
{
ObjectInfo.MappingConvention = new ConventionMappingConvention(
UnitTest.GetConventionMappingSettings(IdentifierStrategy.Assigned));
var customer = new Customer
{
Created = new DateTime(2011, 12, 24),
CreditLimit = 10500.00M,
DateOfBirth = new System.DateTime(1975, 9, 18),
Id = 134875,
Name = "Joe Bloggs",
Status = CustomerStatus.Active,
Updated = DateTime.Now,
Website = new Uri("http://microliteorm.wordpress.com")
};
var sqlDialect = new MySqlDialect();
var sqlQuery = sqlDialect.BuildInsertSqlQuery(ObjectInfo.For(typeof(Customer)), customer);
Assert.Equal("INSERT INTO `Sales`.`Customers` (`Created`,`CreditLimit`,`DateOfBirth`,`Id`,`Name`,`CustomerStatusId`,`Website`) VALUES (@p0,@p1,@p2,@p3,@p4,@p5,@p6)", sqlQuery.CommandText);
Assert.Equal(7, sqlQuery.Arguments.Count);
Assert.Equal(customer.Created, sqlQuery.Arguments[0]);
Assert.Equal(customer.CreditLimit, sqlQuery.Arguments[1]);
Assert.Equal(customer.DateOfBirth, sqlQuery.Arguments[2]);
Assert.Equal(customer.Id, sqlQuery.Arguments[3]);
Assert.Equal(customer.Name, sqlQuery.Arguments[4]);
Assert.Equal(1, sqlQuery.Arguments[5]);
Assert.Equal("http://microliteorm.wordpress.com/", sqlQuery.Arguments[6]);
}
示例3: InsertInstanceQueryForIdentifierStrategyDbGenerated
public void InsertInstanceQueryForIdentifierStrategyDbGenerated()
{
ObjectInfo.MappingConvention = new ConventionMappingConvention(
UnitTest.GetConventionMappingSettings(IdentifierStrategy.DbGenerated));
var customer = new Customer
{
Created = new DateTime(2011, 12, 24),
CreditLimit = 10500.00M,
DateOfBirth = new System.DateTime(1975, 9, 18),
Id = 134875,
Name = "Joe Bloggs",
Status = CustomerStatus.Active,
Updated = DateTime.Now,
Website = new Uri("http://microliteorm.wordpress.com")
};
var sqlDialect = new SqlServerCeDialect();
var sqlQuery = sqlDialect.BuildInsertSqlQuery(ObjectInfo.For(typeof(Customer)), customer);
Assert.Equal("INSERT INTO \"Sales\".\"Customers\" (\"Created\",\"CreditLimit\",\"DateOfBirth\",\"Name\",\"CustomerStatusId\",\"Website\") VALUES (@p0,@p1,@p2,@p3,@p4,@p5)", sqlQuery.CommandText);
Assert.Equal(6, sqlQuery.Arguments.Count);
Assert.Equal(customer.Created, sqlQuery.Arguments[0]);
Assert.Equal(customer.CreditLimit, sqlQuery.Arguments[1]);
Assert.Equal(customer.DateOfBirth, sqlQuery.Arguments[2]);
Assert.Equal(customer.Name, sqlQuery.Arguments[3]);
Assert.Equal(1, sqlQuery.Arguments[4]);
Assert.Equal("http://microliteorm.wordpress.com/", sqlQuery.Arguments[5]);
}
示例4: AfterInsertDoesNotSetIdentifierIfExecuteScalarResultIsNullAndIdentifierStrategySequence
public void AfterInsertDoesNotSetIdentifierIfExecuteScalarResultIsNullAndIdentifierStrategySequence()
{
ObjectInfo.MappingConvention = new ConventionMappingConvention(
UnitTest.GetConventionMappingSettings(IdentifierStrategy.Sequence));
var listener = new IdentifierStrategyListener();
var customer = new Customer();
Assert.DoesNotThrow(() => listener.AfterInsert(customer, null));
Assert.Equal(0, customer.Id);
}
示例5: AfterInsertSetsIdentifierValueConvertingItToThePropertyType
public void AfterInsertSetsIdentifierValueConvertingItToThePropertyType()
{
ObjectInfo.MappingConvention = new ConventionMappingConvention(
UnitTest.GetConventionMappingSettings(IdentifierStrategy.DbGenerated));
var customer = new Customer();
decimal scalarResult = 4354;
var listener = new DbGeneratedListener();
listener.AfterInsert(customer, scalarResult);
Assert.Equal(Convert.ToInt32(scalarResult), customer.Id);
}
示例6: AfterInsertSetsIdentifierValue
public void AfterInsertSetsIdentifierValue()
{
ObjectInfo.MappingConvention = new ConventionMappingConvention(
UnitTest.GetConventionMappingSettings(IdentifierStrategy.DbGenerated));
var customer = new Customer();
int scalarResult = 4354;
var listener = new DbGeneratedListener();
listener.AfterInsert(customer, scalarResult);
Assert.Equal(scalarResult, customer.Id);
}
示例7: InsertInstanceQueryForIdentifierStrategyAssigned
public void InsertInstanceQueryForIdentifierStrategyAssigned()
{
ObjectInfo.MappingConvention = new ConventionMappingConvention(
UnitTest.GetConventionMappingSettings(IdentifierStrategy.Assigned));
var sqlDialect = new MsSql2005Dialect();
var customer = new Customer
{
Created = new DateTime(2011, 12, 24),
CreditLimit = 10500.00M,
DateOfBirth = new System.DateTime(1975, 9, 18),
Id = 134875,
Name = "Joe Bloggs",
Status = CustomerStatus.Active,
Updated = DateTime.Now,
Website = new Uri("http://microliteorm.wordpress.com")
};
var sqlQuery = sqlDialect.BuildInsertSqlQuery(ObjectInfo.For(typeof(Customer)), customer);
Assert.Equal("INSERT INTO [Sales].[Customers] ([Created],[CreditLimit],[DateOfBirth],[Id],[Name],[CustomerStatusId],[Website]) VALUES (@p0,@p1,@p2,@p3,@p4,@p5,@p6)", sqlQuery.CommandText);
Assert.Equal(7, sqlQuery.Arguments.Count);
Assert.Equal(DbType.DateTime2, sqlQuery.Arguments[0].DbType);
Assert.Equal(customer.Created, sqlQuery.Arguments[0].Value);
Assert.Equal(DbType.Decimal, sqlQuery.Arguments[1].DbType);
Assert.Equal(customer.CreditLimit, sqlQuery.Arguments[1].Value);
Assert.Equal(DbType.DateTime2, sqlQuery.Arguments[2].DbType);
Assert.Equal(customer.DateOfBirth, sqlQuery.Arguments[2].Value);
Assert.Equal(DbType.Int32, sqlQuery.Arguments[3].DbType);
Assert.Equal(customer.Id, sqlQuery.Arguments[3].Value);
Assert.Equal(DbType.String, sqlQuery.Arguments[4].DbType);
Assert.Equal(customer.Name, sqlQuery.Arguments[4].Value);
Assert.Equal(DbType.Int32, sqlQuery.Arguments[5].DbType);
Assert.Equal((int)customer.Status, sqlQuery.Arguments[5].Value);
Assert.Equal(DbType.String, sqlQuery.Arguments[6].DbType);
Assert.Equal("http://microliteorm.wordpress.com/", sqlQuery.Arguments[6].Value);
}
示例8: DeleteInstanceInvokesListeners
public void DeleteInstanceInvokesListeners()
{
var customer = new Customer
{
Id = 187224
};
var mockSqlDialect = new Mock<ISqlDialect>();
mockSqlDialect.Setup(x => x.BuildDeleteSqlQuery(It.IsNotNull<IObjectInfo>(), customer.Id)).Returns(new SqlQuery(""));
var mockCommand = new Mock<IDbCommand>();
mockCommand.Setup(x => x.ExecuteNonQuery()).Returns(1);
var mockConnection = new Mock<IDbConnection>();
mockConnection.Setup(x => x.CreateCommand()).Returns(mockCommand.Object);
var mockDbDriver = new Mock<IDbDriver>();
mockDbDriver.Setup(x => x.CreateConnection()).Returns(mockConnection.Object);
int counter = 0;
var mockListener1 = new Mock<IDeleteListener>();
mockListener1.Setup(x => x.AfterDelete(customer, 1)).Callback(() => Assert.Equal(4, ++counter));
mockListener1.Setup(x => x.BeforeDelete(customer)).Callback(() => Assert.Equal(1, ++counter));
var mockListener2 = new Mock<IDeleteListener>();
mockListener2.Setup(x => x.AfterDelete(customer, 1)).Callback(() => Assert.Equal(3, ++counter));
mockListener2.Setup(x => x.BeforeDelete(customer)).Callback(() => Assert.Equal(2, ++counter));
var session = new Session(
ConnectionScope.PerTransaction,
mockSqlDialect.Object,
mockDbDriver.Object,
new SessionListeners(
new[] { mockListener1.Object, mockListener2.Object },
new IInsertListener[0],
new IUpdateListener[0]));
session.Delete(customer);
mockListener1.VerifyAll();
mockListener2.VerifyAll();
}
示例9: UpdateInstanceQueryForIdentifierStrategyDbGenerated
public void UpdateInstanceQueryForIdentifierStrategyDbGenerated()
{
ObjectInfo.MappingConvention = new ConventionMappingConvention(
UnitTest.GetConventionMappingSettings(IdentifierStrategy.DbGenerated));
var customer = new Customer
{
Created = new DateTime(2011, 12, 24),
CreditLimit = 10500.00M,
DateOfBirth = new System.DateTime(1975, 9, 18),
Id = 134875,
Name = "Joe Bloggs",
Status = CustomerStatus.Active,
Updated = DateTime.Now,
Website = new Uri("http://microliteorm.wordpress.com")
};
var sqlDialect = new MsSqlDialect();
var sqlQuery = sqlDialect.BuildUpdateSqlQuery(ObjectInfo.For(typeof(Customer)), customer);
Assert.Equal("UPDATE [Sales].[Customers] SET [CreditLimit] = @p0,[DateOfBirth] = @p1,[Name] = @p2,[CustomerStatusId] = @p3,[Updated] = @p4,[Website] = @p5 WHERE [Id] = @p6", sqlQuery.CommandText);
Assert.Equal(7, sqlQuery.Arguments.Count);
Assert.Equal(customer.CreditLimit, sqlQuery.Arguments[0]);
Assert.Equal(customer.DateOfBirth, sqlQuery.Arguments[1]);
Assert.Equal(customer.Name, sqlQuery.Arguments[2]);
Assert.Equal(1, sqlQuery.Arguments[3]);
Assert.Equal(customer.Updated, sqlQuery.Arguments[4]);
Assert.Equal("http://microliteorm.wordpress.com/", sqlQuery.Arguments[5]);
Assert.Equal(customer.Id, sqlQuery.Arguments[6]);
}
示例10: UpdateInstanceReturnsTrueIfRecordUpdated
public void UpdateInstanceReturnsTrueIfRecordUpdated()
{
var customer = new Customer
{
Id = 187224
};
var mockSqlDialect = new Mock<ISqlDialect>();
mockSqlDialect.Setup(x => x.BuildUpdateSqlQuery(It.IsNotNull<IObjectInfo>(), customer)).Returns(new SqlQuery(""));
var mockCommand = new Mock<IDbCommand>();
mockCommand.Setup(x => x.ExecuteNonQuery()).Returns(1);
var mockConnection = new Mock<IDbConnection>();
mockConnection.Setup(x => x.CreateCommand()).Returns(mockCommand.Object);
var mockDbDriver = new Mock<IDbDriver>();
mockDbDriver.Setup(x => x.CreateConnection()).Returns(new MockDbConnectionWrapper(mockConnection.Object));
var session = new AsyncSession(
ConnectionScope.PerTransaction,
mockSqlDialect.Object,
mockDbDriver.Object,
new IDeleteListener[0],
new IInsertListener[0],
new IUpdateListener[0]);
Assert.True(session.UpdateAsync(customer).Result);
mockSqlDialect.VerifyAll();
mockDbDriver.VerifyAll();
mockCommand.VerifyAll();
}
示例11: InsertInvokesListeners
public void InsertInvokesListeners()
{
var customer = new Customer();
object identifier = 23543;
var mockSqlDialect = new Mock<ISqlDialect>();
mockSqlDialect.Setup(x => x.BuildInsertSqlQuery(It.IsNotNull<IObjectInfo>(), customer)).Returns(new SqlQuery(""));
mockSqlDialect.Setup(x => x.BuildSelectInsertIdSqlQuery(It.IsNotNull<IObjectInfo>())).Returns(new SqlQuery(""));
var mockCommand = new Mock<IDbCommand>();
mockCommand.Setup(x => x.ExecuteScalar()).Returns(identifier);
var mockConnection = new Mock<IDbConnection>();
mockConnection.Setup(x => x.CreateCommand()).Returns(mockCommand.Object);
var mockDbDriver = new Mock<IDbDriver>();
mockDbDriver.Setup(x => x.CreateConnection()).Returns(new MockDbConnectionWrapper(mockConnection.Object));
int counter = 0;
var mockListener1 = new Mock<IInsertListener>();
mockListener1.Setup(x => x.AfterInsert(customer, identifier)).Callback(() => Assert.Equal(4, ++counter));
mockListener1.Setup(x => x.BeforeInsert(customer)).Callback(() => Assert.Equal(1, ++counter));
var mockListener2 = new Mock<IInsertListener>();
mockListener2.Setup(x => x.AfterInsert(customer, identifier)).Callback(() => Assert.Equal(3, ++counter));
mockListener2.Setup(x => x.BeforeInsert(customer)).Callback(() => Assert.Equal(2, ++counter));
var session = new AsyncSession(
ConnectionScope.PerTransaction,
mockSqlDialect.Object,
mockDbDriver.Object,
new IDeleteListener[0],
new[] { mockListener1.Object, mockListener2.Object },
new IUpdateListener[0]);
session.InsertAsync(customer).Wait();
mockListener1.VerifyAll();
mockListener2.VerifyAll();
}
示例12: InsertBuildsAndExecutesAnInsertCommandOnlyIfIdentifierStrategyAssigned
public void InsertBuildsAndExecutesAnInsertCommandOnlyIfIdentifierStrategyAssigned()
{
ObjectInfo.MappingConvention = new ConventionMappingConvention(
UnitTest.GetConventionMappingSettings(IdentifierStrategy.Assigned));
var customer = new Customer
{
Id = 12345
};
var insertSqlQuery = new SqlQuery("INSERT");
var mockSqlDialect = new Mock<ISqlDialect>();
mockSqlDialect.Setup(x => x.BuildInsertSqlQuery(It.IsNotNull<IObjectInfo>(), customer)).Returns(insertSqlQuery);
mockSqlDialect.Setup(x => x.SupportsSelectInsertedIdentifier).Returns(false);
var mockCommand = new Mock<IDbCommand>();
mockCommand.Setup(x => x.ExecuteNonQuery()).Returns(1);
var mockConnection = new Mock<IDbConnection>();
mockConnection.Setup(x => x.CreateCommand()).Returns(mockCommand.Object);
var mockDbDriver = new Mock<IDbDriver>();
mockDbDriver.Setup(x => x.CreateConnection()).Returns(new MockDbConnectionWrapper(mockConnection.Object));
var session = new AsyncSession(
ConnectionScope.PerTransaction,
mockSqlDialect.Object,
mockDbDriver.Object,
new IDeleteListener[0],
new IInsertListener[0],
new IUpdateListener[0]);
session.InsertAsync(customer).Wait();
mockSqlDialect.Verify(x => x.BuildInsertSqlQuery(It.IsNotNull<IObjectInfo>(), customer), Times.Once());
mockSqlDialect.Verify(x => x.BuildSelectInsertIdSqlQuery(It.IsAny<IObjectInfo>()), Times.Never());
mockDbDriver.VerifyAll();
mockCommand.VerifyAll();
}
示例13: GetUpdateValues_ReturnsPropertyValues_WhenUsingDbGenerated
public void GetUpdateValues_ReturnsPropertyValues_WhenUsingDbGenerated()
{
ObjectInfo.MappingConvention = new ConventionMappingConvention(
UnitTest.GetConventionMappingSettings(IdentifierStrategy.DbGenerated));
var objectInfo = ObjectInfo.For(typeof(Customer));
var customer = new Customer
{
Created = new DateTime(2011, 12, 24),
CreditLimit = 10500.00M,
DateOfBirth = new System.DateTime(1975, 9, 18),
Id = 134875,
Name = "Joe Bloggs",
Status = CustomerStatus.Active,
Updated = DateTime.Now,
Website = new Uri("http://microliteorm.wordpress.com")
};
var values = objectInfo.GetUpdateValues(customer);
Assert.Equal(7, values.Length);
Assert.Equal(DbType.Decimal, values[0].DbType);
Assert.Equal(customer.CreditLimit, values[0].Value);
Assert.Equal(DbType.DateTime2, values[1].DbType);
Assert.Equal(customer.DateOfBirth, values[1].Value);
Assert.Equal(DbType.String, values[2].DbType);
Assert.Equal(customer.Name, values[2].Value);
Assert.Equal(DbType.Int32, values[3].DbType);
Assert.Equal((int)customer.Status, values[3].Value);
Assert.Equal(DbType.DateTime2, values[4].DbType);
Assert.Equal(customer.Updated, values[4].Value);
Assert.Equal(DbType.String, values[5].DbType);
Assert.Equal(customer.Website.ToString(), values[5].Value);
Assert.Equal(DbType.Int32, values[6].DbType);
Assert.Equal(customer.Id, values[6].Value);
}
示例14: GetIdentifierValue_ReturnsPropertyValueOfIdentifierProperty
public void GetIdentifierValue_ReturnsPropertyValueOfIdentifierProperty()
{
var objectInfo = ObjectInfo.For(typeof(Customer));
var customer = new Customer
{
Id = 122323
};
var identifierValue = (int)objectInfo.GetIdentifierValue(customer);
Assert.Equal(customer.Id, identifierValue);
}
示例15: InsertInstanceQueryForIdentifierStrategySequence
public void InsertInstanceQueryForIdentifierStrategySequence()
{
ObjectInfo.MappingConvention = new ConventionMappingConvention(
UnitTest.GetConventionMappingSettings(IdentifierStrategy.Sequence));
var sqlDialect = new FirebirdSqlDialect();
var customer = new Customer
{
Created = new DateTime(2011, 12, 24),
CreditLimit = 10500.00M,
DateOfBirth = new System.DateTime(1975, 9, 18),
Name = "Joe Bloggs",
Status = CustomerStatus.Active,
Updated = DateTime.Now,
Website = new Uri("http://microliteorm.wordpress.com")
};
var sqlQuery = sqlDialect.BuildInsertSqlQuery(ObjectInfo.For(typeof(Customer)), customer);
Assert.Equal("INSERT INTO \"Sales\".\"Customers\" (\"Id\",\"Created\",\"CreditLimit\",\"DateOfBirth\",\"Name\",\"CustomerStatusId\",\"Website\") VALUES (GEN_ID(Customer_Id_Sequence, 1),@p0,@p1,@p2,@p3,@p4,@p5) RETURNING Id", sqlQuery.CommandText);
Assert.Equal(6, sqlQuery.Arguments.Count);
Assert.Equal(DbType.DateTime, sqlQuery.Arguments[0].DbType);
Assert.Equal(customer.Created, sqlQuery.Arguments[0].Value);
Assert.Equal(DbType.Decimal, sqlQuery.Arguments[1].DbType);
Assert.Equal(customer.CreditLimit, sqlQuery.Arguments[1].Value);
Assert.Equal(DbType.DateTime, sqlQuery.Arguments[2].DbType);
Assert.Equal(customer.DateOfBirth, sqlQuery.Arguments[2].Value);
Assert.Equal(DbType.String, sqlQuery.Arguments[3].DbType);
Assert.Equal(customer.Name, sqlQuery.Arguments[3].Value);
Assert.Equal(DbType.Int32, sqlQuery.Arguments[4].DbType);
Assert.Equal((int)customer.Status, sqlQuery.Arguments[4].Value);
Assert.Equal(DbType.String, sqlQuery.Arguments[5].DbType);
Assert.Equal("http://microliteorm.wordpress.com/", sqlQuery.Arguments[5].Value);
}