Exemplo n.º 1
0
 public CipherControllerTests()
 {
     _moqSettings     = new Mock <ICipherSettingsViewModel>();
     _moqSettingsView = new Mock <ICipherSettingsView>();
     _moqCipher       = new Mock <ICipher>();
     _moqCipher.Setup(x => x.CipherName).Returns("MoqCipherName");
     _moqCipher.Setup(x => x.Encrypt(It.IsAny <string>())).Returns("MoqCiphertext");
     _moqRepository = new Mock <IRepository <ICipher> >();
     _moqRepository.Setup(x => x.Read()).Returns(() => new List <ICipher>()
     {
         _moqCipher.Object
     });
     _moqRepository.Setup(x => x.CurrentItem).Returns(() => _moqCipher.Object);
     _moqView    = new Mock <ICipherView>();
     _controller = new CipherController(_moqRepository.Object, _moqView.Object);
 }
Exemplo n.º 2
0
        public void Should_return_status_code_400_with_null_passed_to_controller(string message, string spyName)
        {
            //arrange
            var mockCipherService = new Mock <ICipherService>();

            mockCipherService.Setup(x => x.Decode(message, spyName)).Returns(new Response());

            var controller = new CipherController(mockCipherService.Object);

            //act
            var result = controller.Get(message, null) as ObjectResult;

            //assert
            Assert.IsNotNull(result);
            Assert.AreEqual(result.StatusCode, 400);
            Assert.AreEqual(result.Value, "Bad Data: message and codeName must be populated.");
        }
Exemplo n.º 3
0
        public void Should_return_status_code_200_with_successful_request_to_cipher_controller(string responseMessage, bool success)
        {
            const string message = "1,2,3";
            const string spyName = "James Bond";

            //arrange
            var mockCipherService = new Mock <ICipherService>();
            var response          = new Response()
            {
                Message = responseMessage, StatusCode = 200, Success = success
            };

            mockCipherService.Setup(x => x.Decode(message, spyName)).Returns(response);

            var controller = new CipherController(mockCipherService.Object);

            //act
            var result = controller.Get(message, spyName) as ObjectResult;

            //assert
            Assert.IsNotNull(result);
            Assert.AreEqual(result.StatusCode, 200);
            Assert.AreEqual(result.Value, responseMessage);
        }