本文整理汇总了C#中CustomerRepository.Create方法的典型用法代码示例。如果您正苦于以下问题:C# CustomerRepository.Create方法的具体用法?C# CustomerRepository.Create怎么用?C# CustomerRepository.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CustomerRepository
的用法示例。
在下文中一共展示了CustomerRepository.Create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
using (var context = new DatabaseContext())
{
ICustomerRepository customers = new CustomerRepository(context);
IProductRepository products = new ProductRepository(context);
var github = new Customer() { IsActive = true, Name = "GitHub" };
var microsoft = new Customer() {IsActive = true, Name = "Microsoft"};
var apple = new Customer() { IsActive = false, Name = "Apple" };
customers.Create(github);
customers.Create(microsoft);
customers.Create(apple);
var windows = new Product()
{
CustomerId = microsoft.Id,
Description = "The best OS!",
Name = "Windows 10",
Sku = "AWESOME1"
};
var sourceControl = new Product()
{
CustomerId = github.Id,
Description = "The best hosted source control solution!",
Name = "GitHub Enterprise",
Sku = "AWESOME2"
};
var iphone = new Product()
{
CustomerId = apple.Id,
Description = "The best phone ever created!",
Name = "iPhone 6S",
Sku = "AWESOME3"
};
products.Create(windows);
products.Create(sourceControl);
products.Create(iphone);
foreach (var customer in customers.All.WhereIsActive().ToList())
{
Console.WriteLine(customer.Name);
}
foreach (var customer in customers.GetAllWithProducts().WhereNameBeginsWith("Git").WhereIsActive().ToList())
{
Console.WriteLine(customer.Name);
foreach (var product in customer.Products)
{
Console.WriteLine("-- {0}", product.Name);
}
}
}
}
示例2: Main
static void Main(string[] args)
{
var customerRepository = new CustomerRepository();
var customer = new Customer
{
firstName = "Eric",
lastName = "Brunner",
streetAddress = "my street",
city = "Vienna"
};
customerRepository.Create(customer);
Console.ReadKey();
}
示例3: Create_ArgumentValid_ReturnsTrue
public void Create_ArgumentValid_ReturnsTrue()
{
// ARRANGE
var objectUnderTest = new CustomerRepository();
var mockCustomer = new Mock<ICustomer>();
mockCustomer.SetupGet(context => context.firstName).Returns("Eric");
mockCustomer.SetupGet(context => context.lastName).Returns("Brunner");
mockCustomer.SetupGet(context => context.streetAddress).Returns("my street");
mockCustomer.SetupGet(context => context.city).Returns("Vienna");
// ACT
var result = objectUnderTest.Create(mockCustomer.Object);
// ASSERT
Assert.True(result, "Result has an unexpected value");
mockCustomer.VerifyGet(context => context.firstName, Times.Exactly(1));
mockCustomer.VerifyGet(context => context.lastName, Times.Exactly(1));
mockCustomer.VerifyGet(context => context.streetAddress, Times.Exactly(1));
mockCustomer.VerifyGet(context => context.city, Times.Exactly(1));
}