public static void InsertCustomer(NorthwindEntities db, Customer customer) { Console.WriteLine("INSERTING CUSTOMER..."); var allCustomers = db.Customers; foreach (var item in allCustomers) { if (item.CustomerID.ToLower() == customer.CustomerID.ToLower()) { return; } } db.Customers.Add(customer); db.SaveChanges(); Console.WriteLine("DONE"); }
public void AddCustomerShouldAddDbRecord() { var customer = new Customer() { CustomerID = "ZXC", ContactName = "Asd Qwerty" }; var northwindDbMock = new NorthwindEntities(); Mock.Arrange(() => northwindDbMock.Customers).ReturnsCollection(this.db); Mock.Arrange(() => northwindDbMock.Customers .Add(customer)) .DoInstead((Customer c) => { this.db.Add(c); }); NorthwindDao.InsertCustomer(northwindDbMock, customer); Assert.AreEqual(expected: 3, actual: this.db.Count); }