Esempio n. 1
0
        public void TestDomainTableInfo()
        {
            OrmLiteConfig.DialectProvider = SqliteDialect.Provider;

            InfoTable info = new InfoTable();

            info.Should().NotBeNull();

            Assert.Throws <NullReferenceException>(new TestDelegate(
                                                       delegate
            {
                info.Create(null);
            }));

            Assert.Throws <NullReferenceException>(new TestDelegate(
                                                       delegate
            {
                info.Create_Index(null);
            }));

            PropertyInfo pi = info.GetType().GetProperty("IndexName", BindingFlags.NonPublic | BindingFlags.Instance);

            pi.Should().NotBeNull();

            Assert.IsNotNull(pi.GetValue(info));

            pi = info.GetType().GetProperty("IndexFieldName", BindingFlags.NonPublic | BindingFlags.Instance);
            pi.Should().NotBeNull();

            Assert.IsNotNull(pi.GetValue(info));
        }
Esempio n. 2
0
        public void TestInfoTable()
        {
            using (RepositoryDataSource dataSource = new RepositoryDataSource())
            {
                string filename = Path.GetTempFileName();
                File.Delete(filename);
                File.Exists(filename).Should().BeFalse();

                try
                {
                    dataSource.New(filename);
                    dataSource.IsOpen().Should().BeTrue();

                    InfoTable info = new InfoTable {
                        InfoName = "Setting1", Value = "V1"
                    };
                    IDomainTableRepository <InfoTable> repository = dataSource.DataRepository.GetTableRepositoryFor <InfoTable>();
                    repository.Should().NotBeNull();

                    info = repository.Save(info);
                    info.Id.Should().NotBe(0);

                    InfoTable info2 = new InfoTable();
                    info2 = repository[info.Id];
                    info2.Id.Should().Be(info.Id);
                    info2.InfoName.Should().Be(info.InfoName);
                    info2.Value.Should().Be(info.Value);

                    IList <IField> fields = info.SupportedFields();
                    fields.Should().NotBeNull();

                    fields.Count.Should().Be(2);

                    fields[0].Name.Should().Be(StandardFieldName.InfoName);
                    fields[1].Name.Should().Be(StandardFieldName.Value);

                    ((IEditField)fields[0]).SetValue(0, "Test2");
                    ((IEditField)fields[1]).SetValue(0, "Test3");

                    info.InfoName.Should().Be("Test2");
                    info.Value.Should().Be("Test3");

                    repository.Save(info);
                    info2.Should().NotBe(info);

                    IField infoNameField = info.Field(StandardFieldName.InfoName);
                    infoNameField.GetValue(0).Should().Be("Test2");

                    IField valueField = info.Field(StandardFieldName.Value);
                    valueField.GetValue(0).Should().Be("Test3");
                }
                finally { dataSource.Close(); }

                File.Delete(filename);
            }
        }