public void SetUp() { IDataStore knownPublicKeysStore = new FakeInMemoryDataStoreItem("knownpublickeys.txt"); TypeMap.Register.Singleton <IAsymmetricFactory>(() => new BouncyCastleAsymmetricFactory()); TypeMap.Register.Singleton <IEmailParser>(() => new EmailParser()); TypeMap.Register.Singleton <AxCryptOnlineState>(() => new AxCryptOnlineState()); TypeMap.Register.Singleton <FileLocker>(() => new FileLocker()); TypeMap.Register.Singleton <IPortableFactory>(() => new PortableFactory()); TypeMap.Register.Singleton <INow>(() => new FakeNow()); TypeMap.Register.Singleton <UserPublicKeyUpdateStatus>(() => new UserPublicKeyUpdateStatus()); TypeMap.Register.Singleton <KnownIdentities>(() => new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify)); TypeMap.Register.Singleton <FileSystemState>(() => FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("FileSystemState.txt"))); TypeMap.Register.Singleton <WorkFolder>(() => new WorkFolder(Path.GetPathRoot(Environment.CurrentDirectory) + @"WorkFolder\")); TypeMap.Register.Singleton <SessionNotify>(() => new SessionNotify()); TypeMap.Register.Singleton <UserSettingsVersion>(() => new UserSettingsVersion()); TypeMap.Register.Singleton <ISettingsStore>(() => new SettingsStore(null)); TypeMap.Register.Singleton <UserSettings>(() => (new FakeUserSettings(new IterationCalculator())).Initialize()); TypeMap.Register.New <IStringSerializer>(() => new StringSerializer(New <IAsymmetricFactory>().GetSerializers())); TypeMap.Register.New <KnownPublicKeys>(() => KnownPublicKeys.Load(knownPublicKeysStore, Resolve.Serializer)); TypeMap.Register.New <ILogging>(() => new Logging()); TypeMap.Register.New <string, IDataStore>((path) => new FakeDataStore(path)); TypeMap.Register.New <Sha256>(() => PortableFactory.SHA256Managed()); TypeMap.Register.New <string, IDataContainer>((path) => new FakeDataContainer(path)); New <AxCryptOnlineState>().IsOnline = true; }
public void TestCreateSingleKey() { FakeInMemoryDataStoreItem store = new FakeInMemoryDataStoreItem("KnownPublicKeys.txt"); IAsymmetricPublicKey key = New <IAsymmetricFactory>().CreatePublicKey(Resources.PublicKey1); UserPublicKey userPublicKey = new UserPublicKey(EmailAddress.Parse("*****@*****.**"), key); using (KnownPublicKeys knownPublicKeys = KnownPublicKeys.Load(store, Resolve.Serializer)) { Assert.That(knownPublicKeys.PublicKeys.Count(), Is.EqualTo(0), "There should be no entries now."); knownPublicKeys.AddOrReplace(userPublicKey); Assert.That(knownPublicKeys.PublicKeys.Count(), Is.EqualTo(1), "There should be one entry now."); } using (KnownPublicKeys knownPublicKeys = KnownPublicKeys.Load(store, Resolve.Serializer)) { Assert.That(knownPublicKeys.PublicKeys.Count(), Is.EqualTo(1), "There should be one entry now."); Assert.That(knownPublicKeys.PublicKeys.First(), Is.EqualTo(userPublicKey), "The instances should compare equal"); } }
public static void AssemblySetup() { IDataStore knownPublicKeysStore = new FakeInMemoryDataStoreItem("knownpublickeys.txt"); TypeMap.Register.Singleton <INow>(() => new FakeNow()); TypeMap.Register.Singleton <IReport>(() => new FakeReport()); TypeMap.Register.Singleton <IPortableFactory>(() => new PortableFactory()); TypeMap.Register.Singleton <WorkFolder>(() => new WorkFolder(Path.GetPathRoot(Environment.CurrentDirectory) + @"WorkFolder\")); TypeMap.Register.Singleton <IRuntimeEnvironment>(() => new FakeRuntimeEnvironment()); TypeMap.Register.Singleton <ILogging>(() => new FakeLogging()); TypeMap.Register.Singleton <ISettingsStore>(() => new SettingsStore(null)); TypeMap.Register.Singleton <UserSettingsVersion>(() => new UserSettingsVersion()); TypeMap.Register.Singleton <UserSettings>(() => (new FakeUserSettings(New <IterationCalculator>())).Initialize()); TypeMap.Register.Singleton <KnownIdentities>(() => new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify)); TypeMap.Register.Singleton <ProcessState>(() => new ProcessState()); TypeMap.Register.Singleton <IUIThread>(() => new FakeUIThread()); TypeMap.Register.Singleton <IProgressBackground>(() => new FakeProgressBackground()); TypeMap.Register.Singleton <SessionNotify>(() => new SessionNotify()); TypeMap.Register.Singleton <FileSystemState>(() => FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("FileSystemState.txt"))); TypeMap.Register.Singleton <IStatusChecker>(() => new FakeStatusChecker()); TypeMap.Register.Singleton <IRandomGenerator>(() => new FakeRandomGenerator()); TypeMap.Register.Singleton <CryptoFactory>(() => CreateCryptoFactory()); TypeMap.Register.Singleton <ActiveFileWatcher>(() => new ActiveFileWatcher()); TypeMap.Register.Singleton <IAsymmetricFactory>(() => new BouncyCastleAsymmetricFactory()); TypeMap.Register.Singleton <IEmailParser>(() => new EmailParser()); TypeMap.Register.Singleton <ICache>(() => new FakeCache()); TypeMap.Register.Singleton <AxCryptOnlineState>(() => new AxCryptOnlineState()); TypeMap.Register.Singleton <CryptoPolicy>(() => new CryptoPolicy(new Assembly[0])); TypeMap.Register.Singleton <IVersion>(() => new FakeVersion()); TypeMap.Register.Singleton <IInternetState>(() => new FakeInternetState()); TypeMap.Register.Singleton <ICryptoPolicy>(() => New <LicensePolicy>().Capabilities.CryptoPolicy); TypeMap.Register.Singleton <LicensePolicy>(() => new PremiumForcedLicensePolicy()); TypeMap.Register.Singleton <InactivitySignOut>(() => new InactivitySignOut(TimeSpan.Zero)); TypeMap.Register.Singleton <FileLocker>(() => new FileLocker()); TypeMap.Register.Singleton <FileFilter>(() => new FileFilter()); TypeMap.Register.Singleton <IVerifySignInPassword>(() => new FakeVerifySignInPassword()); TypeMap.Register.Singleton <IPopup>(() => new FakePopup()); TypeMap.Register.Singleton <IKnownFoldersDiscovery>(() => new FakeKnownFoldersDiscovery()); TypeMap.Register.Singleton <IGlobalNotification>(() => new FakeGlobalNotification()); TypeMap.Register.Singleton <CanOpenEncryptedFile>(() => new CanOpenEncryptedFile()); TypeMap.Register.New <AxCryptFactory>(() => new AxCryptFactory()); TypeMap.Register.New <AxCryptFile>(() => new AxCryptFile()); TypeMap.Register.New <ActiveFileAction>(() => new ActiveFileAction()); TypeMap.Register.New <FileOperation>(() => new FileOperation(Resolve.FileSystemState, Resolve.SessionNotify)); TypeMap.Register.New <IdentityViewModel>(() => new IdentityViewModel(Resolve.FileSystemState, Resolve.KnownIdentities, Resolve.UserSettings, Resolve.SessionNotify)); TypeMap.Register.New <FileOperationViewModel>(() => new FileOperationViewModel(Resolve.FileSystemState, Resolve.SessionNotify, Resolve.KnownIdentities, Resolve.ParallelFileOperation, New <IStatusChecker>(), New <IdentityViewModel>())); TypeMap.Register.New <KnownPublicKeys>(() => KnownPublicKeys.Load(knownPublicKeysStore, New <IStringSerializer>())); TypeMap.Register.New <MainViewModel>(() => new MainViewModel(Resolve.FileSystemState, Resolve.UserSettings)); TypeMap.Register.New <string, IDataStore>((path) => new FakeDataStore(path)); TypeMap.Register.New <string, IDataContainer>((path) => new FakeDataContainer(path)); TypeMap.Register.New <string, IDataItem>((path) => CreateDataItem(path)); TypeMap.Register.New <string, IFileWatcher>((path) => new FakeFileWatcher(path)); TypeMap.Register.New <IterationCalculator>(() => new FakeIterationCalculator()); TypeMap.Register.New <IProtectedData>(() => new FakeDataProtection()); TypeMap.Register.New <IStringSerializer>(() => new StringSerializer(New <IAsymmetricFactory>().GetSerializers())); TypeMap.Register.New <LogOnIdentity, IAccountService>((LogOnIdentity identity) => new DeviceAccountService(new LocalAccountService(identity, Resolve.WorkFolder.FileInfo), new NullAccountService(identity))); TypeMap.Register.New <ISystemCryptoPolicy>(() => new ProCryptoPolicy()); TypeMap.Register.New <GlobalApiClient>(() => new GlobalApiClient(Resolve.UserSettings.RestApiBaseUrl, Resolve.UserSettings.ApiTimeout)); TypeMap.Register.New <AxCryptApiClient>(() => new AxCryptApiClient(Resolve.KnownIdentities.DefaultEncryptionIdentity.ToRestIdentity(), Resolve.UserSettings.RestApiBaseUrl, Resolve.UserSettings.ApiTimeout)); TypeMap.Register.New <AxCryptUpdateCheck>(() => new AxCryptUpdateCheck(New <IVersion>().Current)); TypeMap.Register.New <ISingleThread>(() => new SingleThread()); Resolve.UserSettings.SetKeyWrapIterations(new V1Aes128CryptoFactory().CryptoId, 1234); Resolve.UserSettings.ThumbprintSalt = Salt.Zero; Resolve.Log.SetLevel(LogLevel.Debug); }