Browse Source

Fix tests that don't work

pull/90/head
berkansasmaz 5 years ago
parent
commit
68ef25bb46
No known key found for this signature in database GPG Key ID: 3AD81E2CA002230D
  1. 5
      src/EventHub.DbMigrator/Data/EventHubSampleDataSeedContributor.cs
  2. 16
      src/EventHub.DbMigrator/EventHubDbMigratorModule.cs
  3. 2
      src/EventHub.Domain/Events/Registrations/EventRegistrationManager.cs
  4. 6
      src/EventHub.Domain/Organizations/Plans/PlanFeatureManager.cs
  5. 1
      src/EventHub.HttpApi.Host/EventHubHttpApiHostModule.cs
  6. 14
      test/EventHub.Domain.Tests/Events/Registrations/EventRegistrationManager_UnitTests.cs
  7. 14
      test/EventHub.TestBase/EventHubTestBaseModule.cs

5
src/EventHub.DbMigrator/Data/EventHubSampleDataSeedContributor.cs

@ -73,8 +73,7 @@ namespace EventHub.DbMigrator.Data
new IdentityUser(_userSandraId = _guidGenerator.Create(), "SandraWolf", "sandra_wolf@gmail.com"),
new IdentityUser(_userSergeyId = _guidGenerator.Create(), "SergeyPolgul", "sergey_polgul@gmail.com"),
new IdentityUser(_userWellyId = _guidGenerator.Create(), "WellyTambunan", "welly_tambunan@gmail.com"),
new IdentityUser(_userAlessandroId = _guidGenerator.Create(), "AlessandroMuci",
"alessandro_muci@gmail.com"),
new IdentityUser(_userAlessandroId = _guidGenerator.Create(), "AlessandroMuci", "alessandro_muci@gmail.com"),
new IdentityUser(_userMarkId = _guidGenerator.Create(), "MarkGodfrey", "mark_godfrey@gmail.com"),
new IdentityUser(_userTonyId = _guidGenerator.Create(), "TonyBurton", "tony_burton@gmail.com"),
new IdentityUser(_guidGenerator.Create(), "DavidGraus", "david_graus@gmail.com"),
@ -385,4 +384,4 @@ namespace EventHub.DbMigrator.Data
}
}
}
#endif
#endif

16
src/EventHub.DbMigrator/EventHubDbMigratorModule.cs

@ -1,5 +1,7 @@
using EventHub.Admin;
using EventHub.EntityFrameworkCore;
using EventHub.Organizations;
using EventHub.Organizations.Plans;
using Volo.Abp.Autofac;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.Modularity;
@ -17,6 +19,20 @@ namespace EventHub.DbMigrator
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpBackgroundJobOptions>(options => options.IsJobExecutionEnabled = false);
#if DEBUG
Configure<PlanInfoOptions>(options =>
{
options.Infos.Add(new PlanInfoDefinition
{
PlanType = OrganizationPlanType.Free,
Description = "This is a default plan.",
IsActive = true,
Price = 0,
IsExtendable = false
});
});
}
#endif
}
}

2
src/EventHub.Domain/Events/Registrations/EventRegistrationManager.cs

