public static InviteStatus IsValidInvite(Invitation newInvitation) { if (HasPendingAnswers(newInvitation.From)) { return new InviteStatus { Message = "You can not send another invite until you answer all your pending invites or they expire.", StatusType = InviteStatusType.Invalid }; } if (HasPendingInvites(newInvitation.From)) { return new InviteStatus { Message = "You can not send another invite until all your pending invites send are answered or expire.", StatusType = InviteStatusType.Invalid }; } if (!_invitations.Contains(newInvitation)) { newInvitation.SentDate = DateTime.Now; _invitations.Add(newInvitation); return new InviteStatus { Message = "Invite was added successfully.", StatusType = InviteStatusType.Valid }; } else { Invitation first = null; _invitations.TryTake(out first); if (first != null && newInvitation.IsValidInvitation(first)) { _invitations.Add(newInvitation); return new InviteStatus { Message = "Invite was added successfully.", StatusType = InviteStatusType.Valid }; } else { _invitations.Add(first); return new InviteStatus { Message = "Invite already sent. You must wait 5 minutes before sending another one.", StatusType = InviteStatusType.Invalid }; ; } } }
public void Invitation_IsValidInvitation_10MinutesLaterInvitationReturnsTrue() { //Act Invitation first = new Invitation(); Invitation second = new Invitation(); Player p1 = new Player("Alex", "9C6109F9-5320-4411-9D1C-FA13D1CEC544",string.Empty); Player p2 = new Player("Bogdan", "3D072B37-0937-43EB-A77F-137B4DD08E03", string.Empty); //Arrange first.From = p1; first.To = p2; first.SentDate = new DateTime(2012, 12, 9, 10, 0, 0); second.From = p1; second.To = p2; second.SentDate = new DateTime(2012, 12, 9, 10, 0, 0) + TimeSpan.FromMinutes(10); //Assert Assert.IsTrue(second.IsValidInvitation(first)); }