public void Synchronize_GetVersionsAndGetReturnDuplicateEntries_RemovesDuplicates()
        {
            var builder = new SynchronizerBuilder();

            builder.AtypeIdComparer = StringComparer.InvariantCultureIgnoreCase;

            builder.AtypeRepository
            .Expect(r => r.GetVersions(DateTime.Now, DateTime.Now))
            .IgnoreArguments()
            .Return(new[] { EntityIdWithVersion.Create("A1", "v1"), EntityIdWithVersion.Create("a1", "v3") });

            builder.BtypeRepository
            .Expect(r => r.GetVersions(DateTime.Now, DateTime.Now))
            .IgnoreArguments()
            .Return(new[] { EntityIdWithVersion.Create("b1", "v2") });


            Task <IReadOnlyList <EntityWithVersion <string, string> > > aTypeLoadTask = new Task <IReadOnlyList <EntityWithVersion <string, string> > > (
                () => new List <EntityWithVersion <string, string> > {
                EntityWithVersion.Create("A1", "AAAA"), EntityWithVersion.Create("a1", "____")
            });

            aTypeLoadTask.RunSynchronously();
            builder.AtypeRepository
            .Expect(r => r.Get(Arg <ICollection <string> > .Matches(c => c.Count == 1 && c.First() == "A1")))
            .Return(aTypeLoadTask);

            Task <IReadOnlyList <EntityWithVersion <string, string> > > bTypeLoadTask = new Task <IReadOnlyList <EntityWithVersion <string, string> > > (
                () => new List <EntityWithVersion <string, string> > {
                EntityWithVersion.Create("b1", "BBBB"),
            });

            bTypeLoadTask.RunSynchronously();
            builder.BtypeRepository
            .Expect(r => r.Get(Arg <ICollection <string> > .Matches(c => c.Count == 1 && c.First() == "b1")))
            .Return(bTypeLoadTask);


            var knownData = new EntityRelationDataString("A1", "v1", "b1", "v2");

            builder.InitialEntityMatcher
            .Expect(m => m.FindMatchingEntities(null, null, null, null, null))
            .IgnoreArguments()
            .Return(new List <IEntityRelationData <string, string, string, string> > {
                knownData
            });

            builder.InitialSyncStateCreationStrategy
            .Expect(s => s.CreateFor_Unchanged_Unchanged(knownData))
            .Return(new DoNothing <string, string, string, string, string, string> (knownData));

            var synchronizer = builder.Build();

            synchronizer.Synchronize().Wait();

            builder.SynchronizerContext.AssertWasCalled(
                c => c.SaveEntityRelationData(Arg <List <IEntityRelationData <string, string, string, string> > > .Matches(l => l.Count == 1 && l[0] == knownData)));
        }
    public async Task Synchronize_GetVersionsAndGetReturnDuplicateEntries_RemovesDuplicates ()
    {
      var builder = new SynchronizerBuilder();

      builder.AtypeIdComparer = StringComparer.InvariantCultureIgnoreCase;

      builder.AtypeRepository
          .Expect (r => r.GetVersions())
          .IgnoreArguments()
          .Return (
              Task.FromResult<IReadOnlyList<EntityIdWithVersion<string, string>>> (
                  new[] { EntityIdWithVersion.Create ("A1", "v1"), EntityIdWithVersion.Create ("a1", "v3") }));

      builder.BtypeRepository
          .Expect (r => r.GetVersions())
          .IgnoreArguments()
          .Return (
              Task.FromResult<IReadOnlyList<EntityIdWithVersion<string, string>>> (
                  new[] { EntityIdWithVersion.Create ("b1", "v2") }));


      Task<IReadOnlyList<EntityWithVersion<string, string>>> aTypeLoadTask = new Task<IReadOnlyList<EntityWithVersion<string, string>>> (
          () => new List<EntityWithVersion<string, string>> { EntityWithVersion.Create ("A1", "AAAA"), EntityWithVersion.Create ("a1", "____") });
      aTypeLoadTask.RunSynchronously();
      builder.AtypeRepository
          .Expect (r => r.Get (Arg<ICollection<string>>.Matches (c => c.Count == 1 && c.First() == "A1")))
          .Return (aTypeLoadTask);

      Task<IReadOnlyList<EntityWithVersion<string, string>>> bTypeLoadTask = new Task<IReadOnlyList<EntityWithVersion<string, string>>> (
          () => new List<EntityWithVersion<string, string>> { EntityWithVersion.Create ("b1", "BBBB"), });
      bTypeLoadTask.RunSynchronously();
      builder.BtypeRepository
          .Expect (r => r.Get (Arg<ICollection<string>>.Matches (c => c.Count == 1 && c.First() == "b1")))
          .Return (bTypeLoadTask);


      var knownData = new EntityRelationData<string, string, string, string> ("A1", "v1", "b1", "v2");
      builder.InitialEntityMatcher
          .Expect (m => m.FindMatchingEntities (null, null, null, null, null))
          .IgnoreArguments()
          .Return (new List<IEntityRelationData<string, string, string, string>> { knownData });

      builder.InitialSyncStateCreationStrategy
          .Expect (s => s.CreateFor_Unchanged_Unchanged (knownData))
          .Return (new DoNothing<string, string, string, string, string, string> (knownData));

      var synchronizer = builder.Build();
      await synchronizer.Synchronize();

      builder.EntityRelationDataAccess.AssertWasCalled (
          c => c.SaveEntityRelationData (Arg<List<IEntityRelationData<string, string, string, string>>>.Matches (l => l.Count == 1 && l[0] == knownData)));
    }
