public void All_WithZeroUsers_ReturnsView() { //Arrange var dbContext = new MockDbContext().GetContext(); var users = new List <User>(); dbContext.Users.AddRange(users); dbContext.SaveChanges(); var mockUserStore = new Mock <IUserStore <User> >(); var mockUserManager = new Mock <UserManager <User> >( mockUserStore.Object, null, null, null, null, null, null, null, null); mockUserManager.Setup(um => um.GetUserAsync(null)) .ReturnsAsync(new User() { Id = "111" }); var controller = new UsersController(dbContext, mockUserManager.Object, null); //Act var result = controller.All(); Assert.IsInstanceOfType(result, typeof(ViewResult)); }
public void Demote_WithValidId_ShouldRedirectToAdminUsersAll() { //Arrange var dbContext = new MockDbContext().GetContext(); var user = new User() { Id = "aaaaaaa", UserName = "******" }; dbContext.Users.Add(user); dbContext.SaveChanges(); var mockUserStore = new Mock <IUserStore <User> >(); var mockUserManager = new Mock <UserManager <User> >( mockUserStore.Object, null, null, null, null, null, null, null, null); var notificationSender = new Mock <INotificationSender>(); notificationSender.Setup(ns => ns.SendNotification(It.IsAny <string>(), It.IsAny <MessageType>(), It.IsAny <Controller>(), It.IsAny <PageModel>())) .Returns(true); var controller = new UsersController(dbContext, mockUserManager.Object, notificationSender.Object); //Act var result = controller.Demote("aaaaaaa").Result as RedirectToActionResult; //Assert Assert.AreEqual("admin", result.RouteValues["area"]); Assert.AreEqual("users", result.RouteValues["controller"]); Assert.AreEqual("All", result.ActionName); }
public void All_WithSomeFeedback_ShouldReturnView() { //Arrange var dbContext = new MockDbContext().GetContext(); var feedback = new List <Feedback>() { new Feedback() { Id = 1 }, new Feedback() { Id = 2 }, new Feedback() { Id = 3 }, new Feedback() { Id = 4 } }; dbContext.Feedbacks.AddRange(feedback); dbContext.SaveChanges(); //Act var controller = new FeedbackController(dbContext); var result = controller.All(); //Assert Assert.IsInstanceOfType(result as ViewResult, typeof(ViewResult)); }
private void Seed() { this.SeedChildResources(); this.SeedResources(); _context.SaveChanges(); }
public void All_WithSomeComments_ShouldReturnView() { var dbContext = new MockDbContext().GetContext(); var author = new User() { Id = "1" }; dbContext.Comments.AddRange(new List <Comment>() { new Comment() { Message = "tralala", Author = author }, new Comment() { Message = "asdf", Author = author }, new Comment() { Message = "beep", Author = author } }); dbContext.SaveChanges(); var controller = new CommentsController(dbContext, null, null); var result = controller.All() as ViewResult; Assert.IsInstanceOfType(result, typeof(ViewResult)); }
public void TestOrderByOverwrite() { using (var localContext = new MockDbContext(this.options)) { localContext.Add(new Entity { Id = 1, Name = "za" }); localContext.Add(new Entity { Id = 2, Name = "za" }); localContext.Add(new Entity { Id = 3, Name = "aa" }); localContext.SaveChanges(); } var result = this.context.Entities .OrderBy(e => e.Name) .ThenBy(e => e.Id) .OrderByDescending(e => e.Name) .ThenByDescending(e => e.Id) .ToList(); Assert.Equal(result.Select(e => e.Id), new[] { 2, 1, 3 }); }
public void AddGroup(string group, string description = null, string externalGroup = null) { mockDbContext.Groups.Add(new Group { Id = Guid.NewGuid(), Name = group, Description = description, ExternalGroupName = externalGroup }); mockDbContext.SaveChanges(); }
public Test() { DbContextOptions <MockDbContext> options; var builder = new DbContextOptionsBuilder <MockDbContext>(); builder.UseInMemoryDatabase("Test"); options = builder.Options; mockDbContext = new MockDbContext(options); mockDbContext.Database.EnsureDeleted(); mockDbContext.Database.EnsureCreated(); mockDbContext.MockDatas.Add(mockData1); mockDbContext.MockDatas.Add(mockData2); mockDbContext.SaveChanges(); }
public void All_ShouldReturnAllUsersExceptCurrent() { //Arrange var users = new[] { new User() { Id = "111" }, new User() { Id = "222" }, new User() { Id = "333" }, new User() { Id = "444" }, }; var mockDbContext = new MockDbContext().GetContext(); mockDbContext.Users.AddRange(users); mockDbContext.SaveChanges(); var mockUserStore = new Mock <IUserStore <User> >(); var mockUserManager = new Mock <UserManager <User> >( mockUserStore.Object, null, null, null, null, null, null, null, null); mockUserManager.Setup(um => um.GetUserAsync(null)) .ReturnsAsync(users[1]); var controller = new UsersController(mockDbContext, mockUserManager.Object, null); //Act var result = controller.All() as ViewResult; //Assert var model = result.Model as IEnumerable <UsersConciseViewModel>; CollectionAssert.AreEqual(new[] { "111", "333", "444" }, model.Select(u => u.Id).ToArray()); }
public void ChangeFeedbackStatus_FeedbackIsNull_ShouldReturnNotFound() { var dbContext = new MockDbContext().GetContext(); dbContext.Feedbacks.Add(new Feedback() { Id = 1 }); dbContext.SaveChanges(); //Act var controller = new FeedbackController(dbContext); var result = controller.ChangeFeedbackStatus(2); //Assert Assert.IsInstanceOfType(result as NotFoundResult, typeof(NotFoundResult)); }
public void TestExistingCase() { const int id = 1; var provider = new GenericFilterExpressionProvider <Entity, int>( i => new FilterExpressionDictionary <Entity>().AddEquals(e => e.Id == i), new FilterToIntegerConverter(new CultureInfoConversionPriorityCollection())); var expression = provider.Resolve(FilterType.Equals, id.ToString()); using (var context = new MockDbContext()) { context.Add(new Entity { Id = id }); context.SaveChanges(); Assert.Equal(1, context.Entities.Count(expression)); } }
public void Demote_WithInvalidId_ShouldReturnNotFound() { //Arrange var dbContext = new MockDbContext().GetContext(); dbContext.Users.Add(new User() { Id = "aaaaaaa" }); dbContext.SaveChanges(); var controller = new UsersController(dbContext, null, null); //Act var result = controller.Demote("bbbbbbbb").Result; //Assert Assert.IsInstanceOfType(result, typeof(NotFoundResult)); }
public void ChangeFeedbackStatus_ShouldReturn_RedirectToActionResult() { var dbContext = new MockDbContext().GetContext(); dbContext.Feedbacks.Add(new Feedback() { Id = 1, IsRead = false }); dbContext.SaveChanges(); //Act var controller = new FeedbackController(dbContext); var result = controller.ChangeFeedbackStatus(1); var redirectToAction = result as RedirectToActionResult; //Assert Assert.IsInstanceOfType(redirectToAction, typeof(RedirectToActionResult)); }
public void ChangeFeedbackStatus_FeedbackIsNotRead_ShouldReturnIsRead() { var dbContext = new MockDbContext().GetContext(); dbContext.Feedbacks.Add(new Feedback() { Id = 1, IsRead = false }); dbContext.SaveChanges(); //Act var controller = new FeedbackController(dbContext); var result = controller.ChangeFeedbackStatus(1); var feed = dbContext.Feedbacks.Find(1); //Assert Assert.AreEqual(feed.IsRead, true); }
public void ChangeFeedbackStatus_ShouldRedirectTo_AdminFeedbackAll() { var dbContext = new MockDbContext().GetContext(); dbContext.Feedbacks.Add(new Feedback() { Id = 1, IsRead = false }); dbContext.SaveChanges(); //Act var controller = new FeedbackController(dbContext); var result = controller.ChangeFeedbackStatus(1); var redirectToAction = result as RedirectToActionResult; //Assert Assert.AreEqual(redirectToAction.RouteValues["area"], "admin"); Assert.AreEqual(redirectToAction.ControllerName, "feedback"); Assert.AreEqual(redirectToAction.ActionName, "all"); }
public void Excute() { if (!_dbContext.AppRole.Any()) { _dbContext.AppRole.Add(new AppRole() { RoleName = "超级管理员", IsEnableMark = true, DeleteMark = false }); } if (!_dbContext.AppUser.Any()) { string userSecretkey = Md5Helper.Md5(Utils.CreateNo(), 16).ToLower(); string loginPassword = Md5Helper.Md5(DesEncrypt.Encrypt(Md5Helper.Md5("123qwe", 32).ToLower(), userSecretkey).ToLower(), 32).ToLower(); _dbContext.AppUser.AddOrUpdate(new AppUser() { LoginName = "admin", LoginPassword = loginPassword, UserSecretkey = userSecretkey, DeleteMark = false }); } _dbContext.SaveChanges(); if (!_dbContext.UserRole.Any()) { List <AppUser> users = _dbContext.AppUser.ToList(); users?.ForEach(r => { _dbContext.UserRole.Add(new AppUserRole() { UserId = r.Id, RoleId = 1 }); }); } }
public IActionResult SaveClaim([FromForm] MockDatabase data) { try { _data.TransactionID = Guid.NewGuid(); _data.BenefitID = data.BenefitID; _data.PolicyID = data.PolicyID; _data.MemberID = data.MemberID; _data.BenefitName = data.BenefitName; _data.ClaimID = count++; _data.ClaimAmount = data.ClaimAmount; _data.HospitalId = data.HospitalId; _context.MockDatabases.Add(_data); _context.SaveChanges(); _log4net.Info(nameof(SaveClaim) + " method invoked."); using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = new HttpResponseMessage(); StringContent content = new StringContent(JsonConvert.SerializeObject(null), Encoding.UTF8, "application/json"); response = client.PostAsync("https://localhost:44355/api/Members/submitClaim?policyID=" + data.PolicyID + "&memberID=" + data.MemberID + "&benefitID=" + data.BenefitID + "&hospitalID=" + data.HospitalId + "&claimAmt=" + data.ClaimAmount + "&benefit=\"" + data.BenefitName + "\"", content).Result; var responseData = JsonConvert.DeserializeObject <string>(response.Content.ReadAsStringAsync().Result); ViewBag.Status = responseData; return(View("Status")); } } catch (Exception e) { ErrorViewModel error = new ErrorViewModel { ErrorMessage = e.Message }; _log4net.Error("Error Ocuured in " + nameof(SaveClaim) + " Error message : " + e.Message); return(View("Error", error)); } }
public async void Destination_Collection_DbContext() { var stepList = new List <StepValue <MockData> > { new StepValue <MockData>( new MockData { Id = 3, Nome = "Teste 3", Data = new DateTime(2000, 1, 3) }, null ), new StepValue <MockData>( new MockData { Id = 4, Nome = "Teste 4", Data = new DateTime(2000, 1, 4) }, null ) }; var stepValue = await stepList.Load(() => new DbContextDestination(mockDbContext)); mockDbContext.SaveChanges(); var result = await mockDbContext.MockDatas.ToListAsync(); result.Should().HaveCount(4); var item = result.LastOrDefault(); item.Id.Should().Be(4); item.Nome.Should().Be("Teste 4"); item.Data.Should().Be(new DateTime(2000, 1, 4)); }
public void Excute() { string iframe = "iframe"; string expand = "expand"; string menu = "Menu"; string pmenu = "PMenu"; string permission = "Permission"; if (!_dbContext.AppModule.Any()) { _dbContext.AppModule.AddRange(new List <AppModule>() { new AppModule() { PId = 0, Name = "系统管理", LinkUrl = "/Plat/AppModule/Index", Target = expand, TypeCode = pmenu, Icon = "fa fa-home", DeleteMark = false }, new AppModule() { PId = 1, Name = "用户管理", LinkUrl = "/Plat/AppUser/Index", Target = iframe, TypeCode = menu, Icon = "fa fa-user-o", DeleteMark = false }, new AppModule() { PId = 1, Name = "角色管理", LinkUrl = "/Plat/AppRole/Index", Target = iframe, TypeCode = menu, Icon = "fa fa-user-circle", DeleteMark = false }, new AppModule() { PId = 1, Name = "系统功能", LinkUrl = "/Plat/AppModule/Index", Target = iframe, TypeCode = menu, Icon = "fa fa-anchor", DeleteMark = false }, new AppModule() { PId = 1, Name = "测试管理", LinkUrl = "/Home/TestView", Target = iframe, TypeCode = menu, Icon = "fa fa-street-view", DeleteMark = false }, new AppModule() { PId = 1, Name = "系统日志", LinkUrl = "/Plat/LogMessage/Index", Target = iframe, TypeCode = menu, Icon = "fa fa-home", DeleteMark = false }, new AppModule() { PId = 0, Name = "博客管理", Target = expand, TypeCode = pmenu, Icon = "fa fa-cloud-download", DeleteMark = false }, new AppModule() { PId = 7, Name = "字典管理", LinkUrl = "/Plat/ItemsDetail/Index", Target = iframe, TypeCode = menu, Icon = "fa fa-key", DeleteMark = false }, new AppModule() { PId = 7, Name = "文章管理", LinkUrl = "/Plat/Article/Index", Target = iframe, TypeCode = menu, Icon = "fa fa-file-text-o", DeleteMark = false }, new AppModule() { PId = 7, Name = "留言审核", LinkUrl = "/Plat/GuestBook/Index", Target = iframe, TypeCode = menu, Icon = "fa fa-pencil", DeleteMark = false }, new AppModule() { PId = 7, Name = "评论审核", LinkUrl = "/Plat/Review/Index", Target = iframe, TypeCode = menu, Icon = "fa fa-product-hunt", DeleteMark = false }, new AppModule() { PId = 2, Name = "编辑用户页面", LinkUrl = "/Plat/AppUser/Form", Target = iframe, TypeCode = permission, DeleteMark = false }, new AppModule() { PId = 2, Name = "新增用户页面", LinkUrl = "/Plat/AppUser/Form", Target = iframe, TypeCode = permission, DeleteMark = false }, new AppModule() { PId = 2, Name = "刷新用户信息", LinkUrl = "/Plat/AppUser/GetDataGrid", Target = iframe, TypeCode = permission, DeleteMark = false }, new AppModule() { PId = 2, Name = "重置密码", LinkUrl = "/Plat/AppUser/ResetPassword", Target = iframe, TypeCode = permission, DeleteMark = false }, new AppModule() { PId = 2, Name = "删除用户", LinkUrl = "/Plat/AppUser/Delete", Target = iframe, TypeCode = permission, DeleteMark = false }, new AppModule() { PId = 3, Name = "角色授权权限", LinkUrl = "/Plat/AppRole/SaveAuthorize", Target = iframe, TypeCode = permission, DeleteMark = false }, new AppModule() { PId = 3, Name = "角色授权界面", LinkUrl = "/Plat/AppRole/AllotAuthorize", Target = iframe, TypeCode = permission, DeleteMark = false }, new AppModule() { PId = 3, Name = "角色成员权限", LinkUrl = "/Plat/AppRole/SaveMembers", Target = iframe, TypeCode = permission, DeleteMark = false }, new AppModule() { PId = 3, Name = "角色成员界面", LinkUrl = "/Plat/AppRole/AllotUser", Target = iframe, TypeCode = permission, DeleteMark = false }, new AppModule() { PId = 3, Name = "保存角色权限", LinkUrl = "/Plat/AppRole/Edit", Target = iframe, TypeCode = permission, DeleteMark = false }, new AppModule() { PId = 3, Name = "删除角色权限", LinkUrl = "/Plat/AppRole/Delete", Target = iframe, TypeCode = permission, DeleteMark = false }, new AppModule() { PId = 3, Name = "编辑角色界面", LinkUrl = "/Plat/AppRole/Form", Target = iframe, TypeCode = permission, DeleteMark = false }, new AppModule() { PId = 3, Name = "新增角色界面", LinkUrl = "/Plat/AppRole/Form", Target = iframe, TypeCode = permission, DeleteMark = false }, new AppModule() { PId = 3, Name = "刷新角色列表", LinkUrl = "/Plat/AppRole/GetDataGrid", Target = iframe, TypeCode = permission, DeleteMark = false }, new AppModule() { PId = 9, Name = "编辑", LinkUrl = "/Plat/Article/Form", Target = iframe, TypeCode = permission, DeleteMark = false }, new AppModule() { PId = 9, Name = "新增", LinkUrl = "/Plat/Article/Form", Target = iframe, TypeCode = permission, DeleteMark = false }, new AppModule() { PId = 9, Name = "刷新", LinkUrl = "/Plat/Article/GetDataGrid", Target = iframe, TypeCode = permission, DeleteMark = false }, new AppModule() { PId = 9, Name = "删除用户", LinkUrl = "/Plat/Article/Delete", Target = iframe, TypeCode = permission, DeleteMark = false }, }); } _dbContext.SaveChanges(); if (!_dbContext.RoleModule.Any()) { foreach (var appModule in _dbContext.AppModule.ToList()) { _dbContext.RoleModule.Add(new AppRoleModule() { ModuleId = appModule.Id, RoleId = 1 }); } } }