public async Task UserSaves() { var userName = "******"; //var userName = "******" + Guid.NewGuid().ToString().Substring(0, 5); TestDataInitializer.CreateUser(userName); var bio = Guid.NewGuid().ToString(); var user = TestHelper.SetPrincipal(userName); //save start test data using (var repo = new Voat.Data.Repository(user)) { var r = await repo.Save(Domain.Models.ContentType.Submission, 1); VoatAssert.IsValid(r); var submissionSaves = await repo.GetUserSavedItems(Domain.Models.ContentType.Submission, user.Identity.Name); Assert.AreEqual(1, submissionSaves.Count()); Assert.IsTrue(submissionSaves.Any(x => x == 1), "Submission not saved"); r = await repo.Save(Domain.Models.ContentType.Comment, 1); VoatAssert.IsValid(r); var commentSaves = await repo.GetUserSavedItems(Domain.Models.ContentType.Comment, user.Identity.Name); Assert.AreEqual(1, commentSaves.Count()); Assert.IsTrue(commentSaves.Any(x => x == 1), "Comment not saved"); } var q = new QueryUserSaves(Domain.Models.ContentType.Submission).SetUserContext(user); var d = await q.ExecuteAsync(); Assert.AreEqual(1, d.Count); Assert.AreEqual(true, d.Contains(1)); Assert.AreEqual(true, CacheHandler.Instance.Exists(CachingKey.UserSavedItems(Domain.Models.ContentType.Submission, userName))); q = new QueryUserSaves(Domain.Models.ContentType.Comment).SetUserContext(user); d = await q.ExecuteAsync(); Assert.AreEqual(1, d.Count); Assert.AreEqual(true, d.Contains(1)); Assert.AreEqual(true, CacheHandler.Instance.Exists(CachingKey.UserSavedItems(Domain.Models.ContentType.Comment, userName))); //check helper object Assert.AreEqual(true, UserHelper.IsSaved(user, Domain.Models.ContentType.Submission, 1)); Assert.AreEqual(true, UserHelper.IsSaved(user, Domain.Models.ContentType.Comment, 1)); Assert.AreEqual(false, UserHelper.IsSaved(user, Domain.Models.ContentType.Submission, 2)); Assert.AreEqual(false, UserHelper.IsSaved(user, Domain.Models.ContentType.Comment, 2)); var cmd = new SaveCommand(Domain.Models.ContentType.Submission, 2).SetUserContext(user); var response = await cmd.Execute(); VoatAssert.IsValid(response); cmd = new SaveCommand(Domain.Models.ContentType.Comment, 2).SetUserContext(user); response = await cmd.Execute(); VoatAssert.IsValid(response); Assert.AreEqual(true, UserHelper.IsSaved(user, Domain.Models.ContentType.Submission, 2)); Assert.AreEqual(true, UserHelper.IsSaved(user, Domain.Models.ContentType.Comment, 2)); cmd = new SaveCommand(Domain.Models.ContentType.Submission, 1).SetUserContext(user);; response = await cmd.Execute(); VoatAssert.IsValid(response); cmd = new SaveCommand(Domain.Models.ContentType.Comment, 1).SetUserContext(user); response = await cmd.Execute(); VoatAssert.IsValid(response); Assert.AreEqual(false, UserHelper.IsSaved(user, Domain.Models.ContentType.Submission, 1)); Assert.AreEqual(false, UserHelper.IsSaved(user, Domain.Models.ContentType.Comment, 1)); }
public async Task UserSaves() { var userName = "******"; var bio = Guid.NewGuid().ToString(); TestHelper.SetPrincipal(userName); //save start test data using (var repo = new Voat.Data.Repository()) { var r = await repo.Save(Domain.Models.ContentType.Submission, 1); Assert.AreEqual(Status.Success, r.Status); r = await repo.Save(Domain.Models.ContentType.Comment, 1); Assert.AreEqual(Status.Success, r.Status); } var q = new QueryUserSaves(Domain.Models.ContentType.Submission); var d = await q.ExecuteAsync(); Assert.AreEqual(true, d.Contains(1)); Assert.AreEqual(1, d.Count); Assert.AreEqual(true, CacheHandler.Instance.Exists(CachingKey.UserSavedItems(Domain.Models.ContentType.Submission, userName))); q = new QueryUserSaves(Domain.Models.ContentType.Comment); d = await q.ExecuteAsync(); Assert.AreEqual(true, d.Contains(1)); Assert.AreEqual(1, d.Count); Assert.AreEqual(true, CacheHandler.Instance.Exists(CachingKey.UserSavedItems(Domain.Models.ContentType.Comment, userName))); //check helper object Assert.AreEqual(true, UserHelper.IsSaved(Domain.Models.ContentType.Submission, 1)); Assert.AreEqual(true, UserHelper.IsSaved(Domain.Models.ContentType.Comment, 1)); Assert.AreEqual(false, UserHelper.IsSaved(Domain.Models.ContentType.Submission, 2)); Assert.AreEqual(false, UserHelper.IsSaved(Domain.Models.ContentType.Comment, 2)); var cmd = new SaveCommand(Domain.Models.ContentType.Submission, 2); var response = await cmd.Execute(); Assert.AreEqual(Status.Success, response.Status); cmd = new SaveCommand(Domain.Models.ContentType.Comment, 2); response = await cmd.Execute(); Assert.AreEqual(Status.Success, response.Status); Assert.AreEqual(true, UserHelper.IsSaved(Domain.Models.ContentType.Submission, 2)); Assert.AreEqual(true, UserHelper.IsSaved(Domain.Models.ContentType.Comment, 2)); cmd = new SaveCommand(Domain.Models.ContentType.Submission, 1); response = await cmd.Execute(); Assert.AreEqual(Status.Success, response.Status); cmd = new SaveCommand(Domain.Models.ContentType.Comment, 1); response = await cmd.Execute(); Assert.AreEqual(Status.Success, response.Status); Assert.AreEqual(false, UserHelper.IsSaved(Domain.Models.ContentType.Submission, 1)); Assert.AreEqual(false, UserHelper.IsSaved(Domain.Models.ContentType.Comment, 1)); }