public void SetUp() { HttpContext.Current = HttpContextFactory.CreateHttpContext(); routeValues = HttpContext.Current.Request.RequestContext.RouteData.Values; provider = new MvcSiteMapProvider(siteMapPath, parser); }
public BaseDatalistTests() { HttpContext.Current = HttpContextFactory.CreateHttpContext(); urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext); datalist = new BaseDatalistProxy <Role, RoleView>(urlHelper); }
public MvcDatalistTests() { HttpContext.Current = HttpContextFactory.CreateHttpContext(); url = new UrlHelper(HttpContext.Current.Request.RequestContext); datalist = new MvcDatalist <Role, RoleView>(url); using (TestingContext context = new TestingContext()) context.DropData(); }
public void Log_DoesNotSaveChanges() { entry.State = EntityState.Added; HttpContext.Current = HttpContextFactory.CreateHttpContext(); logger.Log(new[] { entry }); Assert.Empty(context.Set <AuditLog>()); }
public DatalistControllerTests() { unitOfWork = Substitute.For <IUnitOfWork>(); controller = Substitute.ForPartsOf <DatalistController>(unitOfWork); HttpContext.Current = HttpContextFactory.CreateHttpContext(); datalist = Substitute.For <AbstractDatalist>(); filter = new DatalistFilter(); }
public void Mutable_FeatureCollection_Wrapped_For_OwinFeatureCollection() { var env = new Dictionary <string, object>(); var contextFactory = new HttpContextFactory(); var context = contextFactory.CreateHttpContext(new OwinFeatureCollection(env)); // Setting a feature will throw if the above feature collection is not wrapped in a mutable feature collection. context.Features.Set <ICustomFeature>(new CustomFeature(100)); Assert.Equal(100, context.Features.Get <ICustomFeature>().Value); }
public void Logout_ExpiresCookie() { HttpContext.Current = HttpContextFactory.CreateHttpContext(); service.Login(account.Username); service.Logout(); DateTime expirationDate = HttpContext.Current.Response.Cookies[0].Expires; Assert.True(expirationDate < DateTime.Now); }
public void Log_DoesNotSave() { entry.State = EntityState.Added; LoggableEntity entity = new LoggableEntity(entry); HttpContext.Current = HttpContextFactory.CreateHttpContext(); logger.Log(entity); Assert.Empty(context.Set <AuditLog>()); }
public void Login_IsCaseInsensitive() { HttpContext.Current = HttpContextFactory.CreateHttpContext(); service.Login(account.Username.ToUpper()); String actual = FormsAuthentication.Decrypt(HttpContext.Current.Response.Cookies[0].Value).Name; String expected = account.Id.ToString(); Assert.Equal(expected, actual); }
public void SetUp() { column = SubstituteColumn <AllTypesView>(); options = SubstituteOptions <AllTypesView>(); columns = SubstituteColumns <AllTypesView, DateTime?>(column); HttpContext.Current = HttpContextFactory.CreateHttpContext(); urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext); Authorization.Provider = Substitute.For <IAuthorizationProvider>(); Authorization.Provider.IsAuthorizedFor(Arg.Any <String>(), Arg.Any <String>(), Arg.Any <String>(), Arg.Any <String>()).Returns(true); }
public void Login_Account() { HttpContext.Current = HttpContextFactory.CreateHttpContext(); service.Login(account.Username.ToUpper()); FormsAuthenticationTicket actual = FormsAuthentication.Decrypt(HttpContext.Current.Response.Cookies[0].Value); FormsAuthenticationTicket expected = new FormsAuthenticationTicket(account.Id.ToString(), true, 0); Assert.Equal(expected.IsPersistent, actual.IsPersistent); Assert.Equal(expected.Name, actual.Name); }
public void Login_CreatesPersistentAuthenticationTicket() { AccountLoginView view = ObjectFactory.CreateAccountLoginView(); HttpContext.Current = HttpContextFactory.CreateHttpContext(); service.Login(view.Username); FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(HttpContext.Current.Response.Cookies[0].Value); Assert.True(ticket.IsPersistent); }
public void SetUp() { context = new TestingContext(); dataContext = new TestingContext(); TestModel model = ObjectFactory.CreateTestModel(); logger = Substitute.ForPartsOf <AuditLogger>(context); HttpContext.Current = HttpContextFactory.CreateHttpContext(); entry = dataContext.Entry <BaseModel>(dataContext.Set <TestModel>().Add(model)); dataContext.Set <TestModel>().RemoveRange(dataContext.Set <TestModel>()); dataContext.SaveChanges(); }
public void Login_SetAccountIdAsAuthenticationTicketValue() { AccountLoginView view = ObjectFactory.CreateAccountLoginView(); HttpContext.Current = HttpContextFactory.CreateHttpContext(); service.Login(view.Username); String actual = FormsAuthentication.Decrypt(HttpContext.Current.Response.Cookies[0].Value).Name; String expected = view.Id; Assert.Equal(expected, actual); }
public void Logout_MakesAccountCookieExpired() { AccountLoginView view = ObjectFactory.CreateAccountLoginView(); HttpContext.Current = HttpContextFactory.CreateHttpContext(); service.Login(view.Username); service.Logout(); DateTime expirationDate = HttpContext.Current.Response.Cookies[0].Expires; Assert.True(expirationDate < DateTime.Now); }
public void Log_MessageForCurrentAccount() { HttpContext.Current = HttpContextFactory.CreateHttpContext(); Logger logger = new Logger(); logger.Log("Test"); String expected = "Account: 1" + Environment.NewLine + "Message: Test" + Environment.NewLine + Environment.NewLine; String actual = File.ReadAllText(log); Assert.StartsWith("Time :", actual); Assert.EndsWith(expected, actual); }
public void Log_MessageWithoutAccount() { HttpContext.Current = HttpContextFactory.CreateHttpContext(); HttpContext.Current.User = null; Logger logger = new Logger(); logger.Log("Test"); String expected = "Account: " + Environment.NewLine + "Message: Test" + Environment.NewLine + Environment.NewLine; String actual = File.ReadAllText(logPath); Assert.True(actual.StartsWith("Time :")); Assert.True(actual.EndsWith(expected)); }
public void SetUp() { context = new TestingContext(); hasher = Substitute.For <IHasher>(); mailClient = Substitute.For <IMailClient>(); hasher.HashPassword(Arg.Any <String>()).Returns("Hashed"); hasher.Verify(Arg.Any <String>(), Arg.Any <String>()).Returns(true); HttpContext.Current = HttpContextFactory.CreateHttpContext(); Authorization.Provider = Substitute.For <IAuthorizationProvider>(); service = new AccountService(new UnitOfWork(context), mailClient, hasher); TearDownData(); SetUpData(); }
public void Log_Logs() { HttpContext.Current = HttpContextFactory.CreateHttpContext(); using (TestingContext context = new TestingContext()) { context.Set <Log>().RemoveRange(context.Set <Log>()); context.SaveChanges(); new Logger(context).Log(new String('L', 10000)); Log expected = new Log(new String('L', 10000)); Log actual = context.Set <Log>().Single(); Assert.AreEqual(expected.AccountId, actual.AccountId); Assert.AreEqual(expected.Message, actual.Message); } }
public void Log_AddsLogToTheSet(String accountId, String identityName, String expectedAccountId) { HttpContext.Current = HttpContextFactory.CreateHttpContext(); HttpContext.Current.User.Identity.Name.Returns(identityName); LoggableEntity entity = new LoggableEntity(entry); logger = new AuditLogger(context, accountId); logger.Log(entity); AuditLog actual = context.ChangeTracker.Entries <AuditLog>().First().Entity; LoggableEntity expected = entity; Assert.Equal(expectedAccountId, actual.AccountId); Assert.Equal(expected.ToString(), actual.Changes); Assert.Equal(expected.Name, actual.EntityName); Assert.Equal(expected.Action, actual.Action); Assert.Equal(expected.Id, actual.EntityId); }
public void Save_LogsOnce(Int32?accountId, String identity, Int32?expectedAccountId) { HttpContext.Current = HttpContextFactory.CreateHttpContext(); HttpContext.Current.User.Identity.Name.Returns(identity); LoggableEntity entity = new LoggableEntity(entry); logger = new AuditLogger(context, accountId); logger.Log(entity); logger.Save(); logger.Save(); AuditLog actual = context.Set <AuditLog>().Single(); LoggableEntity expected = entity; Assert.Equal(expectedAccountId, actual.AccountId); Assert.Equal(expected.ToString(), actual.Changes); Assert.Equal(expected.Name, actual.EntityName); Assert.Equal(expected.Action, actual.Action); Assert.Equal(expected.Id(), actual.EntityId); }
public void SetUp() { HttpContext.Current = HttpContextFactory.CreateHttpContext(); }
public MvcSiteMapProviderTests() { requestContext = HttpContextFactory.CreateHttpContext().Request.RequestContext; provider = new MvcSiteMapProvider(siteMapPath, parser); routeValues = requestContext.RouteData.Values; }
public void TestFixtureSetUp() { HttpContext.Current = HttpContextFactory.CreateHttpContext(); datalist = new BaseDatalistProxy <Role, RoleView>(); unitOfWork = Substitute.For <IUnitOfWork>(); }