public UpdateSampleEntities ( dynamic message ) : void | ||
message | dynamic | The dynamic message from the bus containing the details of the item to be updated |
Результат | void |
public void PutOperationUpdatesEntity() { var publisher = new Mock<IMessagePublisher>(); var logger = new Mock<ILogger>(); var repo = new FakeRepository(); var env = new Mock<IEnvironment>(); var logicClass = new DataOperations(logger.Object, publisher.Object, repo, env.Object); var message = TestMessages.GetTestUpdateSampleEntityMesssage(); var entitys = TestEntities.SetUpSampleEntityFromMessage(message); var responseList = new List<dynamic>(); publisher.Setup(p => p.Publish(It.IsAny<object>(), It.IsAny<string>())).Callback<dynamic, string>((msg, str) => responseList.Add(msg)); message.Needs[0].NewStringValue = "Updated Test"; message.Needs[0].NewIntValue = 456; repo.Entities = entitys; logicClass.UpdateSampleEntities(message); Assert.IsTrue(repo.Entities[0].NewStringValue == "Updated Test"); }
public void PutOperationLogsUpdateFailed() { var publisher = new Mock<IMessagePublisher>(); var logger = new Mock<ILogger>(); var repo = new Mock<IRepository<SampleEntity>>(); var env = new Mock<IEnvironment>(); var logicClass = new DataOperations(logger.Object, publisher.Object, repo.Object, env.Object); var message = TestMessages.GetTestUpdateSampleEntityMesssage(); var entitys = TestEntities.SetUpSampleEntityFromMessage(message); var logResponse = new List<string>(); var responseList = new List<dynamic>(); publisher.Setup(p => p.Publish(It.IsAny<object>(), It.IsAny<string>())).Callback<dynamic, string>((msg, str) => responseList.Add(msg)); logger.Setup(l => l.Error(It.IsAny<Exception>(), It.IsAny<string>(), It.IsAny<object[]>())) .Callback<Exception, string, object[]>((ex, msg, obj) => logResponse.Add(msg)); repo.Setup(r => r.Update(It.IsAny<List<SampleEntity>>())).Throws(new Exception("test exception")); message.Needs[0].NewStringValue = "Updated Test"; message.Needs[0].NewIntValue = 456; logicClass.UpdateSampleEntities(message); Assert.IsTrue(logResponse[0].Contains("Unable to update entity")); }