{/// <summary> /// Takes List of list as input and provide the comparison result as output /// </summary> /// <param name="listsToCompare"></param> /// <returns>SortedCompareList</returns> public override ListCompareResult GetComparedList(ListsToCompare listsToCompare) { ListCompareResult comparisonResult = new ListCompareResult(); if (listsToCompare != null && listsToCompare.Current != null && listsToCompare.Initial != null) { List <KeyValuePairs> initial = new List <KeyValuePairs>(); List <KeyValuePairs> current = new List <KeyValuePairs>(); initial = listsToCompare.Initial.Where(c => c != null).ToList(); // Assign valued to initial current = listsToCompare.Current.Where(c => c != null).ToList(); // Assign valued to Current List <KeyValuePairs> newList = GetNewList(initial, current); // get the newly added items comparing keys List <KeyValuePairs> deleteList = GetDeletedList(initial, current); // get the deleted items comparing keys List <KeyValuePairs> updatedList = GetUpdatedList(initial, current); // get the updated items comparing keys comparisonResult.NewItems = newList; comparisonResult.UpdatedItems = updatedList; comparisonResult.DeletedItems = deleteList; comparisonResult.Message = "Success"; } else { comparisonResult.Message = "Please provide valid input."; } return(comparisonResult); }
public void GetSortedCompareListNullTest() { ListsToCompare listsToCompareTest = new ListsToCompare(); ListCompareResult listCompareResultActual = new ListCompareResult(); listCompareResultActual = commonService.GetComparedList(listsToCompareTest); Assert.AreEqual(listCompareResultActual.Message, "Please provide valid input."); }
public ActionResult <ListCompareResult> ListComparer([FromBody] ListsToCompare listsToCompare) { ListCompareResult ComparisonResult = new ListCompareResult(); try { ComparisonResult = _commonServiceObj.GetComparedList(listsToCompare); } catch (Exception) { ComparisonResult.Message = "Oops!! Something went wrong."; } return(ComparisonResult); }
public HttpResponseMessage Post([FromBody] ListsToCompare listsToCompare) { FinalResult ComparisonResult = new FinalResult(); try { ICommon common = new Common(); ComparisonResult = common.getCompareResult(listsToCompare); ComparisonResult.Message = "Result generated successfully"; } catch (Exception ex) { ComparisonResult.Message = "Could not generate result, exception occured " + ex.InnerException; } return(Request.CreateResponse <FinalResult>(HttpStatusCode.OK, ComparisonResult)); }
public FinalResult getCompareResult(ListsToCompare compareList) { FinalResult ComparisonResult = new FinalResult(); try { if (compareList != null && compareList.Current != null && compareList.Initial != null) { List <BaseList> initial = new List <BaseList>(); List <BaseList> current = new List <BaseList>(); initial = compareList.Initial; current = compareList.Current; //new items to show with the newList list object List <BaseList> newList = current.Where(n => !initial.Any(o => o.Key == n.Key)).ToList(); //updated items to show with the updatedList list object List <BaseList> updatedList = current.Where(u => initial.Any(o => o.Key == u.Key && o.Value != u.Value)).ToList(); //deleted items to show with the deletedList list object List <BaseList> deletedList = initial.Where(d => !current.Any(o => o.Key == d.Key)).ToList(); ComparisonResult.NewItems = newList; ComparisonResult.UpdatedItems = updatedList; ComparisonResult.DeletedItems = deletedList; ComparisonResult.Message = "Success"; } else { ComparisonResult.Message = "Please provide valid input.."; } } catch (Exception e) { ComparisonResult.Message = "Internal Error."; } return(ComparisonResult); //Request.CreateResponse<SortedCompareList>(HttpStatusCode.OK, ComparisonResult); }
public void GetSortedCompareListTest() { ListsToCompare listsToCompareTest = new ListsToCompare(); listsToCompareTest.Current = new List <KeyValuePairs>(); listsToCompareTest.Initial = new List <KeyValuePairs>(); listsToCompareTest.Initial.Add(new KeyValuePairs { Key = 1, Value = "Value1" }); listsToCompareTest.Initial.Add(new KeyValuePairs { Key = 2, Value = "Value2" }); listsToCompareTest.Initial.Add(new KeyValuePairs { Key = 3, Value = "Value3" }); listsToCompareTest.Initial.Add(new KeyValuePairs { Key = 4, Value = "Value4" }); listsToCompareTest.Initial.Add(new KeyValuePairs { Key = 5, Value = "Value5" }); listsToCompareTest.Initial.Add(new KeyValuePairs { Key = 6, Value = "Value6" }); listsToCompareTest.Current.Add(new KeyValuePairs { Key = 1, Value = "Value1" }); listsToCompareTest.Current.Add(new KeyValuePairs { Key = 2, Value = "Value2.1" }); listsToCompareTest.Current.Add(new KeyValuePairs { Key = 5, Value = "Value5" }); listsToCompareTest.Current.Add(new KeyValuePairs { Key = 6, Value = "Value6.1" }); listsToCompareTest.Current.Add(new KeyValuePairs { Key = 7, Value = "Value7" }); listsToCompareTest.Current.Add(new KeyValuePairs { Key = 8, Value = "Value8" }); listsToCompareTest.Current.Add(new KeyValuePairs { Key = 9, Value = "Value9" }); listsToCompareTest.Current.Add(new KeyValuePairs { Key = 10, Value = "Value10" }); ListCompareResult listCompareResultExpected = new ListCompareResult(); listCompareResultExpected.NewItems = new List <KeyValuePairs>(); listCompareResultExpected.NewItems.Add(new KeyValuePairs { Key = 7, Value = "Value7" }); listCompareResultExpected.NewItems.Add(new KeyValuePairs { Key = 8, Value = "Value8" }); listCompareResultExpected.NewItems.Add(new KeyValuePairs { Key = 9, Value = "Value9" }); listCompareResultExpected.NewItems.Add(new KeyValuePairs { Key = 10, Value = "Value10" }); listCompareResultExpected.DeletedItems = new List <KeyValuePairs>(); listCompareResultExpected.DeletedItems.Add(new KeyValuePairs { Key = 3, Value = "Value3" }); listCompareResultExpected.DeletedItems.Add(new KeyValuePairs { Key = 4, Value = "Value4" }); listCompareResultExpected.UpdatedItems = new List <KeyValuePairs>(); listCompareResultExpected.UpdatedItems.Add(new KeyValuePairs { Key = 2, Value = "Value2.1" }); listCompareResultExpected.UpdatedItems.Add(new KeyValuePairs { Key = 6, Value = "Value6.1" }); listCompareResultExpected.Message = "Success"; ListCompareResult listCompareResultActual = new ListCompareResult(); listCompareResultActual = commonService.GetComparedList(listsToCompareTest); Assert.IsTrue(listCompareResultExpected.NewItems.SequenceEqual(listCompareResultActual.NewItems, new CompareListEqualityComparer())); Assert.IsTrue(listCompareResultExpected.DeletedItems.SequenceEqual(listCompareResultActual.DeletedItems, new CompareListEqualityComparer())); Assert.IsTrue(listCompareResultExpected.UpdatedItems.SequenceEqual(listCompareResultActual.UpdatedItems, new CompareListEqualityComparer())); Assert.AreEqual(listCompareResultExpected.Message, listCompareResultActual.Message); }
public abstract ListCompareResult GetComparedList(ListsToCompare listsToCompare);