public async Task UpdateHandler_EntityUpdatedEventData() { var logger = new Mock <ILogger <AuditHandler> >(); var sp = MockServiceProvider(logger); var am = new Mock <IAuditManager>(); sp.Setup(s => s.GetService(typeof(IAuditManager))).Returns(am.Object); var h = new AuditHandler(sp.Object); EventDataObject before = new EventDataObject { Id = "123", Value = "data" }, after = new EventDataObject { Id = "123", Value = "data2" }; var uId = "u-id"; var wc = new WorkContext { CurrentUserId = uId }; var ded = new DomainEvent { Data = new EntityUpdatedDomainEvent(before, after), PerformedByUserId = uId, WorkContext = wc }; await h.UpdateEventHandler(ded); am.Verify(a => a.InsertAuditRecord( It.Is <Type>(t => t == typeof(EventDataObject)), It.Is <string>(i => i == before.Id), It.Is <string>(art => art == AuditRecordTypes.UPDATE), It.Is <WorkContext>(w => w == wc), It.Is <object>(obj => VerifyPayload(obj, before, after))), Times.Once); }
public async Task UpdateHandler_AnonymousObject() { var logger = new Mock <ILogger <AuditHandler> >(); var sp = MockServiceProvider(logger); var am = new Mock <IAuditManager>(); sp.Setup(s => s.GetService(typeof(IAuditManager))).Returns(am.Object); var h = new AuditHandler(sp.Object); var o = new { Id = "123", Value = "data" }; var uId = "u-id"; var wc = new WorkContext { CurrentUserId = uId }; var ded = new DomainEvent { Data = o, PerformedByUserId = uId, WorkContext = wc }; await h.UpdateEventHandler(ded); am.Verify(a => a.InsertAuditRecord( It.Is <Type>(t => t == o.GetType()), It.Is <string>(i => i == null), It.Is <string>(art => art == AuditRecordTypes.UPDATE), It.Is <WorkContext>(w => w == wc), It.Is <object>(obj => obj == o)), Times.Once); }