public async Task TestPostMessageFailed1() { //MemberIdTo is invalid //ReplyIdTo is Invalid HellolingoMailMessage model = new HellolingoMailMessage() { MemberIdTo = 1, ReplyTo = null, Text = "Hello there!" }; int currentUserId = 5; var entitytiesMock = new Mock <IHellolingoEntities>(); entitytiesMock.Setup(e => e.Mails_Insert(It.IsAny <byte?>(), It.IsAny <int?>(), It.IsAny <long?>(), It.IsAny <int?>(), It.IsAny <string>(), It.IsAny <string>())); var mailValidatorMock = new Mock <IMailBoxValidator>(); var controller = new MailBoxController(entitytiesMock.Object, mailValidatorMock.Object); controller.User = new GenericPrincipal(new ClaimsIdentity(new[] { new Claim(CustomClaimTypes.UserId, currentUserId.ToString()) }), null); mailValidatorMock.Setup(v => v.IsReplyToValid(It.IsAny <int?>(), It.IsAny <int>(), It.IsAny <int>())).Returns(Result <bool> .True); mailValidatorMock.Setup(v => v.IsRecipientValid(It.IsAny <int>())).Returns(Result <bool> .True); await controller.PostMessage(model); await controller.PostMessage(model); entitytiesMock.Verify(v => v.Mails_Insert(It.IsAny <byte?>(), It.IsAny <int?>(), It.IsAny <long?>(), It.IsAny <int?>(), It.IsAny <string>(), It.IsAny <string>()), Times.Exactly(2)); }
public async Task TestPostMessageSuccess() { //MemberIdTo is valid //ReplyIdTo is valid HellolingoMailMessage model = new HellolingoMailMessage() { MemberIdTo = 1, ReplyTo = null, Text = "Hello there!" }; int currentUserId = 5; var entitytiesMock = new Mock <IHellolingoEntities>(); entitytiesMock.Setup(e => e.Mails_Insert(It.IsAny <byte?>(), It.IsAny <int?>(), It.IsAny <long?>(), It.IsAny <int?>(), It.IsAny <string>(), It.IsAny <string>())); var mailValidatorMock = new Mock <IMailBoxValidator>(); var controller = new MailBoxController(entitytiesMock.Object, mailValidatorMock.Object); controller.User = new GenericPrincipal(new ClaimsIdentity(new [] { new Claim(CustomClaimTypes.UserId, currentUserId.ToString()) }), null); mailValidatorMock.Setup(v => v.IsReplyToValid(It.IsAny <int?>(), It.IsAny <int>(), It.IsAny <int>())).Returns(Result <bool> .True); mailValidatorMock.Setup(v => v.IsRecipientValid(It.IsAny <int>())).Returns(Result <bool> .True); await controller.PostMessage(model); entitytiesMock.Verify(v => v.Mails_Insert(It.Is((byte?reg) => reg == MailRegulationStatuses.PassAndReview), It.Is((int?p) => p == currentUserId), It.Is((long?p) => p == model.ReplyTo), It.Is((int?p) => p == model.MemberIdTo), It.Is((string p) => p == null), It.Is((string p) => p == model.Text)), Times.Once); }