public void EntityControllerConstructorReadsOutAuthenticationInformationFromAuthenticationProviderIfNotNull()
 {
     Mock.Arrange(() => _authenticationProvider.GetAuthValue())
         .Returns(SAMPLE_BEARER_TOKEN)
         .OccursOnce();
     
     Mock.Arrange(() => _authenticationProvider.GetAuthScheme())
         .Returns(BEARER_AUTH_TYPE)
         .OccursOnce();
     
     var entityController = new EntityController(_authenticationProvider);
     var entityControllerWithPrivateAccess = new PrivateObject(entityController);
     var headersField = (IDictionary<String, String>)entityControllerWithPrivateAccess.GetField(HEADERS_FIELD);
     
     Assert.AreEqual(SAMPLE_BEARER_TOKEN, headersField["Authorization"]);
     Assert.AreEqual(BEARER_AUTH_TYPE, (String)entityControllerWithPrivateAccess.GetField(AUTH_TYPE_FIELD));
     
     Mock.Assert(_authenticationProvider);
 }
        public LifeCycleManager(IAuthenticationProvider authenticationProvider, String entityType)
        {
            Debug.WriteLine("Create new instance of LifeCycleManager for entityType '{0}'", entityType);
            _entityType = entityType;

            lock (_lock)
            {
                if (null == _staticStateMachineConfigLoader)
                {
                    LoadAndComposeParts();
                    _staticStateMachineConfigLoader = _stateMachineConfigLoader;
                    _staticCalloutExecutor = _calloutExecutor;
                }
                else
                {
                    _stateMachineConfigLoader = _staticStateMachineConfigLoader;
                    _calloutExecutor = _staticCalloutExecutor;
                }
            }
            _coreService = new CumulusCoreService.Core(new Uri(ConfigurationManager.AppSettings[CORE_ENDPOINT_URL_KEY]));
            _coreService.BuildingRequest += CoreServiceOnBuildingRequest;

            _entityController = new EntityController(authenticationProvider);
            _stateMachine = new StateMachine.StateMachine();
            ConfigureStateMachine(entityType);
        }
 private String LoadEntity(IAuthenticationProvider authenticationProvider, Uri uri)
 {
     var entityController = new EntityController(authenticationProvider);
     return entityController.LoadEntity(uri);
 }
        public void LoadEntityCallsRestCallExecutorsInvokeMethodWithEntityUriAndAuthHeaders()
        {
            Mock.Arrange(() => _authenticationProvider.GetAuthValue())
                .Returns(SAMPLE_BEARER_TOKEN)
                .OccursOnce();

            Mock.Arrange(() => _authenticationProvider.GetAuthScheme())
                .Returns(BEARER_AUTH_TYPE)
                .OccursOnce();

            var headers = new Dictionary<String, String>();
            headers.Add("Authorization", SAMPLE_BEARER_TOKEN);
            var mockedRestCallExecutor = Mock.Create<RestCallExecutor>();
            Mock.Arrange(() => mockedRestCallExecutor.Invoke(SAMPLE_ENTITY_URI.ToString(), Arg.Is(headers)))
                .IgnoreInstance()
                .OccursOnce();

            var entityController = new EntityController(_authenticationProvider);
            entityController.LoadEntity(SAMPLE_ENTITY_URI);

            Mock.Assert(_authenticationProvider);
            Mock.Assert(mockedRestCallExecutor);
        }
 public void LoadEntityWithNullEntityUriThrowsArgumentNullException()
 {
     var entityController = new EntityController(_authenticationProvider);
     ThrowsAssert.Throws<ArgumentNullException>(() => entityController.LoadEntity(null));
 }
        public void UpdateEntityWithUriPointingToNonExistingEntityThrowsHttpRequestException() 
        {
            Mock.Arrange(() => _authenticationProvider.GetAuthValue())
                .Returns(SAMPLE_BEARER_TOKEN)
                .OccursOnce();

            Mock.Arrange(() => _authenticationProvider.GetAuthScheme())
                .Returns(BEARER_AUTH_TYPE)
                .OccursOnce();

            var headers = new Dictionary<String, String>();
            headers.Add("Authorization", SAMPLE_BEARER_TOKEN);
            var mockedRestCallExecutor = Mock.Create<RestCallExecutor>();
            Mock.Arrange(() => mockedRestCallExecutor.Invoke(HttpMethod.Put, SAMPLE_ENTITY_URI.ToString(), Arg.Is(headers), SAMPLE_ENTITY))
                .IgnoreInstance()
                .Throws<HttpRequestException>()
                .OccursOnce();

            var entityController = new EntityController(_authenticationProvider);
            ThrowsAssert.Throws<HttpRequestException>(() => entityController.UpdateEntity(SAMPLE_ENTITY_URI, SAMPLE_ENTITY));

            Mock.Assert(_authenticationProvider);
            Mock.Assert(mockedRestCallExecutor);
        }
Exemplo n.º 7
0
        private String LoadEntity(IAuthenticationProvider authenticationProvider, Uri uri)
        {
            var entityController = new EntityController(authenticationProvider);

            return(entityController.LoadEntity(uri));
        }
        public void TestInitialize()
        {
            Mock.SetupStatic(typeof(CurrentUserDataProvider));
            Mock.SetupStatic(typeof(HttpContext));
            Mock.SetupStatic(typeof(CredentialCache));

            _stateMachineConfigLoader = Mock.Create<IStateMachineConfigLoader>();
            _authenticationProvider = Mock.Create<IAuthenticationProvider>();
            _coreService = Mock.Create<CumulusCoreService.Core>();
            _calloutExecutor = Mock.Create<ICalloutExecutor>();
            _entityController = Mock.Create<EntityController>();
            _windowsIdentity = Mock.Create<WindowsIdentity>();

            var hashGenerator = Mock.Create<SHA256>();
            Mock.Arrange(() => hashGenerator.ComputeHash(Arg.IsAny<byte[]>()))
                .IgnoreInstance()
                .Returns(StringToByteArray(SAMPLE_TOKEN));
        }