Inheritance: ISitecoreConnectionSettings
        public void SetCxSettingsWithEmptyObjectsForAdvancedSettings()
        {
            var mockCxInfo = new Mock<IConnectionInfo>();
            var element = XElement.Parse((string)this.TestContext.DataRow["driverData"]);
            mockCxInfo.SetupGet(cxInfo => cxInfo.DriverData).Returns(element);
            var cxSettings = new SitecoreConnectionSettings();
            var mapper = new DriverDataCxSettingsMapper();
            mapper.Read(mockCxInfo.Object, cxSettings);

            var view = new ConnectionDialog();
            view.InitializeComponent();
            var driverSettings = new SitecoreDriverSettings() { CxInfo = mockCxInfo.Object, CxSettings = cxSettings, SettingsMapper = new DriverDataCxSettingsMapper() };
            view.Model = driverSettings;
            var controller = new DriverSettingsController(view);
            controller.LoadView(driverSettings);
            view.SaveViewToModelCallback = controller.SaveView;
            //
            //basic settings
            view.ClientUrl = "http://localhost";
            view.Username = "******";
            view.Password = "******";
            view.WebRootPath = @"C:\Windows\Temp";
            view.ContextDatabaseName = "master";
            //
            //advanced settings
            view.NamespacesToAdd = new HashSet<string>();
            view.SearchResultType = new SelectedType();
            view.AppConfigReaderType = new SelectedType();
            view.SchemaBuilderType = new SelectedType();
            view.DriverInitializerType = new SelectedType();
        }
        public void SetCxSettingsNull()
        {
            var mockCxInfo = new Mock<IConnectionInfo>();
            var element = XElement.Parse((string)this.TestContext.DataRow["driverData"]);
            mockCxInfo.SetupGet(cxInfo => cxInfo.DriverData).Returns(element);
            var cxSettings = new SitecoreConnectionSettings();
            var mapper = new DriverDataCxSettingsMapper();
            mapper.Read(mockCxInfo.Object, cxSettings);

            var view = new ConnectionDialog();
            view.InitializeComponent();
            var driverSettings = new SitecoreDriverSettings() { CxInfo = mockCxInfo.Object, CxSettings = cxSettings, SettingsMapper = new DriverDataCxSettingsMapper() };
            view.Model = driverSettings;
            var controller = new DriverSettingsController(view);
            controller.LoadView(driverSettings);
            view.SaveViewToModelCallback = controller.SaveView;
            //
            //basic settings
            view.ClientUrl = null;
            view.Username = null;
            view.Password = null;
            view.WebRootPath = null;
            view.ContextDatabaseName = null;
            //
            //advanced settings
            view.NamespacesToAdd = null;
            view.SearchResultType = null;
            view.AppConfigReaderType = null;
            view.SchemaBuilderType = null;
            view.DriverInitializerType = null;
        }
        public virtual List<ExplorerItem> BuildAssembly(IConnectionInfo cxInfo, AssemblyName assemblyToBuild, ref string nameSpace, ref string typeName)
        {
            var unit = new CodeCompileUnit();
            var namespace2 = new CodeNamespace(nameSpace);
            namespace2.Imports.Add(new CodeNamespaceImport("System"));
            namespace2.Imports.Add(new CodeNamespaceImport("System.Linq"));
            namespace2.Imports.Add(new CodeNamespaceImport("Sitecore.ContentSearch"));
            namespace2.Imports.Add(new CodeNamespaceImport("Sitecore.ContentSearch.SearchTypes"));

            var settings = new SitecoreConnectionSettings();
            var mapper = new DriverDataCxSettingsMapper();
            mapper.Read(cxInfo, settings);

            var selectedType = settings.SearchResultType.GetSelectedType();
            namespace2.Imports.Add(new CodeNamespaceImport(selectedType.Namespace));
            var declaration = new CodeTypeDeclaration(typeName)
            {
                IsClass = true,
                TypeAttributes = TypeAttributes.Public
            };
            namespace2.Types.Add(declaration);
            unit.Namespaces.Add(namespace2);
            var constructor = new CodeConstructor
            {
                Attributes = MemberAttributes.Public
            };
            this.AddConstructorCode(constructor, settings);
            declaration.Members.Add(constructor);
            var indexNames = this.GetIndexNames(cxInfo);
            var list = new List<ExplorerItem>();
            foreach (var str in indexNames)
            {
                this.AddIndexAsProperty(str, selectedType, declaration);
                var item = new ExplorerItem(str, ExplorerItemKind.QueryableObject, ExplorerIcon.Table)
                {
                    IsEnumerable = false
                };
                item.DragText = this.GetDragText(item, settings);
                list.Add(item);
            }
            var provider = new CSharpCodeProvider();
            var options = new CompilerParameters();
            var assemblyFilesToReference = this.GetAssemblyFilesToReference(settings);
            foreach (var str2 in assemblyFilesToReference)
            {
                options.ReferencedAssemblies.Add(str2);
            }
            options.GenerateInMemory = true;
            options.OutputAssembly = assemblyToBuild.CodeBase;
            var results = provider.CompileAssemblyFromDom(options, new CodeCompileUnit[] { unit });
            if (results.Errors.Count > 0)
            {
                throw new Exception(string.Concat(new object[] { "Cannot compile typed context: ", results.Errors[0].ErrorText, " (line ", results.Errors[0].Line, ")" }));
            }
            return list;
        }
        public void AreEqualMethod()
        {
            Assert.IsTrue(CxSettingsCompareHelper.Current.AreEqual(null, null));
            var cxSettings1 = new SitecoreConnectionSettings();
            var cxSettings2 = new SitecoreConnectionSettings();
            Assert.IsTrue(CxSettingsCompareHelper.Current.AreEqual(cxSettings1, cxSettings2));
            cxSettings1.ClientUrl = "aaa";
            Assert.IsFalse(CxSettingsCompareHelper.Current.AreEqual(cxSettings1, cxSettings2));
            cxSettings2.ClientUrl = "aaa";
            Assert.IsTrue(CxSettingsCompareHelper.Current.AreEqual(cxSettings1, cxSettings2));

            cxSettings1.Username = "******";
            Assert.IsFalse(CxSettingsCompareHelper.Current.AreEqual(cxSettings1, cxSettings2));
            cxSettings2.Username = "******";
            Assert.IsTrue(CxSettingsCompareHelper.Current.AreEqual(cxSettings1, cxSettings2));

            cxSettings1.Password = "******";
            Assert.IsFalse(CxSettingsCompareHelper.Current.AreEqual(cxSettings1, cxSettings2));
            cxSettings2.Password = "******";
            Assert.IsTrue(CxSettingsCompareHelper.Current.AreEqual(cxSettings1, cxSettings2));

            cxSettings1.WebRootPath = "ddd";
            Assert.IsFalse(CxSettingsCompareHelper.Current.AreEqual(cxSettings1, cxSettings2));
            cxSettings2.WebRootPath = "ddd";
            Assert.IsTrue(CxSettingsCompareHelper.Current.AreEqual(cxSettings1, cxSettings2));

            cxSettings1.ContextDatabaseName = "eee";
            Assert.IsFalse(CxSettingsCompareHelper.Current.AreEqual(cxSettings1, cxSettings2));
            cxSettings2.ContextDatabaseName = "eee";
            Assert.IsTrue(CxSettingsCompareHelper.Current.AreEqual(cxSettings1, cxSettings2));

            cxSettings1.NamespacesToAdd = new HashSet<string>() {"fff", "ggg"};
            Assert.IsFalse(CxSettingsCompareHelper.Current.AreEqual(cxSettings1, cxSettings2));
            cxSettings2.NamespacesToAdd = new HashSet<string>() { "fff", "ggg" };
            Assert.IsTrue(CxSettingsCompareHelper.Current.AreEqual(cxSettings1, cxSettings2));

            cxSettings1.SearchResultType = new SelectedType(typeof(string));
            Assert.IsFalse(CxSettingsCompareHelper.Current.AreEqual(cxSettings1, cxSettings2));
            cxSettings2.SearchResultType = new SelectedType(typeof(string));
            Assert.IsTrue(CxSettingsCompareHelper.Current.AreEqual(cxSettings1, cxSettings2));

            cxSettings1.AppConfigReaderType = new SelectedType(typeof(string));
            Assert.IsFalse(CxSettingsCompareHelper.Current.AreEqual(cxSettings1, cxSettings2));
            cxSettings2.AppConfigReaderType = new SelectedType(typeof(string));
            Assert.IsTrue(CxSettingsCompareHelper.Current.AreEqual(cxSettings1, cxSettings2));

            cxSettings1.SchemaBuilderType = new SelectedType(typeof(string));
            Assert.IsFalse(CxSettingsCompareHelper.Current.AreEqual(cxSettings1, cxSettings2));
            cxSettings2.SchemaBuilderType = new SelectedType(typeof(string));
            Assert.IsTrue(CxSettingsCompareHelper.Current.AreEqual(cxSettings1, cxSettings2));

            cxSettings1.DriverInitializerType = new SelectedType(typeof(string));
            Assert.IsFalse(CxSettingsCompareHelper.Current.AreEqual(cxSettings1, cxSettings2));
            cxSettings2.DriverInitializerType = new SelectedType(typeof(string));
            Assert.IsTrue(CxSettingsCompareHelper.Current.AreEqual(cxSettings1, cxSettings2));
        }
 public void ReadAppConfigReaderTypeInvalidType()
 {
     var type = typeof(string);
     var mockCxInfo = new Mock<IConnectionInfo>();
     var element = XElement.Parse(string.Format(@"<DriverData><{0} type='{1}' location='{2}' /></DriverData>", DriverDataCxSettingsMapper.KEY_APP_CONFIG_READER_TYPE, type.AssemblyQualifiedName, type.Assembly.Location));
     mockCxInfo.SetupGet(cxInfo => cxInfo.DriverData).Returns(element);
     var cxSettings = new SitecoreConnectionSettings();
     var mapper = new DriverDataCxSettingsMapper();
     mapper.Read(mockCxInfo.Object, cxSettings);
     var selectedType = cxSettings.AppConfigReaderType.GetSelectedType();
     Assert.AreEqual(type, selectedType);
     Assert.IsFalse(cxSettings.SearchResultType.IsValidType(selectedType));
 }
        public void ReadDriverDataEmpty()
        {
            var mockCxInfo = new Mock<IConnectionInfo>();
            var element = XElement.Parse((string)this.TestContext.DataRow["driverData"]);
            mockCxInfo.SetupGet(cxInfo => cxInfo.DriverData).Returns(element);
            var cxSettings = new SitecoreConnectionSettings();
            var mapper = new DriverDataCxSettingsMapper();
            mapper.Read(mockCxInfo.Object, cxSettings);
            Assert.IsNull(cxSettings.ClientUrl, "ClientUrl should be null");
            Assert.IsNull(cxSettings.Username, "Username should be null");
            Assert.IsNull(cxSettings.Password, "Password should be null");
            Assert.IsNull(cxSettings.WebRootPath, "WebRootPath should be null");
            Assert.AreEqual("master", cxSettings.ContextDatabaseName);

            var defaultValues = DefaultValuesForCxSettings.Current;
            var list1 = cxSettings.NamespacesToAdd;
            var list2 = defaultValues.NamespacesToAdd;
            Assert.IsTrue(((list1 == list2) || ((list1.Count == list2.Count) && !list1.Except(list2).Any())));

            Assert.AreEqual(cxSettings.SearchResultType.GetSelectedType(), defaultValues.SearchResultItemType);
            Assert.AreEqual(defaultValues.AppConfigReaderType, cxSettings.AppConfigReaderType.GetSelectedType());
            Assert.AreEqual(defaultValues.SchemaBuilderType, cxSettings.SchemaBuilderType.GetSelectedType());
            Assert.AreEqual(defaultValues.DriverInitializerType, cxSettings.DriverInitializerType.GetSelectedType());
        }
