本文整理汇总了C#中ContextMocks类的典型用法代码示例。如果您正苦于以下问题:C# ContextMocks类的具体用法?C# ContextMocks怎么用?C# ContextMocks使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ContextMocks类属于命名空间,在下文中一共展示了ContextMocks类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Basic_AddStatusType
public void Basic_AddStatusType()
{
TestStore store = ((TestStore)DevWebsiteDataInitializer.FillDefaultDevSet(new TestStore())).FixupReferences();
Organization org = store.Organizations.First();
Mock<AuthIdentityService> perms = new Mock<AuthIdentityService>();
perms.Setup(f => f.HasPermission(PermissionType.AdminOrganization, org.Id)).Returns(true);
// SETUP
var controller = new OrganizationsController(perms.Object, new DataStoreFactory(store));
var mocks = new ContextMocks(controller);
mocks.Request.Setup(r => r.AcceptTypes).Returns(new[] { "application/json" });
int beginCount = org.UnitStatusTypes.Count;
// TEST
UnitStatusType type = new UnitStatusType { Name = "Test Type", IsMissionQualified = false, IsActive = true };
var dataResult = controller.SaveStatus(org.Id, type);
var model = (SubmitResult<UnitStatusType>)dataResult.Data;
// VERIFY
Assert.AreEqual(0, model.Errors.Length);
//Assert.AreEqual(robert.Id, model.Result.OrganizationId, "Org ID should have been populated");
Assert.AreEqual(beginCount + 1, org.UnitStatusTypes.Count);
UnitStatusType savedType = org.UnitStatusTypes.Single(f => f.Id == type.Id);
Assert.AreEqual(type.Name, savedType.Name);
Assert.AreEqual(type.IsActive, savedType.IsActive);
Assert.AreEqual(type.IsMissionQualified, savedType.IsMissionQualified);
}
开发者ID:sartracks,项目名称:SARTracks,代码行数:31,代码来源:OrganizationsControllerTests.cs
示例2: AddToCache
public void AddToCache() {
var mocks = new ContextMocks(controller);
mocks.ViewDataContainer.Object.ViewData[IdHelper.NofServices] = FrameworkHelper.GetServices();
Claim claim = NakedObjectsContext.ObjectPersistor.Instances<Claim>().First();
mocks.HtmlHelper.ViewContext.HttpContext.Session.AddToCache(claim);
Assert.IsTrue(mocks.HtmlHelper.ViewContext.HttpContext.Session.AllCachedObjects().Contains(claim));
}
开发者ID:,项目名称:,代码行数:9,代码来源:
示例3: AddStringToSession
public void AddStringToSession() {
var mocks = new ContextMocks(controller);
mocks.ViewDataContainer.Object.ViewData[IdHelper.NofServices] = FrameworkHelper.GetServices();
HttpSessionStateBase session = mocks.HtmlHelper.ViewContext.HttpContext.Session;
const string testvalue = "test string";
session.AddObjectToSession("key1", testvalue);
Assert.AreEqual(testvalue, session.GetObjectFromSession<string>("key1"));
}
开发者ID:,项目名称:,代码行数:11,代码来源:
示例4: AddPersistentToSession
public void AddPersistentToSession() {
var mocks = new ContextMocks(controller);
mocks.ViewDataContainer.Object.ViewData[IdHelper.NofServices] = FrameworkHelper.GetServices();
HttpSessionStateBase session = mocks.HtmlHelper.ViewContext.HttpContext.Session;
Claim claim = NakedObjectsContext.ObjectPersistor.Instances<Claim>().First();
session.AddObjectToSession("key1", claim);
Assert.AreSame(claim, session.GetObjectFromSession<Claim>("key1"));
}
开发者ID:,项目名称:,代码行数:11,代码来源:
示例5: CollectionMemento
public void CollectionMemento() {
var mocks = new ContextMocks(controller);
mocks.ViewDataContainer.Object.ViewData["Services"] = FrameworkHelper.GetServices();
INakedObject service = NakedObjectsContext.ObjectPersistor.GetService("ClaimRepository");
INakedObjectAction action = service.Specification.GetObjectActions().Where(a => a.Id == "Find").SelectMany(a => a.Actions).Single(a => a.Id == "FindMyClaims");
INakedObject[] parms = new[] { null, "" }.Select(PersistorUtils.CreateAdapter).ToArray();
var cm = new CollectionMemento(service, action, parms);
var claims = (IEnumerable)cm.RecoverCollection().Object;
Assert.AreEqual(5, claims.Cast<object>().Count());
Assert.AreEqual(cm, cm.RecoverCollection().Oid);
}
开发者ID:,项目名称:,代码行数:13,代码来源:
示例6: Designators
public void Designators()
{
TestStore store = ((TestStore)DevWebsiteDataInitializer.FillDefaultDevSet(new TestStore())).FixupReferences();
Guid memberId = store.Members.Single(f => f.FirstName == "Robert").Id;
var perms = new Mock<TestAuthIdentityService>();
var controller = new Mock<MembersController>(perms.Object, new DataStoreFactory(store));
perms.Setup(f => f.HasPermission(PermissionType.ViewMemberBasic, memberId)).Returns(true);
var mocks = new ContextMocks(controller.Object);
mocks.Request.Setup(r => r.AcceptTypes).Returns(new[] { "application/json" });
var dataResult = controller.Object.GetDesignators(memberId, null);
var model = (DesignatorsViewModel[])dataResult.Data;
Assert.AreEqual(1, model.Length, "Wrong number of designators returned");
Assert.AreEqual("1234", model[0].Designator, "Wrong designator returned");
Assert.AreEqual(2, model[0].ForUnits.Length, "Wrong number of units using designator");
Assert.AreEqual("KCSO", model[0].Issuer, "Should be issued by KCSO");
Assert.IsTrue(model[0].ForUnits.Any(f => f == store.Organizations.Single(g => g.Name == "ESAR").Id), "Designator for ESAR");
Assert.IsTrue(model[0].ForUnits.Any(f => f == store.Organizations.Single(g => g.Name == "KCSO").Id), "Designator for KCSO");
}
开发者ID:sartracks,项目名称:SARTracks,代码行数:23,代码来源:MembersControllerTests.cs
示例7: GetMyRoles
public void GetMyRoles()
{
TestStore store = ((TestStore)DevWebsiteDataInitializer.FillDefaultDevSet(new TestStore())).FixupReferences();
var org = store.Organizations.First();
// Setup
var perms = new Mock<TestAuthIdentityService>();
perms.Setup(f => f.UserLogin).Returns("testuser");
perms.Setup(f => f.GetRolesForUser("testuser", true)).Returns(new[] { "role1", "role2", string.Format("[{0}] foo", org.Name) });
var controller = new AccountController(perms.Object, new DataStoreFactory(store));
var mocks = new ContextMocks(controller);
mocks.Request.Setup(r => r.AcceptTypes).Returns(new[] { "application/json" });
//Test
var result = controller.GetMyRoles();
// Verify
Assert.IsNotNull(result.Data);
Assert.IsNotNull(result.Data as IEnumerable<string>);
var data = ((IEnumerable<string>)result.Data).ToArray();
Assert.AreEqual(3, data.Length);
Assert.IsTrue(data.Any(f => f == "[" + org.Name + "] foo"));
}
开发者ID:sartracks,项目名称:SARTracks,代码行数:24,代码来源:AccountsControllerTests.cs
示例8: History
public void History() {
var mocks = new ContextMocks(controller);
Claim claim = NakedObjectsContext.ObjectPersistor.Instances<Claim>().First();
Employee emp = NakedObjectsContext.ObjectPersistor.Instances<Employee>().First();
mocks.ViewDataContainer.Object.ViewData[IdHelper.NofServices] = FrameworkHelper.GetServices();
mocks.HtmlHelper.History(claim);
mocks.HtmlHelper.History(emp);
string s = mocks.HtmlHelper.History().StripWhiteSpace();
CheckResults("History", s);
}
开发者ID:,项目名称:,代码行数:10,代码来源:
示例9: ClearHistoryOthers2
public void ClearHistoryOthers2() {
var controller = new HomeController();
var mocks = new ContextMocks(controller);
mocks.HttpContext.Object.Session.AddToCache(Employee, ObjectCache.ObjectFlag.BreadCrumb);
mocks.HttpContext.Object.Session.AddToCache(Vendor, ObjectCache.ObjectFlag.BreadCrumb);
var result = (ViewResult)controller.ClearHistoryOthers(VendorId, new ObjectAndControlData());
Assert.AreEqual("ViewNameSetAfterTransaction", result.ViewName);
ViewDataDictionary data = result.ViewData;
Assert.IsInstanceOf(typeof(Vendor), data.Model);
}
开发者ID:,项目名称:,代码行数:13,代码来源:
示例10: ClearHistory
public void ClearHistory() {
var controller = new HomeController();
var mocks = new ContextMocks(controller);
mocks.HttpContext.Object.Session.AddToCache(Employee, ObjectCache.ObjectFlag.BreadCrumb);
var result = (ViewResult)controller.ClearHistory(false);
Assert.AreEqual("ObjectView", result.ViewName);
ViewDataDictionary data = result.ViewData;
Assert.IsInstanceOf(typeof(Employee), data.Model);
}
开发者ID:,项目名称:,代码行数:12,代码来源:
示例11: CustomHelperTest
private void CustomHelperTest(Func<ContextMocks, string> func, string toCompare) {
var mocks = new ContextMocks(controller);
var tc = (CustomHelperTestClass) GetTestService("Custom Helper Test Classes").GetAction("New Instance").InvokeReturnObject().NakedObject.Object;
mocks.ViewDataContainer.Object.ViewData.Model = tc;
mocks.ViewDataContainer.Object.ViewData[IdHelper.NofServices] = FrameworkHelper.GetServices();
string s = func(mocks);
CheckResults(toCompare, s);
}
开发者ID:,项目名称:,代码行数:8,代码来源:
示例12: IntPropertyDefault
public void IntPropertyDefault() {
var mocks = new ContextMocks(controller);
INakedObject adapter = FrameworkHelper.GetNakedObject(new CustomHelperTestClass());
mocks.ViewDataContainer.Object.ViewData.Model = adapter.Object;
mocks.ViewDataContainer.Object.ViewData[IdHelper.NofServices] = FrameworkHelper.GetServices();
mocks.ViewDataContainer.Object.ViewData["CustomHelperTestClass-TestIntDefault-Input"] = PersistorUtils.CreateAdapter(0);
string s = mocks.GetHtmlHelper<CustomHelperTestClass>().ObjectPropertyEdit(y => y.TestIntDefault).ToString();
CheckResults("TestIntDefault", s);
}
开发者ID:,项目名称:,代码行数:13,代码来源:
示例13: OneRefParameterPopulatedActionAsDialog
public void OneRefParameterPopulatedActionAsDialog() {
var mocks = new ContextMocks(controller);
var tc = (CustomHelperTestClass)GetTestService("Custom Helper Test Classes").GetAction("New Instance").InvokeReturnObject().NakedObject.Object;
mocks.ViewDataContainer.Object.ViewData.Model = tc;
mocks.ViewDataContainer.Object.ViewData[IdHelper.NofServices] = FrameworkHelper.GetServices();
mocks.ViewDataContainer.Object.ViewData["CustomHelperTestClass-OneRefParameterAction-Parm-Select"] = PersistorUtils.CreateAdapter(tc);
string s = mocks.GetHtmlHelper<CustomHelperTestClass>().ObjectActionAsDialog<CustomHelperTestClass, CustomHelperTestClass>(y => y.OneRefParameterAction).ToString();
CheckResults("OneRefParameterPopulatedActionAsDialog", s);
}
开发者ID:,项目名称:,代码行数:13,代码来源:
示例14: CustomHelperTestCollection
private void CustomHelperTestCollection(Func<ContextMocks, string> func, string toCompare) {
var mocks = new ContextMocks(controller);
var tc = (CustomHelperTestClass) GetTestService("Custom Helper Test Classes").GetAction("New Instance").InvokeReturnObject().NakedObject.Object;
var collection = new List<CustomHelperTestClass> {tc};
INakedObject adapter = PersistorUtils.CreateAdapter(collection);
adapter.SetATransientOid(new DummyOid());
mocks.ViewDataContainer.Object.ViewData.Model = collection;
mocks.ViewDataContainer.Object.ViewData[IdHelper.NofServices] = FrameworkHelper.GetServices();
string s = func(mocks);
CheckResults(toCompare, s);
}
开发者ID:,项目名称:,代码行数:13,代码来源:
示例15: CustomHelperTestOtherObj
private void CustomHelperTestOtherObj(Func<ContextMocks, string> func, string toCompare) {
var mocks = new ContextMocks(controller);
mocks.ViewDataContainer.Object.ViewData.Model = new object(); // placeholder
mocks.ViewDataContainer.Object.ViewData[IdHelper.NofServices] = FrameworkHelper.GetServices();
string s = func(mocks);
CheckResults(toCompare, s);
}
开发者ID:,项目名称:,代码行数:7,代码来源:
示例16: CustomHelperTestStringIdOnOtherObjectDisabled
public void CustomHelperTestStringIdOnOtherObjectDisabled() {
var mocks = new ContextMocks(controller);
CustomHelperTestClass tc = TestClass;
mocks.ViewDataContainer.Object.ViewData.Model = new object(); // placeholder
string s = mocks.HtmlHelper.ObjectAction(tc, "DisabledAction").ToString();
CheckResults("DisabledAction", s);
}
开发者ID:,项目名称:,代码行数:9,代码来源:
示例17: CustomHelperTestStringIdOnOtherObjectEdit
public void CustomHelperTestStringIdOnOtherObjectEdit() {
var mocks = new ContextMocks(controller);
CustomHelperTestClass tc = TestClass;
mocks.ViewDataContainer.Object.ViewData.Model = new object();
string s = mocks.HtmlHelper.ObjectActionOnTransient(tc, "NoParameterAction").ToString();
CheckResults("NoParameterEditAction", s);
}
开发者ID:,项目名称:,代码行数:9,代码来源:
示例18: CustomHelperTestCompareDirectOtherObj
private void CustomHelperTestCompareDirectOtherObj(Func<ContextMocks, string> func, string toCompare) {
var mocks = new ContextMocks(controller);
mocks.ViewDataContainer.Object.ViewData.Model = new object();
mocks.ViewDataContainer.Object.ViewData[IdHelper.NofServices] = FrameworkHelper.GetServices();
string s = func(mocks);
Assert.AreEqual(toCompare, s);
}
开发者ID:,项目名称:,代码行数:7,代码来源:
示例19: DateTimePropertyEdit
public void DateTimePropertyEdit() {
var mocks = new ContextMocks(controller);
INakedObject adapter = FrameworkHelper.GetNakedObject(new NotPersistedTestClass());
mocks.ViewDataContainer.Object.ViewData.Model = adapter.Object;
mocks.ViewDataContainer.Object.ViewData[IdHelper.NofServices] = FrameworkHelper.GetServices();
string s = mocks.GetHtmlHelper<NotPersistedTestClass>().ObjectPropertyEdit(y => y.TestDateTime).ToString();
CheckResults("TestDateTime", s);
}
开发者ID:,项目名称:,代码行数:11,代码来源:
示例20: RefPropertyStringEditExistingValue
public void RefPropertyStringEditExistingValue() {
var mocks = new ContextMocks(controller);
var tc = (CustomHelperTestClass)GetTestService("Custom Helper Test Classes").GetAction("New Instance").InvokeReturnObject().NakedObject.Object;
mocks.ViewDataContainer.Object.ViewData.Model = tc;
mocks.ViewDataContainer.Object.ViewData[IdHelper.NofServices] = FrameworkHelper.GetServices();
var id = FrameworkHelper.GetObjectId(tc);
mocks.ViewDataContainer.Object.ViewData.ModelState.SetModelValue("CustomHelperTestClass-TestRef-Select", new ValueProviderResult(id, null, null));
string s = mocks.GetHtmlHelper<CustomHelperTestClass>().ObjectPropertyEdit("TestRef").ToString();
CheckResults("RefPropertyStringEditExistingValue", s);
}
开发者ID:,项目名称:,代码行数:14,代码来源:
注:本文中的ContextMocks类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论