Inheritance: WebsiteCallbackHandler
 // ReSharper disable InconsistentNaming - Unit Tests
 public void Save_WithNullParameters_Expected_ThrowsArgumentNullException()
 // ReSharper restore InconsistentNaming - Unit Tests
 {
     var handler = new ConnectCallbackHandler();
     handler.Save(null, null);
     handler.Save(null, null);
 }
        // ReSharper disable InconsistentNaming - Unit Tests
        public void Save_WithValidConnection_Expected_InvokesSaveEnvironment()
        // ReSharper restore InconsistentNaming - Unit Tests
        {

            var mockConnection = new Mock<IEnvironmentConnection>();
            mockConnection.Setup(connection => connection.ServerEvents).Returns(new Mock<IEventPublisher>().Object);
            var mockResourceRepo = new Mock<IResourceRepository>();
            var env = new EnvironmentModel(Guid.NewGuid(), mockConnection.Object, mockResourceRepo.Object, new Mock<IStudioResourceRepository>().Object);

            var currentRepository = new Mock<IEnvironmentRepository>();
            currentRepository.Setup(c => c.ActiveEnvironment).Returns(env);
            currentRepository.Setup(e => e.Save(It.IsAny<IEnvironmentModel>())).Verifiable();
            currentRepository.Setup(e => e.Fetch(It.IsAny<IEnvironmentModel>())).Returns(new Mock<IEnvironmentModel>().Object);

            var handler = new ConnectCallbackHandler(currentRepository.Object);
            handler.Save(ConnectionJson, null);

            // ReSharper disable PossibleUnintendedReferenceComparison - expected to be the same instance
            currentRepository.Verify(r => r.Save(It.IsAny<IEnvironmentModel>()));
            // ReSharper restore PossibleUnintendedReferenceComparison
        }
 // ReSharper disable InconsistentNaming - Unit Tests
 public void Save_WithInvalidJson_Expected_ThrowsJsonReaderException()
 // ReSharper restore InconsistentNaming - Unit Tests
 {
     var handler = new ConnectCallbackHandler();
     handler.Save("xxxxx", null);
 }
        // ReSharper disable InconsistentNaming - Unit Tests
        public void Save_WithValidConnection_Expected_InvokesSaveEnvironmentWithCategory()
        // ReSharper restore InconsistentNaming - Unit Tests
        {
            // BUG: 8786 - TWR - 2013.02.20
            var mockConnection = new Mock<IEnvironmentConnection>();
            mockConnection.Setup(connection => connection.ServerEvents).Returns(new Mock<IEventPublisher>().Object);
            var mockResourceRepo = new Mock<IResourceRepository>();
            var enviro = new EnvironmentModel(Guid.NewGuid(), mockConnection.Object, mockResourceRepo.Object, new Mock<IStudioResourceRepository>().Object);

            var currentRepository = new Mock<IEnvironmentRepository>();
            currentRepository.Setup(e => e.Save(It.IsAny<IEnvironmentModel>())).Verifiable();
            currentRepository.Setup(c => c.ActiveEnvironment).Returns(enviro);

            var env = new Mock<IEnvironmentModel>();
            env.SetupProperty(e => e.Category); // start tracking sets/gets to this property

            currentRepository.Setup(e => e.Fetch(It.IsAny<IEnvironmentModel>())).Returns(env.Object);

            var handler = new ConnectCallbackHandler(new Mock<IEventAggregator>().Object, currentRepository.Object);
            handler.Save(ConnectionJson, null);

            // ReSharper disable PossibleUnintendedReferenceComparison - expected to be the same instance
            currentRepository.Verify(r => r.Save(It.IsAny<IEnvironmentModel>()));
            // ReSharper restore PossibleUnintendedReferenceComparison
        }
 public void Save_WithNullParameters_Expected_ThrowsArgumentNullException()
 {
     var handler = new ConnectCallbackHandler();
     handler.Save(null, null);
     handler.Save(null, null);
 }
 public void Save_WithInvalidJson_Expected_ThrowsJsonReaderException()
 {
     var handler = new ConnectCallbackHandler();
     handler.Save("xxxxx", null);
 }
