Beispiel #1
0
        public void Encryptor_Decrypt()
        {
            EncryptorController controller = new EncryptorController();
            ActionResult        result     = controller._Decrypt() as ActionResult;

            Assert.IsNotNull(result);
        }
Beispiel #2
0
        public void Encryptor_Encrypt()
        {
            EncryptorController controller = new EncryptorController();
            ActionResult        result     = controller._Encrypt(1, "direct", "crypt", null, "абвгд") as ActionResult;

            Assert.IsNotNull(result);
        }
Beispiel #3
0
        public void EncryptorIndex()
        {
            EncryptorController controller = new EncryptorController();
            ViewResult          result     = controller.Index() as ViewResult;

            Assert.IsNotNull(result);
        }
Beispiel #4
0
        public void DoCryptography()
        {
            EncryptorController controller = new EncryptorController();

            controller.Request = new HttpRequestMessage();
            controller.Request.SetConfiguration(new HttpConfiguration());
            // Wrong KeyWord 1
            {
                Models.InputDataModel inp = new Models.InputDataModel()
                {
                    InputFile = null,
                    InputText = plainText,
                    FromFile  = false,
                    KeyWord   = "qwe",
                    ToEncrypt = true
                };
                var response = controller.DoCryptography(inp);
                Models.EncryptionResultModel result = JsonConvert.DeserializeObject <Models.EncryptionResultModel>(response.Content.ReadAsStringAsync().Result);
                // Утверждение
                Assert.IsTrue(result.IsError);
                Assert.AreEqual(EncryptorController.ErrorMsg.InvalidKeyWord.GetDescription(), result.Content);
            }
            // Wrong KeyWord 2
            {
                Models.InputDataModel inp = new Models.InputDataModel()
                {
                    InputFile = null,
                    InputText = plainText,
                    FromFile  = false,
                    KeyWord   = "привет мир",
                    ToEncrypt = true
                };
                var response = controller.DoCryptography(inp);
                Models.EncryptionResultModel result = JsonConvert.DeserializeObject <Models.EncryptionResultModel>(response.Content.ReadAsStringAsync().Result);
                // Утверждение
                Assert.IsTrue(result.IsError);
                Assert.AreEqual(EncryptorController.ErrorMsg.InvalidKeyWord.GetDescription(), result.Content);
            }
            // Wrong file extention
            {
                Models.InputDataModel inp = new Models.InputDataModel()
                {
                    InputFile = new MultipartDataMediaFormatter.Infrastructure.HttpFile("fileName.wrongFType", "application/octet-stream", Encoding.UTF8.GetBytes(plainText)),
                    InputText = null,
                    FromFile  = true,
                    KeyWord   = keyWord,
                    ToEncrypt = true
                };
                var response = controller.DoCryptography(inp);
                Models.EncryptionResultModel result = JsonConvert.DeserializeObject <Models.EncryptionResultModel>(response.Content.ReadAsStringAsync().Result);
                // Утверждение
                Assert.IsTrue(result.IsError);
                Assert.AreEqual(EncryptorController.ErrorMsg.InvalidFileExtention.GetDescription(), result.Content);
            }
            // Correct encoding from rawText (textarea)
            {
                Models.InputDataModel inp = new Models.InputDataModel()
                {
                    InputFile = null,
                    InputText = plainText,
                    FromFile  = false,
                    KeyWord   = "привет",
                    ToEncrypt = true
                };
                var response = controller.DoCryptography(inp);
                Models.EncryptionResultModel result = JsonConvert.DeserializeObject <Models.EncryptionResultModel>(response.Content.ReadAsStringAsync().Result);
                // Утверждение
                Assert.IsFalse(result.IsError);
                Assert.AreEqual(cipherText, result.Content);
            }
            // Correct decoding from rawText (textarea)
            {
                Models.InputDataModel inp = new Models.InputDataModel()
                {
                    InputFile = null,
                    InputText = cipherText,
                    FromFile  = false,
                    KeyWord   = keyWord,
                    ToEncrypt = false
                };
                var response = controller.DoCryptography(inp);
                Models.EncryptionResultModel result = JsonConvert.DeserializeObject <Models.EncryptionResultModel>(response.Content.ReadAsStringAsync().Result);
                // Утверждение
                Assert.IsFalse(result.IsError);
                Assert.AreEqual(plainText, result.Content);
            }
            // Correct encoding from file.txt
            {
                Models.InputDataModel inp = new Models.InputDataModel()
                {
                    InputFile = new MultipartDataMediaFormatter.Infrastructure.HttpFile("fileName.txt", "application/octet-stream", Encoding.UTF8.GetBytes(plainText)),
                    InputText = null,
                    FromFile  = true,
                    KeyWord   = keyWord,
                    ToEncrypt = true
                };
                var response = controller.DoCryptography(inp);
                Models.EncryptionResultModel result = JsonConvert.DeserializeObject <Models.EncryptionResultModel>(response.Content.ReadAsStringAsync().Result);
                // Утверждение
                Assert.IsFalse(result.IsError);
                Assert.AreEqual(cipherText, result.Content);
            }
            // Correct decoding from file.txt
            {
                Models.InputDataModel inp = new Models.InputDataModel()
                {
                    InputFile = new MultipartDataMediaFormatter.Infrastructure.HttpFile("fileName.txt", "application/octet-stream", Encoding.UTF8.GetBytes(cipherText)),
                    InputText = null,
                    FromFile  = true,
                    KeyWord   = keyWord,
                    ToEncrypt = false
                };
                var response = controller.DoCryptography(inp);
                Models.EncryptionResultModel result = JsonConvert.DeserializeObject <Models.EncryptionResultModel>(response.Content.ReadAsStringAsync().Result);
                // Утверждение
                Assert.IsFalse(result.IsError);
                Assert.AreEqual(plainText, result.Content);
            }
            // Correct encoding from file.docx
            {
                string pathTest           = projectDir + "/TestFiles/Test_1.docx";
                string pathTestResult     = projectDir + "/TestFiles/Test_1_result.docx";
                Models.InputDataModel inp = new Models.InputDataModel()
                {
                    InputFile = new MultipartDataMediaFormatter.Infrastructure.HttpFile("fileName.docx", "application/octet-stream",
                                                                                        System.IO.File.ReadAllBytes(pathTest)),
                    InputText = null,
                    FromFile  = true,
                    KeyWord   = keyWord,
                    ToEncrypt = true
                };
                var response = controller.DoCryptography(inp);
                Models.EncryptionResultModel result = JsonConvert.DeserializeObject <Models.EncryptionResultModel>(response.Content.ReadAsStringAsync().Result);
                // Утверждение
                Assert.IsFalse(result.IsError);
                Assert.AreEqual(cipherText, result.Content.Replace("\f", "").Replace("\r", "").Replace("", "").TrimEnd()); //raw text
            }
        }