public void ShouldSynchronizeStatus()
        {
            using (Mocks.Record())
            {
                SetupResult.For(_masterStub.GetAll()).Return(new[] { Entry("1", "/done") });

                Expect.Call(_slaveMock.GetAll()).Return(new[] { Entry("1", "Development") });
                _slaveMock.UpdateStatus(Entry("1", "Done"));
            }
            using (Mocks.Playback())
            {
                _synchronizer.Synchronize();
            }
        }
        public void ShouldCreateMissingSynchronizationEntriesInSlave()
        {
            using (Mocks.Record())
            {
                SetupResult.For(_masterStub.GetAll()).Return(new[] { Entry("1", "scheduled") });

                Expect.Call(_slaveMock.GetAll()).Return(new SynchronizationEntry[0]);
                _slaveMock.Create(Entry("1", "planned"));
            }
            using (Mocks.Playback())
            {
                _synchronizer.Synchronize();
            }
        }
        public void Synchronize()
        {
            var masterEntries = _master.GetAll().ToDictionary(e => e.Id);
            var slaveEntries  = _slave.GetAll().ToDictionary(e => e.Id);

            foreach (var masterId in masterEntries.Keys)
            {
                if (!slaveEntries.ContainsKey(masterId))
                {
                    continue;
                }

                var slaveEntry  = slaveEntries[masterId];
                var masterEntry = masterEntries[masterId];

                var slaveProperties             = FilterForSynchronization(_slave, slaveEntry.Properties);
                var slaveMappedMasterProperties = FilterForSynchronization(_slave, MapProperties(_master, masterEntry.Properties));

                SynchronizationEntry updateEntry = null;

                if (!AreEqual(slaveMappedMasterProperties, slaveProperties))
                {
                    Console.WriteLine("Properties differ");
                    Console.WriteLine("Slavemapped master:" + slaveMappedMasterProperties.Select(kv => kv.Value).Join(','));
                    Console.WriteLine("Slave             :" + slaveProperties.Select(kv => kv.Value).Join(','));


                    updateEntry = new SynchronizationEntry(masterId, slaveEntry.Status, slaveMappedMasterProperties)
                    {
                        Ordinal = slaveEntry.Ordinal
                    };
                }

                if (SynchronizeOrdinal && masterEntry.Ordinal != slaveEntry.Ordinal)
                {
                    Console.WriteLine("Ordinals differ: {0}-{1}", masterEntry, slaveEntry);
                    updateEntry = new SynchronizationEntry(masterId, slaveEntry.Status, slaveMappedMasterProperties)
                    {
                        Ordinal = masterEntry.Ordinal
                    };
                }

                if (updateEntry != null)
                {
                    _slave.UpdateData(updateEntry);
                }
            }
        }
        public void Synchronize()
        {
            var masterEntries = _master.GetAll().ToDictionary(e => e.Id);
            var slaveEntries  = _slave.GetAll().ToDictionary(e => e.Id);

            foreach (var masterId in masterEntries.Keys)
            {
                if (slaveEntries.ContainsKey(masterId))
                {
                    SynchronizationEntry masterMappedSlaveEntry;
                    if (!TryGetMasterEntry(slaveEntries[masterId], out masterMappedSlaveEntry))
                    {
                        continue;
                    }

                    if (masterMappedSlaveEntry.Status == masterEntries[masterId].Status)
                    {
                        continue;
                    }

                    if (masterMappedSlaveEntry.TimeStamp.HasValue && masterEntries[masterId].TimeStamp.HasValue && masterMappedSlaveEntry.TimeStamp > masterEntries[masterId].TimeStamp)
                    {
                        continue;
                    }


                    SynchronizationEntry slaveMappedMasterEntry;
                    if (!TryGetSlaveEntry(masterEntries[masterId], out slaveMappedMasterEntry))
                    {
                        continue;
                    }

                    if (slaveMappedMasterEntry.Status != slaveEntries[masterId].Status)
                    {
                        Console.WriteLine("Status differ: {0}-{1}", slaveMappedMasterEntry, slaveEntries[masterId]);

                        _slave.UpdateStatus(slaveMappedMasterEntry);
                    }
                }
            }
        }
        public void Synchronize()
        {
            var masterEntries = _master.GetAll();
            var slaveEntries  = _slave.GetAll();

            var idsForDeletion =
                slaveEntries.Select(e => e.Id).Except(
                    masterEntries.Where(me => _map.ContainsKey(_master, me.Status)).Select(e => e.Id));

            foreach (var id in idsForDeletion)
            {
                var entry = slaveEntries.Where(e => e.Id == id).Single();
                _slave.Delete(entry);
            }

            var idsForCreation = masterEntries.Select(e => e.Id).Except(slaveEntries.Select(e => e.Id));

            foreach (var id in idsForCreation)
            {
                try
                {
                    var entry = masterEntries.Where(e => e.Id == id).Single();

                    SynchronizationEntry slaveEntry;

                    if (TryGetSlaveEntry(entry, out slaveEntry))
                    {
                        _slave.Create(slaveEntry);
                    }
                }
                catch (InvalidOperationException e)
                {
                    throw new InvalidOperationException("Id='" + id + "'", e);
                }
            }
        }