Ejemplo n.º 7
0
        public static bool ShowDialog(IEnvironmentModel environment, ResourceType resourceType, string resourcePath, string cateogy, string resourceId = null, string srcId = null, string resourceName = null)
        {
            const int ServiceDialogHeight = 582;
            const int ServiceDialogWidth = 941;
            bool? isSuccessful = true;

            if(environment == null)
            {
                throw new ArgumentNullException("environment");
            }

            // Silly people not checking for nulls on properties that warper other properties?! ;)
            if(environment.Connection == null)
            {
                if(!environment.IsConnected)
                {
                    environment.Connect();
                }

                // server must not be up, just do nothing ;)
                if(!environment.IsConnected)
                {
                    return false;
                }
                // else we managed to connect ;)
            }

            if(environment.Connection != null)
            {
                var workspaceId = GlobalConstants.ServerWorkspaceID;

                string pageName;
                WebsiteCallbackHandler pageHandler;
                double width;
                double height;
                string leftTitle = string.Empty;
                string rightTitle = environment.Name + " (" + environment.Connection.AppServerUri + ")";
                switch(resourceType)
                {
                    case ResourceType.Server:
                        pageName = "sources/server";
                        pageHandler = new ConnectCallbackHandler();
                        if(!String.IsNullOrEmpty(resourceId) && !String.IsNullOrEmpty(resourceName))
                        {
                            leftTitle = "Edit - " + resourceName;
                        }
                        else
                        {
                            leftTitle = "New Server";
                        }

                        width = 704;
                        height = 520;
                        break;

                    case ResourceType.ServerSource:
                        pageName = "sources/server";
                        pageHandler = new ConnectCallbackHandler();
                        if(!String.IsNullOrEmpty(resourceId) && !String.IsNullOrEmpty(resourceName))
                        {
                            leftTitle = "Edit - " + resourceName;
                        }
                        else
                        {
                            leftTitle = "New Server";
                        }

                        width = 704;
                        height = 520;
                        break;

                    case ResourceType.DbService:
                        pageName = "services/dbservice";
                        pageHandler = new DbServiceCallbackHandler();
                        width = ServiceDialogWidth;
                        height = ServiceDialogHeight;
                        break;

                    case ResourceType.DbSource:
                        pageName = "sources/dbsource";
                        srcId = resourceId;
                        pageHandler = new SourceCallbackHandler();
                        width = 704;
                        height = 517;
                        if(!String.IsNullOrEmpty(resourceId) && !String.IsNullOrEmpty(resourceName))
                        {
                            leftTitle = "Edit - " + resourceName;
                        }
                        else
                        {
                            leftTitle = "New Datbase Source";
                        }
                        break;

                    case ResourceType.PluginService:
                        pageName = "services/pluginservice";
                        pageHandler = new ServiceCallbackHandler();
                        width = ServiceDialogWidth;
                        height = ServiceDialogHeight;
                        break;

                    case ResourceType.PluginSource:
                        pageName = "sources/pluginsource";
                        srcId = resourceId;
                        pageHandler = new SourceCallbackHandler();
                        if(!String.IsNullOrEmpty(resourceId) && !String.IsNullOrEmpty(resourceName))
                        {
                            leftTitle = "Edit - " + resourceName;
                        }
                        else
                        {
                            leftTitle = "New Plugin Source";
                        }
                        width = 700;
                        height = 517;
                        break;

                    case ResourceType.EmailSource:  // PBI 953 - 2013.05.16 - TWR - Added
                        pageName = "sources/emailsource";
                        srcId = resourceId;
                        pageHandler = new SourceCallbackHandler();
                        if(!String.IsNullOrEmpty(resourceId) && !String.IsNullOrEmpty(resourceName))
                        {
                            leftTitle = "Edit - " + resourceName;
                        }
                        else
                        {
                            leftTitle = "New Email Source";
                        }
                        width = 704;
                        height = 488;
                        break;

                    case ResourceType.WebSource:    // PBI 5656 - 2013.05.20 - TWR - Added
                        pageName = "sources/websource";
                        srcId = resourceId;
                        pageHandler = new WebSourceCallbackHandler();
                        if(!String.IsNullOrEmpty(resourceId) && !String.IsNullOrEmpty(resourceName))
                        {
                            leftTitle = "Edit - " + resourceName;
                        }
                        else
                        {
                            leftTitle = "New Web Source";
                        }
                        width = 704;
                        height = 517;
                        break;

                    case ResourceType.WebService:   // PBI 1220 - 2013.05.20 - TWR - Added
                        pageName = "services/webservice";
                        pageHandler = new ServiceCallbackHandler();
                        width = ServiceDialogWidth;
                        height = ServiceDialogHeight;
                        break;
                    default:
                        return false;
                }

                var envirDisplayName = FullyEncodeServerDetails(environment.Connection);
                resourcePath = HttpUtility.UrlEncode(resourcePath);

                string selectedPath = "";
                if(cateogy != null)
                {
                    selectedPath = cateogy.Equals("Unassigned") || string.IsNullOrEmpty(cateogy) ? "" : cateogy;
                    var lastIndexOf = selectedPath.LastIndexOf("\\", StringComparison.Ordinal);
                    if(lastIndexOf != -1)
                    {
                        selectedPath = selectedPath.Substring(0, lastIndexOf);
                    }
                    selectedPath = selectedPath.Replace("\\", "\\\\");
                }


                string relativeUriString = string.Format("{0}?wid={1}&rid={2}&envir={3}&path={4}&sourceID={5}&category={6}", pageName, workspaceId, resourceId, envirDisplayName, resourcePath, srcId, selectedPath);

                if(!IsTestMode)
                {
                    // this must be a property ;)
                    isSuccessful = environment.ShowWebPageDialog(SiteName, relativeUriString, pageHandler, width, height, leftTitle, rightTitle);
                }
                else
                {
                    TestModeRelativeUri = relativeUriString;
                }
            }
            return isSuccessful.HasValue && isSuccessful.Value;
        }