public void Initialize() { var adapter = new CustomerAdapter(); JohnDoe = adapter.AddCustomer(new CustomerBuilder().JohnDoe(ObjectMother.Instance.Books.FiveDysfunctions).Build()); adapter.SaveChanges(); JaneDoe = adapter.AddCustomer(new CustomerBuilder().JaneDoe( ObjectMother.Instance.Books.PhoenixProject).Build()); adapter.SaveChanges(); }
public static Customer PrepareJohnDoeCustomer() { var adapter = new CustomerAdapter(); var customer = adapter.AddCustomer(new CustomerBuilder().JohnDoe().Build()); adapter.SaveChanges(); return(customer); }
public void AdapterAddCustomerTest() { var expected = new CustomerBuilder().JohnDoe().Build(); var adapter = new CustomerAdapter(); var response = adapter.AddCustomer(expected); Assert.IsNotNull(response); var comparison = Utilities.CompareObjects(expected, response); Assert.IsTrue(comparison.AreEqual, $"Expected [{expected}] Actual [{response}]"); }
public void ShouldAddConvertedCustomerToRepositoryAndReturnUpdated() { ICustomerRepository repository = Substitute.For<ICustomerRepository>(); ICustomerMapper mapper = Substitute.For<ICustomerMapper>(); Customer dto = new Customer(); CustomerData viewModelInput = new CustomerData(); CustomerData viewModelOutput = new CustomerData(); mapper.Convert(viewModelInput).Returns(dto); mapper.Convert(dto).Returns(viewModelOutput); CustomerAdapter adapter = new CustomerAdapter(repository) { CustomerMapper = mapper }; CustomerData result = adapter.AddCustomer(viewModelInput); Assert.AreSame(viewModelOutput, result, "The updated view model was not returned."); mapper.Received().Convert(viewModelInput); repository.Received().Add(dto); mapper.Received().Convert(dto); }
public void ShouldAddConvertedCustomerToRepositoryAndReturnUpdated() { ICustomerRepository repository = Substitute.For <ICustomerRepository>(); ICustomerMapper mapper = Substitute.For <ICustomerMapper>(); Customer dto = new Customer(); CustomerData viewModelInput = new CustomerData(); CustomerData viewModelOutput = new CustomerData(); mapper.Convert(viewModelInput).Returns(dto); mapper.Convert(dto).Returns(viewModelOutput); CustomerAdapter adapter = new CustomerAdapter(repository) { CustomerMapper = mapper }; CustomerData result = adapter.AddCustomer(viewModelInput); Assert.AreSame(viewModelOutput, result, "The updated view model was not returned."); mapper.Received().Convert(viewModelInput); repository.Received().Add(dto); mapper.Received().Convert(dto); }
public static void Main(string[] args) { #if singleton //Singleton Pattern Player p1 = Player.Instance; Console.WriteLine($"Name = {p1.Name}, Lvl = {p1.Level}"); #endif #if factory //Factory Pattern Gameboard gb = new Gameboard(); gb.PlayArea(1); #endif #if strategy //Strategy Pattern ShoppingCart cart1 = new ShoppingCart(new TenPercentDiscountStrategy()); cart1.CustomerName = "John Doe"; cart1.BillAmount = 100; Console.WriteLine($"Customer = {cart1.CustomerName}, Bal = ${cart1.GetFinalBill()}"); ShoppingCart cart2 = new ShoppingCart(new FiftyPercentDiscountStrategy()); cart2.CustomerName = "Jack Wilson"; cart2.BillAmount = 200; Console.WriteLine($"Customer = {cart2.CustomerName}, Bal = ${cart2.GetFinalBill()}"); #endif #if chainofresponsibility //Chain of responsibility Material material = new Material { MaterialID = Guid.NewGuid(), Name = "Pebbles", PartNumber = "234", DrawingNumber = "345", Budget = 100000 }; Approver engineer = new EngineeringApprover(); Approver purchasing = new PurchasingApprover(); Approver finance = new FinanceApprover(); engineer.SetNextApprover(purchasing); purchasing.SetNextApprover(finance); string reason = ""; if (engineer.ApproveMaterial(material, ref reason)) { Console.WriteLine($"Approved. {reason}"); } else { Console.WriteLine($"Disapproved. Reason: {reason}"); } #endif #if observer Amazon amzn = new Amazon(1752.12); Investor joe = new Investor("Joe"); joe.BuyStock(amzn); amzn.PriceChanged(1800.12); #endif #if adapter CustomerDTO customerDTO = new CustomerDTO { ID = 1, FirstName = "John", LastName = "Doe", Address = "123 Main St", City = "Portland", State = "OR", PostalCode = "12345" }; ICustomerList customerList = new CustomerAdapter(); customerList.AddCustomer(customerDTO); List <Customer> c = customerList.GetCustomers(); #endif #if COI #endif //Do not delete Console.ReadKey(); }