Ejemplo n.º 3
0
        public async Task Synchronize_GetVersionsAndGetReturnDuplicateEntries_RemovesDuplicates()
        {
            var builder = new SynchronizerBuilder();

            builder.AtypeIdComparer = StringComparer.InvariantCultureIgnoreCase;
            builder.BtypeIdComparer = StringComparer.InvariantCultureIgnoreCase;

            builder.AtypeRepository
            .Expect(r => r.GetAllVersions(new string[] { }, 0, NullGetVersionsLogger.Instance))
            .IgnoreArguments()
            .Return(
                Task.FromResult <IEnumerable <EntityVersion <string, string> > > (
                    new[] { EntityVersion.Create("A1", "v1"), EntityVersion.Create("a1", "v3") }));

            builder.BtypeRepository
            .Expect(r => r.GetAllVersions(new string[] { }, 0, NullGetVersionsLogger.Instance))
            .IgnoreArguments()
            .Return(
                Task.FromResult <IEnumerable <EntityVersion <string, string> > > (
                    new[] { EntityVersion.Create("b1", "v2") }));


            var aTypeLoadTask = Task.FromResult <IEnumerable <EntityWithId <string, string> > > (
                new List <EntityWithId <string, string> > {
                EntityWithId.Create("A1", "AAAA"), EntityWithId.Create("a1", "____")
            });

            builder.AtypeRepository
            .Expect(r => r.Get(
                        Arg <ICollection <string> > .Matches(c => c.Count == 1 && c.First() == "A1"),
                        Arg <ILoadEntityLogger> .Is.NotNull,
                        Arg <int> .Is.Anything))
            .Return(aTypeLoadTask);

            var bTypeLoadTask = Task.FromResult <IEnumerable <EntityWithId <string, string> > > (
                new List <EntityWithId <string, string> > {
                EntityWithId.Create("b1", "BBBB"),
            });

            builder.BtypeRepository
            .Expect(r => r.Get(
                        Arg <ICollection <string> > .Matches(c => c.Count == 1 && c.First() == "b1"),
                        Arg <ILoadEntityLogger> .Is.NotNull,
                        Arg <int> .Is.Anything))
            .Return(bTypeLoadTask);

            var knownData = new EntityRelationData <string, string, string, string> ("A1", "v1", "b1", "v2");

            builder.InitialEntityMatcher
            .Expect(m => m.FindMatchingEntities(null, null, null, null, null))
            .IgnoreArguments()
            .Return(new List <IEntityRelationData <string, string, string, string> > {
                knownData
            });

            builder.InitialSyncStateCreationStrategy
            .Expect(s => s.CreateFor_Unchanged_Unchanged(knownData))
            .Return(new DoNothing <string, string, string, string, string, string, int> (knownData));

            builder.AtypeRepository.Stub(_ => _.VerifyUnknownEntities(null, 0)).IgnoreArguments().Return(Task.FromResult(0));
            builder.BtypeRepository.Stub(_ => _.VerifyUnknownEntities(null, 0)).IgnoreArguments().Return(Task.FromResult(0));

            var synchronizer = builder.Build();
            await synchronizer.Synchronize(NullSynchronizationLogger.Instance, 0);

            builder.EntityRelationDataAccess.AssertWasCalled(
                c => c.SaveEntityRelationData(Arg <List <IEntityRelationData <string, string, string, string> > > .Matches(l => l.Count == 1 && l[0] == knownData)));
        }