Ejemplo n.º 1
0
        public void Locale()
        {
            var englishGreatBritain = new Locales(this.DatabaseSession).EnglishGreatBritain;
            var dutchBelgium = new Locales(this.DatabaseSession).DutchBelgium;

            new C1Builder(this.DatabaseSession).WithC1AllorsString("c1A").WithC1AllorsDecimal(10.5M).Build();
            new C1Builder(this.DatabaseSession).WithC1AllorsString("c1B").WithC1AllorsDecimal(11.5M).Build();

            this.DatabaseSession.Derive(true);

            var column1 = new CsvExportPath(C1s.Meta.C1AllorsString);
            var column2 = new CsvExportPath(C1s.Meta.C1AllorsDecimal);

            var export = new CsvExport("Test");
            export.Columns.Add(column1);
            export.Columns.Add(column2);

            var extent = this.DatabaseSession.Extent(C1s.Meta.ObjectType).AddSort(C1s.Meta.C1AllorsString);

            var user = new Users(this.DatabaseSession).GetCurrentUser();
            var acls = new AccessControlListCache(user);

            var csvEn = export.Write(extent, englishGreatBritain, acls);
            var csvNl = export.Write(extent, dutchBelgium, acls);

            Assert.AreNotEqual(csvEn, csvNl);
        }
Ejemplo n.º 2
0
        public void Constructor()
        {
            var dutchBelgium = new Locales(this.DatabaseSession).DutchBelgium;

            new C1Builder(this.DatabaseSession).WithC1AllorsString("c1A").WithC1C2One2One(new C2Builder(this.DatabaseSession).WithC2AllorsString("c2A").Build()).Build();
            new C1Builder(this.DatabaseSession).WithC1AllorsString("c1B").WithC1C2One2One(new C2Builder(this.DatabaseSession).WithC2AllorsString("c2B").Build()).Build();

            this.DatabaseSession.Derive(true);

            var aclMock = new Mock<IAccessControlList>();
            aclMock.Setup(acl => acl.CanRead(It.IsAny<PropertyType>())).Returns(true);
            var acls = new AccessControlListCache(null, (allorsObject, user) => aclMock.Object);

            var export = new CsvExport("Test");
            export.Columns.Add(new CsvExportPath(C1s.Meta.C1AllorsString));
            export.Columns.Add(new CsvExportFunction<C1>("Function", (c1, aclFactory) => CsvExport.Escape("Hello " + c1.C1AllorsString)));

            var extent = this.DatabaseSession.Extent(C1s.Meta.ObjectType).AddSort(C1s.Meta.C1AllorsString);
            var csv = export.Write(extent, dutchBelgium, acls);

            Assert.AreEqual(
            @"""C1AllorsString"";""Function""
            ""c1A"";""Hello c1A""
            ""c1B"";""Hello c1B""".Replace("\r\n", "\n"),
                    csv.Replace("\r\n", "\n"));
        }
Ejemplo n.º 3
0
        public void One2Many()
        {
            var dutchBelgium = new Locales(this.Session).DutchBelgium;

            new C1Builder(this.Session)
                .WithC1AllorsString("c1A")
                .WithC1C2One2Many(new C2Builder(this.Session).WithC2AllorsString("c2A").Build())
                .Build();

            new C1Builder(this.Session)
                .WithC1AllorsString("c1B")
                .WithC1C2One2Many(new C2Builder(this.Session).WithC2AllorsString("c2B").Build())
                .WithC1C2One2Many(new C2Builder(this.Session).WithC2AllorsString("c2C").Build())
                .Build();

            this.Session.Derive(true);

            var export = new CsvExport("Test");
            export.Columns.Add(new CsvExportPath(C1s.Meta.C1AllorsString));
            export.Columns.Add(new CsvExportPath(new Path(C1s.Meta.C1C2One2Manies, C2s.Meta.C2AllorsString)));

            var extent = this.Session.Extent(C1s.Meta.ObjectType).AddSort(C1s.Meta.C1AllorsString);

            var aclMock = new Mock<IAccessControlList>();
            aclMock.Setup(acl => acl.CanRead(It.IsAny<PropertyType>())).Returns(true);
            var acls = new AccessControlListCache(null, (allorsObject, user) => aclMock.Object);

            var csv = export.Write(extent, dutchBelgium, acls);

            Assert.AreEqual(
            @"""C1AllorsString"";""C2AllorsString""
            ""c1A"";""c2A""
            ""c1B"";""c2B;c2C""".Replace("\r\n", "\n"),
                    csv.Replace("\r\n", "\n"));
        }
Ejemplo n.º 4
0
        public override void Write(CsvExport file, CultureInfo cultureInfo, StringBuilder stringBuilder, IObject obj, IAccessControlListFactory aclFactory)
        {
            var value = this.ObjectFunction != null?this.ObjectFunction((T)obj, aclFactory) : this.ObjectAndCultureInfoFunction((T)obj, aclFactory, cultureInfo);

            if (this.AutoEscape)
            {
                value = CsvExport.Escape(value);
            }

            stringBuilder.Append(value);
        }
