Inheritance: global::System.ComponentModel.INotifyPropertyChanged
        public void GetManagementUriSucceeds()
        {
            // Arrange
            var managementUriName = SchedulerAppSettings.Keys.EXTERNAL_WORKFLOW_MANAGEMENT_URI_NAME;
            var managementUri = new ManagementUri()
            {
                Id = 42
                ,
                Name = managementUriName
                ,
                ManagementCredentialId = 5
            };
            var managementUris = new List<ManagementUri>()
            {
                managementUri
            };
            
            var dataServiceQuery = Mock.Create<DataServiceQuery<ManagementUri>>();
            Mock.Arrange(() => dataServiceQuery.Where(e => e.Name == managementUriName))
                .IgnoreInstance()
                .Returns(managementUris.AsQueryable())
                .MustBeCalled();

            var sut = new ActivitiPluginConfigurationManager();

            // Act
            var result = sut.GetManagementUri(dataServiceQuery, managementUriName);

            // Assert
            Assert.AreEqual(managementUriName, result.Name);
        }
        public void UpdateConfigurationSucceeds()
        {
            // Arrange
            Mock.SetupStatic(typeof(ConfigurationManager));
            Mock.Arrange(() => ConfigurationManager.AppSettings[Arg.IsAny<string>()])
                .Returns(SchedulerAppSettings.Keys.EXTERNAL_WORKFLOW_MANAGEMENT_URI_NAME)
                .MustBeCalled();

            var client = Mock.Create<ActivitiClient>();
            Mock.Arrange(() => client.Login(Arg.IsAny<NetworkCredential>()))
                .IgnoreInstance()
                .Returns(true)
                .MustBeCalled();

            var serverBaseUri = new Uri("http://www.example.com:9080/activiti-rest/service/");
            var managementCredentialId = 5;
            var managementUriName = SchedulerAppSettings.Keys.EXTERNAL_WORKFLOW_MANAGEMENT_URI_NAME;
            var managementUri = new ManagementUri()
            {
                Id = 42
                ,
                Name = managementUriName
                ,
                ManagementCredentialId = managementCredentialId
                ,
                Value = string.Format("{{\"ServerUri\":\"{0}\"}}", serverBaseUri)
            };
            var managementUris = new List<ManagementUri>()
            {
                managementUri
            };

            var dataServiceQueryManagementUris = Mock.Create<DataServiceQuery<ManagementUri>>();
            Mock.Arrange(() => dataServiceQueryManagementUris.Where(e => e.Name == managementUriName))
                .IgnoreInstance()
                .Returns(managementUris.AsQueryable())
                .MustBeCalled();

            var encryptedPassword = "******";
            var managementCredential = new ManagementCredential()
            {
                Id = managementCredentialId
                ,
                Name = managementUriName
                ,
                Username = Username
                ,
                Password = Password
                ,
                EncryptedPassword = encryptedPassword
            };
            var managementCredentials = new List<ManagementCredential>()
            {
                managementCredential
            };

            var dataServiceQueryManagementCredentials = Mock.Create<DataServiceQuery<ManagementCredential>>();
            Mock.Arrange(() => dataServiceQueryManagementCredentials.Where(e => e.Id == managementCredentialId))
                .IgnoreInstance()
                .Returns(managementCredentials.AsQueryable())
                .MustBeCalled();

            var endpoints = Mock.Create<AppclusiveEndpoints>(Constructor.Mocked);
            var apiCore = Mock.Create<Api.Core.Core>(Constructor.Mocked);
            endpoints.Core = apiCore;
            var parameters = new DictionaryParameters();
            parameters.Add(typeof(AppclusiveEndpoints).ToString(), endpoints);

            var sut = new ActivitiPlugin();
            Mock.NonPublic.Arrange<string>(sut, "managementUriName")
                .IgnoreInstance()
                .Returns(managementUriName);

            // Act
            sut.Configuration = parameters;

            // Assert
            Mock.Arrange(() => ConfigurationManager.AppSettings[Arg.IsAny<string>()]);
            Mock.Assert(client);
            Mock.Assert(endpoints);
            Mock.Assert(dataServiceQueryManagementUris);
            Mock.Assert(dataServiceQueryManagementCredentials);

            Assert.IsTrue(sut.Configuration.ContainsKey("ServerBaseUri"));
            var actualServerBaseUri = sut.Configuration["ServerBaseUri"] as Uri;
            Assert.IsNotNull(actualServerBaseUri);
            Assert.AreEqual(serverBaseUri, actualServerBaseUri);

            Assert.IsTrue(sut.Configuration.ContainsKey("Credential"));
            var actualCredential = sut.Configuration["Credential"] as NetworkCredential;
            Assert.IsNotNull(actualCredential);
            Assert.AreEqual(Username, actualCredential.UserName);
            Assert.AreEqual(Password, actualCredential.Password);
        }
        public void InitialiseSucceeds()
        {
            // Arrange
            var client = Mock.Create<ActivitiClient>();
            Mock.Arrange(() => client.Login(Arg.IsAny<NetworkCredential>()))
                .IgnoreInstance()
                .Returns(true)
                .MustBeCalled();

            var serverBaseUri = new Uri("http://www.example.com:9080/activiti-rest/service/");
            var managementCredentialId = 5;
            var managementUriName = SchedulerAppSettings.Keys.EXTERNAL_WORKFLOW_MANAGEMENT_URI_NAME;
            var managementUri = new ManagementUri()
            {
                Id = 42
                ,
                Name = managementUriName
                ,
                ManagementCredentialId = managementCredentialId
                ,
                Value = string.Format("{{\"ServerUri\":\"{0}\"}}", serverBaseUri)
            };
            var managementUris = new List<ManagementUri>()
            {
                managementUri
            };

            var dataServiceQueryManagementUris = Mock.Create<DataServiceQuery<ManagementUri>>();
            Mock.Arrange(() => dataServiceQueryManagementUris.Where(e => e.Name == managementUriName))
                .IgnoreInstance()
                .Returns(managementUris.AsQueryable())
                .MustBeCalled();

            var encryptedPassword = "******";
            var managementCredential = new ManagementCredential()
            {
                Id = managementCredentialId
                ,
                Name = managementUriName
                ,
                Username = Username
                ,
                Password = Password
                ,
                EncryptedPassword = encryptedPassword
            };
            var managementCredentials = new List<ManagementCredential>()
            {
                managementCredential
            };

            var dataServiceQueryManagementCredentials = Mock.Create<DataServiceQuery<ManagementCredential>>();
            Mock.Arrange(() => dataServiceQueryManagementCredentials.Where(e => e.Id == managementCredentialId))
                .IgnoreInstance()
                .Returns(managementCredentials.AsQueryable())
                .MustBeCalled();

            var endpoints = Mock.Create<AppclusiveEndpoints>(Constructor.Mocked);
            var apiCore = Mock.Create<Api.Core.Core>(Constructor.Mocked);
            endpoints.Core = apiCore;
            var parameters = new DictionaryParameters();
            parameters.Add(typeof(AppclusiveEndpoints).ToString(), endpoints);
            
            Mock.SetupStatic(typeof(ConfigurationManager));
            Mock.Arrange(() => ConfigurationManager.AppSettings[Arg.IsAny<string>()])
                .Returns(managementUriName)
                .MustBeCalled();

            var logger = new Logger();

            var sut = new ActivitiPlugin();

            // Act
            var result = sut.Initialise(parameters, logger, true);

            // Assert
            Mock.Assert(() => ConfigurationManager.AppSettings[Arg.IsAny<string>()]);
            Mock.Assert(client);

            Assert.IsTrue(result);
            Assert.IsTrue(sut.IsInitialised);
            Assert.IsTrue(sut.IsActive);
        }
        public void LogSucceeds()
        {
            // Arrange
            var client = Mock.Create<ActivitiClient>();
            Mock.Arrange(() => client.Login(Arg.IsAny<NetworkCredential>()))
                .IgnoreInstance()
                .Returns(true)
                .MustBeCalled();

            var managementUriName = SchedulerAppSettings.Keys.EXTERNAL_WORKFLOW_MANAGEMENT_URI_NAME;
            var serverBaseUri = new Uri("http://www.example.com:9080/activiti-rest/service/");
            var managementCredentialId = 5;
            var managementUri = new ManagementUri()
            {
                Id = 42
                ,
                Name = managementUriName
                ,
                ManagementCredentialId = managementCredentialId
                ,
                Value = string.Format("{{\"ServerUri\":\"{0}\"}}", serverBaseUri)
            };

            var encryptedPassword = "******";
            var managementCredential = new ManagementCredential()
            {
                Id = managementCredentialId
                ,
                Name = managementUriName
                ,
                Username = Username
                ,
                Password = Password
                ,
                EncryptedPassword = encryptedPassword
            };

            var activitiPluginConfigurationManager = Mock.Create<ActivitiPluginConfigurationManager>();
            Mock.Arrange(() => activitiPluginConfigurationManager.GetManagementUriName())
                .IgnoreInstance()
                .Returns(managementUriName)
                .MustBeCalled();
            Mock.Arrange(() => activitiPluginConfigurationManager.GetManagementUri(Arg.IsAny<DataServiceQuery<ManagementUri>>(), Arg.IsAny<string>()))
                .IgnoreInstance()
                .Returns(managementUri)
                .MustBeCalled();
            Mock.Arrange(() => activitiPluginConfigurationManager.GetManagementCredential(Arg.IsAny<DataServiceQuery<ManagementCredential>>(), Arg.IsAny<long>()))
                .IgnoreInstance()
                .Returns(managementCredential)
                .MustBeCalled();
            
            var endpoints = Mock.Create<AppclusiveEndpoints>(Constructor.Mocked);
            var apiCore = Mock.Create<Api.Core.Core>(Constructor.Mocked);
            endpoints.Core = apiCore;
            var parameters = new DictionaryParameters();
            parameters.Add(typeof(AppclusiveEndpoints).ToString(), endpoints);

            var message = "arbitrary-message";
            var logger = new Logger();
            var sut = new ActivitiPlugin();

            sut.Initialise(parameters, logger, true);

            // Act
            sut.Logger.WriteLine(message);

            // Assert
            Mock.Assert(client);
            Mock.Assert(activitiPluginConfigurationManager);
        }