public void GivenDeleteStudentMessage_WhenCallingDeleteStudentHandler_ThenCorrespondingReplyIsSend()
        {
            // Arrange
            var repositry = new Mock <ISqlRepository <IStudent> >(MockBehavior.Strict);

            repositry.Setup(s => s.List(null, null, 0, 0)).Returns(new List <Student>
            {
                new Student("test1", "1")
                {
                    Id = 1
                },
                new Student("test2", "2")
                {
                    Id = 2
                }
            });
            var createdStudent = new Student("oli", "");

            repositry.Setup(h => h.DeleteStudent(createdStudent.Id));

            var claimsHelper = new Mock <IClaimsHelper>(MockBehavior.Strict);

            claimsHelper.Setup(h => h.GetClaims()).Returns(new Claims()
            {
                UserClaims = new UserClaim()
                {
                    Username = "******"
                }
            });

            var context = new Mock <IConsumeContext>(MockBehavior.Strict);

            context.Setup(c => c.Reply(It.IsAny <DeleteStudentReplyMessage>()));

            var handler = new SqlDeleteStudentHandler(repositry.Object, claimsHelper.Object)
            {
                Context = context.Object
            };

            DeleteStudentMessage      request = new DeleteStudentMessage(Guid.NewGuid(), (int)createdStudent.Id);
            DeleteStudentReplyMessage reply   = null;

            // Act
            handler.Execute(request);

            // Assert
            context.Verify(c => c.Reply(It.IsAny <DeleteStudentReplyMessage>()), Times.Once);
        }
Пример #2
0
        public void Execute(DeleteStudentMessage message)
        {
            var username = _claimsHelper.GetClaims().UserClaims.Username;

            if (username == "ofebres-cordero")
            {
                _repository.DeleteStudent(message.Id);
                var replyMessage = new DeleteStudentReplyMessage(message.CorrelationId);
                Context.Reply(replyMessage);
            }
            else
            {
                Console.WriteLine("Request Failed - Invalid Token");
                Context.Reply(new DeleteStudentReplyMessage(message.CorrelationId));
            }
        }
Пример #3
0
        public void Execute(DeleteStudentMessage message)
        {
            var test = Thread.CurrentPrincipal.Identity.Name;

            if (test == "ofebres-cordero")
            {
                _studentRepository.Delete(message.Id);
                var replyMessage = new DeleteStudentReplyMessage(message.CorrelationId);
                Context.Reply(replyMessage);
            }
            else
            {
                Console.WriteLine("Request Failed - Invalid Token");
            }

            Context.Reply(new DeleteStudentReplyMessage(message.CorrelationId));
        }
        public void GivenDeletingStudent_WhenDeleting_ThenCorrespondingStudentIsDeleted()
        {
            // Arrange

            var testStudent = new Student("OliCreationTest", "test")
            {
                Id = 1
            };
            DeleteStudentMessage      request = null;
            DeleteStudentReplyMessage reply   = null;

            var queryCountWrapper = new Mock <IQueryCountWrapper>();

            queryCountWrapper.SetupGet(qcw => qcw.QueryCount).Returns(0);

            var bus = new Mock <IBus>(MockBehavior.Strict);

            bus
            .Setup(b => b.SendRequest
                   <DeleteStudentMessage, DeleteStudentReplyMessage>
                       (It.IsAny <string>(), It.IsAny <DeleteStudentMessage>(), null, It.IsAny <int>()))
            .Returns <string, DeleteStudentMessage, Dictionary <string, string>, int>(
                (endpoint, message, headers, timeout) =>
            {
                request = message;
                reply   = new DeleteStudentReplyMessage(message.CorrelationId);
                return(reply);
            });

            var claimsHelper = new Mock <IClaimsHelper>(MockBehavior.Strict);
            var controller   = new StudentController(bus.Object, claimsHelper.Object, queryCountWrapper.Object);

            // Act
            var result         = controller.Delete((int)testStudent.Id);
            var okObjectResult = result as ObjectResult;

            // Assert

            Assert.Equal(reply.CorrelationId, okObjectResult.Value);
        }