Example #1
0
        public async void should_correctly_encrypt_save_then_reload()
        {
            var filename = "encrypted_save.bin";

            Console.WriteLine("{0}/{1}", Environment.CurrentDirectory, filename);

            var serializer          = new JsonSerializer();
            var deserializer        = new JsonDeserializer();
            var encryptor           = new AesEncryptor("dummy-password-123");
            var encryptionProcessor = new EncryptDataProcessor(encryptor);
            var decryptionProcessor = new DecryptDataProcessor(encryptor);
            var fileEndpoint        = new FileEndpoint(filename);

            var dummyData       = GameData.CreateRandom();
            var output          = serializer.Serialize(dummyData);
            var encryptedOutput = await encryptionProcessor.Process(output);

            await fileEndpoint.Send(encryptedOutput);

            var data = await fileEndpoint.Receive();

            var decryptedData = await decryptionProcessor.Process(data);

            var outputModel = deserializer.Deserialize <GameData>(decryptedData);

            Assert.AreEqual(dummyData, outputModel);
        }
Example #2
0
        public async void should_correctly_do_a_full_send_then_receive_in_single_pipeline()
        {
            var filename = "example_save.json";

            _testOutputHelper.WriteLine("{0}/{1}", Environment.CurrentDirectory, filename);

            var serializer          = new JsonSerializer();
            var deserializer        = new JsonDeserializer();
            var memoryEndpoint      = new InMemoryEndpoint();
            var encryptor           = new AesEncryptor("some-password");
            var encryptionProcessor = new EncryptDataProcessor(encryptor);
            var decryptionProcessor = new DecryptDataProcessor(encryptor);

            var saveToBinaryFilePipeline = new PipelineBuilder()
                                           .StartFromInput()
                                           .SerializeWith(serializer)
                                           .ProcessWith(encryptionProcessor)
                                           .ThenSendTo(memoryEndpoint)
                                           .ThenReceiveFrom(memoryEndpoint)
                                           .ProcessWith(decryptionProcessor)
                                           .DeserializeWith <GameData>(deserializer)
                                           .Build();

            var dummyData   = GameData.CreateRandom();
            var outputModel = await saveToBinaryFilePipeline.Execute(dummyData);

            Assert.AreEqual(dummyData, outputModel);
        }