public void EditPostDoesntTouchAlreadyPublishedEntrysPublishDate() { FakePostService postService = new FakePostService(); FakeUserService userService = new FakeUserService(); Guid postID = Guid.NewGuid(); DateTime publishedDate = DateTime.Now.AddDays(-1); postService.AddedPosts.Add(new Oxite.Models.Post() { ID = postID, Published = publishedDate }); Post newPost = new Post() { title = "PostTitle", description = "PostDescription", mt_excerpt = "PostBodyShort", mt_basename = "PostSlug" }; MetaWeblogAPI service = new MetaWeblogAPI(postService, null, userService, null, null); service.EditPost(postID.ToString(), "test", "test", newPost, true); Assert.Equal(publishedDate, postService.AddedPosts[0].Published); }
public void NewPostCreatesSlugForEntry() { FakePostService postService = new FakePostService(); FakeAreaService areaService = new FakeAreaService(); FakeTagService tagService = new FakeTagService(); FakeUserService userService = new FakeUserService(); FakeRegularExpressions regularExpressions = new FakeRegularExpressions(); Guid areaID = Guid.NewGuid(); areaService.StoredAreas.Add("test", new Oxite.Models.Area() { ID = areaID }); Post newPost = new Post() { title = "This is a test", description = "A Test", dateCreated = DateTime.Now, mt_basename = "" }; MetaWeblogAPI service = new MetaWeblogAPI(postService, areaService, userService, null, regularExpressions); service.NewPost(areaID.ToString(), "test", "test", newPost, false); Oxite.Models.Post savedPost = postService.AddedPosts[0]; Assert.Equal("This-is-a-test", savedPost.Slug); }
public void EditPostSavesChangesToTextFields() { FakePostService postService = new FakePostService(); FakeUserService userService = new FakeUserService(); Guid postID = Guid.NewGuid(); postService.AddedPosts.Add(new Oxite.Models.Post() { ID = postID, }); Post newPost = new Post() { title = "PostTitle", description = "PostDescription", mt_excerpt = "PostBodyShort", mt_basename = "PostSlug" }; MetaWeblogAPI service = new MetaWeblogAPI(postService, null, userService, null, null); bool success = service.EditPost(postID.ToString(), "test", "test", newPost, false); Assert.True(success); Oxite.Models.Post edited = postService.AddedPosts[0]; Assert.Equal(newPost.title, edited.Title); Assert.Equal(newPost.description, edited.Body); Assert.Equal(newPost.mt_excerpt, edited.BodyShort); Assert.Equal(newPost.mt_basename, edited.Slug); }
public void NewPostAddsToService() { FakePostService postService = new FakePostService(); FakeAreaService areaService = new FakeAreaService(); FakeTagService tagService = new FakeTagService(); FakeUserService userService = new FakeUserService(); Guid areaID = Guid.NewGuid(); areaService.StoredAreas.Add("test", new Oxite.Models.Area() { ID = areaID }); MetaWeblogAPI service = new MetaWeblogAPI(postService, areaService, userService, null, null); Post newPost = new Post() { title = "Test", description = "A Test", dateCreated = DateTime.Now, mt_basename = "test" }; string postIDString = service.NewPost(areaID.ToString(), "test", "test", newPost, false); Assert.NotNull(postIDString); Assert.Equal(1, postService.AddedPosts.Count); Assert.Equal(postService.AddedPosts[0].ID.ToString(), postIDString); Assert.Equal("Test", postService.AddedPosts[0].Title); Assert.Equal("A Test", postService.AddedPosts[0].Body); Assert.Equal(newPost.dateCreated, postService.AddedPosts[0].Created); Assert.Equal("test", postService.AddedPosts[0].Slug); Assert.Equal(Oxite.Models.EntityState.Normal, postService.AddedPosts[0].State); }
public void NewPostFaultsForNonParsableBlogID() { FakeUserService userService = new FakeUserService(); MetaWeblogAPI service = new MetaWeblogAPI(null, null, userService, null, null); Assert.Throws <FormatException>(() => service.NewPost("xxx", "test", "test", null, false)); }
public void NewPostAddsPassedCategoriesAsTags() { FakePostService postService = new FakePostService(); FakeAreaService areaService = new FakeAreaService(); FakeTagService tagService = new FakeTagService(); FakeUserService userService = new FakeUserService(); Guid areaID = Guid.NewGuid(); Guid tag1ID = Guid.NewGuid(); Guid tag2ID = Guid.NewGuid(); areaService.StoredAreas.Add("test", new Oxite.Models.Area() { ID = areaID }); Post newPost = new Post() { categories = new[] { "Test1", "Test2" }, title = "Test", description = "A Test", dateCreated = DateTime.Now, mt_basename = "test" }; MetaWeblogAPI service = new MetaWeblogAPI(postService, areaService, userService, null, null); service.NewPost(areaID.ToString(), "test", "test", newPost, false); Assert.Equal(1, postService.AddedPosts.Count); Oxite.Models.Post savedPost = postService.AddedPosts[0]; Assert.Equal(2, savedPost.Tags.Count); Assert.Contains("Test1", savedPost.Tags.Select(t => t.Name)); Assert.Contains("Test2", savedPost.Tags.Select(t => t.Name)); }
public void GetCategoriesFaultsOnNullUser() { FakeUserService userService = new FakeUserService(); MetaWeblogAPI service = new MetaWeblogAPI(null, null, userService, null, null); Assert.Throws <ArgumentException>(() => service.GetCategories(null, null, null)); }
public void EditPostPublishesIfPublishIsTrue() { FakePostService postService = new FakePostService(); FakeUserService userService = new FakeUserService(); Guid postID = Guid.NewGuid(); postService.AddedPosts.Add(new Oxite.Models.Post() { ID = postID, }); Post newPost = new Post() { title = "PostTitle", description = "PostDescription", mt_excerpt = "PostBodyShort", mt_basename = "PostSlug" }; MetaWeblogAPI service = new MetaWeblogAPI(postService, null, userService, null, null); service.EditPost(postID.ToString(), "test", "test", newPost, true); Assert.True(DateTime.Today < postService.AddedPosts[0].Published); }
public void GetPostFaultsOnBadID() { FakePostService postService = new FakePostService(); FakeUserService userService = new FakeUserService(); MetaWeblogAPI service = new MetaWeblogAPI(postService, null, userService, null, null); Assert.Throws <ArgumentOutOfRangeException>(() => service.GetPost(Guid.NewGuid().ToString(), "test", "test")); }
public void TestsCleanup() { this.userService = null; this.navigationService = null; this.localizationService = null; this.dialogService = null; this.registerViewModel = null; }
public void GetPostReturnsPost() { FakePostService postService = new FakePostService(); FakeUserService userService = new FakeUserService(); DateTime now = DateTime.Now; Oxite.Models.Post fakePost = new Oxite.Models.Post() { Title = "Title", Body = "Body", Created = DateTime.Now, Published = DateTime.Now, ID = Guid.NewGuid(), Creator = new Oxite.Models.User() { DisplayName = "Test User", Name = "user" }, BodyShort = "Excerpt", Slug = "Slug" }; fakePost.Area = new Oxite.Models.Area() { ID = Guid.NewGuid(), Name = "Blog1", DisplayName = "Blog One" }; fakePost.Tags = new List <Oxite.Models.Tag>(new[] { new Oxite.Models.Tag() { ID = Guid.NewGuid(), Name = "Tag1" }, new Oxite.Models.Tag() { ID = Guid.NewGuid(), Name = "Tag2" } }); postService.AddedPosts.Add(fakePost); MetaWeblogAPI service = new MetaWeblogAPI(postService, null, userService, null, null); Post post = service.GetPost(fakePost.ID.ToString(), "test", "test"); Assert.NotNull(post); Assert.Equal(fakePost.Title, post.title); Assert.Equal(fakePost.Body, post.description); Assert.Equal(fakePost.Created, post.dateCreated); Assert.Equal(fakePost.Creator.ID, new Guid(post.userid)); Assert.Equal(fakePost.BodyShort, post.mt_excerpt); Assert.Equal(fakePost.Slug, post.mt_basename); foreach (string category in post.categories) { Assert.Contains <string>(category, fakePost.Tags.Select(t => t.Name)); } }
public void NewPostFaultsOnNullUser() { FakeUserService userService = new FakeUserService(); Guid areaID = Guid.NewGuid(); MetaWeblogAPI service = new MetaWeblogAPI(null, null, userService, null, null); Assert.Throws <ArgumentException>(() => service.NewPost(Guid.NewGuid().ToString(), null, null, new Post(), false)); }
public void NewPostFaultsOnBadUsernamePassword() { FakeUserService userService = new FakeUserService(); MetaWeblogAPI service = new MetaWeblogAPI(null, null, userService, null, null); userService.Authenticate = false; Assert.Throws <System.Security.Authentication.InvalidCredentialException>(() => service.NewPost(Guid.NewGuid().ToString(), "test", "test", null, false)); }
public void TestsCleanUp() { this.userService = null; this.storageService = null; this.navigationService = null; this.localizationService = null; this.dialogService = null; this.loginViewModel = null; }
public void TestsInitialize() { this.userService = new FakeUserService(); this.navigationService = new FakeNavigationService(); this.localizationService = new FakeLocalizationService(); this.dialogService = new FakeDialogService(); this.registerViewModel = new RegisterViewModel(this.userService, this.navigationService, this.localizationService, this.dialogService); }
public void TestsInitialize() { this.userService = new FakeUserService(); this.storageService = new FakeStorageService(); this.navigationService = new FakeNavigationService(); this.localizationService = new FakeLocalizationService(); this.dialogService = new FakeDialogService(); this.loginViewModel = new LoginViewModel(this.userService, this.storageService, this.navigationService, this.localizationService, this.dialogService); }
public void SignInSetsModelStateErrorIfUserDoesNotExist() { FakeUserService userService = new FakeUserService(); userService.Authenticate = false; UserController controller = new UserController(null, userService); controller.SignIn("test", "test", false, null); Assert.False(controller.ModelState.IsValid); Assert.False(controller.ModelState.IsValidField("_FORM")); }
public void SignInRedirectsToUrlForNonNullReturnUrl() { FakeUserService userService = new FakeUserService(); FakeFormsAuthentication formsAuth = new FakeFormsAuthentication(); UserController controller = new UserController(formsAuth, userService); ActionResult result = controller.SignIn("test", "test", true, "/test") as ActionResult; Assert.IsType <RedirectResult>(result); RedirectResult redirectResult = result as RedirectResult; Assert.Equal("/test", redirectResult.Url); }
public ActionResult Index(string id) { IUserService userService = new FakeUserService(); var user = userService.GetUserByName(id); ViewBag.UserId = ""; var sender = userService.GetUserByName(this.User.Identity.Name); // 获取在线用户列表 List <SelectListItem> onlineUserList = new List <SelectListItem>(); onlineUserList.Add(new SelectListItem() { Text = "请选择在线用户", Value = "" }); var allUsers = userService.GetUsers(); foreach (var ou in allUsers) { if (ou.UserName == sender.UserName) { continue; } SelectListItem item = new SelectListItem(); item.Text = ou.DisplayName; item.Value = ou.UserName; if (user != null && ou.UserName == user.UserName) { item.Selected = true; } onlineUserList.Add(item); } ViewData["OnlineUsers"] = onlineUserList; ViewBag.Sender = sender.DisplayName; if (sender.UserRole == Models.UserRole.管理员) { ViewBag.CanBroadcast = true; } else { ViewBag.CanBroadcast = false; } return(View()); }
public void NewPostSetsCreatorToUser() { FakePostService postService = new FakePostService(); FakeAreaService areaService = new FakeAreaService(); FakeTagService tagService = new FakeTagService(); FakeUserService userService = new FakeUserService(); Guid areaID = Guid.NewGuid(); MetaWeblogAPI service = new MetaWeblogAPI(postService, areaService, userService, null, null); service.NewPost(areaID.ToString(), "test", "test", new Post(), false); Oxite.Model.Post newPost = postService.AddedPosts[0]; Assert.Equal("test", newPost.Creator.Name); }
public void GetCategoriesReturnsAllTags() { FakeTagService tagService = new FakeTagService(); FakeUserService userService = new FakeUserService(); tagService.StoredTags.Add("test", new Oxite.Models.Tag() { Name = "test" }); MetaWeblogAPI service = new MetaWeblogAPI(null, null, userService, tagService, null); CategoryInfo[] categories = service.GetCategories(null, "test", "test"); Assert.Equal(1, categories.Length); Assert.Equal("test", categories[0].description); }
public void GetRecentPostsReturnsNumberOfPostsInBlog() { FakeUserService userService = new FakeUserService(); FakePostService postService = new FakePostService(); Guid areaID = Guid.NewGuid(); Oxite.Models.Post post1 = new Oxite.Models.Post() { ID = Guid.NewGuid(), Creator = new Oxite.Models.User(), Area = new Oxite.Models.Area() { ID = areaID }, Slug = "Post1", Created = DateTime.Now, Tags = new List <Oxite.Models.Tag>() }; Oxite.Models.Post post2 = new Oxite.Models.Post() { ID = Guid.NewGuid(), Creator = new Oxite.Models.User(), Area = new Oxite.Models.Area() { ID = areaID }, Slug = "Post2", Created = DateTime.Now, Tags = new List <Oxite.Models.Tag>() }; postService.AddedPosts.AddRange(new[] { post1, post2 }); MetaWeblogAPI service = new MetaWeblogAPI(postService, null, userService, null, null); Post[] posts = service.GetRecentPosts(areaID.ToString(), "test", "test", 2); Assert.NotNull(posts); Assert.Equal(2, posts.Length); Assert.Contains <Guid>(post1.ID, posts.Select(p => new Guid(p.postid))); Assert.Contains <Guid>(post2.ID, posts.Select(p => new Guid(p.postid))); }
public void NewPostAddsExcerptAsBodyShort() { FakePostService postService = new FakePostService(); FakeAreaService areaService = new FakeAreaService(); FakeTagService tagService = new FakeTagService(); FakeUserService userService = new FakeUserService(); Guid areaID = Guid.NewGuid(); MetaWeblogAPI service = new MetaWeblogAPI(postService, areaService, userService, null, null); Post newPost = new Post() { mt_excerpt = "Preview", title = "Test", description = "A Test", dateCreated = DateTime.Now, mt_basename = "test" }; service.NewPost(areaID.ToString(), "test", "test", newPost, false); Assert.Equal(newPost.mt_excerpt, postService.AddedPosts[0].BodyShort); }
public void NewPostSetsPublishDateToNullIfPublishFalse() { FakePostService postService = new FakePostService(); FakeAreaService areaService = new FakeAreaService(); FakeTagService tagService = new FakeTagService(); FakeUserService userService = new FakeUserService(); Guid areaID = Guid.NewGuid(); MetaWeblogAPI service = new MetaWeblogAPI(postService, areaService, userService, null, null); Post newPost = new Post() { title = "Test", description = "A Test", dateCreated = DateTime.Now, mt_basename = "test" }; service.NewPost(areaID.ToString(), "test", "test", newPost, false); Assert.Null(postService.AddedPosts[0].Published); }
public void EditPostEditsTagList() { FakePostService postService = new FakePostService(); FakeUserService userService = new FakeUserService(); Guid postID = Guid.NewGuid(); postService.AddedPosts.Add(new Oxite.Models.Post() { ID = postID, Title = "PreTitle", Body = "PreBody", BodyShort = "PreBodyShort", Tags = new List <Oxite.Models.Tag>(new Oxite.Models.Tag[] { new Oxite.Models.Tag() { Name = "Old1" }, new Oxite.Models.Tag() { Name = "Both1" } }) }); Post newPost = new Post() { categories = new[] { "New1", "Both1" }, title = "PostTitle", description = "PostDescription", mt_excerpt = "PostBodyShort" }; MetaWeblogAPI service = new MetaWeblogAPI(postService, null, userService, null, null); service.EditPost(postID.ToString(), "test", "test", newPost, false); Oxite.Models.Post edited = postService.AddedPosts[0]; Assert.Equal(2, edited.Tags.Count()); Assert.Contains("New1", edited.Tags.Select(t => t.Name)); Assert.Contains("Both1", edited.Tags.Select(t => t.Name)); }
public void DeletePostDeletesPost() { Guid postID = Guid.NewGuid(); FakePostService postService = new FakePostService(); FakeUserService userService = new FakeUserService(); postService.AddedPosts.Add(new Oxite.Models.Post() { ID = postID, State = Oxite.Models.EntityState.Normal }); MetaWeblogAPI service = new MetaWeblogAPI(postService, null, userService, null, null); bool ret = service.DeletePost(null, postID.ToString(), "test", "test", false); Assert.True(ret); Assert.Equal(1, postService.RemovedPosts.Count); Assert.Equal(postID, postService.RemovedPosts[0].ID); }
private bool LoginUser(string userName, string password) { IUserService userService = new FakeUserService(); bool loginSuccess = userService.ValidateUser(userName, password); if (loginSuccess) { var usr = userService.GetUserByName(userName); AuthenticationManager.SignIn( new ClaimsIdentity( new[] { new Claim(ClaimsIdentity.DefaultNameClaimType, userName), new Claim("DisplayName", usr.DisplayName) }, DefaultAuthenticationTypes.ApplicationCookie) ); } return(loginSuccess); }
public void SignInSetsCookieForValidUser() { FakeUserService userService = new FakeUserService(); FakeFormsAuthentication formsAuth = new FakeFormsAuthentication(); RouteCollection routes = new RouteCollection(); routes.Add("Posts", new Route("", new MvcRouteHandler())); UrlHelper helper = new UrlHelper(new RequestContext(new FakeHttpContext(new Uri("http://oxite.net/"), "~/"), new RouteData()), routes); UserController controller = new UserController(formsAuth, userService) { Url = helper }; controller.SignIn("test", "test", true, null); Assert.Equal("test", formsAuth.LastUserName); Assert.True(formsAuth.LastPersistCookie); }
/// <summary> /// Gets the user's information by login ID after object is constructed /// </summary> public void CreateUserSession() { //So, again, like throughout this //trash heap, basically Im trying to quickly //emulate the same behavior that I had implemented //previously in the corp AD environment. //Because the whole thing lived inside of the corp intranet, //basically we had the luxury of just setting needed items //into a session to be used through the application and not //worry too too much about security restrictions...so thats whats here this.ID = UserHandler.ReturnLogInID(); var fsu = new FakeUserService(); var objUsr = fsu.GetUserByLogin(ID); this.UserObject = objUsr; //Finally set it into a session state... HttpContext.Current.Session["currentUser"] = this; }
public async Task AuthenticateUseCase_ValidInput_ShouldReturnTheUser() { // Arrange var userService = new FakeUserService(); var presenter = new FakeAuthenticateOutputHandler(); var sut = new AuthenticateUseCase(presenter, userService); var input = new AuthenticationInput("username", "password"); // Act await sut.Execute(input); // Assert presenter.ErrorMessage .Should() .BeNull(); presenter.ViewModel .Should() .BeEquivalentTo(userService.User); }