public IActionResult CreateStudent([FromBody] Student newStudent)
        {
            if (newStudent == null)
            {
                return(NotFound("Incomplete student data"));
            }
            var request = new CreateStudentMessage(Guid.NewGuid(), newStudent);

            _bus.SendRequest <CreateStudentMessage, CreateStudentReplyMessage>("ClassroomApi_Consumer", request, null,
                                                                               (int)TimeSpan.FromMinutes(2).TotalMilliseconds);
            return(new AcceptedResult {
                Value = "Student Created"
            });
        }
        public void GivenCreateStudentMessage_WhenCallingCreateStudentHandler_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.CreateStudent(createdStudent));

            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 <CreateStudentReplyMessage>()));

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

            CreateStudentMessage      request = new CreateStudentMessage(Guid.NewGuid(), createdStudent);
            CreateStudentReplyMessage reply   = null;

            // Act
            handler.Execute(request);



            // Assert
            context.Verify(c => c.Reply(It.IsAny <CreateStudentReplyMessage>()), Times.Once);
        }
        public void GivenCreatingStudent_WhenPosting_ThenCorrespondingStudentIsCreated()
        {
            // Arrange

            var testStudent = new Student("OliCreationTest", "test");
            CreateStudentMessage      request = null;
            CreateStudentReplyMessage 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
                   <CreateStudentMessage, CreateStudentReplyMessage>
                       (It.IsAny <string>(), It.IsAny <CreateStudentMessage>(), null, It.IsAny <int>()))
            .Returns <string, CreateStudentMessage, Dictionary <string, string>, int>(
                (endpoint, message, headers, timeout) =>
            {
                request = message;
                reply   = new CreateStudentReplyMessage(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.CreateStudent(testStudent);
            var okObjectResult = result as AcceptedResult;

            // Assert

            Assert.NotNull(okObjectResult);
        }