Ejemplo n.º 5
0
        public void Locale()
        {
            var englishGreatBritain = new Locales(this.DatabaseSession).EnglishGreatBritain;
            var dutchBelgium = new Locales(this.DatabaseSession).DutchBelgium;

            new C1Builder(this.DatabaseSession).WithC1AllorsString("c1A").WithC1AllorsDecimal(10.5M).Build();
            new C1Builder(this.DatabaseSession).WithC1AllorsString("c1B").WithC1AllorsDecimal(11.5M).Build();

            this.DatabaseSession.Derive(true);

            var csvFile = new CsvExport("Test");
            csvFile.Columns.Add(new CsvExportPath(C1s.Meta.C1AllorsString));
            csvFile.Columns.Add(new CsvExportFunction<C1>(
                "Function",
                (c1, acl, cultureInfo) =>
                    {
                        if (c1.C1AllorsDecimal.HasValue)
                        {
                            return CsvExport.Escape(c1.C1AllorsDecimal.Value.ToString(cultureInfo));
                        }

                        return string.Empty;
                    }));

            var extent = this.DatabaseSession.Extent(C1s.Meta.ObjectType).AddSort(C1s.Meta.C1AllorsString);

            var aclMock = new Mock<IAccessControlList>();
            aclMock.Setup(acl => acl.CanRead(It.IsAny<PropertyType>())).Returns(true);
            var acls = new AccessControlListCache(null, (allorsObject, user) => aclMock.Object);

            var csvEn = csvFile.Write(extent, englishGreatBritain, acls);
            var csvNl = csvFile.Write(extent, dutchBelgium, acls);

            Assert.AreNotEqual(csvEn, csvNl);

            Assert.AreEqual(
            @"""C1AllorsString"";""Function""
            ""c1A"";""10,5""
            ""c1B"";""11,5""".Replace("\r\n", "\n"),
            csvNl.Replace("\r\n", "\n"));

            Assert.AreEqual(
            @"""C1AllorsString"",""Function""
            ""c1A"",""10.5""
            ""c1B"",""11.5""".Replace("\r\n", "\n"),
            csvEn.Replace("\r\n", "\n"));
        }
Ejemplo n.º 6
0
        public override void Write(CsvExport file, CultureInfo cultureInfo, StringBuilder stringBuilder, IObject obj, IAccessControlListFactory aclFactory)
        {
            var value = this.Path.Get(obj, aclFactory) ?? this.EmptyValue;

            if (value != null)
            {
                var actualFormatProvider = this.FormatProvider ?? cultureInfo;

                var set = value as ISet<object>;
                if (set != null)
                {
                    stringBuilder.Append("\"");

                    var actualSubfieldSeparator = this.SubfieldSeparator ?? file.SubfieldSeparator ?? cultureInfo.TextInfo.ListSeparator;

                    var first = true;
                    foreach (var item in set)
                    {
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            stringBuilder.Append(actualSubfieldSeparator);
                        }

                        var escapedStringValue = this.GetEscapedStringValue(actualFormatProvider, item);
                        stringBuilder.Append(escapedStringValue);
                    }

                    stringBuilder.Append("\"");
                }
                else
                {
                    stringBuilder.Append("\"");

                    var escapedStringValue = this.GetEscapedStringValue(actualFormatProvider, value);
                    stringBuilder.Append(escapedStringValue);

                    stringBuilder.Append("\"");
                }
            }
        }
Ejemplo n.º 7
0
        public override void Write(CsvExport file, CultureInfo cultureInfo, StringBuilder stringBuilder, IObject obj, IAccessControlListFactory aclFactory)
        {
            var value = this.Path.Get(obj, aclFactory) ?? this.EmptyValue;

            if (value != null)
            {
                var actualFormatProvider = this.FormatProvider ?? cultureInfo;

                var set = value as ISet <object>;
                if (set != null)
                {
                    stringBuilder.Append("\"");

                    var actualSubfieldSeparator = this.SubfieldSeparator ?? file.SubfieldSeparator ?? cultureInfo.TextInfo.ListSeparator;

                    var first = true;
                    foreach (var item in set)
                    {
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            stringBuilder.Append(actualSubfieldSeparator);
                        }

                        var escapedStringValue = this.GetEscapedStringValue(actualFormatProvider, item);
                        stringBuilder.Append(escapedStringValue);
                    }

                    stringBuilder.Append("\"");
                }
                else
                {
                    stringBuilder.Append("\"");

                    var escapedStringValue = this.GetEscapedStringValue(actualFormatProvider, value);
                    stringBuilder.Append(escapedStringValue);

                    stringBuilder.Append("\"");
                }
            }
        }
 public abstract void Write(CsvExport file, CultureInfo cultureInfo, StringBuilder stringBuilder, IObject obj, IAccessControlListFactory aclFactory);
Ejemplo n.º 9
0
 public abstract void Write(CsvExport file, CultureInfo cultureInfo, StringBuilder stringBuilder, IObject obj, IAccessControlListFactory aclFactory);
Ejemplo n.º 10
0
        public void OperandTypeConstructor()
        {
            var dutchBelgium = new Locales(this.DatabaseSession).DutchBelgium;

            new C1Builder(this.DatabaseSession).WithC1AllorsString("c1A").WithC1AllorsDecimal(10.5M).Build();
            new C1Builder(this.DatabaseSession).WithC1AllorsString("c1B").WithC1AllorsDecimal(11.5M).Build();

            this.DatabaseSession.Derive(true);

            var csvFile = new CsvExport("Test");
            csvFile.Columns.Add(new CsvExportPath(C1s.Meta.C1AllorsString));
            csvFile.Columns.Add(new CsvExportPath(C1s.Meta.C1AllorsDecimal));

            var aclMock = new Mock<IAccessControlList>();
            aclMock.Setup(acl => acl.CanRead(It.IsAny<PropertyType>())).Returns(true);
            var acls = new AccessControlListCache(null, (allorsObject, user) => aclMock.Object);

            var extent = this.DatabaseSession.Extent(C1s.Meta.ObjectType).AddSort(C1s.Meta.C1AllorsString);
            var csv = csvFile.Write(extent, dutchBelgium, acls);

            Assert.AreEqual(
            @"""C1AllorsString"";""C1AllorsDecimal""
            ""c1A"";""10,5""
            ""c1B"";""11,5""".Replace("\r\n", "\n"),
                    csv.Replace("\r\n", "\n"));
        }