本文整理汇总了C#中ContextMocks类的典型用法代码示例。如果您正苦于以下问题:C# ContextMocks类的具体用法?C# ContextMocks怎么用?C# ContextMocks使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContextMocks类属于命名空间,在下文中一共展示了ContextMocks类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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));
}
示例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"));
}
示例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"));
}
示例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);
}
示例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");
}
示例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"));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}