/// <summary> /// Sends a product order to the vendor. /// </summary> /// <param name="product">Product to order.</param> /// <param name="quantity">Quantity of the product to order.</param> /// <returns></returns> public OperationResult PlaceOrder(Product product, int quantity) { //// Guard clauses make sure passed in values are within constraints. //if (product == null) throw new ArgumentNullException(nameof(product)); //if (quantity <= 0) throw new ArgumentOutOfRangeException(nameof(product)); //var success = false; //var orderText = "Order from ACME, Inc" + "\n" + // "Product: " + product.ProductCode + "\n" + // "Quantity: " + quantity; //var emailService = new EmailService(); //var confirmation = emailService.SendMessage("New Order", orderText, Email); //if (confirmation.StartsWith("Message sent: ")) //{ // success = true; //} //var operationResult = new OperationResult(success, orderText); //return operationResult; //// Example of method chaining return PlaceOrder(product, quantity, null, null); }
/// <summary> /// Sends a product order to the vendor. /// </summary> /// <param name="product">Product to order.</param> /// <param name="quantity">Quantity of the product to order.</param> /// <param name="deliverBy">Requested delivery date.</param> /// <returns></returns> public OperationResult PlaceOrder(Product product, int quantity, DateTimeOffset? deliverBy = null) { //// Guard clauses make sure passed in values are within constraints. //if (product == null) throw new ArgumentNullException(nameof(product)); //if (quantity <= 0) throw new ArgumentOutOfRangeException(nameof(product)); //if (deliverBy <= DateTimeOffset.Now) throw new ArgumentOutOfRangeException(nameof(deliverBy)); //var success = false; //var orderText = "Order from ACME, Inc" + "\n" + // "Product: " + product.ProductCode + "\n" + // "Quantity: " + quantity; //if (deliverBy.HasValue) //{ // orderText += "\n" + "Deliver By: " + deliverBy.Value.ToString("d"); //} //var emailService = new EmailService(); //var confirmation = emailService.SendMessage("New Order", orderText, Email); //if (confirmation.StartsWith("Message sent: ")) //{ // success = true; //} //var operationResult = new OperationResult(success, orderText); //return operationResult; return PlaceOrder(product, quantity, deliverBy, null); }
/// <summary> /// Sends a product order to the vendor. /// </summary> /// <param name="product">Product to order.</param> /// <param name="quantity">Quantity of the product to order.</param> /// <param name="includeAddress">True to include the shipping address in the order.</param> /// <param name="sendCopy">True to send a copy of the email to the current user.</param> /// <returns>Success flag and order text</returns> public OperationResult PlaceOrder(Product product, int quantity, IncludeAddress includeAddress, SendCopy sendCopy) { var orderText = "Test"; if (includeAddress == IncludeAddress.Yes) orderText += " With Address"; if (sendCopy == SendCopy.Yes) orderText += " With Copy"; var operationResult = new OperationResult(true, orderText); return operationResult; }
public void MinimumPriceTest_Default() { //Arrage var currentProduct = new Product(); var expectedMessage = 0.96m; //Act var actual = currentProduct.MinimumPrice; //Assert Assert.AreEqual(expectedMessage, actual); }
public void MinimumPriceTest_Bulk() { //Arrange var currentProduct = new Product(1, "Bulk Tools", ""); var expected = 9.99m; //Act var actual = currentProduct.MinimumPrice; //Assert Assert.AreEqual(expected, actual); }
public void SayHello_ParameterizedConstructor_Test() { //Arrange var currentProduct = new Product("Honda", 2346, "Nice car from Japan"); var expected = "Hello Honda (2346): Nice car from Japan" + " Available on: "; //Act var actual = currentProduct.SayHello(); //Assert Assert.AreEqual(expected, actual); }
public void SayHello_ParameterizedConstructor() { //Arrange var currentProduct = new Product(1, "Saw", "15-inch steel blade hand saw"); var expected = "Hello Saw (1): 15-inch steel blade hand saw"; //Act var actual = currentProduct.SayHello(); //Assert Assert.AreEqual(expected, actual); }
public void ProductName_Format() { //Arrange var currentProduct = new Product(); currentProduct.ProductName = " Steel Hammer "; var expected = "Steel Hammer"; //Act var actual = currentProduct.ProductName; //Assert Assert.AreEqual(expected, actual); }
public void CalculateSuggestedPriceTest() { // Arrange var currentProduct = new Product(1, "Saw", ""); currentProduct.Cost = 50m; var expected = 55m; // Act var actual = currentProduct.CalculateSuggestedPrice(10m); // Assert Assert.AreEqual(expected, actual); }
public void CalculateSuggestedPriceTest() { // Arrange var currentProduct = new Product(1, "Saw", ""); currentProduct.Cost = 50m; var expected = new OperationResult<decimal>(55m, ""); // Act var actual = currentProduct.CalculateSuggestedPrice(10m); // Assert Assert.AreEqual(expected.Result, actual.Result); Assert.AreEqual(expected.Message, actual.Message); }
public void SayHello_ParamterizedConstructor() { //Arrange var currentProduct = new Product(1, "Hammer", "A sturdy tool"); var expected = "Hello Hammer (1): A sturdy tool" + " Available on: "; //Act var actual = currentProduct.SayHello(); //Assert Assert.AreEqual(expected, actual); }
public void SayHelloTest() { //Arrange var currentProduct = new Product(); currentProduct.ProductName = "Saw"; currentProduct.ProductId = 1; currentProduct.Description = "15-inch steel blade hand saw"; var expected = "Hello Saw (1): 15-inch steel blade hand saw"; //Act var actual = currentProduct.SayHello(); //Assert Assert.AreEqual(expected, actual); }
public void PlaceOrderTest() { // Arrange var vender = new Vendor(); var product = new Product(1, "Hammer", ""); var expected = new OperationResult(true, "Order from ACME, Inc\nProduct: Tools-1\nQuantity: 1"); // Act var actual = vender.PlaceOrder(product, 1); // Assert Assert.AreEqual(expected.Success, actual.Success); Assert.AreEqual(expected.Message, actual.Message); }
public void SayHelloTest() { //Arrange var currentProduct = new Product(); currentProduct.ProductName = "Honda"; currentProduct.ProductId = 2346; currentProduct.Description = "Nice car from Japan"; currentProduct.ProductVendor.CompanyName = "Honda Ltd."; var expected = "Hello Honda (2346): Nice car from Japan" + " Available on: "; //Act var actual = currentProduct.SayHello(); //Assert Assert.AreEqual(expected, actual); }
public void SayHello_ParameterizedConstructorTest() { //Arrage var currentProduct = new Product(1,"Saw", "Steel Blade hand saw"); //currentProduct.ProductId = 1; //currentProduct.ProductName = "Saw"; //currentProduct.Description = "Steel Blade hand saw"; var expectedMessage = "Hello Saw (1) Steel Blade hand saw"; //Act Console.WriteLine("Current Product" + currentProduct.ProductName); var actual = currentProduct.SayHello(); //Assert Assert.AreEqual(expectedMessage, actual); }
public void SayHelloParmTest() { //arrange var currentProduct = new Product(1, "Saw", "15-inch steel blade hand saw"); var expected = "Hello Saw (1) 15-inch steel blade hand saw" + " Available on: "; //act var actual = currentProduct.SayHello(); //assert Assert.AreEqual(expected, actual); }
public void PlaceOrderTest() { // Arrange var vendor = new Vendor(); var product = new Product(1, "Saw", ""); var expected = new OperationResult(true, "Order from Acme, Inc\r\nProduct: Saw\r\nQuantity: 12" + "\r\nInstructions: standard delivery"); // Act var actual = vendor.PlaceOrder(product, 12); // Assert Assert.AreEqual(expected.Success, actual.Success); Assert.AreEqual(expected.Message, actual.Message); }
public void ProductName_TooLong() { //Arrange var currentProduct = new Product(); currentProduct.ProductName = "Steel Bladed Hand Saw"; string expected = null; string expectedMessage = "Product Name cannot be more than 20 characters"; //Act var actual = currentProduct.ProductName; var actualMessage = currentProduct.ValidationMessage; //Assert Assert.AreEqual(expected, actual); Assert.AreEqual(expectedMessage, actualMessage); }
public void PlaceOrder_NoDeliveryDate() { // Arrange var vendor = new Vendor(); var product = new Product(1, "Saw", ""); var expected = new OperationResult<bool,string>(true, "Order from Acme, Inc\r\nProduct: Saw\r\nQuantity: 12" + "\r\nInstructions: Deliver to Suite 42"); // Act var actual = vendor.PlaceOrder(product, 12, instructions: "Deliver to Suite 42"); // Assert Assert.AreEqual(expected.Result, actual.Result); Assert.AreEqual(expected.Message, actual.Message); }
public void PlaceOrderTest() { // Arrange var vendor = new Vendor(); var product = new Product(); var expected = new OperationResult(true, "Order from Acme, Inc\r\nProduct: Tools-1\r\nQuantity: 12"); // Act var actual = vendor.PlaceOrder(product, 12); Console.WriteLine(expected.Message); Console.WriteLine(actual.Message); // Assert Assert.AreEqual(expected.Success, actual.Success); Assert.AreEqual(expected.Message, actual.Message); }
public void ProductName_TooShort() { //Arrange var currentProduct = new Product(); currentProduct.ProductName = "aw"; string expected = null; string expectedMessage = "Product Name must be at least 3 characters"; //Act var actual = currentProduct.ProductName; var actualMessage = currentProduct.ValidationMessage; //Assert Assert.AreEqual(expected, actual); Assert.AreEqual(expectedMessage, actualMessage); }
public void PlaceOrder_3Parameters() { // Arrange var vendor = new Vendor(); var product = new Product(1, "Saw", ""); var expected = new OperationResult(true, "Order from Acme, Inc\r\nProduct: Tools-1\r\nQuantity: 12" + "\r\nDeliver By: 10/25/2015"); // Act var actual = vendor.PlaceOrder(product, 12, new DateTimeOffset(2015, 10, 25, 0, 0, 0, new TimeSpan(-7, 0, 0))); // Assert Assert.AreEqual(expected.Success, actual.Success); Assert.AreEqual(expected.Message, actual.Message); }
public void SayHelloTest() { //Arrage var currentProduct = new Product(); currentProduct.ProductId = 1; currentProduct.ProductName = "Saw"; currentProduct.Description = "Steel Blade hand saw"; currentProduct.ProductVendor.CompanyName = "ABC Ltd"; var expectedMessage = "Hello Saw (1) Steel Blade hand saw"; //Act var actual = currentProduct.SayHello(); //Assert Assert.AreEqual(expectedMessage, actual); }
public void ProductName_JustRight() { //Arrange var currentProduct = new Product(); currentProduct.ProductName = "Saw"; string expected = "Saw"; string expectedMessage = null; //Act var actual = currentProduct.ProductName; var actualMessage = currentProduct.ValidationMessage; //Assert Assert.AreEqual(expected, actual); Assert.AreEqual(expectedMessage, actualMessage); }
public void SayHello_ObjectInitializer_Test() { //Arrange var currentProduct = new Product { ProductName = "Honda", ProductId = 2346, Description = "Nice car from Japan", }; var expected = "Hello Honda (2346): Nice car from Japan" + " Available on: "; //Act var actual = currentProduct.SayHello(); //Assert Assert.AreEqual(expected, actual); }
public void PlaceOrder_3Parameters() { // Arrange var vendor = new Vendor(); var product = new Product(1, "Saw", ""); var expected = new OperationResult<bool>(true, "Order from Acme, Inc\r\nProduct: Saw\r\nQuantity: 12" + "\r\nDeliver By: 10/25/2018" + "\r\nInstructions: standard delivery"); // Act var actual = vendor.PlaceOrder(product, 12, new DateTimeOffset(2018, 10, 25, 0, 0, 0, new TimeSpan(-7, 0, 0))); // Assert Assert.AreEqual(expected.Result, actual.Result); Assert.AreEqual(expected.Message, actual.Message); }
public void SayHello_ObjectInitializer() { //Arrange var currentProduct = new Product { ProductId = 1, ProductName = "Saw", Description = "15-inch steel blade hand saw" }; var expected = "Hello Saw (1): 15-inch steel blade hand saw"; //Act var actual = currentProduct.SayHello(); //Assert Assert.AreEqual(expected, actual); }
public void SayHello_ObjectInitializer() { var currentProduct = new Product { ProductId = 1, ProductName = "Hammer", Description = "A sturdy tool" }; var expected = "Hello Hammer (1): A sturdy tool" + " Available on: "; //Act var actual = currentProduct.SayHello(); //Assert Assert.AreEqual(expected, actual); }
public void SayHelloTest() { //Arrange var currentProduct = new Product(); currentProduct.ProductId = 1; currentProduct.ProductName = "Hammer"; currentProduct.Description = "A sturdy tool"; currentProduct.ProductVendor.CompanyName = "XYZ Corporation"; var expected = "Hello Hammer (1): A sturdy tool" + " Available on: "; //Act var actual = currentProduct.SayHello(); //Assert Assert.AreEqual(expected, actual); }
/// <summary> /// Sends a product order to the vendor. /// </summary> /// <param name="product">Product to order.</param> /// <param name="quantity">Quantity of the product to order.</param> /// <param name="deliverBy">Requested delivery date.</param> /// <param name="instructions">Delivery instructions.</param> /// <returns></returns> public OperationResult<bool, string> PlaceOrder(Product product, int quantity, DateTimeOffset? deliverBy = null, string instructions = "standard delivery") { if (product == null) throw new ArgumentNullException(nameof(product)); if (quantity <= 0) throw new ArgumentOutOfRangeException(nameof(quantity)); if (deliverBy <= DateTimeOffset.Now) throw new ArgumentOutOfRangeException(nameof(deliverBy)); var success = false; var orderTextBuilder = new StringBuilder("Order from Acme, Inc" + System.Environment.NewLine + "Product: " + product.ProductName + System.Environment.NewLine + "Quantity: " + quantity); if (deliverBy.HasValue) { orderTextBuilder.Append( System.Environment.NewLine + "Deliver By: " + deliverBy.Value.ToString("d")); } if (!String.IsNullOrWhiteSpace(instructions)) { orderTextBuilder.Append( System.Environment.NewLine + "Instructions: " + instructions); } var orderText = orderTextBuilder.ToString(); var emailService = new EmailService(); var confirmation = emailService.SendMessage("New Order", orderText, this.Email); if (confirmation.StartsWith("Message sent:")) { success = true; } var operationResult = new OperationResult<bool,string>(success, orderText); return operationResult; }