本文整理汇总了C#中RhetosTestContainer类的典型用法代码示例。如果您正苦于以下问题:C# RhetosTestContainer类的具体用法?C# RhetosTestContainer怎么用?C# RhetosTestContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RhetosTestContainer类属于命名空间,在下文中一共展示了RhetosTestContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SqlObject
public void SqlObject()
{
using (var container = new RhetosTestContainer())
{
container.Resolve<ISqlExecuter>().ExecuteSql(new[]
{
"DELETE FROM TestSqlWorkarounds.E",
"INSERT INTO TestSqlWorkarounds.E (I) VALUES (100)"
});
string report = "";
container.Resolve<ISqlExecuter>().ExecuteReader(
@"SELECT E.I, V1.I1, V2.I2
FROM TestSqlWorkarounds.E
INNER JOIN TestSqlWorkarounds.V1 ON V1.ID = E.ID
INNER JOIN TestSqlWorkarounds.V2 ON V2.ID = E.ID",
reader => report += reader.GetInt32(0) + ", " + reader.GetInt32(1) + ", " + reader.GetInt32(2) + ".");
Assert.AreEqual("100, 101, 102.", report);
report = "";
container.Resolve<ISqlExecuter>().ExecuteReader(
@"SELECT X FROM TestSqlWorkarounds.V3 ORDER BY X",
reader => report += reader.GetInt32(0) + ".");
Assert.AreEqual("101.102.", report);
}
}
示例2: ComputeForNewBaseItems
public void ComputeForNewBaseItems()
{
using (var container = new RhetosTestContainer())
{
var repository = container.Resolve<Common.DomRepository>();
var d1ID = Guid.NewGuid();
container.Resolve<ISqlExecuter>().ExecuteSql(new[]
{
"DELETE FROM Test9.Document;",
"DELETE FROM Test9.DocumentCreationInfo;",
"INSERT INTO Test9.Document (ID, Name) SELECT '" + d1ID + "', 'd1'"
});
Assert.AreEqual("", ReportDocumentCreationInfo(repository), "initial");
repository.Test9.DocumentCreationInfo.Recompute();
Assert.AreEqual("d1:1", ReportDocumentCreationInfo(repository), "initial recalc");
var documents = repository.Test9.Document;
var d2ID = Guid.NewGuid();
documents.Insert(new[] { new Test9.Document { ID = d2ID, Name = "d2" } });
Assert.AreEqual("d1:1, d2:2", ReportDocumentCreationInfo(repository), "autorecompute after new");
var d3ID = Guid.NewGuid();
var d4ID = Guid.NewGuid();
documents.Insert(new[] { new Test9.Document { ID = d3ID, Name = "d3" }, new Test9.Document { ID = d4ID, Name = "d4" } });
Assert.AreEqual("d1:1, d2:2, d3:4, d4:4", ReportDocumentCreationInfo(repository), "autorecompute after new2");
documents.Save(null, new[] { new Test9.Document { ID = d1ID, Name = "d1x" } }, new[] { new Test9.Document { ID = d3ID } });
Assert.AreEqual("d1x:1, d2:2, d4:4", ReportDocumentCreationInfo(repository), "autorecompute after update&delete");
}
}
示例3: LeavePredefinedUser
public void LeavePredefinedUser()
{
using (var container = new RhetosTestContainer())
{
var genericRepositories = container.Resolve<GenericRepositories>();
var repository = container.Resolve<Common.DomRepository>();
string currentUserName = container.Resolve<IUserInfo>().UserName;
Assert.IsTrue(!string.IsNullOrWhiteSpace(currentUserName));
var currentPrincipal = new Common.Principal { Name = currentUserName };
genericRepositories.InsertOrReadId(currentPrincipal, p => p.Name);
string otherUserName = "otherUser-" + Guid.NewGuid();
var otherPrincipal = new Common.Principal { Name = otherUserName };
genericRepositories.InsertOrReadId(otherPrincipal, p => p.Name);
var testItem1 = new TestCreatedBy.Simple { ID = Guid.NewGuid(), Name = "test1", AuthorID = otherPrincipal.ID };
var testItem2 = new TestCreatedBy.Simple { ID = Guid.NewGuid(), Name = "test2" };
repository.TestCreatedBy.Simple.Insert(testItem1, testItem2);
Assert.AreEqual(
"test1 " + otherUserName + ", test2 " + currentUserName,
TestUtility.DumpSorted(repository.TestCreatedBy.Simple
.Query(new[] { testItem1.ID, testItem2.ID })
.Select(item => item.Name + " " + item.Author.Name)));
}
}
示例4: NonEditablePropertyUpdate
public void NonEditablePropertyUpdate()
{
using (var container = new RhetosTestContainer())
{
var simpleID = Guid.NewGuid();
container.Resolve<ISqlExecuter>().ExecuteSql(new[]
{
"DELETE FROM TestDenyUserEdit.Simple",
"DELETE FROM TestDenyUserEdit.Parent",
"INSERT INTO TestDenyUserEdit.Simple (ID, Editable, NonEditable) VALUES (" + SqlUtility.QuoteGuid(simpleID) + ", 'a', 'x')"
});
var repository = container.Resolve<Common.DomRepository>();
Assert.AreEqual("a x null", DumpSimple(repository));
var simple = new TestDenyUserEdit.Simple { ID = simpleID, Editable = "b", NonEditable = "x" };
repository.TestDenyUserEdit.Simple.Save(null, new[] { simple }, null, true);
Assert.AreEqual("b x null", DumpSimple(repository));
simple.NonEditable = "y";
TestUtility.ShouldFail(() => repository.TestDenyUserEdit.Simple.Save(null, new[] { simple }, null, true),
"Simple", "NonEditable", "not allowed");
}
}
示例5: AutoInherit
public void AutoInherit()
{
using (var container = new RhetosTestContainer())
{
var names = new[] { "1", "1b", "2", "3", "4" };
var itemsE4 = names.Select(name => new TestRowPermissions4.E4 { ID = Guid.NewGuid(), Name4 = name }).ToList();
var itemsE3 = names.Select((name, x) => new TestRowPermissions3.E3 { ID = Guid.NewGuid(), Name3 = name, E4 = itemsE4[x] }).ToList();
var itemsE2 = names.Select((name, x) => new TestRowPermissions2.E2 { ID = Guid.NewGuid(), Name2 = name, E3 = itemsE3[x] }).ToList();
var itemsE1 = names.Select((name, x) => new TestRowPermissions1.E1 { ID = Guid.NewGuid(), Name1 = name, E2 = itemsE2[x] }).ToList();
var reposE1 = container.Resolve<GenericRepository<TestRowPermissions1.E1>>();
var reposE1Browse = container.Resolve<GenericRepository<TestRowPermissions1.E1Browse>>();
var reposE1BrowseRP = container.Resolve<GenericRepository<TestRowPermissions1.E1BrowseRP>>();
var reposE2 = container.Resolve<GenericRepository<TestRowPermissions2.E2>>();
var reposE3 = container.Resolve<GenericRepository<TestRowPermissions3.E3>>();
var reposE4 = container.Resolve<GenericRepository<TestRowPermissions4.E4>>();
reposE4.Save(itemsE4, null, reposE4.Read());
reposE3.Save(itemsE3, null, reposE3.Read());
reposE2.Save(itemsE2, null, reposE2.Read());
reposE1.Save(itemsE1, null, reposE1.Read());
Assert.AreEqual("4", TestUtility.DumpSorted(reposE4.Read<Common.RowPermissionsReadItems>(), item => item.Name4));
Assert.AreEqual("3->3", TestUtility.DumpSorted(reposE3.Read<Common.RowPermissionsReadItems>(), item => item.Name3 + "->" + item.E4.Name4));
Assert.AreEqual("2, 3", TestUtility.DumpSorted(reposE2.Read<Common.RowPermissionsReadItems>(), item => item.Name2));
Assert.AreEqual("1, 2, 3", TestUtility.DumpSorted(reposE1.Read<Common.RowPermissionsReadItems>(), item => item.Name1));
Assert.AreEqual("1, 2, 3", TestUtility.DumpSorted(reposE1Browse.Read<Common.RowPermissionsReadItems>(), item => item.Name1Browse));
Assert.AreEqual("1, 1b, 2, 3", TestUtility.DumpSorted(reposE1BrowseRP.Read<Common.RowPermissionsReadItems>(), item => item.Name1Browse));
}
}
示例6: CreatedIndexes
public void CreatedIndexes()
{
using (var container = new RhetosTestContainer())
{
var sql = @"SELECT
i.name + '.' + c.name
FROM
sys.indexes i
INNER JOIN sys.index_columns ic ON ic.object_id = i.object_id AND ic.index_id = i.index_id
INNER JOIN sys.columns c ON c.object_id = ic.object_id AND c.column_id = ic.column_id
WHERE
c.object_id IN (OBJECT_ID('TestCloning.Clone1'), OBJECT_ID('TestCloning.Clone2'), OBJECT_ID('TestCloning.Clone3'))
ORDER BY
i.name, ic.key_ordinal";
string[] expected =
("IX_Clone2_Parent.ParentID IX_Clone2_Start_Parent.Start IX_Clone2_Start_Parent.ParentID"
+ " IX_Clone3_Code.Code IX_Clone3_Parent.ParentID IX_Clone3_Start_Parent.Start"
+ " IX_Clone3_Start_Parent.ParentID PK_Clone1.ID PK_Clone2.ID PK_Clone3.ID").Split(' ');
var actual = new List<string>();
container.Resolve<ISqlExecuter>().ExecuteReader(sql, reader => actual.Add(reader.GetString(0)));
Assert.AreEqual(TestUtility.DumpSorted(expected), TestUtility.DumpSorted(actual));
}
}
示例7: SqlFunction
public void SqlFunction()
{
using (var container = new RhetosTestContainer())
{
Assert.AreEqual("11", ReportSqlQueryResult(container.Resolve<ISqlExecuter>(), "SELECT * FROM TestSqlWorkarounds.Fun2(10)"));
}
}
示例8: LazyLoadReferenceBaseExtensionLinkedItems
public void LazyLoadReferenceBaseExtensionLinkedItems()
{
using (var container = new RhetosTestContainer())
{
var repository = container.Resolve<Common.DomRepository>();
repository.TestLazyLoad.Simple.Delete(repository.TestLazyLoad.Simple.Load());
repository.TestLazyLoad.SimpleBase.Delete(repository.TestLazyLoad.SimpleBase.Load());
repository.TestLazyLoad.Parent.Delete(repository.TestLazyLoad.Parent.Load());
var p1 = new TestLazyLoad.Parent { ID = Guid.NewGuid(), Name = "p1" };
repository.TestLazyLoad.Parent.Insert(p1);
var sb1 = new TestLazyLoad.SimpleBase { ID = Guid.NewGuid(), Name = "sb1" };
var sb2 = new TestLazyLoad.SimpleBase { ID = Guid.NewGuid(), Name = "sb2" };
repository.TestLazyLoad.SimpleBase.Insert(sb1, sb2);
var s1 = new TestLazyLoad.Simple { ID = sb1.ID, ParentID = p1.ID };
var s2 = new TestLazyLoad.Simple { ID = sb2.ID, ParentID = p1.ID };
repository.TestLazyLoad.Simple.Insert(s1, s2);
container.Resolve<IPersistenceCache>().ClearCache();
var loadedSimple = repository.TestLazyLoad.Simple.Query().ToList();
Assert.AreEqual("p1/sb1, p1/sb2", TestUtility.DumpSorted(loadedSimple, item => item.Parent.Name + "/" + item.Base.Name));
container.Resolve<IPersistenceCache>().ClearCache();
var loadedBase = repository.TestLazyLoad.SimpleBase.Query().ToList();
Assert.AreEqual("p1/sb1, p1/sb2", TestUtility.DumpSorted(loadedBase, item => item.Extension_Simple.Parent.Name + "/" + item.Name));
container.Resolve<IPersistenceCache>().ClearCache();
var loadedParent = repository.TestLazyLoad.Parent.Query().ToList().Single();
Assert.AreEqual("p1/sb1, p1/sb2", TestUtility.DumpSorted(loadedParent.Children, item => item.Parent.Name + "/" + item.Base.Name));
}
}
示例9: ReportLegacy2
static string ReportLegacy2(RhetosTestContainer container, Common.DomRepository domRepository)
{
container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();
var loaded = domRepository.Test13.Legacy2.Query().Select(l2 => l2.Leg1.Name + " " + l2.NameNew + " " + l2.Same);
return string.Join(", ", loaded.OrderBy(x => x));
}
示例10: QueryComplex
public void QueryComplex()
{
using (var container = new RhetosTestContainer())
{
var repository = container.Resolve<Common.DomRepository>();
container.Resolve<ISqlExecuter>().ExecuteSql(new[]
{
"DELETE FROM TestEntity.Permission",
"DELETE FROM TestEntity.Principal",
"DELETE FROM TestEntity.Claim",
"INSERT INTO TestEntity.Claim (ID, ClaimResource, ClaimRight) SELECT '4074B807-FA5A-4772-9631-198E89A302DE', 'res1', 'rig1'",
"INSERT INTO TestEntity.Claim (ID, ClaimResource, ClaimRight) SELECT 'A45F7194-7288-4B25-BC77-4FCC920A1479', 'res2', 'rig2'",
"INSERT INTO TestEntity.Principal (ID, Name) SELECT 'A45F7194-7288-4B25-BC77-4FCC920A1479', 'p1'",
"INSERT INTO TestEntity.Permission (ID, PrincipalID, ClaimID, IsAuthorized) SELECT '65D4B68E-B0E7-491C-9405-800F531866CA', 'A45F7194-7288-4B25-BC77-4FCC920A1479', '4074B807-FA5A-4772-9631-198E89A302DE', 0",
"INSERT INTO TestEntity.Permission (ID, PrincipalID, ClaimID, IsAuthorized) SELECT 'B7F19BA7-C70F-46ED-BFC7-29A44DFECA9B', 'A45F7194-7288-4B25-BC77-4FCC920A1479', 'A45F7194-7288-4B25-BC77-4FCC920A1479', 1"
});
var q1 = repository.TestEntity.Principal.Query();
var q2 = repository.TestEntity.Permission.Query();
var loaded =
from principal in q1
from permission in q2
where principal.Name == "p1" && permission.Principal == principal && permission.IsAuthorized.Value
select permission.Claim.ClaimResource + "." + permission.Claim.ClaimRight;
Assert.AreEqual("res2.rig2", loaded.Single());
}
}
示例11: UpdateLockedData
public void UpdateLockedData()
{
using (var container = new RhetosTestContainer())
{
container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
var repository = container.Resolve<Common.DomRepository>();
var s1 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s1", Count = -1 };
var s2 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s2", Count = 1 };
repository.TestLockItems.Simple.Insert(new[] { s1, s2 });
AssertData("s1, s2", repository);
foreach (var e in new[] { s1, s2 })
e.Name = e.Name + "x";
AssertData("s1, s2", repository);
TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s1 }), "Name is locked if count negative.");
TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s2, s1 }), "Name is locked if count negative.");
TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s1, s2 }), "Name is locked if count negative.");
AssertData("s1, s2", repository);
repository.TestLockItems.Simple.Update(new[] { s2 });
AssertData("s1, s2x", repository);
}
}
示例12: SearchOnIndexTable
public void SearchOnIndexTable()
{
Assert.IsTrue(dataPrepared.Value);
using (var container = new RhetosTestContainer(false))
{
var tests = new Dictionary<string, string>
{
{ "\"ab*\"", "ab, abc, cd ab" },
{ "\"12*\"", "123, ab, xy" },
{ "a'b", "" },
{ "a'#'b", "" },
};
var repository = container.Resolve<Common.DomRepository>();
foreach (var test in tests)
{
Console.WriteLine("Searching '" + test.Key + "'");
var filtered = repository.TestFullTextSearch.Simple_Search.Query()
.Where(item => DatabaseExtensionFunctions.FullTextSearch(item.ID, test.Key, "TestFullTextSearch.Simple_Search", "*"))
.Select(item => item.Base.Name).ToList();
Assert.AreEqual(test.Value, TestUtility.DumpSorted(filtered), "Searching '" + test.Key + "'.");
filtered = repository.TestFullTextSearch.Simple_Search.Query()
.Where(item => DatabaseExtensionFunctions.FullTextSearch(item.ID, test.Key, "TestFullTextSearch.Simple_Search", "Text"))
.Select(item => item.Base.Name).ToList();
Assert.AreEqual(test.Value, TestUtility.DumpSorted(filtered), "Searching '" + test.Key + "'.");
}
}
}
示例13: PersistPartial
public void PersistPartial()
{
using (var container = new RhetosTestContainer())
{
container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestComputedFrom.PersistPartial" });
var repository = container.Resolve<Common.DomRepository>();
Assert.AreEqual("", TestUtility.DumpSorted(repository.TestComputedFrom.PersistPartial.All(), Dump));
repository.TestComputedFrom.PersistPartial.RecomputeFromSource(new Rhetos.Dom.DefaultConcepts.FilterAll(), items => items.Where(item => item.Name == "aa"));
container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();
Assert.AreEqual("aa", TestUtility.DumpSorted(repository.TestComputedFrom.PersistPartial.All(), Dump), "recompute all with SaveFilter to sync only Name aa ");
repository.TestComputedFrom.PersistPartial.RecomputeFromSource();
container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();
Assert.AreEqual("aa, bb", TestUtility.DumpSorted(repository.TestComputedFrom.PersistPartial.All(), Dump), "recompute all");
repository.TestComputedFrom.PersistPartial.Delete(repository.TestComputedFrom.PersistPartial.All());
container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();
repository.TestComputedFrom.PersistPartial.RecomputeFromSource(new[] { repository.TestComputedFrom.Source.All().Where(item => item.Name == "bb").Single().ID });
container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();
Assert.AreEqual("bb", TestUtility.DumpSorted(repository.TestComputedFrom.PersistPartial.All(), Dump), "recompute by ID (name bb)");
}
}
示例14: UpdateLockedData
public void UpdateLockedData()
{
using (var container = new RhetosTestContainer())
{
container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestLockItems.Simple;" });
var repository = container.Resolve<Common.DomRepository>();
var s1 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s1" };
var s2 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s2" };
var s3Lock = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s3_lock" };
var s4 = new TestLockItems.Simple { ID = Guid.NewGuid(), Name = "s4" };
repository.TestLockItems.Simple.Insert(new[] { s1, s2, s3Lock, s4 });
AssertData("s1, s2, s3_lock, s4", repository);
foreach (var e in new[] {s1, s2, s3Lock, s4})
e.Name = e.Name + "x";
AssertData("s1, s2, s3_lock, s4", repository);
TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s3Lock }), "Name contains lock mark.");
TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s1, s3Lock }), "Name contains lock mark.");
TestUtility.ShouldFail(() => repository.TestLockItems.Simple.Update(new[] { s3Lock, s4 }), "Name contains lock mark.");
AssertData("s1, s2, s3_lock, s4", repository);
repository.TestLockItems.Simple.Update(new[] { s1 });
AssertData("s1x, s2, s3_lock, s4", repository);
}
}
示例15: FilterNoPermissions
public void FilterNoPermissions()
{
using (var container = new RhetosTestContainer())
{
var repositories = container.Resolve<Common.DomRepository>();
var itemsRepository = repositories.TestRowPermissions.RPRulesItem;
var groupsRepository = repositories.TestRowPermissions.RPRulesGroup;
itemsRepository.Delete(itemsRepository.All());
groupsRepository.Delete(groupsRepository.All());
var g1 = new RPRulesGroup { ID = Guid.NewGuid(), Name = "g1" };
var g2 = new RPRulesGroup { ID = Guid.NewGuid(), Name = "g2" };
var i1 = new RPRulesItem { ID = Guid.NewGuid(), Name = "i1", GroupID = g1.ID };
var i2 = new RPRulesItem { ID = Guid.NewGuid(), Name = "i2", GroupID = g1.ID };
var i3 = new RPRulesItem { ID = Guid.NewGuid(), Name = "i3", GroupID = g2.ID };
var i4 = new RPRulesItem { ID = Guid.NewGuid(), Name = "i4", GroupID = g2.ID };
groupsRepository.Insert(new[] { g1, g2 });
itemsRepository.Insert(new[] { i1, i2, i3, i4 });
var allowedItems = itemsRepository.Filter(itemsRepository.Query(), new Common.RowPermissionsReadItems());
Console.WriteLine(itemsRepository.Query().Expression.ToString());
Console.WriteLine(allowedItems.Expression.ToString());
Assert.AreEqual("", TestUtility.DumpSorted(allowedItems, item => item.Name));
Assert.AreEqual("Common.Queryable.TestRowPermissions_RPRulesItem[]", allowedItems.Expression.ToString(), "No need for query, an empty array should be returned.");
}
}