public void DeleteUnassignedCases()
        {
            var mockOutlook = MockRepository.GenerateStrictMock<IOutlook>();
            var mockFogbugz = MockRepository.GenerateMock<IFogbugzConnector>();
            var mockTaskSync = MockRepository.GenerateMock<ITaskSync>();

            var cases = new List<Case>()
                {
                    new Case() { CaseId = 123 },
                };

            var mockTask1 = CreateOutlookTask(); //Existing task
            mockTask1.SetFogbugzCaseId(123);
            var mockTask2 = CreateOutlookTask(); //Unassigned task
            mockTask2.SetFogbugzCaseId(456);
            var mockTask3 = CreateOutlookTask(); //Other user task

            var tasks = new List<TaskItem>() { mockTask1, mockTask2, mockTask3 };

            mockOutlook.Expect(x => x.SaveTask(mockTask1));
            mockOutlook.Expect(x => x.DeleteTask(mockTask2));

            var tls = new TaskListSync(mockOutlook, mockFogbugz, mockTaskSync);
            tls.SyncTasks(cases, tasks);

            mockOutlook.VerifyAllExpectations();
        }
        public void TasksInFogbugzNotOutlook()
        {
            var mockOutlook = MockRepository.GenerateStrictMock<IOutlook>();
            var mockFogbugz = MockRepository.GenerateMock<IFogbugzConnector>();
            var mockTaskSync = MockRepository.GenerateStrictMock<ITaskSync>();

            var mockTask1 = CreateOutlookTask();
            var mockTask2 = CreateOutlookTask();

            var cases = new List<Case>()
                {
                    new Case() { CaseId = 123 },
                    new Case() { CaseId = 456 },
                };

            mockOutlook.Expect(x => x.CreateTask()).Return(mockTask1);
            mockOutlook.Expect(x => x.CreateTask()).Return(mockTask2);

            mockTaskSync.Expect(x => x.SyncTask(cases[0], mockTask1));
            mockTaskSync.Expect(x => x.SyncTask(cases[1], mockTask2));

            mockOutlook.Expect(x => x.SaveTask(mockTask1));
            mockOutlook.Expect(x => x.SaveTask(mockTask2));

            var tls = new TaskListSync(mockOutlook, mockFogbugz, mockTaskSync);
            tls.SyncTasks(cases, new List<TaskItem>());

            mockOutlook.VerifyAllExpectations();
        }
        public void UpdateMatchingTasks()
        {
            var mockOutlook = MockRepository.GenerateStrictMock<IOutlook>();
            var mockFogbugz = MockRepository.GenerateMock<IFogbugzConnector>();
            var mockTaskSync = MockRepository.GenerateStrictMock<ITaskSync>();

            var mockTask1 = CreateOutlookTask();
            mockTask1.SetFogbugzCaseId(123);
            var mockTask2 = CreateOutlookTask();

            var cases = new List<Case>()
                {
                    new Case() { CaseId = 123 },
                };
            var tasks = new List<TaskItem>() { mockTask1, mockTask2 };

            mockTaskSync.Expect(x => x.SyncTask(cases[0], mockTask1));

            mockOutlook.Expect(x => x.SaveTask(mockTask1));

            var tls = new TaskListSync(mockOutlook, mockFogbugz, mockTaskSync);
            tls.SyncTasks(cases, tasks);

            mockOutlook.VerifyAllExpectations();
        }
        private void RunFullSync()
        {
            Log.Debug("Running a full Fogbugz <-> Outlook sync");

            if (!_outlook.IsOnline)
            {
                Log.Debug("Skipping Outlook sync due to Outlook being disconnected");
                return;
            }

            //Note: This domain needs to be set to your user domain
            var assigneeEmail = string.Format("{0}{1}", Environment.UserName, EmailDomain);
            Log.DebugFormat("User email address identified as {0}", assigneeEmail);
            var fogbugz = new FogbugzConnector(FogbugzUrl, AdminUser, AdminPass, assigneeEmail);

            var fogbugzUser = fogbugz.GetCurrentFogbugzUser();

            if (fogbugzUser == null)
            {
                var msg = string.Format("Could not find a user in Fogbugz associated with the email address '{0}'",
                                        assigneeEmail);
                Log.Error(msg);
                MessageBox.Show(msg);
                return;
            }

            var cases = fogbugz.LoadCases(fogbugzUser.FullName);
            var tasks = _outlook.GetTasksFromDefaultList();

            var taskListSync = new TaskListSync(new OutlookConnector(Application), fogbugz, new TaskSync());
            taskListSync.SyncTasks(cases, tasks);
        }