@ -9,7 +9,7 @@ using Volo.Abp.Timing;
namespace EventHub.Events.Registrations
{
public class EventRegistrationManager : IDomainService
public class EventRegistrationManager : DomainService
{
private readonly IEventRegistrationRepository _eventRegistrationRepository;
private readonly IGuidGenerator _guidGenerator;

6
src/EventHub.Domain/Organizations/Plans/PlanFeatureManager.cs

@ -26,7 +26,7 @@ public class PlanFeatureManager : ITransientDependency
_eventRegistrationRepository = eventRegistrationRepository;
}
public async Task<bool> CanCreateNewEvent(Guid organizationId)
public virtual async Task<bool> CanCreateNewEvent(Guid organizationId)
{
var currentPlanOfOrganization = await GetCurrentPlanByOrganizationIdAsync(organizationId);
@ -35,7 +35,7 @@ public class PlanFeatureManager : ITransientDependency
return currentPlanOfOrganization.Feature.MaxAllowedEventsCount >= totalEventCountByOrganization;
}
public async Task<bool> CanAddNewTrack(Event @event)
public virtual async Task<bool> CanAddNewTrack(Event @event)
{
var currentPlanOfOrganization = await GetCurrentPlanByOrganizationIdAsync(@event.OrganizationId);
@ -44,7 +44,7 @@ public class PlanFeatureManager : ITransientDependency
return currentPlanOfOrganization.Feature.MaxAllowedTracksCountInOneEvent >= tracksCount;
}
public async Task<bool> CanRegisterToEvent(Event @event)
public virtual async Task<bool> CanRegisterToEvent(Event @event)
{
var currentPlanOfOrganization = await GetCurrentPlanByOrganizationIdAsync(@event.OrganizationId);

1
src/EventHub.HttpApi.Host/EventHubHttpApiHostModule.cs

@ -203,7 +203,6 @@ namespace EventHub
.Validate(PlanInfoDefinition.IsValid, "PlanInfoDefinition is not valid!");
var planInfos = context.Services.GetRequiredServiceLazy<IOptions<List<PlanInfoDefinition>>>();
Configure<PlanInfoOptions>(options =>
{
options.AddPlanInfos(planInfos.Value.Value);

14
test/EventHub.Domain.Tests/Events/Registrations/EventRegistrationManager_UnitTests.cs

@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using EventHub.Organizations.Plans;
using NSubstitute;
using Shouldly;
using Volo.Abp.Guids;
@ -37,7 +38,7 @@ namespace EventHub.Events.Registrations
[Fact]
public async Task RegisterAsync()
{
var evnt = new Event(
var @event = new Event(
Guid.NewGuid(),
Guid.NewGuid(),
"1a8j3v0d",
@ -50,23 +51,26 @@ namespace EventHub.Events.Registrations
var user = new IdentityUser(Guid.NewGuid(), "john", "john@abp.io");
var repository = Substitute.For<IEventRegistrationRepository>();
repository.ExistsAsync(evnt.Id, user.Id).Returns(Task.FromResult(false));
repository.ExistsAsync(@event.Id, user.Id).Returns(Task.FromResult(false));
var guidGenerator = SimpleGuidGenerator.Instance;
var clock = Substitute.For<IClock>();
clock.Now.Returns(DateTime.Now);
var planFeatureManager = Substitute.For<PlanFeatureManager>(null, null, null, null);
planFeatureManager.CanRegisterToEvent(@event).Returns(Task.FromResult(true));
var registrationManager = new EventRegistrationManager(
repository, guidGenerator, clock, null
repository, guidGenerator, clock, planFeatureManager
);
await registrationManager.RegisterAsync(evnt, user);
await registrationManager.RegisterAsync(@event, user);
await repository
.Received()
.InsertAsync(
Arg.Is<EventRegistration>(er => er.EventId == evnt.Id && er.UserId == user.Id)
Arg.Is<EventRegistration>(er => er.EventId == @event.Id && er.UserId == user.Id)
);
}
}

14
test/EventHub.TestBase/EventHubTestBaseModule.cs

@ -1,4 +1,6 @@
using System;
using EventHub.Organizations;
using EventHub.Organizations.Plans;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.Authorization;
@ -40,6 +42,18 @@ namespace EventHub
});
context.Services.AddAlwaysAllowAuthorization();
Configure<PlanInfoOptions>(options =>
{
options.Infos.Add(new PlanInfoDefinition
{
PlanType = OrganizationPlanType.Free,
Description = "This is a default plan.",
IsActive = true,
Price = 0,
IsExtendable = false
});
});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)

Loading…
Cancel
Save