Skip to content

Instantly share code, notes, and snippets.

@yohey03518
Created January 14, 2019 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yohey03518/4877b5a042c43b76f4073ac45d6a8d3f to your computer and use it in GitHub Desktop.
Save yohey03518/4877b5a042c43b76f4073ac45d6a8d3f to your computer and use it in GitHub Desktop.
[TestClass]
public class OrderServiceTest
{
[TestMethod]
public void CreateOrders()
{
// Arrange
OrderService orderService = new OrderService();
List<string> names = new List<string> { "Book", "Table", "Pen", "Mouse" };
// Act
orderService.CreateOrdersByNames(names);
// Assert order.Save() has been called for 4 times
}
}
public class OrderService
{
public List<Order> CreateOrdersByNames(List<string> names)
{
List<Order> orders = new List<Order>();
foreach(string name in names)
{
Order order = new Order(name);
order.Save();
orders.Add(order);
}
return orders;
}
}
public class Order : IRepository
{
public Order(string name)
{
this.Name = name;
}
public string Name { get; set; }
public void Save()
{
// Write to DB or File
}
}
public interface IRepository
{
void Save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment