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"));
        }
Exemple #2
0
        public void One2Many()
        {
            var c2A = new C2Builder(this.DatabaseSession).WithC2AllorsString("c2A").Build();
            var c2B = new C2Builder(this.DatabaseSession).WithC2AllorsString("c2B").Build();
            var c2C = new C2Builder(this.DatabaseSession).WithC2AllorsString("c2C").Build();

            var c1a = new C1Builder(this.DatabaseSession)
                .WithC1AllorsString("c1A")
                .WithC1C2One2Many(c2A)
                .Build();

            var c1b = new C1Builder(this.DatabaseSession)
                .WithC1AllorsString("c1B")
                .WithC1C2One2Many(c2B)
                .WithC1C2One2Many(c2C)
                .Build();

            this.DatabaseSession.Derive(true);

            var path = new Path(C1s.Meta.C1C2One2Manies, C2s.Meta.C2AllorsString);

            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 result = (ISet<object>)path.Get(c1a, acls);
            Assert.AreEqual(1, result.Count);
            Assert.IsTrue(result.Contains("c2A"));

            result = (ISet<object>)path.Get(c1b, acls);
            Assert.AreEqual(2, result.Count);
            Assert.IsTrue(result.Contains("c2B"));
            Assert.IsTrue(result.Contains("c2C"));
        }
Exemple #3
0
        public void One2ManyWithPropertyNames()
        {
            var c2A = new C2Builder(this.Session).WithC2AllorsString("c2A").Build();
            var c2B = new C2Builder(this.Session).WithC2AllorsString("c2B").Build();
            var c2C = new C2Builder(this.Session).WithC2AllorsString("c2C").Build();

            var c1A = new C1Builder(this.Session)
                .WithC1AllorsString("c1A")
                .WithC1C2One2Many(c2A)
                .Build();

            var c1B = new C1Builder(this.Session)
                .WithC1AllorsString("c1B")
                .WithC1C2One2Many(c2B)
                .WithC1C2One2Many(c2C)
                .Build();

            this.Session.Derive(true);

            Path path;
            Path.TryParse(C2.Meta.ObjectType, "C2One2ManyC1", out path);

            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 result = (C1)path.Get(c2A, acls);
            Assert.AreEqual(result, c1A);

            result = (C1)path.Get(c2B, acls);
            Assert.AreEqual(result, c1B);
        }
Exemple #4
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);
        }
        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"));
        }
Exemple #6
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"));
        }
Exemple #7
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"));
        }