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

                Expect.Call(_slaveMock.GetAll()).Return(new[] { Entry("1", "planned"), Entry("2", "planned") });
                _slaveMock.Delete(Entry("2", "planned"));
                LastCall.Repeat.Once();
            }
            using (Mocks.Playback())
            {
                _synchronizer.Synchronize();
            }
        }
        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);
                }
            }
        }