public void UserCanPostToSubscribedGroup() { // Mock<Group> mockGroup = new Mock<Group>(); Post post = new Post() {Content = "Some stupid content", PostedDateTime = new DateTime(2010, 01, 01)}; // Group group = mockGroup.Object; Group group = new Group("test"); // mockGroup.Setup(foo => foo.post(post)); // mockGroup.Setup(foo => foo.Equals(It.IsAny<Group>())).Returns(true); LoginId loginid = new LoginId("*****@*****.**"); string firstname = "firstName"; string lastname = "lastName"; Name name = new Name(firstname, lastname); User footballFan = new User(loginid, name); footballFan.Groups.Add(group); try { footballFan.PostToGroup(group, post); } catch (Exception ex) { Assert.Fail("Failed"); } }
public void ShouldBeAbleToCreateGroup() { var group = new Group("test"); groupRepository.Create(group); session.Evict(group); Assert.True(group.Id > 0); Assert.True(groupRepository.Exists(group)); }
public GroupAlreadyExistsException(Group group) : base(string.Format("Group {0} already exists.", group.Name)) { }
public virtual bool Equals(Group other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return other.Id == Id; }
public void MembershipIsUpdatedWhenUserJoinsGroup() { int before = session.CreateSQLQuery("select * from GroupMembershipTable").List().Count; Group group = new Group("test"); user1.CreateGroup(group); session.Flush(); session.Evict(group); int after = session.CreateSQLQuery("select * from GroupMembershipTable").List().Count; Assert.AreEqual(before + 1, after); }
public void UserShouldBeAbleToJoinGroup() { User user = new User(new LoginId("123"), null); Group group = new Group("Nature-Lovers"); user.Join(group); Assert.AreEqual(1, user.Groups.Count()); Assert.True(user.Groups.Contains(group)); }
public void ShouldNotBeAbleToCreateGroupIfAlreadyExists() { User user = new User(new LoginId("123"), null); Group group = new Group() {Name = "Nature-Lovers"}; var repositoryMock = new Moq.Mock<IGroupRepository>(); user.GroupRepository = repositoryMock.Object; repositoryMock.Setup(p => p.Exists(group)).Returns(true); try{ user.CreateGroup(group); Assert.Fail("exception expected"); } catch (GroupAlreadyExistsException){ } repositoryMock.VerifyAll(); }
public void ShouldBeAbleToCreateAGroup() { User user = new User(new LoginId("123"), null); Group group = new Group {Name = "Nature-Lovers"}; var repositoryMock = new Mock<IGroupRepository>(); repositoryMock.Setup(rep => rep.Exists(group)).Returns(false); repositoryMock.Setup(rep => rep.Create(group)); user.GroupRepository = repositoryMock.Object; user.CreateGroup(group); repositoryMock.VerifyAll(); }
public void ShouldAutomaticallyJoinAGroupUponCreatingIt() { User user = new User(new LoginId("123"), null); Group group = new Group { Name = "Nature-Lovers" }; var repositoryMock = new Mock<IGroupRepository>(); repositoryMock.Setup(rep => rep.Exists(It.IsAny<Group>())).Returns(false); repositoryMock.Setup(rep => rep.Create(group)); user.GroupRepository = repositoryMock.Object; user.CreateGroup(group); Assert.AreEqual(group, user.Groups.First()); repositoryMock.VerifyAll(); }
public void InboxShouldShowBothCommentsAndMessagesInDescindingOrderOfDate() { var suchit = new User(new LoginId("*****@*****.**"), new Name("firstName1", "lastName1")); var vivek = new User(new LoginId("*****@*****.**"), new Name("firstName2", "lastName2")) { Profile = new Profile("This is the profile on which user1 will comment") }; var commentOn5Oct = new Comment(suchit, vivek, "This is what I am going to comment", new GetInDate(new DateTime(2010,10,5))); var commentOn15Oct = new Comment(suchit, vivek, "This is a second comment", new GetInDate(new DateTime(2010,10,15))); var group = new Group("group1"); var postOn8Oct = new Post { Content = "content 1 for group1", PostedDateTime = new DateTime(2010, 10, 8) }; var postOn10Oct = new Post { Content = "content 2 for group1", PostedDateTime = new DateTime(2010, 10, 10) }; var groupPosts = new GroupPosts { groupPostList = new List<Post>() {postOn8Oct, postOn10Oct} }; group.MessageList = groupPosts; vivek.Groups.Add(group); vivek.PostToGroup(group,postOn8Oct); vivek.PostToGroup(group,postOn10Oct); Inbox inbox = vivek.GetInbox(); Assert.AreEqual(4, inbox.TotalMessageCount()); Assert.AreEqual(commentOn15Oct.Content, inbox.nextMessage().MessageContent); Assert.AreEqual(postOn10Oct.Content, inbox.nextMessage().MessageContent); Assert.AreEqual(postOn8Oct.Content, inbox.nextMessage().MessageContent); Assert.AreEqual(commentOn5Oct.Content, inbox.nextMessage().MessageContent); }
public bool Exists(Group group) { ICriteria criteria = Session.CreateCriteria(typeof (Group)); criteria.Add(Restrictions.Eq("Name", group.Name)); return criteria.List<Group>().Count != 0; }
public void Create(Group group) { Session.Save(group); }
public virtual void PostToGroup(Group group, Post post) { if (belongsToGroup(group)){ group.post(post); } else{ throw new UserHasNotSubscribedException(); } }
public virtual void Join(Group group) { if (!Groups.Contains(group)){ Groups.Add(group); } }
public virtual void CreateGroup(Group group) { var groupExists = GroupRepository.Exists(group); if (groupExists){ throw new GroupAlreadyExistsException(group); } GroupRepository.Create(group); Join(group); }
public virtual bool belongsToGroup(Group group) { return this.Groups.Contains(group); }