mirror of https://github.com/abpframework/abp.git
98 changed files with 720 additions and 5071 deletions
@ -0,0 +1,32 @@ |
|||
using System; |
|||
using System.Data; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.Uow; |
|||
using Volo.Abp.Users; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling; |
|||
|
|||
public class ExceptionHandingUnitOfWork : UnitOfWork |
|||
{ |
|||
public ExceptionHandingUnitOfWork( |
|||
IServiceProvider serviceProvider, |
|||
IUnitOfWorkEventPublisher unitOfWorkEventPublisher, |
|||
IOptions<AbpUnitOfWorkDefaultOptions> options) |
|||
: base(serviceProvider, unitOfWorkEventPublisher, options) |
|||
{ |
|||
|
|||
} |
|||
public async override Task SaveChangesAsync(CancellationToken cancellationToken = default) |
|||
{ |
|||
if (ServiceProvider.GetRequiredService<ICurrentUser>().Id == Guid.Empty) |
|||
{ |
|||
throw new AbpDbConcurrencyException(); |
|||
} |
|||
|
|||
await base.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
@ -1,5 +1,5 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"Default": "Server=localhost;Database=BackgroundJobsDemoApp;Trusted_Connection=True" |
|||
"Default": "Server=localhost;Database=BackgroundJobsDemoApp;Trusted_Connection=True;TrustServerCertificate=True" |
|||
} |
|||
} |
|||
@ -1,5 +1,5 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"Default": "Server=localhost;Database=BackgroundJobsDemoApp;Trusted_Connection=True" |
|||
"Default": "Server=localhost;Database=BackgroundJobsDemoApp;Trusted_Connection=True;TrustServerCertificate=True" |
|||
} |
|||
} |
|||
@ -1,17 +1,10 @@ |
|||
@inject NavigationManager Navigation |
|||
@inject IJSRuntime JSRuntime |
|||
|
|||
@code { |
|||
@code { |
|||
|
|||
protected override void OnInitialized() |
|||
{ |
|||
bool isWebAssembly = JSRuntime is IJSInProcessRuntime; |
|||
if (isWebAssembly) |
|||
{ |
|||
Navigation.NavigateTo($"authentication/login?returnUrl={Uri.EscapeDataString(Navigation.Uri)}"); |
|||
} |
|||
else |
|||
{ |
|||
Navigation.NavigateTo($"account/login?returnUrl={Uri.EscapeDataString(Navigation.Uri)}", true); |
|||
} |
|||
} |
|||
} |
|||
Navigation.NavigateTo($"account/login?returnUrl={Uri.EscapeDataString(Navigation.Uri)}", true); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
@inject NavigationManager Navigation |
|||
|
|||
@using Volo.Abp.DependencyInjection |
|||
@using Volo.Abp.AspNetCore.Components.Web.BasicTheme.Themes.Basic |
|||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication |
|||
@inherits RedirectToLogin |
|||
@attribute [ExposeServices(typeof(RedirectToLogin))] |
|||
@attribute [Dependency(ReplaceServices = true)] |
|||
|
|||
@code { |
|||
|
|||
protected override void OnInitialized() |
|||
{ |
|||
Navigation.NavigateToLogin("authentication/login"); |
|||
} |
|||
|
|||
} |
|||
@ -1,5 +1,5 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"Default": "Server=localhost;Database=BlobStoring_Host;Trusted_Connection=True" |
|||
"Default": "Server=localhost;Database=BlobStoring_Host;Trusted_Connection=True;TrustServerCertificate=True" |
|||
} |
|||
} |
|||
|
|||
@ -1,6 +1,6 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"SqlServer": "Server=localhost;Database=BloggingTestApp;Trusted_Connection=True", |
|||
"SqlServer": "Server=localhost;Database=BloggingTestApp;Trusted_Connection=True;TrustServerCertificate=True", |
|||
"MongoDb": "mongodb://localhost:27017/BloggingTestApp" |
|||
} |
|||
} |
|||
@ -1,5 +1,5 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"Default": "Server=(localdb)\\MSSQLLocalDB;Database=CmsKit_Unified;Trusted_Connection=True" |
|||
"Default": "Server=(localdb)\\MSSQLLocalDB;Database=CmsKit_Unified;Trusted_Connection=True;TrustServerCertificate=True" |
|||
} |
|||
} |
|||
|
|||
@ -1,3 +1,3 @@ |
|||
{ |
|||
"ConnectionString": "Server=localhost;Database=VoloDocs;Trusted_Connection=True" |
|||
"ConnectionString": "Server=localhost;Database=VoloDocs;Trusted_Connection=True;TrustServerCertificate=True" |
|||
} |
|||
@ -1,5 +1,5 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"Default": "Server=(LocalDb)\\MSSQLLocalDB;Database=SettingManagementDemoApp;Trusted_Connection=True" |
|||
"Default": "Server=(LocalDb)\\MSSQLLocalDB;Database=SettingManagementDemoApp;Trusted_Connection=True;TrustServerCertificate=True" |
|||
} |
|||
} |
|||
|
|||
@ -1,2 +1,3 @@ |
|||
export * from './config-options.token'; |
|||
export * from './re-login-confirmation.token'; |
|||
export * from './extensions.token'; |
|||
|
|||
@ -0,0 +1,5 @@ |
|||
import { InjectionToken } from '@angular/core'; |
|||
|
|||
export const RE_LOGIN_CONFIRMATION_TOKEN = new InjectionToken<boolean>( |
|||
'RE_LOGIN_CONFIRMATION_TOKEN', |
|||
); |
|||
@ -0,0 +1,62 @@ |
|||
import { CoreTestingModule } from '@abp/ng.core/testing'; |
|||
import { ThemeBasicTestingModule } from '@abp/ng.theme.basic/testing'; |
|||
import { ThemeSharedTestingModule } from '@abp/ng.theme.shared/testing'; |
|||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; |
|||
import { NgxValidateCoreModule } from '@ngx-validate/core'; |
|||
import { HomeComponent } from './home.component'; |
|||
import { OAuthService } from 'angular-oauth2-oidc'; |
|||
import { AuthService } from '@abp/ng.core'; |
|||
|
|||
describe('HomeComponent', () => { |
|||
let fixture: ComponentFixture<HomeComponent>; |
|||
const mockOAuthService = jasmine.createSpyObj('OAuthService', ['hasValidAccessToken']); |
|||
const mockAuthService = jasmine.createSpyObj('AuthService', ['navigateToLogin']); |
|||
beforeEach(waitForAsync(() => { |
|||
TestBed.configureTestingModule({ |
|||
declarations: [HomeComponent], |
|||
imports: [ |
|||
CoreTestingModule.withConfig(), |
|||
ThemeSharedTestingModule.withConfig(), |
|||
ThemeBasicTestingModule.withConfig(), |
|||
NgxValidateCoreModule, |
|||
], |
|||
providers: [ |
|||
/* mock providers here */ |
|||
{ |
|||
provide: OAuthService, |
|||
useValue: mockOAuthService, |
|||
}, |
|||
{ |
|||
provide: AuthService, |
|||
useValue: mockAuthService, |
|||
}, |
|||
], |
|||
}).compileComponents(); |
|||
})); |
|||
|
|||
beforeEach(() => { |
|||
fixture = TestBed.createComponent(HomeComponent); |
|||
fixture.detectChanges(); |
|||
}); |
|||
|
|||
it('should be initiated', () => { |
|||
expect(fixture.componentInstance).toBeTruthy(); |
|||
}); |
|||
|
|||
describe('when login state is true', () => { |
|||
beforeAll(() => { |
|||
mockOAuthService.hasValidAccessToken.and.returnValue(true); |
|||
}); |
|||
|
|||
it('hasLoggedIn should be true', () => { |
|||
expect(fixture.componentInstance.hasLoggedIn).toBeTrue(); |
|||
expect(mockOAuthService.hasValidAccessToken).toHaveBeenCalled(); |
|||
}); |
|||
|
|||
it('button should not be exists', () => { |
|||
const element = fixture.nativeElement; |
|||
const cardTitle = element.querySelector('.card-title'); |
|||
expect(cardTitle).toBeTruthy(); |
|||
}); |
|||
}); |
|||
}); |
|||
@ -0,0 +1,100 @@ |
|||
import { CoreTestingModule } from "@abp/ng.core/testing"; |
|||
import { ThemeBasicTestingModule } from "@abp/ng.theme.basic/testing"; |
|||
import { ThemeSharedTestingModule } from "@abp/ng.theme.shared/testing"; |
|||
import { ComponentFixture, TestBed, waitForAsync } from "@angular/core/testing"; |
|||
import { NgxValidateCoreModule } from "@ngx-validate/core"; |
|||
import { HomeComponent } from "./home.component"; |
|||
import { OAuthService } from 'angular-oauth2-oidc'; |
|||
import { AuthService } from '@abp/ng.core'; |
|||
|
|||
|
|||
describe("HomeComponent", () => { |
|||
let fixture: ComponentFixture<HomeComponent>; |
|||
const mockOAuthService = jasmine.createSpyObj('OAuthService', ['hasValidAccessToken']) |
|||
const mockAuthService = jasmine.createSpyObj('AuthService', ['navigateToLogin']) |
|||
beforeEach( |
|||
waitForAsync(() => { |
|||
TestBed.configureTestingModule({ |
|||
declarations: [HomeComponent], |
|||
imports: [ |
|||
CoreTestingModule.withConfig(), |
|||
ThemeSharedTestingModule.withConfig(), |
|||
ThemeBasicTestingModule.withConfig(), |
|||
NgxValidateCoreModule, |
|||
], |
|||
providers: [ |
|||
/* mock providers here */ |
|||
{ |
|||
provide: OAuthService, |
|||
useValue: mockOAuthService |
|||
}, |
|||
{ |
|||
provide: AuthService, |
|||
useValue: mockAuthService |
|||
} |
|||
], |
|||
}).compileComponents(); |
|||
}) |
|||
); |
|||
|
|||
beforeEach(() => { |
|||
fixture = TestBed.createComponent(HomeComponent); |
|||
fixture.detectChanges(); |
|||
}); |
|||
|
|||
it("should be initiated", () => { |
|||
expect(fixture.componentInstance).toBeTruthy(); |
|||
}); |
|||
|
|||
|
|||
|
|||
describe('when login state is true', () => { |
|||
beforeAll(() => { |
|||
mockOAuthService.hasValidAccessToken.and.returnValue(true) |
|||
}); |
|||
|
|||
it("hasLoggedIn should be true", () => { |
|||
|
|||
expect(fixture.componentInstance.hasLoggedIn).toBeTrue(); |
|||
expect(mockOAuthService.hasValidAccessToken).toHaveBeenCalled() |
|||
}) |
|||
|
|||
it("button should not be exists", () => { |
|||
const element = fixture.nativeElement |
|||
const button = element.querySelector('[role="button"]') |
|||
expect(button).toBeNull() |
|||
}) |
|||
|
|||
}) |
|||
|
|||
describe('when login state is false', () => { |
|||
beforeAll(() => { |
|||
mockOAuthService.hasValidAccessToken.and.returnValue(false) |
|||
}); |
|||
|
|||
it("hasLoggedIn should be false", () => { |
|||
|
|||
expect(fixture.componentInstance.hasLoggedIn).toBeFalse(); |
|||
expect(mockOAuthService.hasValidAccessToken).toHaveBeenCalled() |
|||
}) |
|||
|
|||
it("button should be exists", () => { |
|||
const element = fixture.nativeElement |
|||
const button = element.querySelector('[role="button"]') |
|||
expect(button).toBeDefined() |
|||
}) |
|||
describe('when button clicked', () => { |
|||
|
|||
beforeEach(() => { |
|||
const element = fixture.nativeElement |
|||
const button = element.querySelector('[role="button"]') |
|||
button.click() |
|||
}); |
|||
|
|||
it("navigateToLogin have been called", () => { |
|||
expect(mockAuthService.navigateToLogin).toHaveBeenCalled() |
|||
}) |
|||
}) |
|||
}) |
|||
|
|||
}); |
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,5 +1,5 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"Default": "Server=(LocalDb)\\MSSQLLocalDB;Database=MyProjectName_Unified;Trusted_Connection=True" |
|||
"Default": "Server=(LocalDb)\\MSSQLLocalDB;Database=MyProjectName_Unified;Trusted_Connection=True;TrustServerCertificate=True" |
|||
} |
|||
} |
|||
Loading…
Reference in new issue