Beispiel #1
0
 public void SetUp()
 {
     var webLinkFactoryMock = new Mock<IWebLinkFactory<WebLink>>();
     webLinkFactoryMock
         .Setup(m => m.CreateWebLink(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<WebLinkCategory>()))
         .Returns<string, string, WebLinkCategory>((d, u, c) => new WebLink(d, u, c));
     webLinkFactory = webLinkFactoryMock.Object;
 }
Beispiel #2
0
        public void SetUp()
        {
            var webLinkFactoryMock = new Mock <IWebLinkFactory <WebLink> >();

            webLinkFactoryMock
            .Setup(m => m.CreateWebLink(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <WebLinkCategory>()))
            .Returns <string, string, WebLinkCategory>((d, u, c) => new WebLink(d, u, c));
            webLinkFactory = webLinkFactoryMock.Object;
        }
Beispiel #3
0
        public static CollectionDiffWithValue <T, T> Sync <T>(IList <T> oldLinks, IEnumerable <WebLinkContract> newLinks, IWebLinkFactory <T> webLinkFactory)
            where T : WebLink
        {
            var diff    = CollectionHelper.Diff(oldLinks, newLinks, (n1, n2) => n1.Id == n2.Id);
            var created = new List <T>();
            var edited  = new List <T>();

            foreach (var n in diff.Removed)
            {
                oldLinks.Remove(n);
            }

            foreach (var linkEntry in newLinks)
            {
                var entry = linkEntry;
                var old   = (entry.Id != 0 ? oldLinks.FirstOrDefault(n => n.Id == entry.Id) : null);

                if (old != null)
                {
                    if (!old.ContentEquals(linkEntry))
                    {
                        old.Category    = linkEntry.Category;
                        old.Description = linkEntry.Description;
                        old.Url         = linkEntry.Url;
                        edited.Add(old);
                    }
                }
                else
                {
                    var n = webLinkFactory.CreateWebLink(linkEntry.Description, linkEntry.Url, linkEntry.Category);
                    created.Add(n);
                }
            }

            return(new CollectionDiffWithValue <T, T>(created, diff.Removed, diff.Unchanged, edited));
        }
Beispiel #4
0
        public static CollectionDiff <T, T> SyncByValue <T>(IList <T> oldLinks, IEnumerable <ArchivedWebLinkContract> newLinks, IWebLinkFactory <T> webLinkFactory)
            where T : WebLink
        {
            var diff    = CollectionHelper.Diff(oldLinks, newLinks, (n1, n2) => n1.ContentEquals(n2));
            var created = new List <T>();

            foreach (var n in diff.Removed)
            {
                oldLinks.Remove(n);
            }

            foreach (var linkEntry in diff.Added)
            {
                var n = webLinkFactory.CreateWebLink(linkEntry.Description, linkEntry.Url, linkEntry.Category);
                created.Add(n);
            }

            return(new CollectionDiff <T, T>(created, diff.Removed, diff.Unchanged));
        }
 public CollectionDiff <T, T> SyncByValue(IEnumerable <ArchivedWebLinkContract> newLinks, IWebLinkFactory <T> webLinkFactory)
 {
     return(WebLink.SyncByValue(Links, newLinks, webLinkFactory));
 }
 public CollectionDiffWithValue <T, T> Sync(IEnumerable <WebLinkContract> newLinks, IWebLinkFactory <T> webLinkFactory)
 {
     return(WebLink.Sync(Links, newLinks, webLinkFactory));
 }