public void Execute(UpdateStudentMessage message) { var username = _claimsHelper.GetClaims().UserClaims.Username; if (username == "ofebres-cordero") { var student = _repository.Read(message.StudentId); var propertiesOnStudent = typeof(Student).GetProperties(); foreach (var propertyInfo in propertiesOnStudent) { var existingValue = propertyInfo.GetValue(student); var newValue = propertyInfo.GetValue(message.UpdatedStudent); if (newValue != existingValue && newValue != null) { propertyInfo.SetValue(student, newValue); } } var replyMessage = new UpdateStudentReplyMessage(message.CorrelationId); student.Id = message.StudentId; _repository.UpdateStudent(student); Context.Reply(replyMessage); } else { Console.WriteLine("Request Failed - Invalid Token"); Context.Reply(new GetAllStudentsReplyMessage(message.CorrelationId)); } }
public void Execute(UpdateStudentMessage message) { var test = Thread.CurrentPrincipal.Identity.Name; if (test == "ofebres-cordero") { var replyMessage = new UpdateStudentReplyMessage(message.CorrelationId); _studentRepository.Update(message.StudentId, message.UpdatedFields); // updates the student given a particular ID and fields to be updated Context.Reply(replyMessage); } else { Console.WriteLine("Request Failed - Invalid Token"); } Context.Reply(new GetAllStudentsReplyMessage(message.CorrelationId)); }
public void GivenUpdatingStudent_WhenPutting_ThenCorrespondingStudentIsUpdated() { // Arrange var testStudent = new Student("OliCreationTest", "test") { Id = 1 }; var updatedStudent = new Student("override", "override"); UpdateStudentMessage request = null; UpdateStudentReplyMessage 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 <UpdateStudentMessage, UpdateStudentReplyMessage> (It.IsAny <string>(), It.IsAny <UpdateStudentMessage>(), null, It.IsAny <int>())) .Returns <string, UpdateStudentMessage, Dictionary <string, string>, int>( (endpoint, message, headers, timeout) => { request = message; reply = new UpdateStudentReplyMessage(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.Update(1, updatedStudent); var okObjectResult = result as AcceptedResult; // Assert Assert.NotNull(okObjectResult); }
[Fact] // TODO public void GivenUpdateStudentMessage_WhenCallingUpgradeStudentHandler_ThenCorrespondingReplyIsSend() { // Arrange var repositry = new Mock <ISqlRepository <IStudent> >(MockBehavior.Strict); var updatedStudent = new Student("test1Updated", "1Updated"); repositry.Setup(s => s.UpdateStudent(updatedStudent)); repositry.Setup(s => s.Read(1)).Returns(updatedStudent); 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 <UpdateStudentReplyMessage>())); var handler = new SqlUpdateStudentHandler(repositry.Object, claimsHelper.Object) { Context = context.Object }; UpdateStudentMessage request = new UpdateStudentMessage(Guid.NewGuid(), 1, updatedStudent); UpdateStudentReplyMessage reply = null; // Act handler.Execute(request); // Assert context.Verify(c => c.Reply(It.IsAny <UpdateStudentReplyMessage>()), Times.Once); }