public void TestForLinkOrdersMissingValue() { // Arrange var orderLinkSummary = new OrderLinkSummary() { LinkId = -1, StatusCode = HttpStatusCode.OK, Message = "OrderId is either null or 0" }; OrderLinkInput orderLinkInput = new OrderLinkInput() { OrderIds = null, Name = null }; var linkOrder = new Mock <ILinkOrder>(); var controller = new OrderLinkingController(linkOrder.Object); linkOrder.Setup(x => x.ValidateAndAdd(It.IsAny <List <int> >(), It.IsAny <string>())).Returns(orderLinkSummary); //Act var data = controller.LinkOrders(orderLinkInput); //Assert Assert.Equal(data.Message, orderLinkSummary.Message); Assert.Equal(data.LinkId, orderLinkSummary.LinkId); Assert.Equal(data.StatusCode, orderLinkSummary.StatusCode); }
public void TestForLinkOrdersCorrectValue() { // Arrange var orderLinkSummary = new OrderLinkSummary() { LinkId = 1, StatusCode = HttpStatusCode.Created, Message = "Successfully Linked" }; OrderLinkInput orderLinkInput = new OrderLinkInput() { OrderIds = new List <int>() { 1, 2, 3 }, Name = "Link1" }; var linkOrder = new Mock <ILinkOrder>(); var controller = new OrderLinkingController(linkOrder.Object); linkOrder.Setup(x => x.ValidateAndAdd(It.IsAny <List <int> >(), It.IsAny <string>())).Returns(orderLinkSummary); //Act var data = controller.LinkOrders(orderLinkInput); //Assert Assert.Equal(data.Message, orderLinkSummary.Message); Assert.Equal(data.LinkId, orderLinkSummary.LinkId); Assert.Equal(data.StatusCode, orderLinkSummary.StatusCode); }
public void TestForValidateAndAddCorrectValue() { // Arrange var orderLinkSummary = new OrderLinkSummary() { LinkId = 1, StatusCode = 0, Message = "Successfully Linked" }; List <int> orderIds = new List <int>() { 1, 2, 3 }; string name = "Link1"; List <Order> orders = new List <Order>(); orders.Add(new Order() { Id = 1, ProductSymbol = "8Ad6", SubAccountId = 19 }); orders.Add(new Order() { Id = 2, ProductSymbol = "8Ad6", SubAccountId = 19 }); orders.Add(new Order() { Id = 3, ProductSymbol = "8Ad6", SubAccountId = 19 }); var orderLinkDao = new Mock <IOrderLinkDao>(); var ordersDao = new Mock <IOrdersDao>(); var linkOrder = new LinkOrder(orderLinkDao.Object, ordersDao.Object); ordersDao.Setup(x => x.GetOrders(It.IsAny <List <int> >())).Returns(orders); orderLinkDao.Setup(x => x.CreateLink(It.IsAny <string>())).Returns((1, string.Empty)); ordersDao.Setup(x => x.UpdateOrders(It.IsAny <List <int> >(), It.IsAny <int>())).Returns((1, string.Empty)); //Act var data = linkOrder.ValidateAndAdd(orderIds, name); //Assert Assert.Equal(data.Message, orderLinkSummary.Message); Assert.Equal(data.LinkId, orderLinkSummary.LinkId); Assert.Equal(data.StatusCode, orderLinkSummary.StatusCode); }
public OrderLinkSummary ValidateAndAdd(List <int> orderIds, string name) { OrderLinkSummary orderLinkSummary = new OrderLinkSummary(); orderLinkSummary.LinkId = -1; try { List <Order> orders = new List <Order>(); orders = ordersDao.GetOrders(orderIds).ToList(); int count = orders.GroupBy(group => new { group.ProductSymbol, group.SubAccountId }).Count(); if (count == 1) { int existingLinkIdCount = orders.Where(order => !string.IsNullOrEmpty(order.LinkId.ToString())).Count(); if (existingLinkIdCount > 0) { orderLinkSummary.Message = "Link already exists"; } else { (orderLinkSummary.LinkId, orderLinkSummary.Message) = orderLinkDao.CreateLink(name); if (orderLinkSummary.LinkId != -1) { ordersDao.UpdateOrders(orderIds, orderLinkSummary.LinkId); } orderLinkSummary.Message = "Successfully Linked"; } } else { orderLinkSummary.Message = "ProductSymbol and SubAccount do not match."; } } catch (Exception ex) { orderLinkSummary.Message = ex.Message; } return(orderLinkSummary); }