Exemplo n.º 1
0
        public void UpdatesFrom1To2Correctly()
        {
            INoteRepositoryUpdater updater = new NoteRepositoryUpdater();
            XDocument xml = XDocument.Parse(Version1Repository);

            bool result = updater.Update(xml);
            NoteRepositoryModel repository = XmlUtils.DeserializeFromXmlDocument <NoteRepositoryModel>(xml);

            Assert.IsTrue(result);
            Assert.IsNotNull(repository);
            Assert.AreEqual(new Guid("093b917a-f69f-4dd3-91b7-ad175fe0a4c1"), repository.Id);
            Assert.AreEqual(3, repository.Notes.Count);
            Assert.AreEqual(new Guid("a2b16ab9-9f7f-4389-916f-f2ef9a2f3a3a"), repository.Notes[0].Id);
            string noteContent = repository.Notes[0].HtmlContent;

            Assert.IsTrue(noteContent.Contains("<h1>Borrowed</h1>"));
            Assert.IsTrue(noteContent.Contains("<p>• &#39;The Black Magician Trilogy&#39;"));
            Assert.AreEqual(new Guid("70a25de4-2141-4164-aefc-b9b2624a112c"), repository.Notes[1].Id);
            noteContent = repository.Notes[1].HtmlContent;
            Assert.IsFalse(noteContent.Contains("<h1>")); // no title
            Assert.IsTrue(noteContent.Contains("<p>- Milk"));
            noteContent = repository.Notes[2].HtmlContent;
            Assert.IsTrue(noteContent.Contains("&lt;field&gt;"));

            Assert.AreEqual(1, repository.DeletedNotes.Count);
            Assert.AreEqual(new Guid("fae40c63-d850-4b78-a8bd-609893d2983b"), repository.DeletedNotes[0]);

            Assert.AreEqual(NoteRepositoryModel.NewestSupportedRevision, repository.Revision);
        }
