/// <inheritdoc /> public Task <T> Handle(GetRequest <T> request, CancellationToken cancellationToken, RequestHandlerDelegate <T> next) { if (request == default) { throw new ArgumentNullException(nameof(request)); } if (next == default) { throw new ArgumentNullException(nameof(next)); } if (!_options.UseScopedLogging) { return(Handle()); } using (request.Scope) { return(Handle()); } async Task <T> Handle() { var start = new GetNotification(request.KeyValues, request.Logger); await _mediator.Publish(start, cancellationToken).ConfigureAwait(false); var response = await next().ConfigureAwait(false); var finish = new GetNotification <T>(response, request.Logger); await _mediator.Publish(finish, cancellationToken).ConfigureAwait(false); return(response); } }
public async Task CreatePost() { //Arrange var link = $"/{_controller}/{nameof(Create)}"; var request = new HttpRequestMessage(HttpMethod.Post, link); request.Content = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("Id", "0"), new KeyValuePair <string, string>("Name", "Test"), new KeyValuePair <string, string>("Type", "T"), new KeyValuePair <string, string>("Description", "Test"), new KeyValuePair <string, string>("__RequestVerificationToken", EnsureAntiforgeryToken(link).Result) }); //Act var response = await GetClient.SendAsync(request).ConfigureAwait(false); //Assert Assert.Equal(HttpStatusCode.Found, response.StatusCode); Assert.False(GetNotification.HasNotification(LogLevelExtension.ReturnLevel)); //Arrange response.Dispose(); request.Dispose(); }
public async Task GetAll() { //Arrange | Act var result = await GetColumnRepository.GetAll().ConfigureAwait(false); //Assert Assert.NotNull(result); Assert.False(GetNotification.HasNotification(LogLevelExtension.ReturnLevel)); }
public async Task Sync() { //Arrange | Act var result = await GetSyscatSyncService.Sync().ConfigureAwait(false); //Assert Assert.True(result); Assert.False(GetNotification.HasNotification(LogLevelExtension.ReturnLevel)); }
public void PostgreSettingsNull() { //Arrange | Act var repository = new ColumnRepository(null, GetNotification); //Assert Assert.True(GetNotification.HasNotification(LogLevelExtension.ReturnLevel)); var notifications = GetNotification.GetNotification(LogLevelExtension.ReturnLevel); Assert.Equal(Resources.PostGreSettingMissing, notifications.First().Message); }
public async Task Error() { //Arrange var request = new HttpRequestMessage(HttpMethod.Get, $"/{_controller}/{nameof(Error)}"); //Act var response = await GetClient.SendAsync(request).ConfigureAwait(false); //Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.False(GetNotification.HasNotification(LogLevelExtension.ReturnLevel)); //Arrange response.Dispose(); request.Dispose(); }
public async Task IndexFilter() { //Arrange var filterName = "AAA"; var request = new HttpRequestMessage(HttpMethod.Get, $"/{_controller}/{nameof(Index)}?tableName={_tableName}&name={filterName}"); //Act var response = await GetClient.SendAsync(request).ConfigureAwait(false); //Assert Assert.Equal(HttpStatusCode.Found, response.StatusCode); Assert.False(GetNotification.HasNotification(LogLevelExtension.ReturnLevel)); //Arrange response.Dispose(); request.Dispose(); }
public void PostgreSettingsEmpty() { //Arrange var settings = new Mock <IOptions <PostgreSetting> >(); settings.Setup(c => c.Value).Returns(new PostgreSetting()); //Act var repository = new ColumnRepository(settings.Object, GetNotification); //Assert Assert.True(GetNotification.HasNotification(LogLevelExtension.ReturnLevel)); var notifications = GetNotification.GetNotification(LogLevelExtension.ReturnLevel); Assert.Equal(Resources.PostGreSettingMissing, notifications.First().Message); }
public async Task ColumnMoq() { //Arrange Syscat Column var insertSyscatColumn = new SyscatColumn() { ColName = "Test", ColNo = 1, Default = "'False'", Identity = 'N', Length = 1, Nulls = 'Y', TabName = "Insert", TypeName = "Ins" }; var updateSyscatColumn = new SyscatColumn() { ColName = "Test", ColNo = 1, Default = "'False'", Identity = 'N', Length = 1, Nulls = 'Y', TabName = "Update", TypeName = "Upd" }; var listSyscatColumn = new List <SyscatColumn>() { insertSyscatColumn, updateSyscatColumn }; //Arrange Syscat Repository var moqSyscatRepository = new Mock <ISyscatRepository>(); moqSyscatRepository .Setup(c => c.GetColumn()) .ReturnsAsync(listSyscatColumn); //Arrange Column Repository var updateColumnEntity = new ColumnEntity() { Default = "'False'", IsIdentity = 'N', IsNull = 'Y', Length = 1, Name = "Test", Number = 1, SyncId = "Update.Test", TableName = "Update", Type = "Upd" }; var listColumnEntity = new List <ColumnEntity>() { updateColumnEntity }; //Arrange Column Repository var moqColumnRepository = new Mock <IColumnRepository>(); moqColumnRepository .Setup(c => c.GetAll()) .ReturnsAsync(listColumnEntity); moqColumnRepository .Setup(c => c.Insert(It.IsAny <IEnumerable <ColumnEntity> >())) .ReturnsAsync(true); moqColumnRepository .Setup(c => c.Update(It.IsAny <IEnumerable <ColumnExternalEntity> >())) .ReturnsAsync(true); //Arrange var syncService = new SyscatSyncService(GetNotification, moqSyscatRepository.Object, moqColumnRepository.Object, GetTableRepository); //Act var result = await syncService.ColumnSync().ConfigureAwait(false); //Assert Assert.True(result); Assert.False(GetNotification.HasNotification(LogLevelExtension.ReturnLevel)); }
public async Task TableMoq() { //Arrange Syscat Table var insertSyscatTable = new SyscatTable() { ColCount = 1, TabName = "Insert", Type = 'I' }; var updateSyscatTable = new SyscatTable() { ColCount = 1, TabName = "Update", Type = 'U' }; var listSyscatTable = new List <SyscatTable>() { insertSyscatTable, updateSyscatTable }; //Arrange Syscat Repository var moqSyscatRepository = new Mock <ISyscatRepository>(); moqSyscatRepository .Setup(c => c.GetTable()) .ReturnsAsync(listSyscatTable); //Arrange Syscat Table var updateTableEntity = new TableEntity() { SyncId = "Update", TableName = "Update", Type = 'I' }; var listTableEntity = new List <TableEntity>() { updateTableEntity }; //Arrange Table Repository var moqTableRepository = new Mock <ITableRepository>(); moqTableRepository .Setup(c => c.GetAll()) .ReturnsAsync(listTableEntity); moqTableRepository .Setup(c => c.Insert(It.IsAny <IEnumerable <TableEntity> >())) .ReturnsAsync(true); moqTableRepository .Setup(c => c.Update(It.IsAny <IEnumerable <TableExternalEntity> >())) .ReturnsAsync(true); //Arrange var syncService = new SyscatSyncService(GetNotification, moqSyscatRepository.Object, GetColumnRepository, moqTableRepository.Object); //Act var result = await syncService.TableSync().ConfigureAwait(false); //Assert Assert.True(result); Assert.False(GetNotification.HasNotification(LogLevelExtension.ReturnLevel)); }