public void CreateRepositoryTwiceThrowsException()
        {
            var repository = CreateRepository();

            repository.Create(RepositoryTestsBase.GetUniqueFilePath(), "DefaultName");

            Assert.That(() => repository.Create("", "DefaultName"), Throws.InstanceOf <ApplicationException>());
        }
        public void CloseTwiceRepositoryThrowsException()
        {
            var repository = CreateRepository();

            repository.Create(RepositoryTestsBase.GetUniqueFilePath(), "DefaultName");
            repository.Close();

            Assert.That(repository.Close, Throws.InstanceOf <ApplicationException>());
            Assert.That(repository.FilePath, Is.Null.Or.Empty);
        }
        public void OpenCreatedRepositoryThrowsException()
        {
            var repository     = CreateRepository();
            var uniqueFilePath = RepositoryTestsBase.GetUniqueFilePath(true);

            repository.Create(uniqueFilePath, "DefaultName");

            Assert.That(() => repository.Open(""), Throws.InstanceOf <ApplicationException>());
            Assert.That(repository.FilePath, Is.EqualTo(uniqueFilePath));
        }
        public void OpenTwiceThrowsException()
        {
            var repository     = CreateRepository();
            var uniqueFilePath = RepositoryTestsBase.GetUniqueFilePath(true);

            repository.Create(uniqueFilePath, "Test");
            repository.Close();

            repository.Open(uniqueFilePath);

            Assert.That(() => repository.Open(uniqueFilePath), Throws.InstanceOf <ApplicationException>());
        }
        public void CreateRepositoryWhenFileExistsThrowsException(bool withExtension)
        {
            var repository = CreateRepository();
            var targetFilePathWithoutExtension = RepositoryTestsBase.GetUniqueFilePath();
            var targetFilePathWithExtension    = targetFilePathWithoutExtension + SystemConstants.DatabaseExtension;

            File.WriteAllText(targetFilePathWithExtension, @"Test");

            var targetFileToSet = withExtension ? targetFilePathWithExtension : targetFilePathWithoutExtension;

            Assert.That(() => repository.Create(targetFileToSet, "MyRepository"), Throws.InstanceOf <ApplicationException>());
        }
        public void OpenCreatedRepository(bool close)
        {
            var repository     = CreateRepository();
            var uniqueFilePath = RepositoryTestsBase.GetUniqueFilePath(true);

            repository.Create(uniqueFilePath, "Test");
            if (close)
            {
                repository.Close();
            }

            Assert.That(() => repository.Open(uniqueFilePath), close ? (IResolveConstraint)Throws.Nothing : Throws.InstanceOf <ApplicationException>());
        }
        public void CreateRepository(bool withExtension)
        {
            var repository = CreateRepository();
            var targetFilePathWithoutExtension = RepositoryTestsBase.GetUniqueFilePath();
            var targetFilePathWithExtension    = targetFilePathWithoutExtension + SystemConstants.DatabaseExtension;

            repository.Create(withExtension ? targetFilePathWithExtension : targetFilePathWithoutExtension, "MyRepository");
            _context.Received(1).UpdateRecentAccountInformation(repository.FilePath);

            Assert.That(File.Exists(targetFilePathWithExtension));
            AssertFileContentIsCorrect(targetFilePathWithExtension, "MyRepository");
            Assert.That(repository.Name, Is.EqualTo("MyRepository"));
            Assert.That(repository.IsOpen, Is.True);

            repository.Close();
        }
        public void CreateRepositoryWithEmptyNameThrowsExcpetion(string name)
        {
            var repository = CreateRepository();

            Assert.That(() => repository.Create(RepositoryTestsBase.GetUniqueFilePath(true), name), Throws.InstanceOf <ArgumentException>());
        }