Exemplo n.º 2
0
        internal static IEnumerable <NoteModel> EnumerateNotesToExport(
            NoteRepositoryModel repository, bool exportUnprotectedNotes, bool exportProtectedNotes)
        {
            foreach (NoteModel note in repository.Notes)
            {
                // Ignore deleted notes
                if (note.InRecyclingBin)
                {
                    continue;
                }

                if (!note.SafeIdSpecified)
                {
                    if (exportUnprotectedNotes)
                    {
                        yield return(note); // Unprotected note
                    }
                }
                else
                {
                    if (exportProtectedNotes && repository.Safes.FindById(note.SafeId).IsOpen)
                    {
                        yield return(note); // Protected note
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void UpdateNewerNotes()
        {
            NoteModel note1 = new NoteModel {
                HtmlContent = "11", ModifiedAt = new DateTime(2000, 01, 01)
            };
            NoteModel note2 = new NoteModel {
                HtmlContent = "22", ModifiedAt = new DateTime(2000, 02, 02)
            };
            NoteRepositoryModel clientRepo = new NoteRepositoryModel();

            clientRepo.Notes.Add(note1);
            clientRepo.Notes.Add(note2);
            NoteRepositoryModel serverRepo = new NoteRepositoryModel();
            NoteModel           note3      = new NoteModel {
                HtmlContent = "33", Id = note1.Id, ModifiedAt = new DateTime(2000, 01, 08)
            };                                                                                                              // newer, should win
            NoteModel note4 = new NoteModel {
                HtmlContent = "44", Id = note2.Id, ModifiedAt = new DateTime(2000, 01, 28)
            };                                                                                                              // older, should loose

            serverRepo.Notes.Add(note3);
            serverRepo.Notes.Add(note4);

            NoteRepositoryMerger merger = new NoteRepositoryMerger();
            NoteRepositoryModel  result = merger.Merge(clientRepo, serverRepo);

            Assert.AreEqual(2, result.Notes.Count);
            Assert.AreEqual("33", result.Notes[0].HtmlContent);
            Assert.AreEqual("22", result.Notes[1].HtmlContent);
        }
Exemplo n.º 4
0
        public void NoDuplicatesOnDeletedNotes()
        {
            Guid note1Id = new Guid("10000000000000000000000000000000");
            Guid note2Id = new Guid("20000000000000000000000000000000");
            Guid note3Id = new Guid("30000000000000000000000000000000");

            NoteRepositoryModel serverRepo = new NoteRepositoryModel();

            serverRepo.DeletedNotes.Add(note1Id);
            serverRepo.DeletedNotes.Add(note2Id);
            serverRepo.DeletedNotes.Add(note3Id);
            NoteRepositoryModel clientRepo = new NoteRepositoryModel();

            clientRepo.DeletedNotes.Add(note2Id); // deleted in both repos
            clientRepo.Notes.Add(new NoteModel {
                Id = note3Id
            });                                                   // not yet deleted

            NoteRepositoryMerger merger = new NoteRepositoryMerger();
            NoteRepositoryModel  result = merger.Merge(clientRepo, serverRepo);

            Assert.AreEqual(3, result.DeletedNotes.Count);
            Assert.IsTrue(result.DeletedNotes.Contains(note1Id));
            Assert.IsTrue(result.DeletedNotes.Contains(note2Id));
            Assert.IsTrue(result.DeletedNotes.Contains(note3Id));
        }
Exemplo n.º 5
0
        public void UseOrderCorrectlyIfNoNewNotes()
        {
            NoteRepositoryModel clientRepo = new NoteRepositoryModel();
            NoteModel           note102    = new NoteModel();
            NoteModel           note104    = new NoteModel();

            clientRepo.Notes.Add(note102);
            clientRepo.Notes.Add(note104);
            NoteRepositoryModel serverRepo = new NoteRepositoryModel();
            NoteModel           note202    = note102.Clone();
            NoteModel           note204    = note104.Clone();

            serverRepo.Notes.Add(note204);
            serverRepo.Notes.Add(note202);

            // Take order of client
            NoteRepositoryMerger merger = new NoteRepositoryMerger();

            clientRepo.OrderModifiedAt = new DateTime(2000, 01, 02); // newer
            serverRepo.OrderModifiedAt = new DateTime(2000, 01, 01); // older
            NoteRepositoryModel result = merger.Merge(clientRepo, serverRepo);

            Assert.AreEqual(2, result.Notes.Count);
            Assert.AreEqual(note102.Id, result.Notes[0].Id);
            Assert.AreEqual(note104.Id, result.Notes[1].Id);
        }
        private NoteRepositoryModel CreateTestRepository()
        {
            NoteRepositoryModel model = new NoteRepositoryModel();

            model.Id = new Guid("3538c76a-eee9-4905-adcf-946f8b527c37");
            model.Safes.Add(new SafeModel {
                Id = new Guid("543d7b84-db8b-4c2b-a9e2-6e105c686f26")
            });

            // Note inside safe
            model.Notes.Add(new NoteModel {
                Id = new Guid("6821aab9-d388-49f9-94a7-5ab366ca168e"), SafeId = model.Safes[0].Id
            });

            // Notes outside safe
            model.Notes.Add(new NoteModel {
                Id = new Guid("2ed4d12d-b1a8-4107-9bcf-736e80899465")
            });
            model.Notes.Add(new NoteModel {
                Id = new Guid("08e28535-88a8-4fc0-b6bb-3a5651cc594c")
            });

            // Deleted note
            model.DeletedNotes.Add(new Guid("c84e7eb9-f671-4b9f-a7e7-a013a5e1cef7"));
            return(model);
        }
Exemplo n.º 7
0
        public void ResetSafeRemovesNotesAndSafes()
        {
            Guid note1Id = new Guid("10000000000000000000000000000000");
            Guid note2Id = new Guid("20000000000000000000000000000000");
            Guid safeAId = new Guid("A0000000000000000000000000000000");
            Guid safeBId = new Guid("B0000000000000000000000000000000");
            NoteRepositoryModel repository = new NoteRepositoryModel();

            repository.Notes.Add(new NoteModel {
                Id = note1Id, SafeId = safeAId
            });                                                                     // locked, should be deleted
            repository.Notes.Add(new NoteModel {
                Id = note2Id, SafeId = null
            });                                                                  // unlocked, should be kept
            repository.Safes.Add(new SafeModel {
                Id = safeAId
            });
            repository.Safes.Add(new SafeModel {
                Id = safeBId
            });

            Mock <INavigationService>        navigationService        = new Mock <INavigationService>();
            Mock <IRepositoryStorageService> repositoryStorageService = new Mock <IRepositoryStorageService>();

            repositoryStorageService.
            Setup(m => m.LoadRepositoryOrDefault(out repository));
            Mock <IFeedbackService> feedbackService = new Mock <IFeedbackService>();

            feedbackService.
            Setup(m => m.ShowMessageAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButtons>(), It.IsAny <bool>()))
            .ReturnsAsync(MessageBoxResult.Continue);

            OpenSafeViewModel viewModel = new OpenSafeViewModel(
                navigationService.Object,
                CommonMocksAndStubs.LanguageService(),
                new Mock <ISvgIconService>().Object,
                new Mock <IThemeService>().Object,
                new Mock <IBaseUrlService>().Object,
                feedbackService.Object,
                CommonMocksAndStubs.CryptoRandomService(),
                new Mock <ISettingsService>().Object,
                repositoryStorageService.Object,
                null);

            viewModel.ResetSafeCommand.Execute(null);

            // Note is deleted and added to the deleted list
            Assert.AreEqual(1, repository.Notes.Count);
            Assert.AreEqual(note2Id, repository.Notes[0].Id);
            Assert.AreEqual(1, repository.DeletedNotes.Count);
            Assert.AreEqual(note1Id, repository.DeletedNotes[0]);

            // Safes are removed
            Assert.AreEqual(0, repository.Safes.Count);

            // Is marked as modified and navigated away, so it will be stored.
            Assert.IsTrue(viewModel.Modified);
            navigationService.Verify(m => m.Navigate(It.Is <Navigation>(v => v.ControllerId == ControllerNames.OpenSafe)));
            feedbackService.Verify(m => m.ShowMessageAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButtons>(), It.Is <bool>(v => v == true)), Times.Once);
        }
Exemplo n.º 8
0
        public void RemoveNotesDeletedOnTheClient()
        {
            NoteRepositoryModel serverRepo = new NoteRepositoryModel();
            NoteModel           note1      = new NoteModel();
            NoteModel           note2      = new NoteModel();
            NoteModel           note3      = new NoteModel();

            serverRepo.Notes.Add(note1);
            serverRepo.Notes.Add(note2);
            serverRepo.Notes.Add(note3);
            NoteRepositoryModel clientRepo = new NoteRepositoryModel();

            clientRepo.DeletedNotes.Add(note2.Id);
            clientRepo.DeletedNotes.Add(note1.Id);
            clientRepo.DeletedNotes.Add(note3.Id);

            NoteRepositoryMerger merger = new NoteRepositoryMerger();
            NoteRepositoryModel  result = merger.Merge(clientRepo, serverRepo);

            Assert.AreEqual(0, result.Notes.Count);
            Assert.AreEqual(3, result.DeletedNotes.Count);
            Assert.IsTrue(result.DeletedNotes.Contains(note1.Id));
            Assert.IsTrue(result.DeletedNotes.Contains(note2.Id));
            Assert.IsTrue(result.DeletedNotes.Contains(note3.Id));
        }
        public void StoresRepositoryToDevice()
        {
            NoteRepositoryModel repositoryModel = new NoteRepositoryModel();

            Mock <IStoryBoard> storyBoard = new Mock <IStoryBoard>();

            storyBoard.
            Setup(m => m.LoadFromSession <NoteRepositoryModel>(It.Is <SynchronizationStorySessionKey>(p => p == SynchronizationStorySessionKey.CloudRepository))).
            Returns(repositoryModel);
            Mock <ILanguageService>          languageService          = new Mock <ILanguageService>();
            Mock <IFeedbackService>          feedbackService          = new Mock <IFeedbackService>();
            Mock <IRepositoryStorageService> repositoryStorageService = new Mock <IRepositoryStorageService>();

            // Run step
            var step = new StoreCloudRepositoryToDeviceAndQuitStep(
                SynchronizationStoryStepId.StoreCloudRepositoryToDeviceAndQuit, storyBoard.Object, languageService.Object, feedbackService.Object, repositoryStorageService.Object);

            Assert.DoesNotThrowAsync(step.Run);

            // repository is stored to the local device
            repositoryStorageService.Verify(m => m.TrySaveRepository(It.Is <NoteRepositoryModel>(r => r == repositoryModel)), Times.Once);

            // Next step is called
            storyBoard.Verify(m => m.ContinueWith(It.Is <SynchronizationStoryStepId>(x => x == SynchronizationStoryStepId.StopAndShowRepository)), Times.Once);
        }
        private static NoteRepositoryViewModel CreateMockedNoteRepositoryViewModel(NoteRepositoryModel repository)
        {
            SettingsModel settingsModel = new SettingsModel {
                DefaultNoteInsertion = NoteInsertionMode.AtTop
            };
            Mock <ISettingsService> settingsService = new Mock <ISettingsService>();

            settingsService.
            Setup(m => m.LoadSettingsOrDefault()).Returns(settingsModel);

            Mock <IRepositoryStorageService> repositoryStorageService = new Mock <IRepositoryStorageService>();

            repositoryStorageService.
            Setup(m => m.LoadRepositoryOrDefault(out repository));

            return(new NoteRepositoryViewModel(
                       new Mock <INavigationService>().Object,
                       new Mock <ILanguageService>().Object,
                       new Mock <ISvgIconService>().Object,
                       new Mock <IThemeService>().Object,
                       new Mock <IBaseUrlService>().Object,
                       new Mock <IStoryBoardService>().Object,
                       new Mock <IFeedbackService>().Object,
                       settingsService.Object,
                       CommonMocksAndStubs.EnvironmentService(),
                       CommonMocksAndStubs.CryptoRandomService(),
                       repositoryStorageService.Object));
        }
        public void GetModificationFingerprintDetectsNoteChanges()
        {
            NoteRepositoryModel model1 = CreateNoteRepositoryModel();
            NoteRepositoryModel model2 = CreateNoteRepositoryModel();
            model2.Notes[0].ModifiedAt = new DateTime(1984, 02, 21);

            Assert.AreNotEqual(model1.GetModificationFingerprint(), model2.GetModificationFingerprint());
        }
        public void GetModificationFingerprintDetectsRevisionUpdates()
        {
            NoteRepositoryModel model1 = CreateNoteRepositoryModel();
            NoteRepositoryModel model2 = CreateNoteRepositoryModel();
            model2.Revision = 8;

            Assert.AreNotEqual(model1.GetModificationFingerprint(), model2.GetModificationFingerprint());
        }
Exemplo n.º 13
0
        public void GetModificationFingerprintDetectsEqualityForEqualRepositories()
        {
            NoteRepositoryModel model1 = CreateNoteRepositoryModel();
            NoteRepositoryModel model2 = CreateNoteRepositoryModel();

            Assert.AreEqual(model1.GetModificationFingerprint(), model2.GetModificationFingerprint());
            Assert.AreEqual(model1.GetModificationFingerprint(), model1.GetModificationFingerprint());
        }
Exemplo n.º 14
0
        private static NoteViewModel CreateMockedNoteViewModel(NoteModel note, NoteRepositoryModel repository)
        {
            Mock <IRepositoryStorageService> repositoryStorageService = new Mock <IRepositoryStorageService>();

            repositoryStorageService.
            Setup(m => m.LoadRepositoryOrDefault(out repository));
            return(CreateMockedNoteViewModel(note, repositoryStorageService.Object));
        }
Exemplo n.º 15
0
        public void MergeSafes()
        {
            Guid     safe1Id    = new Guid("10000000000000000000000000000000");
            Guid     safe2Id    = new Guid("20000000000000000000000000000000");
            Guid     safe3Id    = new Guid("30000000000000000000000000000000");
            Guid     safe4Id    = new Guid("40000000000000000000000000000000");
            Guid     safe5Id    = new Guid("50000000000000000000000000000000");
            Guid     safe6Id    = new Guid("60000000000000000000000000000000");
            DateTime newerDate  = new DateTime(2008, 08, 08);
            DateTime middleDate = new DateTime(2006, 06, 06);

            NoteRepositoryModel serverRepo = new NoteRepositoryModel();
            SafeModel           safeS1     = new SafeModel {
                Id = safe2Id, SerializeableKey = "s1", ModifiedAt = newerDate
            };
            SafeModel safeS2 = new SafeModel {
                Id = safe4Id, SerializeableKey = "s2", ModifiedAt = middleDate
            };
            SafeModel safeS3 = new SafeModel {
                Id = safe6Id, SerializeableKey = "s3", ModifiedAt = middleDate
            };

            serverRepo.Safes.AddRange(new[] { safeS1, safeS2, safeS3 });
            AddNotesWithSafeIds(serverRepo, new[] { safe2Id, safe4Id, safe6Id });

            NoteRepositoryModel clientRepo = new NoteRepositoryModel();
            SafeModel           safeC1     = new SafeModel {
                Id = safe5Id, SerializeableKey = "c1", ModifiedAt = middleDate
            };
            SafeModel safeC2 = new SafeModel {
                Id = safe4Id, SerializeableKey = "c2", ModifiedAt = newerDate
            };
            SafeModel safeC3 = new SafeModel {
                Id = safe2Id, SerializeableKey = "c3", ModifiedAt = middleDate
            };
            SafeModel safeC4 = new SafeModel {
                Id = safe1Id, SerializeableKey = "c4", ModifiedAt = middleDate
            };
            SafeModel safeC5 = new SafeModel {
                Id = safe3Id, SerializeableKey = "c5", ModifiedAt = middleDate
            };

            clientRepo.Safes.AddRange(new[] { safeC1, safeC2, safeC3, safeC4, safeC5 });
            AddNotesWithSafeIds(clientRepo, new[] { safe5Id, safe4Id, safe2Id, safe1Id, safe3Id });

            NoteRepositoryMerger merger = new NoteRepositoryMerger();
            NoteRepositoryModel  result = merger.Merge(clientRepo, serverRepo);
            SafeListModel        safes  = result.Safes;

            Assert.AreEqual(6, safes.Count);
            Assert.AreEqual(safe5Id, safes[0].Id); Assert.AreEqual("c1", safes[0].SerializeableKey);
            Assert.AreEqual(safe2Id, safes[1].Id); Assert.AreEqual("s1", safes[1].SerializeableKey);
            Assert.AreEqual(safe1Id, safes[2].Id); Assert.AreEqual("c4", safes[2].SerializeableKey);
            Assert.AreEqual(safe3Id, safes[3].Id); Assert.AreEqual("c5", safes[3].SerializeableKey);
            Assert.AreEqual(safe4Id, safes[4].Id); Assert.AreEqual("c2", safes[4].SerializeableKey);
            Assert.AreEqual(safe6Id, safes[5].Id); Assert.AreEqual("s3", safes[5].SerializeableKey);
        }
        internal static byte[] EncryptRepository(NoteRepositoryModel repository, string transferCode, ICryptoRandomService randomService, string encryptionAlgorithm)
        {
            byte[]             binaryRepository = XmlUtils.SerializeToXmlBytes(repository);
            EncryptorDecryptor encryptor        = new EncryptorDecryptor("SilentNotes");

            // The key derivation cost is set to low, because we can be sure that the transferCode
            // is a very strong password, and to not overload slow mobile devices.
            return(encryptor.Encrypt(binaryRepository, transferCode, Crypto.KeyDerivation.KeyDerivationCostType.Low, randomService, encryptionAlgorithm));
        }
        public void GetModificationFingerprintDetectsDifferencesInDeletedNotes()
        {
            NoteRepositoryModel model1 = CreateNoteRepositoryModel();
            NoteRepositoryModel model2 = CreateNoteRepositoryModel();
            model1.DeletedNotes.Add(new Guid("db73989f-5d88-43f9-bae3-bdc1b9607479"));
            model2.DeletedNotes.Add(new Guid("0152d7da-397c-43ba-b586-e5ea6f8e7c4e"));

            Assert.AreNotEqual(model1.GetModificationFingerprint(), model2.GetModificationFingerprint());
        }
Exemplo n.º 18
0
 private static void AddNotesWithSafeIds(NoteRepositoryModel repo, IEnumerable <Guid> safeIds)
 {
     foreach (Guid safeId in safeIds)
     {
         repo.Notes.Add(new NoteModel {
             SafeId = safeId
         });
     }
 }
        public void EnumerateNotesToExport_DoesNotReturnProtectedNoteBecauseSafeIsClosed()
        {
            NoteRepositoryModel repository = CreateTestRepository();
            var notes = ExportViewModel.EnumerateNotesToExport(repository, true, true).ToList();

            Assert.AreEqual(2, notes.Count);
            Assert.AreSame(repository.Notes[1], notes[0]);
            Assert.AreSame(repository.Notes[2], notes[1]);
        }
Exemplo n.º 20
0
        private void AddWelcomeNote(NoteRepositoryModel repositoryModel)
        {
            NoteModel welcomeNote = new NoteModel
            {
                HtmlContent = _languageService.LoadText("welcome_note"),
            };

            repositoryModel.Notes.Add(welcomeNote);
        }
        public void EnumerateNotesToExport_ReturnsProtectedNotesOnly()
        {
            NoteRepositoryModel repository = CreateTestRepository();

            repository.Safes[0].Key = new byte[] { 88 };
            var notes = ExportViewModel.EnumerateNotesToExport(repository, false, true).ToList();

            Assert.AreEqual(1, notes.Count);
            Assert.AreSame(repository.Notes[0], notes[0]);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RepositoryStorageServiceBase"/> class.
        /// </summary>
        public RepositoryStorageServiceBase(IXmlFileService xmlFileService, ILanguageService languageService)
        {
            _xmlFileService  = xmlFileService;
            _languageService = languageService;
            _updater         = new NoteRepositoryUpdater();

#if (DEMO && DEBUG)
            _cachedRepository = new DemoNoteRepositoryModel();
#endif
        }
 private static NoteRepositoryModel CreateNoteRepositoryModel()
 {
     NoteRepositoryModel model = new NoteRepositoryModel();
     model.Id = new Guid("3538c76a-eee9-4905-adcf-946f8b527c37");
     model.Revision = 2;
     model.OrderModifiedAt = new DateTime(2018, 02, 21);
     model.Notes.Add(new NoteModel { ModifiedAt = new DateTime(2018, 02, 22) });
     model.DeletedNotes.Add(new Guid("c84e7eb9-f671-4b9f-a7e7-a013a5e1cef7"));
     return model;
 }
Exemplo n.º 24
0
        private static byte[] CreateEncryptedRepository(string password, NoteRepositoryModel repository = null)
        {
            if (repository == null)
            {
                repository = new NoteRepositoryModel();
            }
            byte[]   serializedRepository = XmlUtils.SerializeToXmlBytes(repository);
            ICryptor encryptor            = new Cryptor("SilentNotes", CommonMocksAndStubs.CryptoRandomService());

            return(encryptor.Encrypt(serializedRepository, CryptoUtils.StringToSecureString(password), SilentNotes.Crypto.KeyDerivation.KeyDerivationCostType.Low, BouncyCastleTwofishGcm.CryptoAlgorithmName));
        }
        /// <inheritdoc/>
        public RepositoryStorageLoadResult LoadRepositoryOrDefault(out NoteRepositoryModel repositoryModel)
        {
            if (_cachedRepository != null)
            {
                repositoryModel = _cachedRepository;
                return(RepositoryStorageLoadResult.SuccessfullyLoaded);
            }

            RepositoryStorageLoadResult result;

            repositoryModel = null;
            bool modelWasUpdated = false;

            try
            {
                // A new repository is created only if it does not yet exist, we won't overwrite
                // an invalid repository.
                if (RepositoryExists())
                {
                    string xmlFilePath = Path.Combine(GetDirectoryPath(), Config.RepositoryFileName);
                    if (!_xmlFileService.TryLoad(xmlFilePath, out XDocument xml))
                    {
                        throw new Exception("Invalid XML");
                    }

                    result          = RepositoryStorageLoadResult.SuccessfullyLoaded;
                    modelWasUpdated = _updater.Update(xml);
                    repositoryModel = XmlUtils.DeserializeFromXmlDocument <NoteRepositoryModel>(xml);
                }
                else
                {
                    result                   = RepositoryStorageLoadResult.CreatedNewEmptyRepository;
                    repositoryModel          = new NoteRepositoryModel();
                    repositoryModel.Revision = NoteRepositoryModel.NewestSupportedRevision;
                    AddWelcomeNote(repositoryModel);
                    modelWasUpdated = true;
                }
            }
            catch (Exception)
            {
                result          = RepositoryStorageLoadResult.InvalidRepository;
                repositoryModel = null;
                modelWasUpdated = false;
            }

            // Automatically save settings if they where modified by an update
            if (modelWasUpdated)
            {
                TrySaveRepository(repositoryModel);
            }
            _cachedRepository = repositoryModel;
            return(result);
        }
Exemplo n.º 26
0
        public void IsPinned_SetToTrue_MovesNotePositionToTop()
        {
            NoteRepositoryModel repository     = CreateTestRepository();
            NoteModel           noteToBePinned = repository.Notes[1];
            NoteViewModel       noteViewModel  = CreateMockedNoteViewModel(noteToBePinned, repository);

            noteViewModel.IsPinned = true;
            noteViewModel.OnStoringUnsavedData();

            Assert.AreSame(noteToBePinned, repository.Notes[0]); // Now on first position
            Assert.IsTrue(noteToBePinned.IsPinned);
        }
        public void NewNote_IsAddedAsFirstIfNoOtherNotesExist()
        {
            NoteRepositoryModel model = new NoteRepositoryModel();

            NoteRepositoryViewModel viewModel = CreateMockedNoteRepositoryViewModel(model);

            viewModel.NewNoteCommand.Execute(null);

            // New note is at position 1, after first pinned note
            Assert.AreEqual(1, model.Notes.Count);
            Assert.IsFalse(model.Notes[0].IsPinned);
        }
        public void EnumerateNotesToExport_ReturnsUnprotectedNotesOnly()
        {
            NoteRepositoryModel repository = CreateTestRepository();

            repository.Notes[0].SafeId = repository.Safes[0].Id;

            var notes = ExportViewModel.EnumerateNotesToExport(repository, true, false).ToList();

            Assert.AreEqual(2, notes.Count);
            Assert.AreSame(repository.Notes[1], notes[0]);
            Assert.AreSame(repository.Notes[2], notes[1]);
        }
        public void StoreMergedRepositoryWhenDifferent()
        {
            const string transferCode = "abcdefgh";
            SerializeableCloudStorageCredentials credentialsFromSession = new SerializeableCloudStorageCredentials();
            var settingsModel = CreateSettingsModel(transferCode);
            NoteRepositoryModel repositoryModelLocal = new NoteRepositoryModel();

            repositoryModelLocal.Notes.Add(new NoteModel());
            NoteRepositoryModel repositoryModelCloud = new NoteRepositoryModel();

            repositoryModelCloud.Notes.Add(new NoteModel());

            Mock <IStoryBoard> storyBoard = new Mock <IStoryBoard>();

            storyBoard.
            Setup(m => m.LoadFromSession <SerializeableCloudStorageCredentials>(It.Is <int>(p => p == SynchronizationStorySessionKey.CloudStorageCredentials.ToInt()))).
            Returns(credentialsFromSession);
            storyBoard.
            Setup(m => m.LoadFromSession <NoteRepositoryModel>(It.Is <int>(p => p == SynchronizationStorySessionKey.CloudRepository.ToInt()))).
            Returns(repositoryModelCloud);     // same as from repositoryStorageService
            Mock <ISettingsService> settingsService = new Mock <ISettingsService>();

            settingsService.
            Setup(m => m.LoadSettingsOrDefault()).Returns(settingsModel);
            Mock <IRepositoryStorageService> repositoryStorageService = new Mock <IRepositoryStorageService>();

            repositoryStorageService.
            Setup(m => m.LoadRepositoryOrDefault(out repositoryModelLocal));     // same as from storyBoard
            Mock <ICloudStorageClient> cloudStorageClient = new Mock <ICloudStorageClient>();

            // Run step
            var step = new StoreMergedRepositoryAndQuitStep(
                SynchronizationStoryStepId.StoreLocalRepositoryToCloudAndQuit.ToInt(),
                storyBoard.Object,
                CommonMocksAndStubs.LanguageService(),
                CommonMocksAndStubs.FeedbackService(),
                settingsService.Object,
                CommonMocksAndStubs.CryptoRandomService(),
                repositoryStorageService.Object,
                CommonMocksAndStubs.CloudStorageClientFactory(cloudStorageClient.Object));

            Assert.DoesNotThrowAsync(step.Run);

            // repository is stored to the local device
            repositoryStorageService.Verify(m => m.TrySaveRepository(It.IsAny <NoteRepositoryModel>()), Times.Once);

            // repository is stored to the cloud
            cloudStorageClient.Verify(m => m.UploadFileAsync(It.IsAny <string>(), It.IsAny <byte[]>(), It.IsAny <CloudStorageCredentials>()), Times.Once);

            // Next step is called
            storyBoard.Verify(m => m.ContinueWith(It.Is <int>(x => x == SynchronizationStoryStepId.StopAndShowRepository.ToInt())), Times.Once);
        }
Exemplo n.º 30
0
        public void Update_SetsNewestVersionNumber()
        {
            // Set revision too small
            NoteRepositoryModel repository = new NoteRepositoryModel {
                Revision = NoteRepositoryModel.NewestSupportedRevision - 1
            };
            XDocument repositoryXml = XmlUtils.SerializeToXmlDocument(repository);

            INoteRepositoryUpdater updater = new NoteRepositoryUpdater();

            Assert.IsTrue(updater.Update(repositoryXml));
            Assert.AreEqual(NoteRepositoryModel.NewestSupportedRevision.ToString(), repositoryXml.Root.Attribute("revision").Value);
        }