Ejemplo n.º 7
0
 protected virtual ISitecoreConnectionSettings GetCxSettings(IConnectionInfo cxInfo)
 {
     var settings = new SitecoreConnectionSettings();
     var mapper = new DriverDataCxSettingsMapper();
     mapper.Read(cxInfo, settings);
     return settings;
 }
 public void ReadDriverDataNamespaces()
 {
     var mockCxInfo = new Mock<IConnectionInfo>();
     var element = XElement.Parse((string)this.TestContext.DataRow["driverData"]);
     mockCxInfo.SetupGet(cxInfo => cxInfo.DriverData).Returns(element);
     var cxSettings = new SitecoreConnectionSettings();
     var mapper = new DriverDataCxSettingsMapper();
     mapper.Read(mockCxInfo.Object, cxSettings);
     var count = Int32.Parse((string)this.TestContext.DataRow["count"]);
     Assert.AreEqual(count, cxSettings.NamespacesToAdd.Count);
 }
 public void ReadSettingsRequired()
 {
     var mockCxInfo = new Mock<IConnectionInfo>();
     var element = XElement.Parse((string)this.TestContext.DataRow["driverData"]);
     mockCxInfo.SetupGet(cxInfo => cxInfo.DriverData).Returns(element);
     var cxSettings = new SitecoreConnectionSettings();
     var mapper = new DriverDataCxSettingsMapper();
     mapper.Read(mockCxInfo.Object, cxSettings);
     var clientUrl = (string)this.TestContext.DataRow["clientUrl"];
     var username = (string)this.TestContext.DataRow["username"];
     var password = (string)this.TestContext.DataRow["password"];
     var webRootPath = (string)this.TestContext.DataRow["webRootPath"];
     Assert.AreEqual(clientUrl, cxSettings.ClientUrl);
     Assert.AreEqual(username, cxSettings.Username);
     Assert.AreEqual(password, cxSettings.Password);
     Assert.AreEqual(webRootPath, cxSettings.WebRootPath);
 }
 public void ReadSettingsOptional()
 {
     var mockCxInfo = new Mock<IConnectionInfo>();
     var element = XElement.Parse((string)this.TestContext.DataRow["driverData"]);
     mockCxInfo.SetupGet(cxInfo => cxInfo.DriverData).Returns(element);
     var cxSettings = new SitecoreConnectionSettings();
     var mapper = new DriverDataCxSettingsMapper();
     mapper.Read(mockCxInfo.Object, cxSettings);
     var defaultValues = DefaultValuesForCxSettings.Current;
     Assert.AreEqual(cxSettings.ContextDatabaseName, defaultValues.ContextDatabaseName, "context database name should not be '{0}'", cxSettings.ContextDatabaseName);
     Assert.IsTrue(cxSettings.NamespacesToAdd.SetEquals(defaultValues.NamespacesToAdd), "namespaces loaded by the mapper do not match the default namespaces");
     DoMatch(defaultValues.SearchResultItemType, cxSettings.SearchResultType);
     DoMatch(defaultValues.AppConfigReaderType, cxSettings.AppConfigReaderType);
     DoMatch(defaultValues.SchemaBuilderType, cxSettings.SchemaBuilderType);
     DoMatch(defaultValues.DriverInitializerType, cxSettings.DriverInitializerType);
 }
 public void ReadSearchResultTypeNoWebRootPathSpecified()
 {
     var mockCxInfo = new Mock<IConnectionInfo>();
     var element = XElement.Parse(string.Format(@"<DriverData><{0} type='{1}' /></DriverData>", DriverDataCxSettingsMapper.KEY_SEARCH_RESULT_TYPE, "xxx"));
     mockCxInfo.SetupGet(cxInfo => cxInfo.DriverData).Returns(element);
     var cxSettings = new SitecoreConnectionSettings();
     var mapper = new DriverDataCxSettingsMapper();
     mapper.Read(mockCxInfo.Object, cxSettings); //will throw an exception because the default type cannot be resolved without a valid webRootPath
 }
 public void ReadSearchResultTypeNotFound()
 {
     var mockCxInfo = new Mock<IConnectionInfo>();
     var element = XElement.Parse(string.Format(@"<DriverData webRootPath='{0}'><{1} type='{2}' /></DriverData>", @"c:\Sitecore\sc80\Website", DriverDataCxSettingsMapper.KEY_SEARCH_RESULT_TYPE, "xxx"));
     mockCxInfo.SetupGet(cxInfo => cxInfo.DriverData).Returns(element);
     var cxSettings = new SitecoreConnectionSettings();
     var mapper = new DriverDataCxSettingsMapper();
     mapper.Read(mockCxInfo.Object, cxSettings);
     Assert.AreEqual(DefaultValuesForCxSettings.Current.SearchResultItemType, cxSettings.SearchResultType.GetSelectedType());
 }
 public void ReadSearchResultTypeEmptyTag()
 {
     var mockCxInfo = new Mock<IConnectionInfo>();
     var element = XElement.Parse(@"<DriverData><searchResultType></searchResultType></DriverData>");
     mockCxInfo.SetupGet(cxInfo => cxInfo.DriverData).Returns(element);
     var cxSettings = new SitecoreConnectionSettings();
     var mapper = new DriverDataCxSettingsMapper();
     mapper.Read(mockCxInfo.Object, cxSettings);
     Assert.AreEqual(DefaultValuesForCxSettings.Current.SearchResultItemType, cxSettings.SearchResultType.GetSelectedType());
 }
 public void ReadSearchResultType()
 {
     var type = this.GetType();
     var mockCxInfo = new Mock<IConnectionInfo>();
     var element = XElement.Parse(string.Format(@"<DriverData webRootPath='{0}'><{1} type='{2}' location='{3}' /></DriverData>", @"c:\Sitecore\sc80\Website", DriverDataCxSettingsMapper.KEY_SEARCH_RESULT_TYPE, type.AssemblyQualifiedName, type.Assembly.Location));
     mockCxInfo.SetupGet(cxInfo => cxInfo.DriverData).Returns(element);
     var cxSettings = new SitecoreConnectionSettings();
     var mapper = new DriverDataCxSettingsMapper();
     mapper.Read(mockCxInfo.Object, cxSettings);
     var selectedType = cxSettings.SearchResultType.GetSelectedType();
     Assert.AreEqual(type, selectedType);
     Assert.IsTrue(cxSettings.SearchResultType.IsValidType(selectedType));
 }
 public void ReadSchemaBuilderType()
 {
     var type = typeof(SitecoreSchemaBuilder);
     var mockCxInfo = new Mock<IConnectionInfo>();
     var element = XElement.Parse(string.Format(@"<DriverData><{0} type='{1}' location='{2}' /></DriverData>", DriverDataCxSettingsMapper.KEY_SCHEMA_BUILDER_TYPE, type.AssemblyQualifiedName, type.Assembly.Location));
     mockCxInfo.SetupGet(cxInfo => cxInfo.DriverData).Returns(element);
     var cxSettings = new SitecoreConnectionSettings();
     var mapper = new DriverDataCxSettingsMapper();
     mapper.Read(mockCxInfo.Object, cxSettings);
     var selectedType = cxSettings.SchemaBuilderType.GetSelectedType();
     Assert.AreEqual(type, selectedType);
     Assert.IsTrue(cxSettings.SchemaBuilderType.IsValidType(selectedType));
 }
 public void ReadDriverDataNull()
 {
     var mockCxInfo = new Mock<IConnectionInfo>();
     var cxSettings = new SitecoreConnectionSettings();
     var mapper = new DriverDataCxSettingsMapper();
     mapper.Read(mockCxInfo.Object, cxSettings);
 }